vizkit3d
qtvariantproperty.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 **
6 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 **
8 ** This file is part of a Qt Solutions component.
9 **
10 ** You may use this file under the terms of the BSD license as follows:
11 **
12 ** "Redistribution and use in source and binary forms, with or without
13 ** modification, are permitted provided that the following conditions are
14 ** met:
15 ** * Redistributions of source code must retain the above copyright
16 ** notice, this list of conditions and the following disclaimer.
17 ** * Redistributions in binary form must reproduce the above copyright
18 ** notice, this list of conditions and the following disclaimer in
19 ** the documentation and/or other materials provided with the
20 ** distribution.
21 ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
22 ** the names of its contributors may be used to endorse or promote
23 ** products derived from this software without specific prior written
24 ** permission.
25 **
26 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
37 **
38 ****************************************************************************/
39 
40 
41 #ifndef QTVARIANTPROPERTY_H
42 #define QTVARIANTPROPERTY_H
43 
44 #include "qtpropertybrowser.h"
45 #include "qteditorfactory.h"
46 #include <QtCore/QVariant>
47 #include <QtGui/QIcon>
48 
49 #if QT_VERSION >= 0x040400
50 QT_BEGIN_NAMESPACE
51 #endif
52 
53 typedef QMap<int, QIcon> QtIconMap;
54 typedef QMap<const QtProperty *, QtProperty *> PropertyMap;
55 
57 class QtVariantProperty;
58 
60 {
61  QtVariantProperty *q_ptr;
62 public:
64 
66 };
67 
69 {
71  Q_DECLARE_PUBLIC(QtVariantPropertyManager)
72 public:
74 
79 
80  void slotValueChanged(QtProperty *property, int val);
81  void slotRangeChanged(QtProperty *property, int min, int max);
82  void slotSingleStepChanged(QtProperty *property, int step);
83  void slotValueChanged(QtProperty *property, double val);
84  void slotRangeChanged(QtProperty *property, double min, double max);
85  void slotSingleStepChanged(QtProperty *property, double step);
86  void slotDecimalsChanged(QtProperty *property, int prec);
87  void slotValueChanged(QtProperty *property, bool val);
88  void slotValueChanged(QtProperty *property, const QString &val);
89  void slotRegExpChanged(QtProperty *property, const QRegExp &regExp);
90  void slotEchoModeChanged(QtProperty *property, int);
91  void slotValueChanged(QtProperty *property, const QDate &val);
92  void slotRangeChanged(QtProperty *property, const QDate &min, const QDate &max);
93  void slotValueChanged(QtProperty *property, const QTime &val);
94  void slotValueChanged(QtProperty *property, const QDateTime &val);
95  void slotValueChanged(QtProperty *property, const QKeySequence &val);
96  void slotValueChanged(QtProperty *property, const QChar &val);
97  void slotValueChanged(QtProperty *property, const QLocale &val);
98  void slotValueChanged(QtProperty *property, const QPoint &val);
99  void slotValueChanged(QtProperty *property, const QPointF &val);
100  void slotValueChanged(QtProperty *property, const QSize &val);
101  void slotRangeChanged(QtProperty *property, const QSize &min, const QSize &max);
102  void slotValueChanged(QtProperty *property, const QSizeF &val);
103  void slotRangeChanged(QtProperty *property, const QSizeF &min, const QSizeF &max);
104  void slotValueChanged(QtProperty *property, const QRect &val);
105  void slotConstraintChanged(QtProperty *property, const QRect &val);
106  void slotValueChanged(QtProperty *property, const QRectF &val);
107  void slotConstraintChanged(QtProperty *property, const QRectF &val);
108  void slotValueChanged(QtProperty *property, const QColor &val);
109  void slotEnumChanged(QtProperty *property, int val);
110  void slotEnumNamesChanged(QtProperty *property, const QStringList &enumNames);
111  void slotEnumIconsChanged(QtProperty *property, const QMap<int, QIcon> &enumIcons);
112  void slotValueChanged(QtProperty *property, const QSizePolicy &val);
113  void slotValueChanged(QtProperty *property, const QFont &val);
114  void slotValueChanged(QtProperty *property, const QCursor &val);
115  void slotFlagChanged(QtProperty *property, int val);
116  void slotFlagNamesChanged(QtProperty *property, const QStringList &flagNames);
117  void slotPropertyInserted(QtProperty *property, QtProperty *parent, QtProperty *after);
118  void slotPropertyRemoved(QtProperty *property, QtProperty *parent);
119 
120  void valueChanged(QtProperty *property, const QVariant &val);
121 
122  int internalPropertyToType(QtProperty *property) const;
123  QtVariantProperty *createSubProperty(QtVariantProperty *parent, QtVariantProperty *after,
124  QtProperty *internal);
125  void removeSubProperty(QtVariantProperty *property);
126 
127  QMap<int, QtAbstractPropertyManager *> m_typeToPropertyManager;
128  QMap<int, QMap<QString, int> > m_typeToAttributeToAttributeType;
129 
130  QMap<const QtProperty *, QPair<QtVariantProperty *, int> > m_propertyToType;
131 
132  QMap<int, int> m_typeToValueType;
133 
134 
135  QMap<QtProperty *, QtVariantProperty *> m_internalToProperty;
136 
137  const QString m_constraintAttribute;
138  const QString m_singleStepAttribute;
139  const QString m_decimalsAttribute;
140  const QString m_enumIconsAttribute;
141  const QString m_enumNamesAttribute;
142  const QString m_flagNamesAttribute;
143  const QString m_maximumAttribute;
144  const QString m_minimumAttribute;
145  const QString m_regExpAttribute;
146  const QString m_echoModeAttribute;
147 };
148 
150 {
151 public:
153  QVariant value() const;
154  QVariant attributeValue(const QString &attribute) const;
155  int valueType() const;
156  int propertyType() const;
157 
158  void setValue(const QVariant &value);
159  void setAttribute(const QString &attribute, const QVariant &value);
160 protected:
162 private:
165 };
166 
168 
170 {
171  Q_OBJECT
172 public:
173  QtVariantPropertyManager(QObject *parent = 0);
175 
176  virtual QtVariantProperty *addProperty(int propertyType, const QString &name = QString());
177 
178  int propertyType(const QtProperty *property) const;
179  int valueType(const QtProperty *property) const;
180  QtVariantProperty *variantProperty(const QtProperty *property) const;
181 
182  virtual bool isPropertyTypeSupported(int propertyType) const;
183  virtual int valueType(int propertyType) const;
184  virtual QStringList attributes(int propertyType) const;
185  virtual int attributeType(int propertyType, const QString &attribute) const;
186 
187  virtual QVariant value(const QtProperty *property) const;
188  virtual QVariant attributeValue(const QtProperty *property, const QString &attribute) const;
189 
190  static int enumTypeId();
191  static int flagTypeId();
192  static int groupTypeId();
193  static int iconMapTypeId();
194 public Q_SLOTS:
195  virtual void setValue(QtProperty *property, const QVariant &val);
196  virtual void setAttribute(QtProperty *property,
197  const QString &attribute, const QVariant &value);
198 Q_SIGNALS:
199  void valueChanged(QtProperty *property, const QVariant &val);
200  void attributeChanged(QtProperty *property,
201  const QString &attribute, const QVariant &val);
202 protected:
203  virtual bool hasValue(const QtProperty *property) const;
204  QString valueText(const QtProperty *property) const;
205  QIcon valueIcon(const QtProperty *property) const;
206  virtual void initializeProperty(QtProperty *property);
207  virtual void uninitializeProperty(QtProperty *property);
208  virtual QtProperty *createProperty();
209 private:
211  Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, int))
212  Q_PRIVATE_SLOT(d_func(), void slotRangeChanged(QtProperty *, int, int))
213  Q_PRIVATE_SLOT(d_func(), void slotSingleStepChanged(QtProperty *, int))
214  Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, double))
215  Q_PRIVATE_SLOT(d_func(), void slotRangeChanged(QtProperty *, double, double))
216  Q_PRIVATE_SLOT(d_func(), void slotSingleStepChanged(QtProperty *, double))
217  Q_PRIVATE_SLOT(d_func(), void slotDecimalsChanged(QtProperty *, int))
218  Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, bool))
219  Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QString &))
220  Q_PRIVATE_SLOT(d_func(), void slotRegExpChanged(QtProperty *, const QRegExp &))
221  Q_PRIVATE_SLOT(d_func(), void slotEchoModeChanged(QtProperty *, int))
222  Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QDate &))
223  Q_PRIVATE_SLOT(d_func(), void slotRangeChanged(QtProperty *, const QDate &, const QDate &))
224  Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QTime &))
225  Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QDateTime &))
226  Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QKeySequence &))
227  Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QChar &))
228  Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QLocale &))
229  Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QPoint &))
230  Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QPointF &))
231  Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QSize &))
232  Q_PRIVATE_SLOT(d_func(), void slotRangeChanged(QtProperty *, const QSize &, const QSize &))
233  Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QSizeF &))
234  Q_PRIVATE_SLOT(d_func(), void slotRangeChanged(QtProperty *, const QSizeF &, const QSizeF &))
235  Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QRect &))
236  Q_PRIVATE_SLOT(d_func(), void slotConstraintChanged(QtProperty *, const QRect &))
237  Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QRectF &))
238  Q_PRIVATE_SLOT(d_func(), void slotConstraintChanged(QtProperty *, const QRectF &))
239  Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QColor &))
240  Q_PRIVATE_SLOT(d_func(), void slotEnumNamesChanged(QtProperty *, const QStringList &))
241  Q_PRIVATE_SLOT(d_func(), void slotEnumIconsChanged(QtProperty *, const QMap<int, QIcon> &))
242  Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QSizePolicy &))
243  Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QFont &))
244  Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QCursor &))
245  Q_PRIVATE_SLOT(d_func(), void slotFlagNamesChanged(QtProperty *, const QStringList &))
246 
247  Q_PRIVATE_SLOT(d_func(), void slotPropertyInserted(QtProperty *, QtProperty *, QtProperty *))
248  Q_PRIVATE_SLOT(d_func(), void slotPropertyRemoved(QtProperty *, QtProperty *))
249  Q_DECLARE_PRIVATE(QtVariantPropertyManager)
250  Q_DISABLE_COPY(QtVariantPropertyManager)
251 };
252 
254 
256 {
257  QtVariantEditorFactory *q_ptr;
258  Q_DECLARE_PUBLIC(QtVariantEditorFactory)
259 public:
260 
274 
275  QMap<QtAbstractEditorFactoryBase *, int> m_factoryToType;
276  QMap<int, QtAbstractEditorFactoryBase *> m_typeToFactory;
277 };
278 
280 {
281  Q_OBJECT
282 public:
283  QtVariantEditorFactory(QObject *parent = 0);
285 protected:
286  void connectPropertyManager(QtVariantPropertyManager *manager);
287  QWidget *createEditor(QtVariantPropertyManager *manager, QtProperty *property,
288  QWidget *parent);
289  void disconnectPropertyManager(QtVariantPropertyManager *manager);
290 private:
292  Q_DECLARE_PRIVATE(QtVariantEditorFactory)
293  Q_DISABLE_COPY(QtVariantEditorFactory)
294 };
295 
296 #if QT_VERSION >= 0x040400
297 QT_END_NAMESPACE
298 #endif
299 
300 Q_DECLARE_METATYPE(QIcon)
301 Q_DECLARE_METATYPE(QtIconMap)
302 #endif
QtLineEditFactory * m_lineEditFactory
Definition: qtvariantproperty.h:264
const QString m_flagNamesAttribute
Definition: qtvariantproperty.h:142
The QtLineEditFactory class provides QLineEdit widgets for properties created by QtStringPropertyMana...
Definition: qteditorfactory.h:277
QtFontEditorFactory * m_fontEditorFactory
Definition: qtvariantproperty.h:273
QtCursorEditorFactory * m_cursorEditorFactory
Definition: qtvariantproperty.h:271
The QtKeySequenceEditorFactory class provides editor widgets for properties created by QtKeySequenceP...
Definition: qteditorfactory.h:412
QMap< int, QtAbstractEditorFactoryBase * > m_typeToFactory
Definition: qtvariantproperty.h:276
The QtVariantPropertyManager class provides and manages QVariant based properties.
Definition: qtvariantproperty.h:169
bool m_creatingSubProperties
Definition: qtvariantproperty.h:76
The QtAbstractPropertyManager provides an interface for property managers.
Definition: qtpropertybrowser.h:153
The QtDateTimeEditFactory class provides QDateTimeEdit widgets for properties created by QtDateTimePr...
Definition: qteditorfactory.h:380
QtEnumEditorFactory * m_comboBoxFactory
Definition: qtvariantproperty.h:270
const QString m_enumNamesAttribute
Definition: qtvariantproperty.h:141
QMap< int, QMap< QString, int > > m_typeToAttributeToAttributeType
Definition: qtvariantproperty.h:128
bool m_destroyingSubProperties
Definition: qtvariantproperty.h:77
The QtCheckBoxFactory class provides QCheckBox widgets for properties created by QtBoolPropertyManage...
Definition: qteditorfactory.h:205
The QtTimeEditFactory class provides QTimeEdit widgets for properties created by QtTimePropertyManage...
Definition: qteditorfactory.h:346
int m_propertyType
Definition: qtvariantproperty.h:78
QMap< const QtProperty *, QPair< QtVariantProperty *, int > > m_propertyToType
Definition: qtvariantproperty.h:130
QtVariantPropertyPrivate(QtVariantPropertyManager *m)
Definition: qtvariantproperty.h:63
QMap< QtProperty *, QtVariantProperty * > m_internalToProperty
Definition: qtvariantproperty.h:135
The QtDoubleSpinBoxFactory class provides QDoubleSpinBox widgets for properties created by QtDoublePr...
Definition: qteditorfactory.h:240
The QtAbstractEditorFactory is the base template class for editor factories.
Definition: qtpropertybrowser.h:205
QtDateTimeEditFactory * m_dateTimeEditFactory
Definition: qtvariantproperty.h:267
const QString m_maximumAttribute
Definition: qtvariantproperty.h:143
The QtFontEditorFactory class provides font editing for properties created by QtFontPropertyManager o...
Definition: qteditorfactory.h:672
Definition: qtvariantproperty.h:68
bool m_creatingProperty
Definition: qtvariantproperty.h:75
QtDateEditFactory * m_dateEditFactory
Definition: qtvariantproperty.h:265
const QString m_echoModeAttribute
Definition: qtvariantproperty.h:146
The QtCursorEditorFactory class provides QComboBox widgets for properties created by QtCursorProperty...
Definition: qteditorfactory.h:554
QMap< int, QIcon > QtIconMap
Definition: qtvariantproperty.h:53
QMap< QtAbstractEditorFactoryBase *, int > m_factoryToType
Definition: qtvariantproperty.h:275
QMap< const QtProperty *, QtProperty * > PropertyMap
Definition: qtvariantproperty.h:54
QMap< int, QtAbstractPropertyManager * > m_typeToPropertyManager
Definition: qtvariantproperty.h:127
QtColorEditorFactory * m_colorEditorFactory
Definition: qtvariantproperty.h:272
The QtColorEditorFactory class provides color editing for properties created by QtColorPropertyManage...
Definition: qteditorfactory.h:603
The QtCharEditorFactory class provides editor widgets for properties created by QtCharPropertyManager...
Definition: qteditorfactory.h:473
QtCharEditorFactory * m_charEditorFactory
Definition: qtvariantproperty.h:269
Definition: qtvariantproperty.h:255
const QString m_singleStepAttribute
Definition: qtvariantproperty.h:138
Definition: qtvariantproperty.h:59
QtCheckBoxFactory * m_checkBoxFactory
Definition: qtvariantproperty.h:263
#define QT_QTPROPERTYBROWSER_EXPORT
Definition: qtpropertybrowser.h:66
The QtVariantProperty class is a convenience class handling QVariant based properties.
Definition: qtvariantproperty.h:149
The QtSpinBoxFactory class provides QSpinBox widgets for properties created by QtIntPropertyManager o...
Definition: qteditorfactory.h:102
QtKeySequenceEditorFactory * m_keySequenceEditorFactory
Definition: qtvariantproperty.h:268
const QString m_constraintAttribute
Definition: qtvariantproperty.h:137
The QtProperty class encapsulates an instance of a property.
Definition: qtpropertybrowser.h:74
The QtVariantEditorFactory class provides widgets for properties created by QtVariantPropertyManager ...
Definition: qtvariantproperty.h:279
QtDoubleSpinBoxFactory * m_doubleSpinBoxFactory
Definition: qtvariantproperty.h:262
QtSpinBoxFactory * m_spinBoxFactory
Definition: qtvariantproperty.h:261
QtTimeEditFactory * m_timeEditFactory
Definition: qtvariantproperty.h:266
QtVariantPropertyManager * manager
Definition: qtvariantproperty.h:65
const QString m_regExpAttribute
Definition: qtvariantproperty.h:145
QMap< int, int > m_typeToValueType
Definition: qtvariantproperty.h:132
const QString m_decimalsAttribute
Definition: qtvariantproperty.h:139
The QtDateEditFactory class provides QDateEdit widgets for properties created by QtDatePropertyManage...
Definition: qteditorfactory.h:312
const QString m_minimumAttribute
Definition: qtvariantproperty.h:144
const QString m_enumIconsAttribute
Definition: qtvariantproperty.h:140
The QtEnumEditorFactory class provides QComboBox widgets for properties created by QtEnumPropertyMana...
Definition: qteditorfactory.h:507