summaryrefslogtreecommitdiff
path: root/utils/wpseditor/gui/src/QPropertyEditor/Property.h
diff options
context:
space:
mode:
Diffstat (limited to 'utils/wpseditor/gui/src/QPropertyEditor/Property.h')
-rw-r--r--utils/wpseditor/gui/src/QPropertyEditor/Property.h157
1 files changed, 157 insertions, 0 deletions
diff --git a/utils/wpseditor/gui/src/QPropertyEditor/Property.h b/utils/wpseditor/gui/src/QPropertyEditor/Property.h
new file mode 100644
index 0000000000..52d6842987
--- /dev/null
+++ b/utils/wpseditor/gui/src/QPropertyEditor/Property.h
@@ -0,0 +1,157 @@
1// *************************************************************************************************
2//
3// QPropertyEditor v 0.1
4//
5// --------------------------------------
6// Copyright (C) 2007 Volker Wiendl
7//
8//
9// This library is free software; you can redistribute it and/or
10// modify it under the terms of the GNU Lesser General Public
11// License as published by the Free Software Foundation; either
12// version 2.1 of the License, or any later version.
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// You should have received a copy of the GNU Lesser General Public
20// License along with this library; if not, write to the Free Software
21// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22//
23// *************************************************************************************************
24
25#ifndef PROPERTY_H_
26#define PROPERTY_H_
27
28#include <Qt/qwidget.h>
29#include <Qt/qstyleoption.h>
30#include <Qt/qvariant.h>
31
32/**
33 * The Property class is the base class for all properties in the QPropertyEditor
34 * You can implement custom properties inherited from this class to further enhence the
35 * functionality of the QPropertyEditor
36 */
37class Property : public QObject {
38 Q_OBJECT
39
40public:
41
42 /**
43 * Constructor
44 *
45 * @param name the name of the property within the propertyObject (will be used in the QPropertyEditorWidget view too)
46 * @param propertyObject the object that contains the property
47 * @param parent optional parent object
48 */
49 Property(const QString& name = QString(), QObject* propertyObject = 0, QObject* parent = 0);
50
51 /**
52 * The value stored by this property
53 * @return QVariant the data converted to a QVariant
54 */
55 virtual QVariant value(int role = Qt::UserRole) const;
56 /**
57 * Sets the value stored by this property
58 * @param value the data converted to a QVariant
59 */
60 virtual void setValue(const QVariant& value);
61
62 /**
63 * Returns the QObject which contains the property managed by this instance
64 * @return QObject* pointer to the QObject that contains user defined properties
65 */
66 QObject* propertyObject() {
67 return m_propertyObject;
68 }
69
70 /**
71 * Flag if property is used for indicating a group or really manages a property
72 * @return bool true if this property is only used to display a category in the QPropertyEditorWidget
73 */
74 bool isRoot() {
75 return m_propertyObject == 0;
76 }
77
78 /**
79 * Flag if the property can be set
80 * @return bool true if this property has no set method
81 */
82 bool isReadOnly();
83
84 /**
85 * Returns the row of this instance within the QPropertyModel
86 * @return int row within the QPropertyModel
87 */
88 int row() {
89 return parent()->children().indexOf(this);
90 }
91
92 /**
93 * returns optional settings for the editor widget that is used to manipulate the properties value
94 * @return QString a string that contains property settings for the editor widget (e.g. "minimum=1.0;maximum=10.0;")
95 */
96 QString editorHints() {
97 return m_hints;
98 }
99
100 /**
101 * Sets properties for the editor widget that is used to manipulate the data value managed by this instance
102 * @param hints a string containing property settings for the editor widget that manipulates this property
103 */
104 virtual void setEditorHints(const QString& hints) {
105 m_hints = hints;
106 }
107
108 /**
109 * Creates an editor for the data managed by this instance
110 * @param parent widget the newly created editor widget will be child of
111 * @param option currently not used
112 * @return QWidget* pointer to the editor widget
113 */
114 virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option);
115
116 /**
117 * Returns the data of the editor widget used to manipulate this instance
118 * @return QVariant the data converted to a QVariant
119 */
120 virtual QVariant editorData(QWidget *editor);
121
122 /**
123 * Changes the editor widget's data to a specific value
124 * @param editor the editor widget
125 * @param data the data to set in the editor widget
126 * @return bool true if editor widget was set to the given data successfully, false if the data can not be set in the editor (e.g. wrong datatype)
127 */
128 virtual bool setEditorData(QWidget *editor, const QVariant& data);
129
130 /**
131 * Tries to find the first property that manages the given propertyObject
132 * @param propertyObject
133 * @return Property
134 */
135 Property* findPropertyObject(QObject* propertyObject);
136
137private slots:
138 /**
139 * This slot is used to immediately set the properties when the editor widget's value of a double or float
140 * property has changed
141 * @param value the new value
142 */
143 void setValue(double value);
144 /**
145 * This slot is used to immediately set the properties when the editor widget's value of an integer
146 * property has changed
147 * @param value the new value
148 */
149 void setValue(int value);
150
151private:
152 QObject* m_propertyObject;
153 QString m_hints;
154
155};
156
157#endif