Seamly2D
Code documentation
vboolproperty.cpp
Go to the documentation of this file.
1 /************************************************************************
2  **
3  ** @file vboolproperty.cpp
4  ** @author hedgeware <internal(at)hedgeware.net>
5  ** @date
6  **
7  ** @brief
8  ** @copyright
9  ** All rights reserved. This program and the accompanying materials
10  ** are made available under the terms of the GNU Lesser General Public License
11  ** (LGPL) version 2.1 which accompanies this distribution, and is available at
12  ** http://www.gnu.org/licenses/lgpl-2.1.html
13  **
14  ** This library is distributed in the hope that it will be useful,
15  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  ** Lesser General Public License for more details.
18  **
19  *************************************************************************/
20 
21 #include "vboolproperty.h"
22 
23 #include <QFlags>
24 #include <QObject>
25 
26 #include "../vproperty_p.h"
27 
28 
31 
32 VPE::VBoolProperty::VBoolProperty(const QString& name) :
33  VProperty(name, QVariant::Bool)
34 {
35  d_ptr->VariantValue.setValue(false);
36  d_ptr->VariantValue.convert(QVariant::Bool);
37 
38  // I'm not sure, how Qt handles the translations...
39  if (TrueText.isNull())
40  {
41  TrueText = tr("True");
42  }
43  if (FalseText.isNull())
44  {
45  FalseText = tr("False");
46  }
47 }
48 
49 
50 //! Get the data how it should be displayed
51 QVariant VPE::VBoolProperty::data (int column, int role) const
52 {
53  if (column == DPC_Data && (Qt::DisplayRole == role || Qt::EditRole == role))
54  {
55  return d_ptr->VariantValue.toBool() ? TrueText : FalseText;
56  }
57  if (column == DPC_Data && Qt::CheckStateRole == role)
58  {
59  return d_ptr->VariantValue.toBool() ? Qt::Checked : Qt::Unchecked;
60  }
61  else
62  return VProperty::data(column, role);
63 }
64 
65 bool VPE::VBoolProperty::setData(const QVariant &data, int role)
66 {
67  if (Qt::CheckStateRole == role)
68  {
69  d_ptr->VariantValue = (Qt::Checked == static_cast<Qt::CheckState>(data.toInt()));
70  return true;
71  }
72 
73  return false;
74 }
75 
76 //! Returns item flags
77 Qt::ItemFlags VPE::VBoolProperty::flags(int column) const
78 {
79  if (column == DPC_Data)
80  {
81  return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable;
82  }
83  else
84  return VProperty::flags(column);
85 }
86 
87 QString VPE::VBoolProperty::type() const
88 {
89  return "bool";
90 }
91 
92 VPE::VProperty *VPE::VBoolProperty::clone(bool include_children, VProperty *container) const
93 {
94  return VProperty::clone(include_children, container ? container : new VBoolProperty(getName()));
95 }
The VBoolProperty can take two states: True or False.
Definition: vboolproperty.h:40
virtual bool setData(const QVariant &data, int role=Qt::EditRole) Q_DECL_OVERRIDE
This is used by the model to set the data.
virtual VProperty * clone(bool include_children=true, VProperty *container=NULL) const Q_DECL_OVERRIDE
Clones this property.
virtual Qt::ItemFlags flags(int column=DPC_Name) const Q_DECL_OVERRIDE
Returns item flags.
virtual QString type() const Q_DECL_OVERRIDE
Returns a string containing the type of the property.
static QVariant FalseText
The (translatable) text displayed when the property is set to false (default: "False")
Definition: vboolproperty.h:76
VBoolProperty(const QString &name)
Default constructor.
virtual QVariant data(int column=DPC_Name, int role=Qt::DisplayRole) const Q_DECL_OVERRIDE
Get the data how it should be displayed.
static QVariant TrueText
The (translatable) text displayed when the property is set to true (default: "True")
Definition: vboolproperty.h:73
QVariant VariantValue
The property's value. This does not have to be used by subclasses, but it makes sense in cases where ...
Definition: vproperty_p.h:40
virtual Q_REQUIRED_RESULT VProperty * clone(bool include_children=true, VProperty *container=nullptr) const
Clones this property.
Definition: vproperty.cpp:372
virtual Qt::ItemFlags flags(int column=DPC_Name) const
Returns item flags.
Definition: vproperty.cpp:156
VPropertyPrivate * d_ptr
The protected structure holding the member variables (to assure binary compatibility)
Definition: vproperty.h:214
virtual QVariant data(int column=DPC_Name, int role=Qt::DisplayRole) const
Get the data how it should be displayed.
Definition: vproperty.cpp:68