Seamly2D
Code documentation
vpointfproperty.cpp
Go to the documentation of this file.
1 /************************************************************************
2  **
3  ** @file vpointfproperty.cpp
4  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
5  ** @date 27 8, 2014
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 "vpointfproperty.h"
22 
23 #include <QFlags>
24 #include <QList>
25 #include <QPointF>
26 
27 #include "../vproperty_p.h"
28 #include "vnumberproperty.h"
29 
31  : VProperty(name, QVariant::PointF)
32 {
33  d_ptr->VariantValue.setValue(0);
34  d_ptr->VariantValue.convert(QVariant::PointF);
35 
36  DoubleSpinboxProperty *tempX = new DoubleSpinboxProperty("X coordinate:");
37  addChild(tempX);
38  tempX->setUpdateBehaviour(true, false);
39 
40  DoubleSpinboxProperty *tempY = new DoubleSpinboxProperty("Y coordinate:");
41  addChild(tempY);
42  tempY->setUpdateBehaviour(true, false);
43 
44  setValue(QPointF());
45 }
46 
47 QVariant VPE::VPointFProperty::data(int column, int role) const
48 {
49  if (column == DPC_Data && Qt::DisplayRole == role)
50  {
51  return getPointF();
52  }
53  else
54  return VProperty::data(column, role);
55 }
56 
57 Qt::ItemFlags VPE::VPointFProperty::flags(int column) const
58 {
59  if (column == DPC_Name || column == DPC_Data)
60  {
61  return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
62  }
63  else
64  return Qt::NoItemFlags;
65 }
66 
68 {
69  QPointF tempValue;
70 
71  if (d_ptr->Children.count() < 2)
72  {
73  return tempValue;
74  }
75 
76  tempValue.setX(d_ptr->Children.at(0)->getValue().toDouble());
77  tempValue.setY(d_ptr->Children.at(1)->getValue().toDouble());
78 
79  return tempValue;
80 }
81 
82 void VPE::VPointFProperty::setPointF(const QPointF &point)
83 {
84  setPointF(point.x(), point.y());
85 }
86 
87 void VPE::VPointFProperty::setPointF(qreal x, qreal y)
88 {
89  if (d_ptr->Children.count() < 2)
90  {
91  return;
92  }
93 
94  QVariant tempX(x);
95  tempX.convert(QVariant::Double);
96 
97  QVariant tempY(y);
98  tempY.convert(QVariant::Double);
99 
100  d_ptr->Children.at(0)->setValue(tempX);
101  d_ptr->Children.at(1)->setValue(tempY);
102 }
103 
105 {
106  return "pointF";
107 }
108 
109 VPE::VProperty *VPE::VPointFProperty::clone(bool include_children, VProperty *container) const
110 {
111  if (!container)
112  {
113  container = new VPointFProperty(getName());
114 
115  if (!include_children)
116  {
117  QList<VProperty*> tempChildren = container->getChildren();
118  foreach(VProperty *tempChild, tempChildren)
119  {
120  container->removeChild(tempChild);
121  delete tempChild;
122  }
123  }
124  }
125 
126  return VProperty::clone(false, container); // Child
127 }
128 
129 void VPE::VPointFProperty::setValue(const QVariant &value)
130 {
131  QPointF tempPoint = value.toPointF();
132  setPointF(tempPoint);
133 }
134 
136 {
137  QPointF tempValue = getPointF();
138  return QString("%1,%2").arg(QString::number(tempValue.x()), QString::number(tempValue.y()));
139 }
Class for holding a double property.
virtual QVariant data(int column=DPC_Name, int role=Qt::DisplayRole) const Q_DECL_OVERRIDE
Get the data how it should be displayed.
Qt::ItemFlags flags(int column=DPC_Name) const Q_DECL_OVERRIDE
Returns item flags.
VPointFProperty(const QString &name)
virtual QVariant getValue() const Q_DECL_OVERRIDE
Returns the value of the property as a QVariant.
virtual QString type() const Q_DECL_OVERRIDE
Returns a string containing the type of the property.
virtual QPointF getPointF() const
Returns the QPointF.
virtual void setPointF(const QPointF &point)
Sets the QPointF.
virtual void setValue(const QVariant &value) Q_DECL_OVERRIDE
Sets the value of the property.
virtual Q_REQUIRED_RESULT VProperty * clone(bool include_children=true, VProperty *container=nullptr) const Q_DECL_OVERRIDE
Clones this property.
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 void setUpdateBehaviour(bool update_parent, bool update_children)
Sets whether the views should update Parents or children after this property changes.
Definition: vproperty.cpp:326
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
virtual void removeChild(VProperty *child)
Removes a child from the children list, doesn't delete the child!
Definition: vproperty.cpp:297
virtual int addChild(VProperty *child)
Adds a child to this property.
Definition: vproperty.cpp:278
virtual QList< VProperty * > & getChildren()
Returns a reference to the list of children.
Definition: vproperty.cpp:222