Seamly2D
Code documentation
vvector3dproperty.cpp
Go to the documentation of this file.
1 /************************************************************************
2  **
3  ** @file vvector3dproperty.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 "vvector3dproperty.h"
22 
23 #include <QFlags>
24 #include <QList>
25 #include <QStringList>
26 
27 #include "../../vproperty_p.h"
28 #include "../vnumberproperty.h"
29 
31  : VProperty(name, QVariant::String) // todo: QVariant::Vector3D??
32 {
33  QVariant tmpFloat(0); tmpFloat.convert(QVariant::Double);
34  DoubleSpinboxProperty* tmpX = new DoubleSpinboxProperty("X"); addChild(tmpX); tmpX->setUpdateBehaviour(true, false);
35  DoubleSpinboxProperty* tmpY = new DoubleSpinboxProperty("Y"); addChild(tmpY); tmpY->setUpdateBehaviour(true, false);
36  DoubleSpinboxProperty* tmpZ = new DoubleSpinboxProperty("Z"); addChild(tmpZ); tmpZ->setUpdateBehaviour(true, false);
38 }
39 
40 
41 //! Get the data how it should be displayed
42 QVariant VPE::QVector3DProperty::data (int column, int role) const
43 {
44  if (column == DPC_Data && Qt::DisplayRole == role)
45  {
46  Vector3D tmpVect = getVector();
47  return QString("(%1, %2, %3)").arg(QString::number(tmpVect.X),
48  QString::number(tmpVect.Y),
49  QString::number(tmpVect.Z));
50  }
51  else
52  return VProperty::data(column, role);
53 }
54 
55 //! Returns item flags
56 Qt::ItemFlags VPE::QVector3DProperty::flags(int column) const
57 {
58  if (column == DPC_Name || column == DPC_Data)
59  {
60  return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
61  }
62  else
63  return Qt::NoItemFlags;
64 }
65 
66 
67 //! Returns the Vector3d
69 {
70  Vector3D tmpVect;
71 
72  if (d_ptr->Children.count() < 3)
73  {
74  return tmpVect;
75  }
76 
77  tmpVect.X = d_ptr->Children.at(0)->getValue().toDouble();
78  tmpVect.Y = d_ptr->Children.at(1)->getValue().toDouble();
79  tmpVect.Z = d_ptr->Children.at(2)->getValue().toDouble();
80 
81  return tmpVect;
82 }
83 
84 //! Sets the Vector3d
86 {
87  setVector(vect.X, vect.Y, vect.Z);
88 }
89 
90 void VPE::QVector3DProperty::setVector(double x, double y, double z)
91 {
92  if (d_ptr->Children.count() < 3)
93  {
94  return;
95  }
96 
97  QVariant tmpX(x); tmpX.convert(QVariant::Double);
98  QVariant tmpY(y); tmpY.convert(QVariant::Double);
99  QVariant tmpZ(z); tmpZ.convert(QVariant::Double);
100  d_ptr->Children.at(0)->setValue(tmpX);
101  d_ptr->Children.at(1)->setValue(tmpY);
102  d_ptr->Children.at(2)->setValue(tmpZ);
103 }
104 
106 {
107  return "vector3d";
108 }
109 
110 VPE::VProperty* VPE::QVector3DProperty::clone(bool include_children, VProperty* container) const
111 {
112  if (!container)
113  {
114  container = new QVector3DProperty(getName());
115 
116  if (!include_children)
117  {
118  QList<VProperty*> tmpChildren = container->getChildren();
119  foreach (VProperty* tmpChild, tmpChildren)
120  {
121  container->removeChild(tmpChild);
122  delete tmpChild;
123  }
124  }
125  }
126 
127  return VProperty::clone(false, container); // Child
128 }
129 
130 void VPE::QVector3DProperty::setValue(const QVariant &value)
131 {
132  QStringList tmpStrings = value.toString().split(",");
133  if (tmpStrings.count() == 3)
134  {
135  setVector(tmpStrings[0].toDouble(), tmpStrings[1].toDouble(), tmpStrings[2].toDouble());
136  }
137 
138 }
139 
141 {
142  Vector3D tmpVect = getVector();
143  return QString("%1,%2,%3").arg(QString::number(tmpVect.X), QString::number(tmpVect.Y), QString::number(tmpVect.Z));
144 }
Class for holding a double property.
virtual Vector3D getVector() const
Returns the Vector3d.
virtual Qt::ItemFlags flags(int column=DPC_Name) const Q_DECL_OVERRIDE
Returns item flags.
virtual void setValue(const QVariant &value) Q_DECL_OVERRIDE
Sets the value of the property.
virtual QVariant getValue() const Q_DECL_OVERRIDE
Returns the value of the property as a QVariant.
virtual void setVector(const Vector3D &vect)
Sets the Vector3d.
QVector3DProperty(const QString &name)
virtual VProperty * clone(bool include_children=true, VProperty *container=NULL) const Q_DECL_OVERRIDE
Clones this property.
virtual QString type() const Q_DECL_OVERRIDE
Returns a string containing the type of the property.
virtual QVariant data(int column=DPC_Name, int role=Qt::DisplayRole) const Q_DECL_OVERRIDE
Get the data how it should be displayed.
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
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