1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the tools applications of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #include "qtvariantproperty.h"
41 #include "qtpropertymanager.h"
42 #include "qteditorfactory.h"
43 #include <QtCore/QVariant>
44 #include <QtGui/QIcon>
45 #include <QtCore/QDate>
46 #include <QtCore/QLocale>
47 
48 #if defined(Q_CC_MSVC)
49 #    pragma warning(disable: 4786) /* MS VS 6: truncating debug info after 255 characters */
50 #endif
51 
52 QT_BEGIN_NAMESPACE
53 
54 class QtEnumPropertyType
55 {
56 };
57 
58 
59 class QtFlagPropertyType
60 {
61 };
62 
63 
64 class QtGroupPropertyType
65 {
66 };
67 
68 QT_END_NAMESPACE
69 
Q_DECLARE_METATYPE(QtEnumPropertyType)70 Q_DECLARE_METATYPE(QtEnumPropertyType)
71 Q_DECLARE_METATYPE(QtFlagPropertyType)
72 Q_DECLARE_METATYPE(QtGroupPropertyType)
73 
74 QT_BEGIN_NAMESPACE
75 
76 /*!
77     Returns the type id for an enum property.
78 
79     Note that the property's value type can be retrieved using the
80     valueType() function (which is QVariant::Int for the enum property
81     type).
82 
83     \sa propertyType(), valueType()
84 */
85 int QtVariantPropertyManager::enumTypeId()
86 {
87     return qMetaTypeId<QtEnumPropertyType>();
88 }
89 
90 /*!
91     Returns the type id for a flag property.
92 
93     Note that the property's value type can be retrieved using the
94     valueType() function (which is QVariant::Int for the flag property
95     type).
96 
97     \sa propertyType(), valueType()
98 */
flagTypeId()99 int QtVariantPropertyManager::flagTypeId()
100 {
101     return qMetaTypeId<QtFlagPropertyType>();
102 }
103 
104 /*!
105     Returns the type id for a group property.
106 
107     Note that the property's value type can be retrieved using the
108     valueType() function (which is QVariant::Invalid for the group
109     property type, since it doesn't provide any value).
110 
111     \sa propertyType(), valueType()
112 */
groupTypeId()113 int QtVariantPropertyManager::groupTypeId()
114 {
115     return qMetaTypeId<QtGroupPropertyType>();
116 }
117 
118 /*!
119     Returns the type id for a icon map attribute.
120 
121     Note that the property's attribute type can be retrieved using the
122     attributeType() function.
123 
124     \sa attributeType(), QtEnumPropertyManager::enumIcons()
125 */
iconMapTypeId()126 int QtVariantPropertyManager::iconMapTypeId()
127 {
128     return qMetaTypeId<QtIconMap>();
129 }
130 
131 typedef QMap<const QtProperty *, QtProperty *> PropertyMap;
Q_GLOBAL_STATIC(PropertyMap,propertyToWrappedProperty)132 Q_GLOBAL_STATIC(PropertyMap, propertyToWrappedProperty)
133 
134 static QtProperty *wrappedProperty(QtProperty *property)
135 {
136     return propertyToWrappedProperty()->value(property, 0);
137 }
138 
139 class QtVariantPropertyPrivate
140 {
141 public:
QtVariantPropertyPrivate(QtVariantPropertyManager * m)142     QtVariantPropertyPrivate(QtVariantPropertyManager *m) : manager(m) {}
143 
144     QtVariantPropertyManager *manager;
145 };
146 
147 /*!
148     \class QtVariantProperty
149     \internal
150     \inmodule QtDesigner
151     \since 4.4
152 
153     \brief The QtVariantProperty class is a convenience class handling
154     QVariant based properties.
155 
156     QtVariantProperty provides additional API: A property's type,
157     value type, attribute values and current value can easily be
158     retrieved using the propertyType(), valueType(), attributeValue()
159     and value() functions respectively. In addition, the attribute
160     values and the current value can be set using the corresponding
161     setValue() and setAttribute() functions.
162 
163     For example, instead of writing:
164 
165     \snippet doc/src/snippets/code/tools_shared_qtpropertybrowser_qtvariantproperty.cpp 0
166 
167     you can write:
168 
169     \snippet doc/src/snippets/code/tools_shared_qtpropertybrowser_qtvariantproperty.cpp 1
170 
171     QtVariantProperty instances can only be created by the
172     QtVariantPropertyManager class.
173 
174     \sa QtProperty, QtVariantPropertyManager, QtVariantEditorFactory
175 */
176 
177 /*!
178     Creates a variant property using the given \a manager.
179 
180     Do not use this constructor to create variant property instances;
181     use the QtVariantPropertyManager::addProperty() function
182     instead.  This constructor is used internally by the
183     QtVariantPropertyManager::createProperty() function.
184 
185     \sa QtVariantPropertyManager
186 */
QtVariantProperty(QtVariantPropertyManager * manager)187 QtVariantProperty::QtVariantProperty(QtVariantPropertyManager *manager)
188     : QtProperty(manager), d_ptr(new QtVariantPropertyPrivate(manager))
189 {
190 }
191 
192 /*!
193     Destroys this property.
194 
195     \sa QtProperty::~QtProperty()
196 */
~QtVariantProperty()197 QtVariantProperty::~QtVariantProperty()
198 {
199 }
200 
201 /*!
202     Returns the property's current value.
203 
204     \sa valueType(), setValue()
205 */
value() const206 QVariant QtVariantProperty::value() const
207 {
208     return d_ptr->manager->value(this);
209 }
210 
211 /*!
212     Returns this property's value for the specified \a attribute.
213 
214     QtVariantPropertyManager provides a couple of related functions:
215     \l{QtVariantPropertyManager::attributes()}{attributes()} and
216     \l{QtVariantPropertyManager::attributeType()}{attributeType()}.
217 
218     \sa setAttribute()
219 */
attributeValue(const QString & attribute) const220 QVariant QtVariantProperty::attributeValue(const QString &attribute) const
221 {
222     return d_ptr->manager->attributeValue(this, attribute);
223 }
224 
225 /*!
226     Returns the type of this property's value.
227 
228     \sa propertyType()
229 */
valueType() const230 int QtVariantProperty::valueType() const
231 {
232     return d_ptr->manager->valueType(this);
233 }
234 
235 /*!
236     Returns this property's type.
237 
238     QtVariantPropertyManager provides several related functions:
239     \l{QtVariantPropertyManager::enumTypeId()}{enumTypeId()},
240     \l{QtVariantPropertyManager::flagTypeId()}{flagTypeId()} and
241     \l{QtVariantPropertyManager::groupTypeId()}{groupTypeId()}.
242 
243     \sa valueType()
244 */
propertyType() const245 int QtVariantProperty::propertyType() const
246 {
247     return d_ptr->manager->propertyType(this);
248 }
249 
250 /*!
251     Sets the value of this property to \a value.
252 
253     The specified \a value must be of the type returned by
254     valueType(), or of a type that can be converted to valueType()
255     using the QVariant::canConvert() function; otherwise this function
256     does nothing.
257 
258     \sa value()
259 */
setValue(const QVariant & value)260 void QtVariantProperty::setValue(const QVariant &value)
261 {
262     d_ptr->manager->setValue(this, value);
263 }
264 
265 /*!
266     Sets the \a attribute of property to \a value.
267 
268     QtVariantPropertyManager provides the related
269     \l{QtVariantPropertyManager::setAttribute()}{setAttribute()}
270     function.
271 
272     \sa attributeValue()
273 */
setAttribute(const QString & attribute,const QVariant & value)274 void QtVariantProperty::setAttribute(const QString &attribute, const QVariant &value)
275 {
276     d_ptr->manager->setAttribute(this, attribute, value);
277 }
278 
279 class QtVariantPropertyManagerPrivate
280 {
281     QtVariantPropertyManager *q_ptr;
282     Q_DECLARE_PUBLIC(QtVariantPropertyManager)
283 public:
284     QtVariantPropertyManagerPrivate();
285 
286     bool m_creatingProperty;
287     bool m_creatingSubProperties;
288     bool m_destroyingSubProperties;
289     int m_propertyType;
290 
291     void slotValueChanged(QtProperty *property, int val);
292     void slotRangeChanged(QtProperty *property, int min, int max);
293     void slotSingleStepChanged(QtProperty *property, int step);
294     void slotValueChanged(QtProperty *property, double val);
295     void slotRangeChanged(QtProperty *property, double min, double max);
296     void slotSingleStepChanged(QtProperty *property, double step);
297     void slotDecimalsChanged(QtProperty *property, int prec);
298     void slotValueChanged(QtProperty *property, bool val);
299     void slotValueChanged(QtProperty *property, const QString &val);
300     void slotRegExpChanged(QtProperty *property, const QRegExp &regExp);
301     void slotValueChanged(QtProperty *property, const QDate &val);
302     void slotRangeChanged(QtProperty *property, const QDate &min, const QDate &max);
303     void slotValueChanged(QtProperty *property, const QTime &val);
304     void slotValueChanged(QtProperty *property, const QDateTime &val);
305     void slotValueChanged(QtProperty *property, const QKeySequence &val);
306     void slotValueChanged(QtProperty *property, const QChar &val);
307     void slotValueChanged(QtProperty *property, const QLocale &val);
308     void slotValueChanged(QtProperty *property, const QPoint &val);
309     void slotValueChanged(QtProperty *property, const QPointF &val);
310     void slotValueChanged(QtProperty *property, const QSize &val);
311     void slotRangeChanged(QtProperty *property, const QSize &min, const QSize &max);
312     void slotValueChanged(QtProperty *property, const QSizeF &val);
313     void slotRangeChanged(QtProperty *property, const QSizeF &min, const QSizeF &max);
314     void slotValueChanged(QtProperty *property, const QRect &val);
315     void slotConstraintChanged(QtProperty *property, const QRect &val);
316     void slotValueChanged(QtProperty *property, const QRectF &val);
317     void slotConstraintChanged(QtProperty *property, const QRectF &val);
318     void slotValueChanged(QtProperty *property, const QColor &val);
319     void slotEnumChanged(QtProperty *property, int val);
320     void slotEnumNamesChanged(QtProperty *property, const QStringList &enumNames);
321     void slotEnumIconsChanged(QtProperty *property, const QMap<int, QIcon> &enumIcons);
322     void slotValueChanged(QtProperty *property, const QSizePolicy &val);
323     void slotValueChanged(QtProperty *property, const QFont &val);
324     void slotValueChanged(QtProperty *property, const QCursor &val);
325     void slotFlagChanged(QtProperty *property, int val);
326     void slotFlagNamesChanged(QtProperty *property, const QStringList &flagNames);
327     void slotPropertyInserted(QtProperty *property, QtProperty *parent, QtProperty *after);
328     void slotPropertyRemoved(QtProperty *property, QtProperty *parent);
329 
330     void valueChanged(QtProperty *property, const QVariant &val);
331 
332     int internalPropertyToType(QtProperty *property) const;
333     QtVariantProperty *createSubProperty(QtVariantProperty *parent, QtVariantProperty *after,
334             QtProperty *internal);
335     void removeSubProperty(QtVariantProperty *property);
336 
337     QMap<int, QtAbstractPropertyManager *> m_typeToPropertyManager;
338     QMap<int, QMap<QString, int> > m_typeToAttributeToAttributeType;
339 
340     QMap<const QtProperty *, QPair<QtVariantProperty *, int> > m_propertyToType;
341 
342     QMap<int, int> m_typeToValueType;
343 
344 
345     QMap<QtProperty *, QtVariantProperty *> m_internalToProperty;
346 
347     const QString m_constraintAttribute;
348     const QString m_singleStepAttribute;
349     const QString m_decimalsAttribute;
350     const QString m_enumIconsAttribute;
351     const QString m_enumNamesAttribute;
352     const QString m_flagNamesAttribute;
353     const QString m_maximumAttribute;
354     const QString m_minimumAttribute;
355     const QString m_regExpAttribute;
356 };
357 
QtVariantPropertyManagerPrivate()358 QtVariantPropertyManagerPrivate::QtVariantPropertyManagerPrivate() :
359     m_constraintAttribute(QLatin1String("constraint")),
360     m_singleStepAttribute(QLatin1String("singleStep")),
361     m_decimalsAttribute(QLatin1String("decimals")),
362     m_enumIconsAttribute(QLatin1String("enumIcons")),
363     m_enumNamesAttribute(QLatin1String("enumNames")),
364     m_flagNamesAttribute(QLatin1String("flagNames")),
365     m_maximumAttribute(QLatin1String("maximum")),
366     m_minimumAttribute(QLatin1String("minimum")),
367     m_regExpAttribute(QLatin1String("regExp"))
368 {
369 }
370 
internalPropertyToType(QtProperty * property) const371 int QtVariantPropertyManagerPrivate::internalPropertyToType(QtProperty *property) const
372 {
373     int type = 0;
374     QtAbstractPropertyManager *internPropertyManager = property->propertyManager();
375     if (qobject_cast<QtIntPropertyManager *>(internPropertyManager))
376         type = QVariant::Int;
377     else if (qobject_cast<QtEnumPropertyManager *>(internPropertyManager))
378         type = QtVariantPropertyManager::enumTypeId();
379     else if (qobject_cast<QtBoolPropertyManager *>(internPropertyManager))
380         type = QVariant::Bool;
381     else if (qobject_cast<QtDoublePropertyManager *>(internPropertyManager))
382         type = QVariant::Double;
383     return type;
384 }
385 
createSubProperty(QtVariantProperty * parent,QtVariantProperty * after,QtProperty * internal)386 QtVariantProperty *QtVariantPropertyManagerPrivate::createSubProperty(QtVariantProperty *parent,
387             QtVariantProperty *after, QtProperty *internal)
388 {
389     int type = internalPropertyToType(internal);
390     if (!type)
391         return 0;
392 
393     bool wasCreatingSubProperties = m_creatingSubProperties;
394     m_creatingSubProperties = true;
395 
396     QtVariantProperty *varChild = q_ptr->addProperty(type, internal->propertyName());
397 
398     m_creatingSubProperties = wasCreatingSubProperties;
399 
400     varChild->setPropertyName(internal->propertyName());
401     varChild->setToolTip(internal->toolTip());
402     varChild->setStatusTip(internal->statusTip());
403     varChild->setWhatsThis(internal->whatsThis());
404 
405     parent->insertSubProperty(varChild, after);
406 
407     m_internalToProperty[internal] = varChild;
408     propertyToWrappedProperty()->insert(varChild, internal);
409     return varChild;
410 }
411 
removeSubProperty(QtVariantProperty * property)412 void QtVariantPropertyManagerPrivate::removeSubProperty(QtVariantProperty *property)
413 {
414     QtProperty *internChild = wrappedProperty(property);
415     bool wasDestroyingSubProperties = m_destroyingSubProperties;
416     m_destroyingSubProperties = true;
417     delete property;
418     m_destroyingSubProperties = wasDestroyingSubProperties;
419     m_internalToProperty.remove(internChild);
420     propertyToWrappedProperty()->remove(property);
421 }
422 
slotPropertyInserted(QtProperty * property,QtProperty * parent,QtProperty * after)423 void QtVariantPropertyManagerPrivate::slotPropertyInserted(QtProperty *property,
424             QtProperty *parent, QtProperty *after)
425 {
426     if (m_creatingProperty)
427         return;
428 
429     QtVariantProperty *varParent = m_internalToProperty.value(parent, 0);
430     if (!varParent)
431         return;
432 
433     QtVariantProperty *varAfter = 0;
434     if (after) {
435         varAfter = m_internalToProperty.value(after, 0);
436         if (!varAfter)
437             return;
438     }
439 
440     createSubProperty(varParent, varAfter, property);
441 }
442 
slotPropertyRemoved(QtProperty * property,QtProperty * parent)443 void QtVariantPropertyManagerPrivate::slotPropertyRemoved(QtProperty *property, QtProperty *parent)
444 {
445     Q_UNUSED(parent);
446 
447     QtVariantProperty *varProperty = m_internalToProperty.value(property, 0);
448     if (!varProperty)
449         return;
450 
451     removeSubProperty(varProperty);
452 }
453 
valueChanged(QtProperty * property,const QVariant & val)454 void QtVariantPropertyManagerPrivate::valueChanged(QtProperty *property, const QVariant &val)
455 {
456     QtVariantProperty *varProp = m_internalToProperty.value(property, 0);
457     if (!varProp)
458         return;
459     emit q_ptr->valueChanged(varProp, val);
460     emit q_ptr->propertyChanged(varProp);
461 }
462 
slotValueChanged(QtProperty * property,int val)463 void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, int val)
464 {
465     valueChanged(property, QVariant(val));
466 }
467 
slotRangeChanged(QtProperty * property,int min,int max)468 void QtVariantPropertyManagerPrivate::slotRangeChanged(QtProperty *property, int min, int max)
469 {
470     if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0)) {
471         emit q_ptr->attributeChanged(varProp, m_minimumAttribute, QVariant(min));
472         emit q_ptr->attributeChanged(varProp, m_maximumAttribute, QVariant(max));
473     }
474 }
475 
slotSingleStepChanged(QtProperty * property,int step)476 void QtVariantPropertyManagerPrivate::slotSingleStepChanged(QtProperty *property, int step)
477 {
478     if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0))
479         emit q_ptr->attributeChanged(varProp, m_singleStepAttribute, QVariant(step));
480 }
481 
slotValueChanged(QtProperty * property,double val)482 void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, double val)
483 {
484     valueChanged(property, QVariant(val));
485 }
486 
slotRangeChanged(QtProperty * property,double min,double max)487 void QtVariantPropertyManagerPrivate::slotRangeChanged(QtProperty *property, double min, double max)
488 {
489     if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0)) {
490         emit q_ptr->attributeChanged(varProp, m_minimumAttribute, QVariant(min));
491         emit q_ptr->attributeChanged(varProp, m_maximumAttribute, QVariant(max));
492     }
493 }
494 
slotSingleStepChanged(QtProperty * property,double step)495 void QtVariantPropertyManagerPrivate::slotSingleStepChanged(QtProperty *property, double step)
496 {
497     if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0))
498         emit q_ptr->attributeChanged(varProp, m_singleStepAttribute, QVariant(step));
499 }
500 
slotDecimalsChanged(QtProperty * property,int prec)501 void QtVariantPropertyManagerPrivate::slotDecimalsChanged(QtProperty *property, int prec)
502 {
503     if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0))
504         emit q_ptr->attributeChanged(varProp, m_decimalsAttribute, QVariant(prec));
505 }
506 
slotValueChanged(QtProperty * property,bool val)507 void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, bool val)
508 {
509     valueChanged(property, QVariant(val));
510 }
511 
slotValueChanged(QtProperty * property,const QString & val)512 void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QString &val)
513 {
514     valueChanged(property, QVariant(val));
515 }
516 
slotRegExpChanged(QtProperty * property,const QRegExp & regExp)517 void QtVariantPropertyManagerPrivate::slotRegExpChanged(QtProperty *property, const QRegExp &regExp)
518 {
519     if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0))
520         emit q_ptr->attributeChanged(varProp, m_regExpAttribute, QVariant(regExp));
521 }
522 
slotValueChanged(QtProperty * property,const QDate & val)523 void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QDate &val)
524 {
525     valueChanged(property, QVariant(val));
526 }
527 
slotRangeChanged(QtProperty * property,const QDate & min,const QDate & max)528 void QtVariantPropertyManagerPrivate::slotRangeChanged(QtProperty *property, const QDate &min, const QDate &max)
529 {
530     if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0)) {
531         emit q_ptr->attributeChanged(varProp, m_minimumAttribute, QVariant(min));
532         emit q_ptr->attributeChanged(varProp, m_maximumAttribute, QVariant(max));
533     }
534 }
535 
slotValueChanged(QtProperty * property,const QTime & val)536 void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QTime &val)
537 {
538     valueChanged(property, QVariant(val));
539 }
540 
slotValueChanged(QtProperty * property,const QDateTime & val)541 void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QDateTime &val)
542 {
543     valueChanged(property, QVariant(val));
544 }
545 
slotValueChanged(QtProperty * property,const QKeySequence & val)546 void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QKeySequence &val)
547 {
548     QVariant v;
549     v.setValue(val);
550     valueChanged(property, v);
551 }
552 
slotValueChanged(QtProperty * property,const QChar & val)553 void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QChar &val)
554 {
555     valueChanged(property, QVariant(val));
556 }
557 
slotValueChanged(QtProperty * property,const QLocale & val)558 void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QLocale &val)
559 {
560     valueChanged(property, QVariant(val));
561 }
562 
slotValueChanged(QtProperty * property,const QPoint & val)563 void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QPoint &val)
564 {
565     valueChanged(property, QVariant(val));
566 }
567 
slotValueChanged(QtProperty * property,const QPointF & val)568 void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QPointF &val)
569 {
570     valueChanged(property, QVariant(val));
571 }
572 
slotValueChanged(QtProperty * property,const QSize & val)573 void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QSize &val)
574 {
575     valueChanged(property, QVariant(val));
576 }
577 
slotRangeChanged(QtProperty * property,const QSize & min,const QSize & max)578 void QtVariantPropertyManagerPrivate::slotRangeChanged(QtProperty *property, const QSize &min, const QSize &max)
579 {
580     if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0)) {
581         emit q_ptr->attributeChanged(varProp, m_minimumAttribute, QVariant(min));
582         emit q_ptr->attributeChanged(varProp, m_maximumAttribute, QVariant(max));
583     }
584 }
585 
slotValueChanged(QtProperty * property,const QSizeF & val)586 void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QSizeF &val)
587 {
588     valueChanged(property, QVariant(val));
589 }
590 
slotRangeChanged(QtProperty * property,const QSizeF & min,const QSizeF & max)591 void QtVariantPropertyManagerPrivate::slotRangeChanged(QtProperty *property, const QSizeF &min, const QSizeF &max)
592 {
593     if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0)) {
594         emit q_ptr->attributeChanged(varProp, m_minimumAttribute, QVariant(min));
595         emit q_ptr->attributeChanged(varProp, m_maximumAttribute, QVariant(max));
596     }
597 }
598 
slotValueChanged(QtProperty * property,const QRect & val)599 void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QRect &val)
600 {
601     valueChanged(property, QVariant(val));
602 }
603 
slotConstraintChanged(QtProperty * property,const QRect & constraint)604 void QtVariantPropertyManagerPrivate::slotConstraintChanged(QtProperty *property, const QRect &constraint)
605 {
606     if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0))
607         emit q_ptr->attributeChanged(varProp, m_constraintAttribute, QVariant(constraint));
608 }
609 
slotValueChanged(QtProperty * property,const QRectF & val)610 void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QRectF &val)
611 {
612     valueChanged(property, QVariant(val));
613 }
614 
slotConstraintChanged(QtProperty * property,const QRectF & constraint)615 void QtVariantPropertyManagerPrivate::slotConstraintChanged(QtProperty *property, const QRectF &constraint)
616 {
617     if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0))
618         emit q_ptr->attributeChanged(varProp, m_constraintAttribute, QVariant(constraint));
619 }
620 
slotValueChanged(QtProperty * property,const QColor & val)621 void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QColor &val)
622 {
623     valueChanged(property, QVariant(val));
624 }
625 
slotEnumNamesChanged(QtProperty * property,const QStringList & enumNames)626 void QtVariantPropertyManagerPrivate::slotEnumNamesChanged(QtProperty *property, const QStringList &enumNames)
627 {
628     if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0))
629         emit q_ptr->attributeChanged(varProp, m_enumNamesAttribute, QVariant(enumNames));
630 }
631 
slotEnumIconsChanged(QtProperty * property,const QMap<int,QIcon> & enumIcons)632 void QtVariantPropertyManagerPrivate::slotEnumIconsChanged(QtProperty *property, const QMap<int, QIcon> &enumIcons)
633 {
634     if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0)) {
635         QVariant v;
636         v.setValue(enumIcons);
637         emit q_ptr->attributeChanged(varProp, m_enumIconsAttribute, v);
638     }
639 }
640 
slotValueChanged(QtProperty * property,const QSizePolicy & val)641 void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QSizePolicy &val)
642 {
643     valueChanged(property, QVariant(val));
644 }
645 
slotValueChanged(QtProperty * property,const QFont & val)646 void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QFont &val)
647 {
648     valueChanged(property, QVariant(val));
649 }
650 
slotValueChanged(QtProperty * property,const QCursor & val)651 void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QCursor &val)
652 {
653 #ifndef QT_NO_CURSOR
654     valueChanged(property, QVariant(val));
655 #endif
656 }
657 
slotFlagNamesChanged(QtProperty * property,const QStringList & flagNames)658 void QtVariantPropertyManagerPrivate::slotFlagNamesChanged(QtProperty *property, const QStringList &flagNames)
659 {
660     if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0))
661         emit q_ptr->attributeChanged(varProp, m_flagNamesAttribute, QVariant(flagNames));
662 }
663 
664 /*!
665     \class QtVariantPropertyManager
666     \internal
667     \inmodule QtDesigner
668     \since 4.4
669 
670     \brief The QtVariantPropertyManager class provides and manages QVariant based properties.
671 
672     QtVariantPropertyManager provides the addProperty() function which
673     creates QtVariantProperty objects. The QtVariantProperty class is
674     a convenience class handling QVariant based properties inheriting
675     QtProperty. A QtProperty object created by a
676     QtVariantPropertyManager instance can be converted into a
677     QtVariantProperty object using the variantProperty() function.
678 
679     The property's value can be retrieved using the value(), and set
680     using the setValue() slot. In addition the property's type, and
681     the type of its value, can be retrieved using the propertyType()
682     and valueType() functions respectively.
683 
684     A property's type is a QVariant::Type enumerator value, and
685     usually a property's type is the same as its value type. But for
686     some properties the types differ, for example for enums, flags and
687     group types in which case QtVariantPropertyManager provides the
688     enumTypeId(), flagTypeId() and groupTypeId() functions,
689     respectively, to identify their property type (the value types are
690     QVariant::Int for the enum and flag types, and QVariant::Invalid
691     for the group type).
692 
693     Use the isPropertyTypeSupported() function to check if a particular
694     property type is supported. The currently supported property types
695     are:
696 
697     \table
698     \header
699         \li Property Type
700         \li Property Type Id
701     \row
702         \li int
703         \li QVariant::Int
704     \row
705         \li double
706         \li QVariant::Double
707     \row
708         \li bool
709         \li QVariant::Bool
710     \row
711         \li QString
712         \li QVariant::String
713     \row
714         \li QDate
715         \li QVariant::Date
716     \row
717         \li QTime
718         \li QVariant::Time
719     \row
720         \li QDateTime
721         \li QVariant::DateTime
722     \row
723         \li QKeySequence
724         \li QVariant::KeySequence
725     \row
726         \li QChar
727         \li QVariant::Char
728     \row
729         \li QLocale
730         \li QVariant::Locale
731     \row
732         \li QPoint
733         \li QVariant::Point
734     \row
735         \li QPointF
736         \li QVariant::PointF
737     \row
738         \li QSize
739         \li QVariant::Size
740     \row
741         \li QSizeF
742         \li QVariant::SizeF
743     \row
744         \li QRect
745         \li QVariant::Rect
746     \row
747         \li QRectF
748         \li QVariant::RectF
749     \row
750         \li QColor
751         \li QVariant::Color
752     \row
753         \li QSizePolicy
754         \li QVariant::SizePolicy
755     \row
756         \li QFont
757         \li QVariant::Font
758     \row
759         \li QCursor
760         \li QVariant::Cursor
761     \row
762         \li enum
763         \li enumTypeId()
764     \row
765         \li flag
766         \li flagTypeId()
767     \row
768         \li group
769         \li groupTypeId()
770     \endtable
771 
772     Each property type can provide additional attributes,
773     e.g. QVariant::Int and QVariant::Double provides minimum and
774     maximum values. The currently supported attributes are:
775 
776     \table
777     \header
778         \li Property Type
779         \li Attribute Name
780         \li Attribute Type
781     \row
782         \li \c int
783         \li minimum
784         \li QVariant::Int
785     \row
786         \li
787         \li maximum
788         \li QVariant::Int
789     \row
790         \li
791         \li singleStep
792         \li QVariant::Int
793     \row
794         \li \c double
795         \li minimum
796         \li QVariant::Double
797     \row
798         \li
799         \li maximum
800         \li QVariant::Double
801     \row
802         \li
803         \li singleStep
804         \li QVariant::Double
805     \row
806         \li
807         \li decimals
808         \li QVariant::Int
809     \row
810         \li QString
811         \li regExp
812         \li QVariant::RegExp
813     \row
814         \li QDate
815         \li minimum
816         \li QVariant::Date
817     \row
818         \li
819         \li maximum
820         \li QVariant::Date
821     \row
822         \li QPointF
823         \li decimals
824         \li QVariant::Int
825     \row
826         \li QSize
827         \li minimum
828         \li QVariant::Size
829     \row
830         \li
831         \li maximum
832         \li QVariant::Size
833     \row
834         \li QSizeF
835         \li minimum
836         \li QVariant::SizeF
837     \row
838         \li
839         \li maximum
840         \li QVariant::SizeF
841     \row
842         \li
843         \li decimals
844         \li QVariant::Int
845     \row
846         \li QRect
847         \li constraint
848         \li QVariant::Rect
849     \row
850         \li QRectF
851         \li constraint
852         \li QVariant::RectF
853     \row
854         \li
855         \li decimals
856         \li QVariant::Int
857     \row
858         \li \c enum
859         \li enumNames
860         \li QVariant::StringList
861     \row
862         \li
863         \li enumIcons
864         \li iconMapTypeId()
865     \row
866         \li \c flag
867         \li flagNames
868         \li QVariant::StringList
869     \endtable
870 
871     The attributes for a given property type can be retrieved using
872     the attributes() function. Each attribute has a value type which
873     can be retrieved using the attributeType() function, and a value
874     accessible through the attributeValue() function. In addition, the
875     value can be set using the setAttribute() slot.
876 
877     QtVariantManager also provides the valueChanged() signal which is
878     emitted whenever a property created by this manager change, and
879     the attributeChanged() signal which is emitted whenever an
880     attribute of such a property changes.
881 
882     \sa QtVariantProperty, QtVariantEditorFactory
883 */
884 
885 /*!
886     \fn void QtVariantPropertyManager::valueChanged(QtProperty *property, const QVariant &value)
887 
888     This signal is emitted whenever a property created by this manager
889     changes its value, passing a pointer to the \a property and the
890     new \a value as parameters.
891 
892     \sa setValue()
893 */
894 
895 /*!
896     \fn void QtVariantPropertyManager::attributeChanged(QtProperty *property,
897                 const QString &attribute, const QVariant &value)
898 
899     This signal is emitted whenever an attribute of a property created
900     by this manager changes its value, passing a pointer to the \a
901     property, the \a attribute and the new \a value as parameters.
902 
903     \sa setAttribute()
904 */
905 
906 /*!
907     Creates a manager with the given \a parent.
908 */
QtVariantPropertyManager(QObject * parent)909 QtVariantPropertyManager::QtVariantPropertyManager(QObject *parent)
910     : QtAbstractPropertyManager(parent), d_ptr(new QtVariantPropertyManagerPrivate)
911 {
912     d_ptr->q_ptr = this;
913 
914     d_ptr->m_creatingProperty = false;
915     d_ptr->m_creatingSubProperties = false;
916     d_ptr->m_destroyingSubProperties = false;
917     d_ptr->m_propertyType = 0;
918 
919     // IntPropertyManager
920     QtIntPropertyManager *intPropertyManager = new QtIntPropertyManager(this);
921     d_ptr->m_typeToPropertyManager[QVariant::Int] = intPropertyManager;
922     d_ptr->m_typeToAttributeToAttributeType[QVariant::Int][d_ptr->m_minimumAttribute] = QVariant::Int;
923     d_ptr->m_typeToAttributeToAttributeType[QVariant::Int][d_ptr->m_maximumAttribute] = QVariant::Int;
924     d_ptr->m_typeToAttributeToAttributeType[QVariant::Int][d_ptr->m_singleStepAttribute] = QVariant::Int;
925     d_ptr->m_typeToValueType[QVariant::Int] = QVariant::Int;
926     connect(intPropertyManager, SIGNAL(valueChanged(QtProperty*,int)),
927                 this, SLOT(slotValueChanged(QtProperty*,int)));
928     connect(intPropertyManager, SIGNAL(rangeChanged(QtProperty*,int,int)),
929                 this, SLOT(slotRangeChanged(QtProperty*,int,int)));
930     connect(intPropertyManager, SIGNAL(singleStepChanged(QtProperty*,int)),
931                 this, SLOT(slotSingleStepChanged(QtProperty*,int)));
932     // DoublePropertyManager
933     QtDoublePropertyManager *doublePropertyManager = new QtDoublePropertyManager(this);
934     d_ptr->m_typeToPropertyManager[QVariant::Double] = doublePropertyManager;
935     d_ptr->m_typeToAttributeToAttributeType[QVariant::Double][d_ptr->m_minimumAttribute] =
936             QVariant::Double;
937     d_ptr->m_typeToAttributeToAttributeType[QVariant::Double][d_ptr->m_maximumAttribute] =
938             QVariant::Double;
939     d_ptr->m_typeToAttributeToAttributeType[QVariant::Double][d_ptr->m_singleStepAttribute] =
940             QVariant::Double;
941     d_ptr->m_typeToAttributeToAttributeType[QVariant::Double][d_ptr->m_decimalsAttribute] =
942             QVariant::Int;
943     d_ptr->m_typeToValueType[QVariant::Double] = QVariant::Double;
944     connect(doublePropertyManager, SIGNAL(valueChanged(QtProperty*,double)),
945                 this, SLOT(slotValueChanged(QtProperty*,double)));
946     connect(doublePropertyManager, SIGNAL(rangeChanged(QtProperty*,double,double)),
947                 this, SLOT(slotRangeChanged(QtProperty*,double,double)));
948     connect(doublePropertyManager, SIGNAL(singleStepChanged(QtProperty*,double)),
949                 this, SLOT(slotSingleStepChanged(QtProperty*,double)));
950     connect(doublePropertyManager, SIGNAL(decimalsChanged(QtProperty*,int)),
951                 this, SLOT(slotDecimalsChanged(QtProperty*,int)));
952     // BoolPropertyManager
953     QtBoolPropertyManager *boolPropertyManager = new QtBoolPropertyManager(this);
954     d_ptr->m_typeToPropertyManager[QVariant::Bool] = boolPropertyManager;
955     d_ptr->m_typeToValueType[QVariant::Bool] = QVariant::Bool;
956     connect(boolPropertyManager, SIGNAL(valueChanged(QtProperty*,bool)),
957                 this, SLOT(slotValueChanged(QtProperty*,bool)));
958     // StringPropertyManager
959     QtStringPropertyManager *stringPropertyManager = new QtStringPropertyManager(this);
960     d_ptr->m_typeToPropertyManager[QVariant::String] = stringPropertyManager;
961     d_ptr->m_typeToValueType[QVariant::String] = QVariant::String;
962     d_ptr->m_typeToAttributeToAttributeType[QVariant::String][d_ptr->m_regExpAttribute] =
963             QVariant::RegExp;
964     connect(stringPropertyManager, SIGNAL(valueChanged(QtProperty*,QString)),
965                 this, SLOT(slotValueChanged(QtProperty*,QString)));
966     connect(stringPropertyManager, SIGNAL(regExpChanged(QtProperty*,QRegExp)),
967                 this, SLOT(slotRegExpChanged(QtProperty*,QRegExp)));
968     // DatePropertyManager
969     QtDatePropertyManager *datePropertyManager = new QtDatePropertyManager(this);
970     d_ptr->m_typeToPropertyManager[QVariant::Date] = datePropertyManager;
971     d_ptr->m_typeToValueType[QVariant::Date] = QVariant::Date;
972     d_ptr->m_typeToAttributeToAttributeType[QVariant::Date][d_ptr->m_minimumAttribute] =
973             QVariant::Date;
974     d_ptr->m_typeToAttributeToAttributeType[QVariant::Date][d_ptr->m_maximumAttribute] =
975             QVariant::Date;
976     connect(datePropertyManager, SIGNAL(valueChanged(QtProperty*,QDate)),
977                 this, SLOT(slotValueChanged(QtProperty*,QDate)));
978     connect(datePropertyManager, SIGNAL(rangeChanged(QtProperty*,QDate,QDate)),
979                 this, SLOT(slotRangeChanged(QtProperty*,QDate,QDate)));
980     // TimePropertyManager
981     QtTimePropertyManager *timePropertyManager = new QtTimePropertyManager(this);
982     d_ptr->m_typeToPropertyManager[QVariant::Time] = timePropertyManager;
983     d_ptr->m_typeToValueType[QVariant::Time] = QVariant::Time;
984     connect(timePropertyManager, SIGNAL(valueChanged(QtProperty*,QTime)),
985                 this, SLOT(slotValueChanged(QtProperty*,QTime)));
986     // DateTimePropertyManager
987     QtDateTimePropertyManager *dateTimePropertyManager = new QtDateTimePropertyManager(this);
988     d_ptr->m_typeToPropertyManager[QVariant::DateTime] = dateTimePropertyManager;
989     d_ptr->m_typeToValueType[QVariant::DateTime] = QVariant::DateTime;
990     connect(dateTimePropertyManager, SIGNAL(valueChanged(QtProperty*,QDateTime)),
991                 this, SLOT(slotValueChanged(QtProperty*,QDateTime)));
992     // KeySequencePropertyManager
993     QtKeySequencePropertyManager *keySequencePropertyManager = new QtKeySequencePropertyManager(this);
994     d_ptr->m_typeToPropertyManager[QVariant::KeySequence] = keySequencePropertyManager;
995     d_ptr->m_typeToValueType[QVariant::KeySequence] = QVariant::KeySequence;
996     connect(keySequencePropertyManager, SIGNAL(valueChanged(QtProperty*,QKeySequence)),
997                 this, SLOT(slotValueChanged(QtProperty*,QKeySequence)));
998     // CharPropertyManager
999     QtCharPropertyManager *charPropertyManager = new QtCharPropertyManager(this);
1000     d_ptr->m_typeToPropertyManager[QVariant::Char] = charPropertyManager;
1001     d_ptr->m_typeToValueType[QVariant::Char] = QVariant::Char;
1002     connect(charPropertyManager, SIGNAL(valueChanged(QtProperty*,QChar)),
1003                 this, SLOT(slotValueChanged(QtProperty*,QChar)));
1004     // LocalePropertyManager
1005     QtLocalePropertyManager *localePropertyManager = new QtLocalePropertyManager(this);
1006     d_ptr->m_typeToPropertyManager[QVariant::Locale] = localePropertyManager;
1007     d_ptr->m_typeToValueType[QVariant::Locale] = QVariant::Locale;
1008     connect(localePropertyManager, SIGNAL(valueChanged(QtProperty*,QLocale)),
1009                 this, SLOT(slotValueChanged(QtProperty*,QLocale)));
1010     connect(localePropertyManager->subEnumPropertyManager(), SIGNAL(valueChanged(QtProperty*,int)),
1011                 this, SLOT(slotValueChanged(QtProperty*,int)));
1012     connect(localePropertyManager, SIGNAL(propertyInserted(QtProperty*,QtProperty*,QtProperty*)),
1013                 this, SLOT(slotPropertyInserted(QtProperty*,QtProperty*,QtProperty*)));
1014     connect(localePropertyManager, SIGNAL(propertyRemoved(QtProperty*,QtProperty*)),
1015                 this, SLOT(slotPropertyRemoved(QtProperty*,QtProperty*)));
1016     // PointPropertyManager
1017     QtPointPropertyManager *pointPropertyManager = new QtPointPropertyManager(this);
1018     d_ptr->m_typeToPropertyManager[QVariant::Point] = pointPropertyManager;
1019     d_ptr->m_typeToValueType[QVariant::Point] = QVariant::Point;
1020     connect(pointPropertyManager, SIGNAL(valueChanged(QtProperty*,QPoint)),
1021                 this, SLOT(slotValueChanged(QtProperty*,QPoint)));
1022     connect(pointPropertyManager->subIntPropertyManager(), SIGNAL(valueChanged(QtProperty*,int)),
1023                 this, SLOT(slotValueChanged(QtProperty*,int)));
1024     connect(pointPropertyManager, SIGNAL(propertyInserted(QtProperty*,QtProperty*,QtProperty*)),
1025                 this, SLOT(slotPropertyInserted(QtProperty*,QtProperty*,QtProperty*)));
1026     connect(pointPropertyManager, SIGNAL(propertyRemoved(QtProperty*,QtProperty*)),
1027                 this, SLOT(slotPropertyRemoved(QtProperty*,QtProperty*)));
1028     // PointFPropertyManager
1029     QtPointFPropertyManager *pointFPropertyManager = new QtPointFPropertyManager(this);
1030     d_ptr->m_typeToPropertyManager[QVariant::PointF] = pointFPropertyManager;
1031     d_ptr->m_typeToValueType[QVariant::PointF] = QVariant::PointF;
1032     d_ptr->m_typeToAttributeToAttributeType[QVariant::PointF][d_ptr->m_decimalsAttribute] =
1033             QVariant::Int;
1034     connect(pointFPropertyManager, SIGNAL(valueChanged(QtProperty*,QPointF)),
1035                 this, SLOT(slotValueChanged(QtProperty*,QPointF)));
1036     connect(pointFPropertyManager, SIGNAL(decimalsChanged(QtProperty*,int)),
1037                 this, SLOT(slotDecimalsChanged(QtProperty*,int)));
1038     connect(pointFPropertyManager->subDoublePropertyManager(), SIGNAL(valueChanged(QtProperty*,double)),
1039                 this, SLOT(slotValueChanged(QtProperty*,double)));
1040     connect(pointFPropertyManager, SIGNAL(propertyInserted(QtProperty*,QtProperty*,QtProperty*)),
1041                 this, SLOT(slotPropertyInserted(QtProperty*,QtProperty*,QtProperty*)));
1042     connect(pointFPropertyManager, SIGNAL(propertyRemoved(QtProperty*,QtProperty*)),
1043                 this, SLOT(slotPropertyRemoved(QtProperty*,QtProperty*)));
1044     // SizePropertyManager
1045     QtSizePropertyManager *sizePropertyManager = new QtSizePropertyManager(this);
1046     d_ptr->m_typeToPropertyManager[QVariant::Size] = sizePropertyManager;
1047     d_ptr->m_typeToValueType[QVariant::Size] = QVariant::Size;
1048     d_ptr->m_typeToAttributeToAttributeType[QVariant::Size][d_ptr->m_minimumAttribute] =
1049             QVariant::Size;
1050     d_ptr->m_typeToAttributeToAttributeType[QVariant::Size][d_ptr->m_maximumAttribute] =
1051             QVariant::Size;
1052     connect(sizePropertyManager, SIGNAL(valueChanged(QtProperty*,QSize)),
1053                 this, SLOT(slotValueChanged(QtProperty*,QSize)));
1054     connect(sizePropertyManager, SIGNAL(rangeChanged(QtProperty*,QSize,QSize)),
1055                 this, SLOT(slotRangeChanged(QtProperty*,QSize,QSize)));
1056     connect(sizePropertyManager->subIntPropertyManager(), SIGNAL(valueChanged(QtProperty*,int)),
1057                 this, SLOT(slotValueChanged(QtProperty*,int)));
1058     connect(sizePropertyManager->subIntPropertyManager(), SIGNAL(rangeChanged(QtProperty*,int,int)),
1059                 this, SLOT(slotRangeChanged(QtProperty*,int,int)));
1060     connect(sizePropertyManager, SIGNAL(propertyInserted(QtProperty*,QtProperty*,QtProperty*)),
1061                 this, SLOT(slotPropertyInserted(QtProperty*,QtProperty*,QtProperty*)));
1062     connect(sizePropertyManager, SIGNAL(propertyRemoved(QtProperty*,QtProperty*)),
1063                 this, SLOT(slotPropertyRemoved(QtProperty*,QtProperty*)));
1064     // SizeFPropertyManager
1065     QtSizeFPropertyManager *sizeFPropertyManager = new QtSizeFPropertyManager(this);
1066     d_ptr->m_typeToPropertyManager[QVariant::SizeF] = sizeFPropertyManager;
1067     d_ptr->m_typeToValueType[QVariant::SizeF] = QVariant::SizeF;
1068     d_ptr->m_typeToAttributeToAttributeType[QVariant::SizeF][d_ptr->m_minimumAttribute] =
1069             QVariant::SizeF;
1070     d_ptr->m_typeToAttributeToAttributeType[QVariant::SizeF][d_ptr->m_maximumAttribute] =
1071             QVariant::SizeF;
1072     d_ptr->m_typeToAttributeToAttributeType[QVariant::SizeF][d_ptr->m_decimalsAttribute] =
1073             QVariant::Int;
1074     connect(sizeFPropertyManager, SIGNAL(valueChanged(QtProperty*,QSizeF)),
1075                 this, SLOT(slotValueChanged(QtProperty*,QSizeF)));
1076     connect(sizeFPropertyManager, SIGNAL(rangeChanged(QtProperty*,QSizeF,QSizeF)),
1077                 this, SLOT(slotRangeChanged(QtProperty*,QSizeF,QSizeF)));
1078     connect(sizeFPropertyManager, SIGNAL(decimalsChanged(QtProperty*,int)),
1079                 this, SLOT(slotDecimalsChanged(QtProperty*,int)));
1080     connect(sizeFPropertyManager->subDoublePropertyManager(), SIGNAL(valueChanged(QtProperty*,double)),
1081                 this, SLOT(slotValueChanged(QtProperty*,double)));
1082     connect(sizeFPropertyManager->subDoublePropertyManager(), SIGNAL(rangeChanged(QtProperty*,double,double)),
1083                 this, SLOT(slotRangeChanged(QtProperty*,double,double)));
1084     connect(sizeFPropertyManager, SIGNAL(propertyInserted(QtProperty*,QtProperty*,QtProperty*)),
1085                 this, SLOT(slotPropertyInserted(QtProperty*,QtProperty*,QtProperty*)));
1086     connect(sizeFPropertyManager, SIGNAL(propertyRemoved(QtProperty*,QtProperty*)),
1087                 this, SLOT(slotPropertyRemoved(QtProperty*,QtProperty*)));
1088     // RectPropertyManager
1089     QtRectPropertyManager *rectPropertyManager = new QtRectPropertyManager(this);
1090     d_ptr->m_typeToPropertyManager[QVariant::Rect] = rectPropertyManager;
1091     d_ptr->m_typeToValueType[QVariant::Rect] = QVariant::Rect;
1092     d_ptr->m_typeToAttributeToAttributeType[QVariant::Rect][d_ptr->m_constraintAttribute] =
1093             QVariant::Rect;
1094     connect(rectPropertyManager, SIGNAL(valueChanged(QtProperty*,QRect)),
1095                 this, SLOT(slotValueChanged(QtProperty*,QRect)));
1096     connect(rectPropertyManager, SIGNAL(constraintChanged(QtProperty*,QRect)),
1097                 this, SLOT(slotConstraintChanged(QtProperty*,QRect)));
1098     connect(rectPropertyManager->subIntPropertyManager(), SIGNAL(valueChanged(QtProperty*,int)),
1099                 this, SLOT(slotValueChanged(QtProperty*,int)));
1100     connect(rectPropertyManager->subIntPropertyManager(), SIGNAL(rangeChanged(QtProperty*,int,int)),
1101                 this, SLOT(slotRangeChanged(QtProperty*,int,int)));
1102     connect(rectPropertyManager, SIGNAL(propertyInserted(QtProperty*,QtProperty*,QtProperty*)),
1103                 this, SLOT(slotPropertyInserted(QtProperty*,QtProperty*,QtProperty*)));
1104     connect(rectPropertyManager, SIGNAL(propertyRemoved(QtProperty*,QtProperty*)),
1105                 this, SLOT(slotPropertyRemoved(QtProperty*,QtProperty*)));
1106     // RectFPropertyManager
1107     QtRectFPropertyManager *rectFPropertyManager = new QtRectFPropertyManager(this);
1108     d_ptr->m_typeToPropertyManager[QVariant::RectF] = rectFPropertyManager;
1109     d_ptr->m_typeToValueType[QVariant::RectF] = QVariant::RectF;
1110     d_ptr->m_typeToAttributeToAttributeType[QVariant::RectF][d_ptr->m_constraintAttribute] =
1111             QVariant::RectF;
1112     d_ptr->m_typeToAttributeToAttributeType[QVariant::RectF][d_ptr->m_decimalsAttribute] =
1113             QVariant::Int;
1114     connect(rectFPropertyManager, SIGNAL(valueChanged(QtProperty*,QRectF)),
1115                 this, SLOT(slotValueChanged(QtProperty*,QRectF)));
1116     connect(rectFPropertyManager, SIGNAL(constraintChanged(QtProperty*,QRectF)),
1117                 this, SLOT(slotConstraintChanged(QtProperty*,QRectF)));
1118     connect(rectFPropertyManager, SIGNAL(decimalsChanged(QtProperty*,int)),
1119                 this, SLOT(slotDecimalsChanged(QtProperty*,int)));
1120     connect(rectFPropertyManager->subDoublePropertyManager(), SIGNAL(valueChanged(QtProperty*,double)),
1121                 this, SLOT(slotValueChanged(QtProperty*,double)));
1122     connect(rectFPropertyManager->subDoublePropertyManager(), SIGNAL(rangeChanged(QtProperty*,double,double)),
1123                 this, SLOT(slotRangeChanged(QtProperty*,double,double)));
1124     connect(rectFPropertyManager, SIGNAL(propertyInserted(QtProperty*,QtProperty*,QtProperty*)),
1125                 this, SLOT(slotPropertyInserted(QtProperty*,QtProperty*,QtProperty*)));
1126     connect(rectFPropertyManager, SIGNAL(propertyRemoved(QtProperty*,QtProperty*)),
1127                 this, SLOT(slotPropertyRemoved(QtProperty*,QtProperty*)));
1128     // ColorPropertyManager
1129     QtColorPropertyManager *colorPropertyManager = new QtColorPropertyManager(this);
1130     d_ptr->m_typeToPropertyManager[QVariant::Color] = colorPropertyManager;
1131     d_ptr->m_typeToValueType[QVariant::Color] = QVariant::Color;
1132     connect(colorPropertyManager, SIGNAL(valueChanged(QtProperty*,QColor)),
1133                 this, SLOT(slotValueChanged(QtProperty*,QColor)));
1134     connect(colorPropertyManager->subIntPropertyManager(), SIGNAL(valueChanged(QtProperty*,int)),
1135                 this, SLOT(slotValueChanged(QtProperty*,int)));
1136     connect(colorPropertyManager, SIGNAL(propertyInserted(QtProperty*,QtProperty*,QtProperty*)),
1137                 this, SLOT(slotPropertyInserted(QtProperty*,QtProperty*,QtProperty*)));
1138     connect(colorPropertyManager, SIGNAL(propertyRemoved(QtProperty*,QtProperty*)),
1139                 this, SLOT(slotPropertyRemoved(QtProperty*,QtProperty*)));
1140     // EnumPropertyManager
1141     int enumId = enumTypeId();
1142     QtEnumPropertyManager *enumPropertyManager = new QtEnumPropertyManager(this);
1143     d_ptr->m_typeToPropertyManager[enumId] = enumPropertyManager;
1144     d_ptr->m_typeToValueType[enumId] = QVariant::Int;
1145     d_ptr->m_typeToAttributeToAttributeType[enumId][d_ptr->m_enumNamesAttribute] =
1146             QVariant::StringList;
1147     d_ptr->m_typeToAttributeToAttributeType[enumId][d_ptr->m_enumIconsAttribute] =
1148             iconMapTypeId();
1149     connect(enumPropertyManager, SIGNAL(valueChanged(QtProperty*,int)),
1150                 this, SLOT(slotValueChanged(QtProperty*,int)));
1151     connect(enumPropertyManager, SIGNAL(enumNamesChanged(QtProperty*,QStringList)),
1152                 this, SLOT(slotEnumNamesChanged(QtProperty*,QStringList)));
1153     connect(enumPropertyManager, SIGNAL(enumIconsChanged(QtProperty*,QMap<int,QIcon>)),
1154                 this, SLOT(slotEnumIconsChanged(QtProperty*,QMap<int,QIcon>)));
1155     // SizePolicyPropertyManager
1156     QtSizePolicyPropertyManager *sizePolicyPropertyManager = new QtSizePolicyPropertyManager(this);
1157     d_ptr->m_typeToPropertyManager[QVariant::SizePolicy] = sizePolicyPropertyManager;
1158     d_ptr->m_typeToValueType[QVariant::SizePolicy] = QVariant::SizePolicy;
1159     connect(sizePolicyPropertyManager, SIGNAL(valueChanged(QtProperty*,QSizePolicy)),
1160                 this, SLOT(slotValueChanged(QtProperty*,QSizePolicy)));
1161     connect(sizePolicyPropertyManager->subIntPropertyManager(), SIGNAL(valueChanged(QtProperty*,int)),
1162                 this, SLOT(slotValueChanged(QtProperty*,int)));
1163     connect(sizePolicyPropertyManager->subIntPropertyManager(), SIGNAL(rangeChanged(QtProperty*,int,int)),
1164                 this, SLOT(slotRangeChanged(QtProperty*,int,int)));
1165     connect(sizePolicyPropertyManager->subEnumPropertyManager(), SIGNAL(valueChanged(QtProperty*,int)),
1166                 this, SLOT(slotValueChanged(QtProperty*,int)));
1167     connect(sizePolicyPropertyManager->subEnumPropertyManager(),
1168                 SIGNAL(enumNamesChanged(QtProperty*,QStringList)),
1169                 this, SLOT(slotEnumNamesChanged(QtProperty*,QStringList)));
1170     connect(sizePolicyPropertyManager, SIGNAL(propertyInserted(QtProperty*,QtProperty*,QtProperty*)),
1171                 this, SLOT(slotPropertyInserted(QtProperty*,QtProperty*,QtProperty*)));
1172     connect(sizePolicyPropertyManager, SIGNAL(propertyRemoved(QtProperty*,QtProperty*)),
1173                 this, SLOT(slotPropertyRemoved(QtProperty*,QtProperty*)));
1174     // FontPropertyManager
1175     QtFontPropertyManager *fontPropertyManager = new QtFontPropertyManager(this);
1176     d_ptr->m_typeToPropertyManager[QVariant::Font] = fontPropertyManager;
1177     d_ptr->m_typeToValueType[QVariant::Font] = QVariant::Font;
1178     connect(fontPropertyManager, SIGNAL(valueChanged(QtProperty*,QFont)),
1179                 this, SLOT(slotValueChanged(QtProperty*,QFont)));
1180     connect(fontPropertyManager->subIntPropertyManager(), SIGNAL(valueChanged(QtProperty*,int)),
1181                 this, SLOT(slotValueChanged(QtProperty*,int)));
1182     connect(fontPropertyManager->subIntPropertyManager(), SIGNAL(rangeChanged(QtProperty*,int,int)),
1183                 this, SLOT(slotRangeChanged(QtProperty*,int,int)));
1184     connect(fontPropertyManager->subEnumPropertyManager(), SIGNAL(valueChanged(QtProperty*,int)),
1185                 this, SLOT(slotValueChanged(QtProperty*,int)));
1186     connect(fontPropertyManager->subEnumPropertyManager(),
1187                 SIGNAL(enumNamesChanged(QtProperty*,QStringList)),
1188                 this, SLOT(slotEnumNamesChanged(QtProperty*,QStringList)));
1189     connect(fontPropertyManager->subBoolPropertyManager(), SIGNAL(valueChanged(QtProperty*,bool)),
1190                 this, SLOT(slotValueChanged(QtProperty*,bool)));
1191     connect(fontPropertyManager, SIGNAL(propertyInserted(QtProperty*,QtProperty*,QtProperty*)),
1192                 this, SLOT(slotPropertyInserted(QtProperty*,QtProperty*,QtProperty*)));
1193     connect(fontPropertyManager, SIGNAL(propertyRemoved(QtProperty*,QtProperty*)),
1194                 this, SLOT(slotPropertyRemoved(QtProperty*,QtProperty*)));
1195     // CursorPropertyManager
1196     QtCursorPropertyManager *cursorPropertyManager = new QtCursorPropertyManager(this);
1197     d_ptr->m_typeToPropertyManager[QVariant::Cursor] = cursorPropertyManager;
1198     d_ptr->m_typeToValueType[QVariant::Cursor] = QVariant::Cursor;
1199     connect(cursorPropertyManager, SIGNAL(valueChanged(QtProperty*,QCursor)),
1200                 this, SLOT(slotValueChanged(QtProperty*,QCursor)));
1201     // FlagPropertyManager
1202     int flagId = flagTypeId();
1203     QtFlagPropertyManager *flagPropertyManager = new QtFlagPropertyManager(this);
1204     d_ptr->m_typeToPropertyManager[flagId] = flagPropertyManager;
1205     d_ptr->m_typeToValueType[flagId] = QVariant::Int;
1206     d_ptr->m_typeToAttributeToAttributeType[flagId][d_ptr->m_flagNamesAttribute] =
1207             QVariant::StringList;
1208     connect(flagPropertyManager, SIGNAL(valueChanged(QtProperty*,int)),
1209                 this, SLOT(slotValueChanged(QtProperty*,int)));
1210     connect(flagPropertyManager, SIGNAL(flagNamesChanged(QtProperty*,QStringList)),
1211                 this, SLOT(slotFlagNamesChanged(QtProperty*,QStringList)));
1212     connect(flagPropertyManager->subBoolPropertyManager(), SIGNAL(valueChanged(QtProperty*,bool)),
1213                 this, SLOT(slotValueChanged(QtProperty*,bool)));
1214     connect(flagPropertyManager, SIGNAL(propertyInserted(QtProperty*,QtProperty*,QtProperty*)),
1215                 this, SLOT(slotPropertyInserted(QtProperty*,QtProperty*,QtProperty*)));
1216     connect(flagPropertyManager, SIGNAL(propertyRemoved(QtProperty*,QtProperty*)),
1217                 this, SLOT(slotPropertyRemoved(QtProperty*,QtProperty*)));
1218     // FlagPropertyManager
1219     int groupId = groupTypeId();
1220     QtGroupPropertyManager *groupPropertyManager = new QtGroupPropertyManager(this);
1221     d_ptr->m_typeToPropertyManager[groupId] = groupPropertyManager;
1222     d_ptr->m_typeToValueType[groupId] = QVariant::Invalid;
1223 }
1224 
1225 /*!
1226     Destroys this manager, and all the properties it has created.
1227 */
~QtVariantPropertyManager()1228 QtVariantPropertyManager::~QtVariantPropertyManager()
1229 {
1230     clear();
1231 }
1232 
1233 /*!
1234     Returns the given \a property converted into a QtVariantProperty.
1235 
1236     If the \a property was not created by this variant manager, the
1237     function returns 0.
1238 
1239     \sa createProperty()
1240 */
variantProperty(const QtProperty * property) const1241 QtVariantProperty *QtVariantPropertyManager::variantProperty(const QtProperty *property) const
1242 {
1243     const QMap<const QtProperty *, QPair<QtVariantProperty *, int> >::const_iterator it = d_ptr->m_propertyToType.constFind(property);
1244     if (it == d_ptr->m_propertyToType.constEnd())
1245         return 0;
1246     return it.value().first;
1247 }
1248 
1249 /*!
1250     Returns true if the given \a propertyType is supported by this
1251     variant manager; otherwise false.
1252 
1253     \sa propertyType()
1254 */
isPropertyTypeSupported(int propertyType) const1255 bool QtVariantPropertyManager::isPropertyTypeSupported(int propertyType) const
1256 {
1257     if (d_ptr->m_typeToValueType.contains(propertyType))
1258         return true;
1259     return false;
1260 }
1261 
1262 /*!
1263    Creates and returns a variant property of the given \a propertyType
1264    with the given \a name.
1265 
1266    If the specified \a propertyType is not supported by this variant
1267    manager, this function returns 0.
1268 
1269    Do not use the inherited
1270    QtAbstractPropertyManager::addProperty() function to create a
1271    variant property (that function will always return 0 since it will
1272    not be clear what type the property should have).
1273 
1274     \sa isPropertyTypeSupported()
1275 */
addProperty(int propertyType,const QString & name)1276 QtVariantProperty *QtVariantPropertyManager::addProperty(int propertyType, const QString &name)
1277 {
1278     if (!isPropertyTypeSupported(propertyType))
1279         return 0;
1280 
1281     bool wasCreating = d_ptr->m_creatingProperty;
1282     d_ptr->m_creatingProperty = true;
1283     d_ptr->m_propertyType = propertyType;
1284     QtProperty *property = QtAbstractPropertyManager::addProperty(name);
1285     d_ptr->m_creatingProperty = wasCreating;
1286     d_ptr->m_propertyType = 0;
1287 
1288     if (!property)
1289         return 0;
1290 
1291     return variantProperty(property);
1292 }
1293 
1294 /*!
1295     Returns the given \a property's value.
1296 
1297     If the given \a property is not managed by this manager, this
1298     function returns an invalid variant.
1299 
1300     \sa setValue()
1301 */
value(const QtProperty * property) const1302 QVariant QtVariantPropertyManager::value(const QtProperty *property) const
1303 {
1304     QtProperty *internProp = propertyToWrappedProperty()->value(property, 0);
1305     if (internProp == 0)
1306         return QVariant();
1307 
1308     QtAbstractPropertyManager *manager = internProp->propertyManager();
1309     if (QtIntPropertyManager *intManager = qobject_cast<QtIntPropertyManager *>(manager)) {
1310         return intManager->value(internProp);
1311     } else if (QtDoublePropertyManager *doubleManager = qobject_cast<QtDoublePropertyManager *>(manager)) {
1312         return doubleManager->value(internProp);
1313     } else if (QtBoolPropertyManager *boolManager = qobject_cast<QtBoolPropertyManager *>(manager)) {
1314         return boolManager->value(internProp);
1315     } else if (QtStringPropertyManager *stringManager = qobject_cast<QtStringPropertyManager *>(manager)) {
1316         return stringManager->value(internProp);
1317     } else if (QtDatePropertyManager *dateManager = qobject_cast<QtDatePropertyManager *>(manager)) {
1318         return dateManager->value(internProp);
1319     } else if (QtTimePropertyManager *timeManager = qobject_cast<QtTimePropertyManager *>(manager)) {
1320         return timeManager->value(internProp);
1321     } else if (QtDateTimePropertyManager *dateTimeManager = qobject_cast<QtDateTimePropertyManager *>(manager)) {
1322         return dateTimeManager->value(internProp);
1323     } else if (QtKeySequencePropertyManager *keySequenceManager = qobject_cast<QtKeySequencePropertyManager *>(manager)) {
1324         return QVariant::fromValue(keySequenceManager->value(internProp));
1325     } else if (QtCharPropertyManager *charManager = qobject_cast<QtCharPropertyManager *>(manager)) {
1326         return charManager->value(internProp);
1327     } else if (QtLocalePropertyManager *localeManager = qobject_cast<QtLocalePropertyManager *>(manager)) {
1328         return localeManager->value(internProp);
1329     } else if (QtPointPropertyManager *pointManager = qobject_cast<QtPointPropertyManager *>(manager)) {
1330         return pointManager->value(internProp);
1331     } else if (QtPointFPropertyManager *pointFManager = qobject_cast<QtPointFPropertyManager *>(manager)) {
1332         return pointFManager->value(internProp);
1333     } else if (QtSizePropertyManager *sizeManager = qobject_cast<QtSizePropertyManager *>(manager)) {
1334         return sizeManager->value(internProp);
1335     } else if (QtSizeFPropertyManager *sizeFManager = qobject_cast<QtSizeFPropertyManager *>(manager)) {
1336         return sizeFManager->value(internProp);
1337     } else if (QtRectPropertyManager *rectManager = qobject_cast<QtRectPropertyManager *>(manager)) {
1338         return rectManager->value(internProp);
1339     } else if (QtRectFPropertyManager *rectFManager = qobject_cast<QtRectFPropertyManager *>(manager)) {
1340         return rectFManager->value(internProp);
1341     } else if (QtColorPropertyManager *colorManager = qobject_cast<QtColorPropertyManager *>(manager)) {
1342         return colorManager->value(internProp);
1343     } else if (QtEnumPropertyManager *enumManager = qobject_cast<QtEnumPropertyManager *>(manager)) {
1344         return enumManager->value(internProp);
1345     } else if (QtSizePolicyPropertyManager *sizePolicyManager =
1346                qobject_cast<QtSizePolicyPropertyManager *>(manager)) {
1347         return sizePolicyManager->value(internProp);
1348     } else if (QtFontPropertyManager *fontManager = qobject_cast<QtFontPropertyManager *>(manager)) {
1349         return fontManager->value(internProp);
1350 #ifndef QT_NO_CURSOR
1351     } else if (QtCursorPropertyManager *cursorManager = qobject_cast<QtCursorPropertyManager *>(manager)) {
1352         return cursorManager->value(internProp);
1353 #endif
1354     } else if (QtFlagPropertyManager *flagManager = qobject_cast<QtFlagPropertyManager *>(manager)) {
1355         return flagManager->value(internProp);
1356     }
1357     return QVariant();
1358 }
1359 
1360 /*!
1361     Returns the given \a property's value type.
1362 
1363     \sa propertyType()
1364 */
valueType(const QtProperty * property) const1365 int QtVariantPropertyManager::valueType(const QtProperty *property) const
1366 {
1367     int propType = propertyType(property);
1368     return valueType(propType);
1369 }
1370 
1371 /*!
1372     \overload
1373 
1374     Returns the value type associated with the given \a propertyType.
1375 */
valueType(int propertyType) const1376 int QtVariantPropertyManager::valueType(int propertyType) const
1377 {
1378     if (d_ptr->m_typeToValueType.contains(propertyType))
1379         return d_ptr->m_typeToValueType[propertyType];
1380     return 0;
1381 }
1382 
1383 /*!
1384     Returns the given \a property's type.
1385 
1386     \sa valueType()
1387 */
propertyType(const QtProperty * property) const1388 int QtVariantPropertyManager::propertyType(const QtProperty *property) const
1389 {
1390     const QMap<const QtProperty *, QPair<QtVariantProperty *, int> >::const_iterator it = d_ptr->m_propertyToType.constFind(property);
1391     if (it == d_ptr->m_propertyToType.constEnd())
1392         return 0;
1393     return it.value().second;
1394 }
1395 
1396 /*!
1397     Returns the given \a property's value for the specified \a
1398     attribute
1399 
1400     If the given \a property was not created by \e this manager, or if
1401     the specified \a attribute does not exist, this function returns
1402     an invalid variant.
1403 
1404     \sa attributes(), attributeType(), setAttribute()
1405 */
attributeValue(const QtProperty * property,const QString & attribute) const1406 QVariant QtVariantPropertyManager::attributeValue(const QtProperty *property, const QString &attribute) const
1407 {
1408     int propType = propertyType(property);
1409     if (!propType)
1410         return QVariant();
1411 
1412     QMap<int, QMap<QString, int> >::ConstIterator it =
1413             d_ptr->m_typeToAttributeToAttributeType.find(propType);
1414     if (it == d_ptr->m_typeToAttributeToAttributeType.constEnd())
1415         return QVariant();
1416 
1417     QMap<QString, int> attributes = it.value();
1418     QMap<QString, int>::ConstIterator itAttr = attributes.find(attribute);
1419     if (itAttr == attributes.constEnd())
1420         return QVariant();
1421 
1422     QtProperty *internProp = propertyToWrappedProperty()->value(property, 0);
1423     if (internProp == 0)
1424         return QVariant();
1425 
1426     QtAbstractPropertyManager *manager = internProp->propertyManager();
1427     if (QtIntPropertyManager *intManager = qobject_cast<QtIntPropertyManager *>(manager)) {
1428         if (attribute == d_ptr->m_maximumAttribute)
1429             return intManager->maximum(internProp);
1430         if (attribute == d_ptr->m_minimumAttribute)
1431             return intManager->minimum(internProp);
1432         if (attribute == d_ptr->m_singleStepAttribute)
1433             return intManager->singleStep(internProp);
1434         return QVariant();
1435     } else if (QtDoublePropertyManager *doubleManager = qobject_cast<QtDoublePropertyManager *>(manager)) {
1436         if (attribute == d_ptr->m_maximumAttribute)
1437             return doubleManager->maximum(internProp);
1438         if (attribute == d_ptr->m_minimumAttribute)
1439             return doubleManager->minimum(internProp);
1440         if (attribute == d_ptr->m_singleStepAttribute)
1441             return doubleManager->singleStep(internProp);
1442         if (attribute == d_ptr->m_decimalsAttribute)
1443             return doubleManager->decimals(internProp);
1444         return QVariant();
1445     } else if (QtStringPropertyManager *stringManager = qobject_cast<QtStringPropertyManager *>(manager)) {
1446         if (attribute == d_ptr->m_regExpAttribute)
1447             return stringManager->regExp(internProp);
1448         return QVariant();
1449     } else if (QtDatePropertyManager *dateManager = qobject_cast<QtDatePropertyManager *>(manager)) {
1450         if (attribute == d_ptr->m_maximumAttribute)
1451             return dateManager->maximum(internProp);
1452         if (attribute == d_ptr->m_minimumAttribute)
1453             return dateManager->minimum(internProp);
1454         return QVariant();
1455     } else if (QtPointFPropertyManager *pointFManager = qobject_cast<QtPointFPropertyManager *>(manager)) {
1456         if (attribute == d_ptr->m_decimalsAttribute)
1457             return pointFManager->decimals(internProp);
1458         return QVariant();
1459     } else if (QtSizePropertyManager *sizeManager = qobject_cast<QtSizePropertyManager *>(manager)) {
1460         if (attribute == d_ptr->m_maximumAttribute)
1461             return sizeManager->maximum(internProp);
1462         if (attribute == d_ptr->m_minimumAttribute)
1463             return sizeManager->minimum(internProp);
1464         return QVariant();
1465     } else if (QtSizeFPropertyManager *sizeFManager = qobject_cast<QtSizeFPropertyManager *>(manager)) {
1466         if (attribute == d_ptr->m_maximumAttribute)
1467             return sizeFManager->maximum(internProp);
1468         if (attribute == d_ptr->m_minimumAttribute)
1469             return sizeFManager->minimum(internProp);
1470         if (attribute == d_ptr->m_decimalsAttribute)
1471             return sizeFManager->decimals(internProp);
1472         return QVariant();
1473     } else if (QtRectPropertyManager *rectManager = qobject_cast<QtRectPropertyManager *>(manager)) {
1474         if (attribute == d_ptr->m_constraintAttribute)
1475             return rectManager->constraint(internProp);
1476         return QVariant();
1477     } else if (QtRectFPropertyManager *rectFManager = qobject_cast<QtRectFPropertyManager *>(manager)) {
1478         if (attribute == d_ptr->m_constraintAttribute)
1479             return rectFManager->constraint(internProp);
1480         if (attribute == d_ptr->m_decimalsAttribute)
1481             return rectFManager->decimals(internProp);
1482         return QVariant();
1483     } else if (QtEnumPropertyManager *enumManager = qobject_cast<QtEnumPropertyManager *>(manager)) {
1484         if (attribute == d_ptr->m_enumNamesAttribute)
1485             return enumManager->enumNames(internProp);
1486         if (attribute == d_ptr->m_enumIconsAttribute) {
1487             QVariant v;
1488             v.setValue(enumManager->enumIcons(internProp));
1489             return v;
1490         }
1491         return QVariant();
1492     } else if (QtFlagPropertyManager *flagManager = qobject_cast<QtFlagPropertyManager *>(manager)) {
1493         if (attribute == d_ptr->m_flagNamesAttribute)
1494             return flagManager->flagNames(internProp);
1495         return QVariant();
1496     }
1497     return QVariant();
1498 }
1499 
1500 /*!
1501     Returns a list of the given \a propertyType 's attributes.
1502 
1503     \sa attributeValue(), attributeType()
1504 */
attributes(int propertyType) const1505 QStringList QtVariantPropertyManager::attributes(int propertyType) const
1506 {
1507     QMap<int, QMap<QString, int> >::ConstIterator it =
1508             d_ptr->m_typeToAttributeToAttributeType.find(propertyType);
1509     if (it == d_ptr->m_typeToAttributeToAttributeType.constEnd())
1510         return QStringList();
1511     return it.value().keys();
1512 }
1513 
1514 /*!
1515     Returns the type of the specified \a attribute of the given \a
1516     propertyType.
1517 
1518     If the given \a propertyType is not supported by \e this manager,
1519     or if the given \a propertyType does not possess the specified \a
1520     attribute, this function returns QVariant::Invalid.
1521 
1522     \sa attributes(), valueType()
1523 */
attributeType(int propertyType,const QString & attribute) const1524 int QtVariantPropertyManager::attributeType(int propertyType, const QString &attribute) const
1525 {
1526     QMap<int, QMap<QString, int> >::ConstIterator it =
1527             d_ptr->m_typeToAttributeToAttributeType.find(propertyType);
1528     if (it == d_ptr->m_typeToAttributeToAttributeType.constEnd())
1529         return 0;
1530 
1531     QMap<QString, int> attributes = it.value();
1532     QMap<QString, int>::ConstIterator itAttr = attributes.find(attribute);
1533     if (itAttr == attributes.constEnd())
1534         return 0;
1535     return itAttr.value();
1536 }
1537 
1538 /*!
1539     \fn void QtVariantPropertyManager::setValue(QtProperty *property, const QVariant &value)
1540 
1541     Sets the value of the given \a property to \a value.
1542 
1543     The specified \a value must be of a type returned by valueType(),
1544     or of type that can be converted to valueType() using the
1545     QVariant::canConvert() function, otherwise this function does
1546     nothing.
1547 
1548     \sa value(), QtVariantProperty::setValue(), valueChanged()
1549 */
setValue(QtProperty * property,const QVariant & val)1550 void QtVariantPropertyManager::setValue(QtProperty *property, const QVariant &val)
1551 {
1552     int propType = val.userType();
1553     if (!propType)
1554         return;
1555 
1556     int valType = valueType(property);
1557 
1558     if (propType != valType && !val.canConvert(static_cast<QVariant::Type>(valType)))
1559         return;
1560 
1561     QtProperty *internProp = propertyToWrappedProperty()->value(property, 0);
1562     if (internProp == 0)
1563         return;
1564 
1565 
1566     QtAbstractPropertyManager *manager = internProp->propertyManager();
1567     if (QtIntPropertyManager *intManager = qobject_cast<QtIntPropertyManager *>(manager)) {
1568         intManager->setValue(internProp, qvariant_cast<int>(val));
1569         return;
1570     } else if (QtDoublePropertyManager *doubleManager = qobject_cast<QtDoublePropertyManager *>(manager)) {
1571         doubleManager->setValue(internProp, qvariant_cast<double>(val));
1572         return;
1573     } else if (QtBoolPropertyManager *boolManager = qobject_cast<QtBoolPropertyManager *>(manager)) {
1574         boolManager->setValue(internProp, qvariant_cast<bool>(val));
1575         return;
1576     } else if (QtStringPropertyManager *stringManager = qobject_cast<QtStringPropertyManager *>(manager)) {
1577         stringManager->setValue(internProp, qvariant_cast<QString>(val));
1578         return;
1579     } else if (QtDatePropertyManager *dateManager = qobject_cast<QtDatePropertyManager *>(manager)) {
1580         dateManager->setValue(internProp, qvariant_cast<QDate>(val));
1581         return;
1582     } else if (QtTimePropertyManager *timeManager = qobject_cast<QtTimePropertyManager *>(manager)) {
1583         timeManager->setValue(internProp, qvariant_cast<QTime>(val));
1584         return;
1585     } else if (QtDateTimePropertyManager *dateTimeManager = qobject_cast<QtDateTimePropertyManager *>(manager)) {
1586         dateTimeManager->setValue(internProp, qvariant_cast<QDateTime>(val));
1587         return;
1588     } else if (QtKeySequencePropertyManager *keySequenceManager = qobject_cast<QtKeySequencePropertyManager *>(manager)) {
1589         keySequenceManager->setValue(internProp, qvariant_cast<QKeySequence>(val));
1590         return;
1591     } else if (QtCharPropertyManager *charManager = qobject_cast<QtCharPropertyManager *>(manager)) {
1592         charManager->setValue(internProp, qvariant_cast<QChar>(val));
1593         return;
1594     } else if (QtLocalePropertyManager *localeManager = qobject_cast<QtLocalePropertyManager *>(manager)) {
1595         localeManager->setValue(internProp, qvariant_cast<QLocale>(val));
1596         return;
1597     } else if (QtPointPropertyManager *pointManager = qobject_cast<QtPointPropertyManager *>(manager)) {
1598         pointManager->setValue(internProp, qvariant_cast<QPoint>(val));
1599         return;
1600     } else if (QtPointFPropertyManager *pointFManager = qobject_cast<QtPointFPropertyManager *>(manager)) {
1601         pointFManager->setValue(internProp, qvariant_cast<QPointF>(val));
1602         return;
1603     } else if (QtSizePropertyManager *sizeManager = qobject_cast<QtSizePropertyManager *>(manager)) {
1604         sizeManager->setValue(internProp, qvariant_cast<QSize>(val));
1605         return;
1606     } else if (QtSizeFPropertyManager *sizeFManager = qobject_cast<QtSizeFPropertyManager *>(manager)) {
1607         sizeFManager->setValue(internProp, qvariant_cast<QSizeF>(val));
1608         return;
1609     } else if (QtRectPropertyManager *rectManager = qobject_cast<QtRectPropertyManager *>(manager)) {
1610         rectManager->setValue(internProp, qvariant_cast<QRect>(val));
1611         return;
1612     } else if (QtRectFPropertyManager *rectFManager = qobject_cast<QtRectFPropertyManager *>(manager)) {
1613         rectFManager->setValue(internProp, qvariant_cast<QRectF>(val));
1614         return;
1615     } else if (QtColorPropertyManager *colorManager = qobject_cast<QtColorPropertyManager *>(manager)) {
1616         colorManager->setValue(internProp, qvariant_cast<QColor>(val));
1617         return;
1618     } else if (QtEnumPropertyManager *enumManager = qobject_cast<QtEnumPropertyManager *>(manager)) {
1619         enumManager->setValue(internProp, qvariant_cast<int>(val));
1620         return;
1621     } else if (QtSizePolicyPropertyManager *sizePolicyManager =
1622                qobject_cast<QtSizePolicyPropertyManager *>(manager)) {
1623         sizePolicyManager->setValue(internProp, qvariant_cast<QSizePolicy>(val));
1624         return;
1625     } else if (QtFontPropertyManager *fontManager = qobject_cast<QtFontPropertyManager *>(manager)) {
1626         fontManager->setValue(internProp, qvariant_cast<QFont>(val));
1627         return;
1628 #ifndef QT_NO_CURSOR
1629     } else if (QtCursorPropertyManager *cursorManager = qobject_cast<QtCursorPropertyManager *>(manager)) {
1630         cursorManager->setValue(internProp, qvariant_cast<QCursor>(val));
1631         return;
1632 #endif
1633     } else if (QtFlagPropertyManager *flagManager = qobject_cast<QtFlagPropertyManager *>(manager)) {
1634         flagManager->setValue(internProp, qvariant_cast<int>(val));
1635         return;
1636     }
1637 }
1638 
1639 /*!
1640     Sets the value of the specified \a attribute of the given \a
1641     property, to \a value.
1642 
1643     The new \a value's type must be of the type returned by
1644     attributeType(), or of a type that can be converted to
1645     attributeType() using the QVariant::canConvert() function,
1646     otherwise this function does nothing.
1647 
1648     \sa attributeValue(), QtVariantProperty::setAttribute(), attributeChanged()
1649 */
setAttribute(QtProperty * property,const QString & attribute,const QVariant & value)1650 void QtVariantPropertyManager::setAttribute(QtProperty *property,
1651         const QString &attribute, const QVariant &value)
1652 {
1653     QVariant oldAttr = attributeValue(property, attribute);
1654     if (!oldAttr.isValid())
1655         return;
1656 
1657     int attrType = value.userType();
1658     if (!attrType)
1659         return;
1660 
1661     if (attrType != attributeType(propertyType(property), attribute) &&
1662                 !value.canConvert((QVariant::Type)attrType))
1663         return;
1664 
1665     QtProperty *internProp = propertyToWrappedProperty()->value(property, 0);
1666     if (internProp == 0)
1667         return;
1668 
1669     QtAbstractPropertyManager *manager = internProp->propertyManager();
1670     if (QtIntPropertyManager *intManager = qobject_cast<QtIntPropertyManager *>(manager)) {
1671         if (attribute == d_ptr->m_maximumAttribute)
1672             intManager->setMaximum(internProp, qvariant_cast<int>(value));
1673         else if (attribute == d_ptr->m_minimumAttribute)
1674             intManager->setMinimum(internProp, qvariant_cast<int>(value));
1675         else if (attribute == d_ptr->m_singleStepAttribute)
1676             intManager->setSingleStep(internProp, qvariant_cast<int>(value));
1677         return;
1678     } else if (QtDoublePropertyManager *doubleManager = qobject_cast<QtDoublePropertyManager *>(manager)) {
1679         if (attribute == d_ptr->m_maximumAttribute)
1680             doubleManager->setMaximum(internProp, qvariant_cast<double>(value));
1681         if (attribute == d_ptr->m_minimumAttribute)
1682             doubleManager->setMinimum(internProp, qvariant_cast<double>(value));
1683         if (attribute == d_ptr->m_singleStepAttribute)
1684             doubleManager->setSingleStep(internProp, qvariant_cast<double>(value));
1685         if (attribute == d_ptr->m_decimalsAttribute)
1686             doubleManager->setDecimals(internProp, qvariant_cast<int>(value));
1687         return;
1688     } else if (QtStringPropertyManager *stringManager = qobject_cast<QtStringPropertyManager *>(manager)) {
1689         if (attribute == d_ptr->m_regExpAttribute)
1690             stringManager->setRegExp(internProp, qvariant_cast<QRegExp>(value));
1691         return;
1692     } else if (QtDatePropertyManager *dateManager = qobject_cast<QtDatePropertyManager *>(manager)) {
1693         if (attribute == d_ptr->m_maximumAttribute)
1694             dateManager->setMaximum(internProp, qvariant_cast<QDate>(value));
1695         if (attribute == d_ptr->m_minimumAttribute)
1696             dateManager->setMinimum(internProp, qvariant_cast<QDate>(value));
1697         return;
1698     } else if (QtPointFPropertyManager *pointFManager = qobject_cast<QtPointFPropertyManager *>(manager)) {
1699         if (attribute == d_ptr->m_decimalsAttribute)
1700             pointFManager->setDecimals(internProp, qvariant_cast<int>(value));
1701         return;
1702     } else if (QtSizePropertyManager *sizeManager = qobject_cast<QtSizePropertyManager *>(manager)) {
1703         if (attribute == d_ptr->m_maximumAttribute)
1704             sizeManager->setMaximum(internProp, qvariant_cast<QSize>(value));
1705         if (attribute == d_ptr->m_minimumAttribute)
1706             sizeManager->setMinimum(internProp, qvariant_cast<QSize>(value));
1707         return;
1708     } else if (QtSizeFPropertyManager *sizeFManager = qobject_cast<QtSizeFPropertyManager *>(manager)) {
1709         if (attribute == d_ptr->m_maximumAttribute)
1710             sizeFManager->setMaximum(internProp, qvariant_cast<QSizeF>(value));
1711         if (attribute == d_ptr->m_minimumAttribute)
1712             sizeFManager->setMinimum(internProp, qvariant_cast<QSizeF>(value));
1713         if (attribute == d_ptr->m_decimalsAttribute)
1714             sizeFManager->setDecimals(internProp, qvariant_cast<int>(value));
1715         return;
1716     } else if (QtRectPropertyManager *rectManager = qobject_cast<QtRectPropertyManager *>(manager)) {
1717         if (attribute == d_ptr->m_constraintAttribute)
1718             rectManager->setConstraint(internProp, qvariant_cast<QRect>(value));
1719         return;
1720     } else if (QtRectFPropertyManager *rectFManager = qobject_cast<QtRectFPropertyManager *>(manager)) {
1721         if (attribute == d_ptr->m_constraintAttribute)
1722             rectFManager->setConstraint(internProp, qvariant_cast<QRectF>(value));
1723         if (attribute == d_ptr->m_decimalsAttribute)
1724             rectFManager->setDecimals(internProp, qvariant_cast<int>(value));
1725         return;
1726     } else if (QtEnumPropertyManager *enumManager = qobject_cast<QtEnumPropertyManager *>(manager)) {
1727         if (attribute == d_ptr->m_enumNamesAttribute)
1728             enumManager->setEnumNames(internProp, qvariant_cast<QStringList>(value));
1729         if (attribute == d_ptr->m_enumIconsAttribute)
1730             enumManager->setEnumIcons(internProp, qvariant_cast<QtIconMap>(value));
1731         return;
1732     } else if (QtFlagPropertyManager *flagManager = qobject_cast<QtFlagPropertyManager *>(manager)) {
1733         if (attribute == d_ptr->m_flagNamesAttribute)
1734             flagManager->setFlagNames(internProp, qvariant_cast<QStringList>(value));
1735         return;
1736     }
1737 }
1738 
1739 /*!
1740     \internal
1741 */
hasValue(const QtProperty * property) const1742 bool QtVariantPropertyManager::hasValue(const QtProperty *property) const
1743 {
1744     if (propertyType(property) == groupTypeId())
1745         return false;
1746     return true;
1747 }
1748 
1749 /*!
1750     \internal
1751 */
valueText(const QtProperty * property) const1752 QString QtVariantPropertyManager::valueText(const QtProperty *property) const
1753 {
1754     const QtProperty *internProp = propertyToWrappedProperty()->value(property, 0);
1755     return internProp ? internProp->valueText() : QString();
1756 }
1757 
1758 /*!
1759     \internal
1760 */
valueIcon(const QtProperty * property) const1761 QIcon QtVariantPropertyManager::valueIcon(const QtProperty *property) const
1762 {
1763     const QtProperty *internProp = propertyToWrappedProperty()->value(property, 0);
1764     return internProp ? internProp->valueIcon() : QIcon();
1765 }
1766 
1767 /*!
1768     \internal
1769 */
initializeProperty(QtProperty * property)1770 void QtVariantPropertyManager::initializeProperty(QtProperty *property)
1771 {
1772     QtVariantProperty *varProp = variantProperty(property);
1773     if (!varProp)
1774         return;
1775 
1776     QMap<int, QtAbstractPropertyManager *>::ConstIterator it =
1777             d_ptr->m_typeToPropertyManager.find(d_ptr->m_propertyType);
1778     if (it != d_ptr->m_typeToPropertyManager.constEnd()) {
1779         QtProperty *internProp = 0;
1780         if (!d_ptr->m_creatingSubProperties) {
1781             QtAbstractPropertyManager *manager = it.value();
1782             internProp = manager->addProperty();
1783             d_ptr->m_internalToProperty[internProp] = varProp;
1784         }
1785         propertyToWrappedProperty()->insert(varProp, internProp);
1786         if (internProp) {
1787             const auto children = internProp->subProperties();
1788             QtVariantProperty *lastProperty = 0;
1789             for (QtProperty *child : children) {
1790                 QtVariantProperty *prop = d_ptr->createSubProperty(varProp, lastProperty, child);
1791                 lastProperty = prop ? prop : lastProperty;
1792             }
1793         }
1794     }
1795 }
1796 
1797 /*!
1798     \internal
1799 */
uninitializeProperty(QtProperty * property)1800 void QtVariantPropertyManager::uninitializeProperty(QtProperty *property)
1801 {
1802     const QMap<const QtProperty *, QPair<QtVariantProperty *, int> >::iterator type_it = d_ptr->m_propertyToType.find(property);
1803     if (type_it == d_ptr->m_propertyToType.end())
1804         return;
1805 
1806     PropertyMap::iterator it = propertyToWrappedProperty()->find(property);
1807     if (it != propertyToWrappedProperty()->end()) {
1808         QtProperty *internProp = it.value();
1809         if (internProp) {
1810             d_ptr->m_internalToProperty.remove(internProp);
1811             if (!d_ptr->m_destroyingSubProperties) {
1812                 delete internProp;
1813             }
1814         }
1815         propertyToWrappedProperty()->erase(it);
1816     }
1817     d_ptr->m_propertyToType.erase(type_it);
1818 }
1819 
1820 /*!
1821     \internal
1822 */
createProperty()1823 QtProperty *QtVariantPropertyManager::createProperty()
1824 {
1825     if (!d_ptr->m_creatingProperty)
1826         return 0;
1827 
1828     QtVariantProperty *property = new QtVariantProperty(this);
1829     d_ptr->m_propertyToType.insert(property, qMakePair(property, d_ptr->m_propertyType));
1830 
1831     return property;
1832 }
1833 
1834 /////////////////////////////
1835 
1836 class QtVariantEditorFactoryPrivate
1837 {
1838     QtVariantEditorFactory *q_ptr;
1839     Q_DECLARE_PUBLIC(QtVariantEditorFactory)
1840 public:
1841 
1842     QtSpinBoxFactory           *m_spinBoxFactory;
1843     QtDoubleSpinBoxFactory     *m_doubleSpinBoxFactory;
1844     QtCheckBoxFactory          *m_checkBoxFactory;
1845     QtLineEditFactory          *m_lineEditFactory;
1846     QtDateEditFactory          *m_dateEditFactory;
1847     QtTimeEditFactory          *m_timeEditFactory;
1848     QtDateTimeEditFactory      *m_dateTimeEditFactory;
1849     QtKeySequenceEditorFactory *m_keySequenceEditorFactory;
1850     QtCharEditorFactory        *m_charEditorFactory;
1851     QtEnumEditorFactory        *m_comboBoxFactory;
1852     QtCursorEditorFactory      *m_cursorEditorFactory;
1853     QtColorEditorFactory       *m_colorEditorFactory;
1854     QtFontEditorFactory        *m_fontEditorFactory;
1855 
1856     QMap<QtAbstractEditorFactoryBase *, int> m_factoryToType;
1857     QMap<int, QtAbstractEditorFactoryBase *> m_typeToFactory;
1858 };
1859 
1860 /*!
1861     \class QtVariantEditorFactory
1862     \internal
1863     \inmodule QtDesigner
1864     \since 4.4
1865 
1866     \brief The QtVariantEditorFactory class provides widgets for properties
1867     created by QtVariantPropertyManager objects.
1868 
1869     The variant factory provides the following widgets for the
1870     specified property types:
1871 
1872     \table
1873     \header
1874         \li Property Type
1875         \li Widget
1876     \row
1877         \li \c int
1878         \li QSpinBox
1879     \row
1880         \li \c double
1881         \li QDoubleSpinBox
1882     \row
1883         \li \c bool
1884         \li QCheckBox
1885     \row
1886         \li QString
1887         \li QLineEdit
1888     \row
1889         \li QDate
1890         \li QDateEdit
1891     \row
1892         \li QTime
1893         \li QTimeEdit
1894     \row
1895         \li QDateTime
1896         \li QDateTimeEdit
1897     \row
1898         \li QKeySequence
1899         \li customized editor
1900     \row
1901         \li QChar
1902         \li customized editor
1903     \row
1904         \li \c enum
1905         \li QComboBox
1906     \row
1907         \li QCursor
1908         \li QComboBox
1909     \endtable
1910 
1911     Note that QtVariantPropertyManager supports several additional property
1912     types for which the QtVariantEditorFactory class does not provide
1913     editing widgets, e.g. QPoint and QSize. To provide widgets for other
1914     types using the variant approach, derive from the QtVariantEditorFactory
1915     class.
1916 
1917     \sa QtAbstractEditorFactory, QtVariantPropertyManager
1918 */
1919 
1920 /*!
1921     Creates a factory with the given \a parent.
1922 */
QtVariantEditorFactory(QObject * parent)1923 QtVariantEditorFactory::QtVariantEditorFactory(QObject *parent)
1924     : QtAbstractEditorFactory<QtVariantPropertyManager>(parent), d_ptr(new QtVariantEditorFactoryPrivate())
1925 {
1926     d_ptr->q_ptr = this;
1927 
1928     d_ptr->m_spinBoxFactory = new QtSpinBoxFactory(this);
1929     d_ptr->m_factoryToType[d_ptr->m_spinBoxFactory] = QVariant::Int;
1930     d_ptr->m_typeToFactory[QVariant::Int] = d_ptr->m_spinBoxFactory;
1931 
1932     d_ptr->m_doubleSpinBoxFactory = new QtDoubleSpinBoxFactory(this);
1933     d_ptr->m_factoryToType[d_ptr->m_doubleSpinBoxFactory] = QVariant::Double;
1934     d_ptr->m_typeToFactory[QVariant::Double] = d_ptr->m_doubleSpinBoxFactory;
1935 
1936     d_ptr->m_checkBoxFactory = new QtCheckBoxFactory(this);
1937     d_ptr->m_factoryToType[d_ptr->m_checkBoxFactory] = QVariant::Bool;
1938     d_ptr->m_typeToFactory[QVariant::Bool] = d_ptr->m_checkBoxFactory;
1939 
1940     d_ptr->m_lineEditFactory = new QtLineEditFactory(this);
1941     d_ptr->m_factoryToType[d_ptr->m_lineEditFactory] = QVariant::String;
1942     d_ptr->m_typeToFactory[QVariant::String] = d_ptr->m_lineEditFactory;
1943 
1944     d_ptr->m_dateEditFactory = new QtDateEditFactory(this);
1945     d_ptr->m_factoryToType[d_ptr->m_dateEditFactory] = QVariant::Date;
1946     d_ptr->m_typeToFactory[QVariant::Date] = d_ptr->m_dateEditFactory;
1947 
1948     d_ptr->m_timeEditFactory = new QtTimeEditFactory(this);
1949     d_ptr->m_factoryToType[d_ptr->m_timeEditFactory] = QVariant::Time;
1950     d_ptr->m_typeToFactory[QVariant::Time] = d_ptr->m_timeEditFactory;
1951 
1952     d_ptr->m_dateTimeEditFactory = new QtDateTimeEditFactory(this);
1953     d_ptr->m_factoryToType[d_ptr->m_dateTimeEditFactory] = QVariant::DateTime;
1954     d_ptr->m_typeToFactory[QVariant::DateTime] = d_ptr->m_dateTimeEditFactory;
1955 
1956     d_ptr->m_keySequenceEditorFactory = new QtKeySequenceEditorFactory(this);
1957     d_ptr->m_factoryToType[d_ptr->m_keySequenceEditorFactory] = QVariant::KeySequence;
1958     d_ptr->m_typeToFactory[QVariant::KeySequence] = d_ptr->m_keySequenceEditorFactory;
1959 
1960     d_ptr->m_charEditorFactory = new QtCharEditorFactory(this);
1961     d_ptr->m_factoryToType[d_ptr->m_charEditorFactory] = QVariant::Char;
1962     d_ptr->m_typeToFactory[QVariant::Char] = d_ptr->m_charEditorFactory;
1963 
1964     d_ptr->m_cursorEditorFactory = new QtCursorEditorFactory(this);
1965     d_ptr->m_factoryToType[d_ptr->m_cursorEditorFactory] = QVariant::Cursor;
1966     d_ptr->m_typeToFactory[QVariant::Cursor] = d_ptr->m_cursorEditorFactory;
1967 
1968     d_ptr->m_colorEditorFactory = new QtColorEditorFactory(this);
1969     d_ptr->m_factoryToType[d_ptr->m_colorEditorFactory] = QVariant::Color;
1970     d_ptr->m_typeToFactory[QVariant::Color] = d_ptr->m_colorEditorFactory;
1971 
1972     d_ptr->m_fontEditorFactory = new QtFontEditorFactory(this);
1973     d_ptr->m_factoryToType[d_ptr->m_fontEditorFactory] = QVariant::Font;
1974     d_ptr->m_typeToFactory[QVariant::Font] = d_ptr->m_fontEditorFactory;
1975 
1976     d_ptr->m_comboBoxFactory = new QtEnumEditorFactory(this);
1977     const int enumId = QtVariantPropertyManager::enumTypeId();
1978     d_ptr->m_factoryToType[d_ptr->m_comboBoxFactory] = enumId;
1979     d_ptr->m_typeToFactory[enumId] = d_ptr->m_comboBoxFactory;
1980 }
1981 
1982 /*!
1983     Destroys this factory, and all the widgets it has created.
1984 */
~QtVariantEditorFactory()1985 QtVariantEditorFactory::~QtVariantEditorFactory()
1986 {
1987 }
1988 
1989 /*!
1990     \internal
1991 
1992     Reimplemented from the QtAbstractEditorFactory class.
1993 */
connectPropertyManager(QtVariantPropertyManager * manager)1994 void QtVariantEditorFactory::connectPropertyManager(QtVariantPropertyManager *manager)
1995 {
1996     const auto intPropertyManagers = manager->findChildren<QtIntPropertyManager *>();
1997     for (QtIntPropertyManager *manager : intPropertyManagers)
1998         d_ptr->m_spinBoxFactory->addPropertyManager(manager);
1999 
2000     const auto doublePropertyManagers = manager->findChildren<QtDoublePropertyManager *>();
2001     for (QtDoublePropertyManager *manager : doublePropertyManagers)
2002         d_ptr->m_doubleSpinBoxFactory->addPropertyManager(manager);
2003 
2004     const auto boolPropertyManagers = manager->findChildren<QtBoolPropertyManager *>();
2005     for (QtBoolPropertyManager *manager : boolPropertyManagers)
2006         d_ptr->m_checkBoxFactory->addPropertyManager(manager);
2007 
2008     const auto stringPropertyManagers = manager->findChildren<QtStringPropertyManager *>();
2009     for (QtStringPropertyManager *manager : stringPropertyManagers)
2010         d_ptr->m_lineEditFactory->addPropertyManager(manager);
2011 
2012     const auto datePropertyManagers = manager->findChildren<QtDatePropertyManager *>();
2013     for (QtDatePropertyManager *manager : datePropertyManagers)
2014         d_ptr->m_dateEditFactory->addPropertyManager(manager);
2015 
2016     const auto timePropertyManagers = manager->findChildren<QtTimePropertyManager *>();
2017     for (QtTimePropertyManager *manager : timePropertyManagers)
2018         d_ptr->m_timeEditFactory->addPropertyManager(manager);
2019 
2020     const auto dateTimePropertyManagers = manager->findChildren<QtDateTimePropertyManager *>();
2021     for (QtDateTimePropertyManager *manager : dateTimePropertyManagers)
2022         d_ptr->m_dateTimeEditFactory->addPropertyManager(manager);
2023 
2024     const auto keySequencePropertyManagers = manager->findChildren<QtKeySequencePropertyManager *>();
2025     for (QtKeySequencePropertyManager *manager : keySequencePropertyManagers)
2026         d_ptr->m_keySequenceEditorFactory->addPropertyManager(manager);
2027 
2028     const auto charPropertyManagers = manager->findChildren<QtCharPropertyManager *>();
2029     for (QtCharPropertyManager *manager : charPropertyManagers)
2030         d_ptr->m_charEditorFactory->addPropertyManager(manager);
2031 
2032     const auto localePropertyManagers = manager->findChildren<QtLocalePropertyManager *>();
2033     for (QtLocalePropertyManager *manager : localePropertyManagers)
2034         d_ptr->m_comboBoxFactory->addPropertyManager(manager->subEnumPropertyManager());
2035 
2036     const auto pointPropertyManagers = manager->findChildren<QtPointPropertyManager *>();
2037     for (QtPointPropertyManager *manager : pointPropertyManagers)
2038         d_ptr->m_spinBoxFactory->addPropertyManager(manager->subIntPropertyManager());
2039 
2040     const auto pointFPropertyManagers = manager->findChildren<QtPointFPropertyManager *>();
2041     for (QtPointFPropertyManager *manager : pointFPropertyManagers)
2042         d_ptr->m_doubleSpinBoxFactory->addPropertyManager(manager->subDoublePropertyManager());
2043 
2044     const auto sizePropertyManagers = manager->findChildren<QtSizePropertyManager *>();
2045     for (QtSizePropertyManager *manager : sizePropertyManagers)
2046         d_ptr->m_spinBoxFactory->addPropertyManager(manager->subIntPropertyManager());
2047 
2048     const auto sizeFPropertyManagers = manager->findChildren<QtSizeFPropertyManager *>();
2049     for (QtSizeFPropertyManager *manager : sizeFPropertyManagers)
2050         d_ptr->m_doubleSpinBoxFactory->addPropertyManager(manager->subDoublePropertyManager());
2051 
2052     const auto rectPropertyManagers = manager->findChildren<QtRectPropertyManager *>();
2053     for (QtRectPropertyManager *manager : rectPropertyManagers)
2054         d_ptr->m_spinBoxFactory->addPropertyManager(manager->subIntPropertyManager());
2055 
2056     const auto rectFPropertyManagers = manager->findChildren<QtRectFPropertyManager *>();
2057     for (QtRectFPropertyManager *manager : rectFPropertyManagers)
2058         d_ptr->m_doubleSpinBoxFactory->addPropertyManager(manager->subDoublePropertyManager());
2059 
2060     const auto colorPropertyManagers = manager->findChildren<QtColorPropertyManager *>();
2061     for (QtColorPropertyManager *manager : colorPropertyManagers) {
2062         d_ptr->m_colorEditorFactory->addPropertyManager(manager);
2063         d_ptr->m_spinBoxFactory->addPropertyManager(manager->subIntPropertyManager());
2064     }
2065 
2066     const auto enumPropertyManagers = manager->findChildren<QtEnumPropertyManager *>();
2067     for (QtEnumPropertyManager *manager : enumPropertyManagers)
2068         d_ptr->m_comboBoxFactory->addPropertyManager(manager);
2069 
2070     const auto sizePolicyPropertyManagers = manager->findChildren<QtSizePolicyPropertyManager *>();
2071     for (QtSizePolicyPropertyManager *manager : sizePolicyPropertyManagers) {
2072         d_ptr->m_spinBoxFactory->addPropertyManager(manager->subIntPropertyManager());
2073         d_ptr->m_comboBoxFactory->addPropertyManager(manager->subEnumPropertyManager());
2074     }
2075 
2076     const auto fontPropertyManagers = manager->findChildren<QtFontPropertyManager *>();
2077     for (QtFontPropertyManager *manager : fontPropertyManagers) {
2078         d_ptr->m_fontEditorFactory->addPropertyManager(manager);
2079         d_ptr->m_spinBoxFactory->addPropertyManager(manager->subIntPropertyManager());
2080         d_ptr->m_comboBoxFactory->addPropertyManager(manager->subEnumPropertyManager());
2081         d_ptr->m_checkBoxFactory->addPropertyManager(manager->subBoolPropertyManager());
2082     }
2083 
2084     const auto cursorPropertyManagers = manager->findChildren<QtCursorPropertyManager *>();
2085     for (QtCursorPropertyManager *manager : cursorPropertyManagers)
2086         d_ptr->m_cursorEditorFactory->addPropertyManager(manager);
2087 
2088     const auto flagPropertyManagers = manager->findChildren<QtFlagPropertyManager *>();
2089     for (QtFlagPropertyManager *manager : flagPropertyManagers)
2090         d_ptr->m_checkBoxFactory->addPropertyManager(manager->subBoolPropertyManager());
2091 }
2092 
2093 /*!
2094     \internal
2095 
2096     Reimplemented from the QtAbstractEditorFactory class.
2097 */
createEditor(QtVariantPropertyManager * manager,QtProperty * property,QWidget * parent)2098 QWidget *QtVariantEditorFactory::createEditor(QtVariantPropertyManager *manager, QtProperty *property,
2099         QWidget *parent)
2100 {
2101     const int propType = manager->propertyType(property);
2102     QtAbstractEditorFactoryBase *factory = d_ptr->m_typeToFactory.value(propType, 0);
2103     if (!factory)
2104         return 0;
2105     return factory->createEditor(wrappedProperty(property), parent);
2106 }
2107 
2108 /*!
2109     \internal
2110 
2111     Reimplemented from the QtAbstractEditorFactory class.
2112 */
disconnectPropertyManager(QtVariantPropertyManager * manager)2113 void QtVariantEditorFactory::disconnectPropertyManager(QtVariantPropertyManager *manager)
2114 {
2115     const auto intPropertyManagers = manager->findChildren<QtIntPropertyManager *>();
2116     for (QtIntPropertyManager *manager : intPropertyManagers)
2117         d_ptr->m_spinBoxFactory->removePropertyManager(manager);
2118 
2119     const auto doublePropertyManagers = manager->findChildren<QtDoublePropertyManager *>();
2120     for (QtDoublePropertyManager *manager : doublePropertyManagers)
2121         d_ptr->m_doubleSpinBoxFactory->removePropertyManager(manager);
2122 
2123     const auto boolPropertyManagers = manager->findChildren<QtBoolPropertyManager *>();
2124     for (QtBoolPropertyManager *manager : boolPropertyManagers)
2125         d_ptr->m_checkBoxFactory->removePropertyManager(manager);
2126 
2127     const auto stringPropertyManagers = manager->findChildren<QtStringPropertyManager *>();
2128     for (QtStringPropertyManager *manager : stringPropertyManagers)
2129         d_ptr->m_lineEditFactory->removePropertyManager(manager);
2130 
2131     const auto datePropertyManagers = manager->findChildren<QtDatePropertyManager *>();
2132     for (QtDatePropertyManager *manager : datePropertyManagers)
2133         d_ptr->m_dateEditFactory->removePropertyManager(manager);
2134 
2135     const auto timePropertyManagers = manager->findChildren<QtTimePropertyManager *>();
2136     for (QtTimePropertyManager *manager : timePropertyManagers)
2137         d_ptr->m_timeEditFactory->removePropertyManager(manager);
2138 
2139     const auto dateTimePropertyManagers = manager->findChildren<QtDateTimePropertyManager *>();
2140     for (QtDateTimePropertyManager *manager : dateTimePropertyManagers)
2141         d_ptr->m_dateTimeEditFactory->removePropertyManager(manager);
2142 
2143     const auto keySequencePropertyManagers = manager->findChildren<QtKeySequencePropertyManager *>();
2144     for (QtKeySequencePropertyManager *manager : keySequencePropertyManagers)
2145         d_ptr->m_keySequenceEditorFactory->removePropertyManager(manager);
2146 
2147     const auto charPropertyManagers = manager->findChildren<QtCharPropertyManager *>();
2148     for (QtCharPropertyManager *manager : charPropertyManagers)
2149         d_ptr->m_charEditorFactory->removePropertyManager(manager);
2150 
2151     const auto localePropertyManagers = manager->findChildren<QtLocalePropertyManager *>();
2152     for (QtLocalePropertyManager *manager : localePropertyManagers)
2153         d_ptr->m_comboBoxFactory->removePropertyManager(manager->subEnumPropertyManager());
2154 
2155     const auto pointPropertyManagers = manager->findChildren<QtPointPropertyManager *>();
2156     for (QtPointPropertyManager *manager : pointPropertyManagers)
2157         d_ptr->m_spinBoxFactory->removePropertyManager(manager->subIntPropertyManager());
2158 
2159     const auto pointFPropertyManagers = manager->findChildren<QtPointFPropertyManager *>();
2160     for (QtPointFPropertyManager *manager : pointFPropertyManagers)
2161         d_ptr->m_doubleSpinBoxFactory->removePropertyManager(manager->subDoublePropertyManager());
2162 
2163     const auto sizePropertyManagers = manager->findChildren<QtSizePropertyManager *>();
2164     for (QtSizePropertyManager *manager : sizePropertyManagers)
2165         d_ptr->m_spinBoxFactory->removePropertyManager(manager->subIntPropertyManager());
2166 
2167     const auto sizeFPropertyManagers = manager->findChildren<QtSizeFPropertyManager *>();
2168     for (QtSizeFPropertyManager *manager : sizeFPropertyManagers)
2169         d_ptr->m_doubleSpinBoxFactory->removePropertyManager(manager->subDoublePropertyManager());
2170 
2171     const auto rectPropertyManagers = manager->findChildren<QtRectPropertyManager *>();
2172     for (QtRectPropertyManager *manager : rectPropertyManagers)
2173         d_ptr->m_spinBoxFactory->removePropertyManager(manager->subIntPropertyManager());
2174 
2175     const auto rectFPropertyManagers = manager->findChildren<QtRectFPropertyManager *>();
2176     for (QtRectFPropertyManager *manager : rectFPropertyManagers)
2177         d_ptr->m_doubleSpinBoxFactory->removePropertyManager(manager->subDoublePropertyManager());
2178 
2179     const auto colorPropertyManagers = manager->findChildren<QtColorPropertyManager *>();
2180     for (QtColorPropertyManager *manager : colorPropertyManagers) {
2181         d_ptr->m_colorEditorFactory->removePropertyManager(manager);
2182         d_ptr->m_spinBoxFactory->removePropertyManager(manager->subIntPropertyManager());
2183     }
2184 
2185     const auto enumPropertyManagers = manager->findChildren<QtEnumPropertyManager *>();
2186     for (QtEnumPropertyManager *manager : enumPropertyManagers)
2187         d_ptr->m_comboBoxFactory->removePropertyManager(manager);
2188 
2189     const auto sizePolicyPropertyManagers = manager->findChildren<QtSizePolicyPropertyManager *>();
2190     for (QtSizePolicyPropertyManager *manager : sizePolicyPropertyManagers) {
2191         d_ptr->m_spinBoxFactory->removePropertyManager(manager->subIntPropertyManager());
2192         d_ptr->m_comboBoxFactory->removePropertyManager(manager->subEnumPropertyManager());
2193     }
2194 
2195     const auto fontPropertyManagers = manager->findChildren<QtFontPropertyManager *>();
2196     for (QtFontPropertyManager *manager : fontPropertyManagers) {
2197         d_ptr->m_fontEditorFactory->removePropertyManager(manager);
2198         d_ptr->m_spinBoxFactory->removePropertyManager(manager->subIntPropertyManager());
2199         d_ptr->m_comboBoxFactory->removePropertyManager(manager->subEnumPropertyManager());
2200         d_ptr->m_checkBoxFactory->removePropertyManager(manager->subBoolPropertyManager());
2201     }
2202 
2203     const auto cursorPropertyManagers = manager->findChildren<QtCursorPropertyManager *>();
2204     for (QtCursorPropertyManager *manager : cursorPropertyManagers)
2205         d_ptr->m_cursorEditorFactory->removePropertyManager(manager);
2206 
2207     const auto flagPropertyManagers = manager->findChildren<QtFlagPropertyManager *>();
2208     for (QtFlagPropertyManager *manager : flagPropertyManagers)
2209         d_ptr->m_checkBoxFactory->removePropertyManager(manager->subBoolPropertyManager());
2210 }
2211 
2212 QT_END_NAMESPACE
2213 
2214 #include "moc_qtvariantproperty.cpp"
2215