Seamly2D
Code documentation
vnumberproperty.h
Go to the documentation of this file.
1 /************************************************************************
2  **
3  ** @file vnumberproperty.h
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 #ifndef VNUMBERPROPERTY_H
22 #define VNUMBERPROPERTY_H
23 
24 #include <qcompilerdetection.h>
25 #include <stddef.h>
26 #include <QMap>
27 #include <QMetaObject>
28 #include <QObject>
29 #include <QString>
30 #include <QStringList>
31 #include <QStyleOptionViewItem>
32 #include <QVariant>
33 #include <QtGlobal>
34 
35 #include "../vproperty.h"
36 
37 namespace VPE
38 {
39 
40 
41 //! Class for holding an integer property
42 class SpinboxProperty : public VProperty
43 {
44  Q_OBJECT
45 public:
46  SpinboxProperty(const QString &name, const QMap<QString, QVariant> &settings);
47 
48  explicit SpinboxProperty(const QString &name);
49 
50  //! Returns an editor widget, or NULL if it doesn't supply one
51  //! \param parent The widget to which the editor will be added as a child
52  //! \options Render options
53  //! \delegate A pointer to the QAbstractItemDelegate requesting the editor. This can be used to connect signals and
54  //! slots.
55  virtual QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &options,
56  const QAbstractItemDelegate *delegate) Q_DECL_OVERRIDE;
57 
58  //! Gets the data from the widget
59  virtual QVariant getEditorData(const QWidget *editor) const Q_DECL_OVERRIDE;
60 
61  //! Sets the settings. Available settings:
62  //!
63  //! key: "Min" - value: Minimum number as integer
64  //! key: "Max" - value: Maximum number as integer
65  virtual void setSetting(const QString &key, const QVariant &value) Q_DECL_OVERRIDE;
66 
67  //! Get the settings. This function has to be implemented in a subclass in order to have an effect
68  virtual QVariant getSetting(const QString &key) const Q_DECL_OVERRIDE;
69 
70  //! Returns the list of keys of the property's settings
71  virtual QStringList getSettingKeys() const Q_DECL_OVERRIDE;
72 
73  //! Returns a string containing the type of the property
74  virtual QString type() const Q_DECL_OVERRIDE;
75 
76  //! Clones this property
77  //! \param include_children Indicates whether to also clone the children
78  //! \param container If a property is being passed here, no new VProperty is being created but instead it is tried
79  //! to fill all the data into container. This can also be used when subclassing this function.
80  //! \return Returns the newly created property (or container, if it was not NULL)
81  Q_REQUIRED_RESULT virtual VProperty *clone(bool include_children = true,
82  VProperty *container = nullptr) const Q_DECL_OVERRIDE;
83 public slots:
84  void valueChanged(int i);
85 protected:
87 
88  static const int StandardMin;// = -1000000;
89  static const int StandardMax;// = 1000000;
90 
91 private:
92  Q_DISABLE_COPY(SpinboxProperty)
93 };
94 
95 
96 //! Class for holding a double property
98 {
99  Q_OBJECT
100 public:
101  DoubleSpinboxProperty(const QString &name, const QMap<QString, QVariant> &settings);
102 
103  explicit DoubleSpinboxProperty(const QString &name);
104 
105  //! Returns an editor widget, or NULL if it doesn't supply one
106  //! \param parent The widget to which the editor will be added as a child
107  //! \options Render options
108  //! \delegate A pointer to the QAbstractItemDelegate requesting the editor. This can be used to connect signals and
109  //! slots.
110  virtual QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &options,
111  const QAbstractItemDelegate *delegate);
112 
113  //! Gets the data from the widget
114  virtual QVariant getEditorData(const QWidget *editor) const;
115 
116  //! Sets the settings. Available settings:
117  //!
118  //! key: "Min" - value: Minimum number as integer
119  //! key: "Max" - value: Maximum number as integer
120  virtual void setSetting(const QString &key, const QVariant &value);
121 
122  //! Get the settings. This function has to be implemented in a subclass in order to have an effect
123  virtual QVariant getSetting(const QString &key) const;
124 
125  //! Returns the list of keys of the property's settings
126  virtual QStringList getSettingKeys() const;
127 
128  //! Returns a string containing the type of the property
129  virtual QString type() const;
130 
131  //! Clones this property
132  //! \param include_children Indicates whether to also clone the children
133  //! \param container If a property is being passed here, no new VProperty is being created but instead it is tried
134  //! to fill all the data into container. This can also be used when subclassing this function.
135  //! \return Returns the newly created property (or container, if it was not NULL)
136  virtual VProperty *clone(bool include_children = true, VProperty *container = NULL) const;
137 
138 protected:
139  //! Number of decimals after the decimal point
141 
142  const static double StandardPrecision;// = 5;
143 
144 private:
145  Q_DISABLE_COPY(DoubleSpinboxProperty)
146 };
147 
148 
149 }
150 
151 #endif // VNUMBERPROPERTY_H
Class for holding a double property.
int Precision
Number of decimals after the decimal point.
virtual QString type() const
Returns a string containing the type of the property.
virtual QVariant getEditorData(const QWidget *editor) const
Gets the data from the widget.
DoubleSpinboxProperty(const QString &name, const QMap< QString, QVariant > &settings)
virtual VProperty * clone(bool include_children=true, VProperty *container=NULL) const
Clones this property.
virtual QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &options, const QAbstractItemDelegate *delegate)
Returns an editor widget, or NULL if it doesn't supply one.
virtual QVariant getSetting(const QString &key) const
Get the settings. This function has to be implemented in a subclass in order to have an effect.
static const double StandardPrecision
virtual void setSetting(const QString &key, const QVariant &value)
Sets the settings. Available settings:
virtual QStringList getSettingKeys() const
Returns the list of keys of the property's settings.
Class for holding an integer property.
virtual QStringList getSettingKeys() const Q_DECL_OVERRIDE
Returns the list of keys of the property's settings.
virtual void setSetting(const QString &key, const QVariant &value) Q_DECL_OVERRIDE
Sets the settings. Available settings:
virtual QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &options, const QAbstractItemDelegate *delegate) Q_DECL_OVERRIDE
Returns an editor widget, or NULL if it doesn't supply one.
SpinboxProperty(const QString &name, const QMap< QString, QVariant > &settings)
static const int StandardMin
static const int StandardMax
virtual QVariant getEditorData(const QWidget *editor) const Q_DECL_OVERRIDE
Gets the data from the widget.
virtual QVariant getSetting(const QString &key) const Q_DECL_OVERRIDE
Get the settings. This function has to be implemented in a subclass in order to have an effect.
virtual Q_REQUIRED_RESULT VProperty * clone(bool include_children=true, VProperty *container=nullptr) const Q_DECL_OVERRIDE
Clones this property.
virtual QString type() const Q_DECL_OVERRIDE
Returns a string containing the type of the property.