valentina/src/libs/vpropertyexplorer/plugins/vboolproperty.cpp

101 lines
2.7 KiB
C++
Raw Normal View History

/************************************************************************
**
** @file vboolproperty.cpp
** @author hedgeware <internal(at)hedgeware.net>
** @date
**
** @brief
** @copyright
** All rights reserved. This program and the accompanying materials
** are made available under the terms of the GNU Lesser General Public License
** (LGPL) version 2.1 which accompanies this distribution, and is available at
** http://www.gnu.org/licenses/lgpl-2.1.html
**
** This library is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Lesser General Public License for more details.
**
*************************************************************************/
#include "vboolproperty.h"
#include <QCheckBox>
#include <QApplication>
#include <QStyle>
#include <QSizePolicy>
#include <QObject>
#include <QSpinBox>
#include "vproperty_p.h"
using namespace VPE;
QVariant VBoolProperty::TrueText;
QVariant VBoolProperty::FalseText;
VBoolProperty::VBoolProperty(const QString& name) :
VProperty(name, QVariant::Bool)
{
d_ptr->VariantValue.setValue(false);
d_ptr->VariantValue.convert(QVariant::Bool);
// I'm not sure, how Qt handles the translations...
2014-09-10 19:57:08 +02:00
if (TrueText.isNull())
{
TrueText = QObject::tr("True");
}
if (FalseText.isNull())
2014-09-10 19:57:08 +02:00
{
FalseText = QObject::tr("False");
}
}
//! Get the data how it should be displayed
QVariant VBoolProperty::data (int column, int role) const
{
2014-09-10 19:57:08 +02:00
if (column == DPC_Data && (Qt::DisplayRole == role || Qt::EditRole == role))
{
return d_ptr->VariantValue.toBool() ? TrueText : FalseText;
2014-09-10 19:57:08 +02:00
}
if (column == DPC_Data && Qt::CheckStateRole == role)
{
return d_ptr->VariantValue.toBool() ? Qt::Checked : Qt::Unchecked;
2014-09-10 19:57:08 +02:00
}
else
return VProperty::data(column, role);
}
bool VBoolProperty::setData(const QVariant &data, int role)
{
2014-09-10 19:57:08 +02:00
if (Qt::CheckStateRole == role)
{
2014-09-10 19:57:08 +02:00
d_ptr->VariantValue = (Qt::Checked == static_cast<Qt::CheckState>(data.toInt()));
return true;
}
return false;
}
//! Returns item flags
Qt::ItemFlags VBoolProperty::flags(int column) const
{
2014-09-10 19:57:08 +02:00
if (column == DPC_Data)
{
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable;
2014-09-10 19:57:08 +02:00
}
else
return VProperty::flags(column);
}
QString VBoolProperty::type() const
{
return "bool";
}
VProperty *VBoolProperty::clone(bool include_children, VProperty *container) const
{
return VProperty::clone(include_children, container ? container : new VBoolProperty(getName()));
}