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 #pragma GCC system_header
41 
42 #ifndef QTVARIANTPROPERTY_H
43 #define QTVARIANTPROPERTY_H
44 
45 #include <QtCore/QVariant>
46 #include <QtGui/QIcon>
47 
48 #include "qteditorfactory.h"
49 #include "qtpropertybrowser.h"
50 
51 #if QT_VERSION >= 0x040400
52 QT_BEGIN_NAMESPACE
53 #endif
54 
55 typedef QMap<int, QIcon> QtIconMap;
56 
59 
61 {
62  public:
64  QVariant value() const;
65  QVariant attributeValue(const QString &attribute) const;
66  int valueType() const;
67  int propertyType() const;
68 
69  void setValue(const QVariant &value);
70  void setAttribute(const QString &attribute, const QVariant &value);
71  protected:
73  private:
76 };
77 
79 {
80  QtVariantProperty *q_ptr;
81  public:
83  : q_ptr(NULL), manager(m) {}
84 
86 };
87 
88 
89 
91 
94 {
95  Q_OBJECT
96  public:
97  explicit QtVariantPropertyManager(QObject *parent = 0);
99 
100  virtual QtVariantProperty *addProperty(int propertyType,
101  const QString &name = QString());
102 
103  int propertyType(const QtProperty *property) const;
104  int valueType(const QtProperty *property) const;
105  QtVariantProperty *variantProperty(const QtProperty *property) const;
106 
107  virtual bool isPropertyTypeSupported(int propertyType) const;
108  virtual int valueType(int propertyType) const;
109  virtual QStringList attributes(int propertyType) const;
110  virtual int attributeType(int propertyType, const QString &attribute) const;
111 
112  virtual QVariant value(const QtProperty *property) const;
113  virtual QVariant attributeValue(const QtProperty *property,
114  const QString &attribute) const;
115 
116  static int enumTypeId();
117  static int flagTypeId();
118  static int groupTypeId();
119  static int iconMapTypeId();
120  public Q_SLOTS:
121  virtual void setValue(QtProperty *property, const QVariant &val);
122  virtual void setAttribute(QtProperty *property,
123  const QString &attribute, const QVariant &value);
124  Q_SIGNALS:
125  void valueChanged(QtProperty *property, const QVariant &val);
126  void attributeChanged(QtProperty *property,
127  const QString &attribute, const QVariant &val);
128  protected:
129  virtual bool hasValue(const QtProperty *property) const;
130  QString valueText(const QtProperty *property) const;
131  QIcon valueIcon(const QtProperty *property) const;
132  virtual void initializeProperty(QtProperty *property);
133  virtual void uninitializeProperty(QtProperty *property);
134  virtual QtProperty *createProperty();
135  private:
137  Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, int))
138  Q_PRIVATE_SLOT(d_func(), void slotRangeChanged(QtProperty *, int, int))
139  Q_PRIVATE_SLOT(d_func(), void slotSingleStepChanged(QtProperty *, int))
140  Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, double))
141  Q_PRIVATE_SLOT(d_func(),
142  void slotRangeChanged(QtProperty *, double, double))
143  Q_PRIVATE_SLOT(d_func(),
144  void slotSingleStepChanged(QtProperty *, double))
145  Q_PRIVATE_SLOT(d_func(),
146  void slotDecimalsChanged(QtProperty *, int))
147  Q_PRIVATE_SLOT(d_func(),
148  void slotValueChanged(QtProperty *, bool))
149  Q_PRIVATE_SLOT(d_func(),
150  void slotValueChanged(QtProperty *, const QString &))
151  Q_PRIVATE_SLOT(d_func(),
152  void slotRegExpChanged(QtProperty *, const QRegExp &))
153  Q_PRIVATE_SLOT(d_func(),
154  void slotEchoModeChanged(QtProperty *, int))
155  Q_PRIVATE_SLOT(d_func(),
156  void slotValueChanged(QtProperty *, const QDate &))
157  Q_PRIVATE_SLOT(d_func(),
158  void slotRangeChanged(QtProperty *, const QDate &, const QDate &))
159  Q_PRIVATE_SLOT(d_func(),
160  void slotValueChanged(QtProperty *, const QTime &))
161  Q_PRIVATE_SLOT(d_func(),
162  void slotValueChanged(QtProperty *, const QDateTime &))
163  Q_PRIVATE_SLOT(d_func(),
164  void slotValueChanged(QtProperty *, const QKeySequence &))
165  Q_PRIVATE_SLOT(d_func(),
166  void slotValueChanged(QtProperty *, const QChar &))
167  Q_PRIVATE_SLOT(d_func(),
168  void slotValueChanged(QtProperty *, const QLocale &))
169  Q_PRIVATE_SLOT(d_func(),
170  void slotValueChanged(QtProperty *, const QPoint &))
171  Q_PRIVATE_SLOT(d_func(),
172  void slotValueChanged(QtProperty *, const QPointF &))
173  Q_PRIVATE_SLOT(d_func(),
174  void slotValueChanged(QtProperty *, const QSize &))
175  Q_PRIVATE_SLOT(d_func(),
176  void slotRangeChanged(QtProperty *, const QSize &, const QSize &))
177  Q_PRIVATE_SLOT(d_func(),
178  void slotValueChanged(QtProperty *, const QSizeF &))
179  Q_PRIVATE_SLOT(d_func(),
180  void slotRangeChanged(QtProperty *, const QSizeF &, const QSizeF &))
181  Q_PRIVATE_SLOT(d_func(),
182  void slotValueChanged(QtProperty *, const QRect &))
183  Q_PRIVATE_SLOT(d_func(),
184  void slotConstraintChanged(QtProperty *, const QRect &))
185  Q_PRIVATE_SLOT(d_func(),
186  void slotValueChanged(QtProperty *, const QRectF &))
187  Q_PRIVATE_SLOT(d_func(),
188  void slotConstraintChanged(QtProperty *, const QRectF &))
189  Q_PRIVATE_SLOT(d_func(),
190  void slotValueChanged(QtProperty *, const QColor &))
191  Q_PRIVATE_SLOT(d_func(),
192  void slotEnumNamesChanged(QtProperty *, const QStringList &))
193  Q_PRIVATE_SLOT(d_func(),
194  void slotEnumIconsChanged(QtProperty *, const QMap<int, QIcon> &))
195  Q_PRIVATE_SLOT(d_func(),
196  void slotValueChanged(QtProperty *, const QSizePolicy &))
197  Q_PRIVATE_SLOT(d_func(),
198  void slotValueChanged(QtProperty *, const QFont &))
199  Q_PRIVATE_SLOT(d_func(),
200  void slotValueChanged(QtProperty *, const QCursor &))
201  Q_PRIVATE_SLOT(d_func(),
202  void slotFlagNamesChanged(QtProperty *, const QStringList &))
203 
204  Q_PRIVATE_SLOT(d_func(),
205  void slotPropertyInserted(QtProperty *, QtProperty *, QtProperty *))
206  Q_PRIVATE_SLOT(d_func(),
207  void slotPropertyRemoved(QtProperty *, QtProperty *))
208  Q_DECLARE_PRIVATE(QtVariantPropertyManager)
209  Q_DISABLE_COPY(QtVariantPropertyManager)
210 };
211 
213 {
215  Q_DECLARE_PUBLIC(QtVariantPropertyManager)
216  public:
218 
219  bool m_creatingProperty;
220  bool m_creatingSubProperties;
221  bool m_destroyingSubProperties;
222  int m_propertyType;
223 
224  void slotValueChanged(QtProperty *property, int val);
225  void slotRangeChanged(QtProperty *property, int min, int max);
226  void slotSingleStepChanged(QtProperty *property, int step);
227  void slotValueChanged(QtProperty *property, double val);
228  void slotRangeChanged(QtProperty *property, double min, double max);
229  void slotSingleStepChanged(QtProperty *property, double step);
230  void slotDecimalsChanged(QtProperty *property, int prec);
231  void slotValueChanged(QtProperty *property, bool val);
232  void slotValueChanged(QtProperty *property, const QString &val);
233  void slotRegExpChanged(QtProperty *property, const QRegExp &regExp);
234  void slotEchoModeChanged(QtProperty *property, int);
235  void slotValueChanged(QtProperty *property, const QDate &val);
236  void slotRangeChanged(QtProperty *property,
237  const QDate &min, const QDate &max);
238  void slotValueChanged(QtProperty *property, const QTime &val);
239  void slotValueChanged(QtProperty *property, const QDateTime &val);
240  void slotValueChanged(QtProperty *property, const QKeySequence &val);
241  void slotValueChanged(QtProperty *property, const QChar &val);
242  void slotValueChanged(QtProperty *property, const QLocale &val);
243  void slotValueChanged(QtProperty *property, const QPoint &val);
244  void slotValueChanged(QtProperty *property, const QPointF &val);
245  void slotValueChanged(QtProperty *property, const QSize &val);
246  void slotRangeChanged(QtProperty *property,
247  const QSize &min, const QSize &max);
248  void slotValueChanged(QtProperty *property, const QSizeF &val);
249  void slotRangeChanged(QtProperty *property, const QSizeF &min,
250  const QSizeF &max);
251  void slotValueChanged(QtProperty *property, const QRect &val);
252  void slotConstraintChanged(QtProperty *property, const QRect &val);
253  void slotValueChanged(QtProperty *property, const QRectF &val);
254  void slotConstraintChanged(QtProperty *property, const QRectF &val);
255  void slotValueChanged(QtProperty *property, const QColor &val);
256  void slotEnumChanged(QtProperty *property, int val);
257  void slotEnumNamesChanged(QtProperty *property,
258  const QStringList &enumNames);
259  void slotEnumIconsChanged(QtProperty *property,
260  const QMap<int, QIcon> &enumIcons);
261  void slotValueChanged(QtProperty *property, const QSizePolicy &val);
262  void slotValueChanged(QtProperty *property, const QFont &val);
263  void slotValueChanged(QtProperty *property, const QCursor &val);
264  void slotFlagChanged(QtProperty *property, int val);
265  void slotFlagNamesChanged(QtProperty *property,
266  const QStringList &flagNames);
267  void slotPropertyInserted(QtProperty *property, QtProperty *parent,
268  QtProperty *after);
269  void slotPropertyRemoved(QtProperty *property, QtProperty *parent);
270 
271  void valueChanged(QtProperty *property, const QVariant &val);
272 
273  int internalPropertyToType(QtProperty *property) const;
274  QtVariantProperty *createSubProperty(QtVariantProperty *parent,
275  QtVariantProperty *after, QtProperty *internal);
276  void removeSubProperty(QtVariantProperty *property);
277 
278  QMap<int, QtAbstractPropertyManager *> m_typeToPropertyManager;
279  QMap<int, QMap<QString, int> > m_typeToAttributeToAttributeType;
280 
281  QMap<const QtProperty *, QPair<QtVariantProperty *, int> >
282  m_propertyToType;
283 
284  QMap<int, int> m_typeToValueType;
285 
286 
287  QMap<QtProperty *, QtVariantProperty *> m_internalToProperty;
288 
289  const QString m_constraintAttribute;
290  const QString m_singleStepAttribute;
291  const QString m_decimalsAttribute;
292  const QString m_enumIconsAttribute;
293  const QString m_enumNamesAttribute;
294  const QString m_flagNamesAttribute;
295  const QString m_maximumAttribute;
296  const QString m_minimumAttribute;
297  const QString m_regExpAttribute;
298  const QString m_echoModeAttribute;
299 };
301 
303 : public QtAbstractEditorFactory<QtVariantPropertyManager>
304 {
305  Q_OBJECT
306  public:
307  explicit QtVariantEditorFactory(QObject *parent = 0);
309  protected:
311  QWidget *createEditor(QtVariantPropertyManager *manager,
312  QtProperty *property, QWidget *parent);
314  private:
316  Q_DECLARE_PRIVATE(QtVariantEditorFactory)
317  Q_DISABLE_COPY(QtVariantEditorFactory)
318 };
319 
321 {
322  QtVariantEditorFactory *q_ptr;
323  Q_DECLARE_PUBLIC(QtVariantEditorFactory)
324  public:
326  : q_ptr(NULL),
327  m_spinBoxFactory(NULL),
328  m_doubleSpinBoxFactory(NULL),
329  m_checkBoxFactory(NULL),
330  m_lineEditFactory(NULL),
331  m_dateEditFactory(NULL),
332  m_timeEditFactory(NULL),
333  m_dateTimeEditFactory(NULL),
334  m_keySequenceEditorFactory(NULL),
335  m_charEditorFactory(NULL),
336  m_comboBoxFactory(NULL),
337  m_cursorEditorFactory(NULL),
338  m_colorEditorFactory(NULL),
339  m_fontEditorFactory(NULL) {}
340 
341 
342  QtSpinBoxFactory *m_spinBoxFactory;
343  QtDoubleSpinBoxFactory *m_doubleSpinBoxFactory;
344  QtCheckBoxFactory *m_checkBoxFactory;
345  QtLineEditFactory *m_lineEditFactory;
346  QtDateEditFactory *m_dateEditFactory;
347  QtTimeEditFactory *m_timeEditFactory;
348  QtDateTimeEditFactory *m_dateTimeEditFactory;
349  QtKeySequenceEditorFactory *m_keySequenceEditorFactory;
350  QtCharEditorFactory *m_charEditorFactory;
351  QtEnumEditorFactory *m_comboBoxFactory;
352  QtCursorEditorFactory *m_cursorEditorFactory;
353  QtColorEditorFactory *m_colorEditorFactory;
354  QtFontEditorFactory *m_fontEditorFactory;
355 
356  QMap<QtAbstractEditorFactoryBase *, int> m_factoryToType;
357  QMap<int, QtAbstractEditorFactoryBase *> m_typeToFactory;
358 };
359 
361 {
362 };
363 
364 
366 {
367 };
368 
369 
371 {
372 };
373 
374  Q_DECLARE_METATYPE(QtEnumPropertyType)
375  Q_DECLARE_METATYPE(QtFlagPropertyType)
376 Q_DECLARE_METATYPE(QtGroupPropertyType)
377 
378 
379 
380 #if QT_VERSION >= 0x040400
381  QT_END_NAMESPACE
382 #endif
383 
384  Q_DECLARE_METATYPE(QIcon)
385 Q_DECLARE_METATYPE(QtIconMap)
386 #endif
virtual QtProperty * createProperty()
Definition: qteditorfactory.h:424
QtProperty * addProperty(const QString &name=QString())
Definition: qteditorfactory.h:583
Definition: qtvariantproperty.h:92
Definition: qtpropertybrowser.h:141
Definition: qteditorfactory.h:544
Definition: qtvariantproperty.h:360
virtual void disconnectPropertyManager(PropertyManager *manager)=0
T min(const std::vector< T > &_values)
get the minimum value of vector of values
Definition: Helpers.hh:157
virtual QString valueText(const QtProperty *property) const
Definition: qteditorfactory.h:345
Definition: qteditorfactory.h:507
Definition: qtvariantproperty.h:365
QtVariantPropertyPrivate(QtVariantPropertyManager *m)
Definition: qtvariantproperty.h:82
Definition: qteditorfactory.h:380
Definition: qtpropertybrowser.h:209
Definition: qteditorfactory.h:782
virtual QIcon valueIcon(const QtProperty *property) const
Definition: qtvariantproperty.h:212
QWidget * createEditor(QtProperty *property, QWidget *parent)
Definition: qtpropertybrowser.h:214
Definition: qteditorfactory.h:700
QMap< int, QIcon > QtIconMap
Definition: qtvariantproperty.h:55
virtual void uninitializeProperty(QtProperty *property)
Definition: qtvariantproperty.h:370
virtual void initializeProperty(QtProperty *property)=0
Definition: qteditorfactory.h:745
Definition: qteditorfactory.h:621
Definition: qtvariantproperty.h:320
Definition: qtvariantproperty.h:78
#define NULL
Definition: CommonTypes.hh:30
#define QT_QTPROPERTYBROWSER_EXPORT
Definition: qtpropertybrowser.h:68
virtual bool hasValue(const QtProperty *property) const
Definition: qtvariantproperty.h:60
Definition: qteditorfactory.h:227
Definition: qtpropertybrowser.h:77
Definition: qtvariantproperty.h:302
QtVariantPropertyManager * manager
Definition: qtvariantproperty.h:85
virtual void connectPropertyManager(PropertyManager *manager)=0
T max(const std::vector< T > &_values)
get the maximum value of vector of values
Definition: Helpers.hh:144
Definition: qteditorfactory.h:467
Definition: qteditorfactory.h:658