File indexing completed on 2024-05-12 04:35:14
0001 /**************************************************************************** 0002 ** 0003 ** Copyright (C) 2016 The Qt Company Ltd. 0004 ** Contact: https://www.qt.io/licensing/ 0005 ** 0006 ** This file is part of the tools applications of the Qt Toolkit. 0007 ** 0008 ** $QT_BEGIN_LICENSE:LGPL$ 0009 ** Commercial License Usage 0010 ** Licensees holding valid commercial Qt licenses may use this file in 0011 ** accordance with the commercial license agreement provided with the 0012 ** Software or, alternatively, in accordance with the terms contained in 0013 ** a written agreement between you and The Qt Company. For licensing terms 0014 ** and conditions see https://www.qt.io/terms-conditions. For further 0015 ** information use the contact form at https://www.qt.io/contact-us. 0016 ** 0017 ** GNU Lesser General Public License Usage 0018 ** Alternatively, this file may be used under the terms of the GNU Lesser 0019 ** General Public License version 3 as published by the Free Software 0020 ** Foundation and appearing in the file LICENSE.LGPL3 included in the 0021 ** packaging of this file. Please review the following information to 0022 ** ensure the GNU Lesser General Public License version 3 requirements 0023 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. 0024 ** 0025 ** GNU General Public License Usage 0026 ** Alternatively, this file may be used under the terms of the GNU 0027 ** General Public License version 2.0 or (at your option) the GNU General 0028 ** Public license version 3 or any later version approved by the KDE Free 0029 ** Qt Foundation. The licenses are as published by the Free Software 0030 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 0031 ** included in the packaging of this file. Please review the following 0032 ** information to ensure the GNU General Public License requirements will 0033 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and 0034 ** https://www.gnu.org/licenses/gpl-3.0.html. 0035 ** 0036 ** $QT_END_LICENSE$ 0037 ** 0038 ****************************************************************************/ 0039 0040 #include "qtvariantproperty.h" 0041 #include "qtpropertymanager.h" 0042 #include "qteditorfactory.h" 0043 #include <QtCore/QVariant> 0044 #include <QtGui/QIcon> 0045 #include <QtCore/QDate> 0046 #include <QtCore/QLocale> 0047 0048 #if defined(Q_CC_MSVC) 0049 # pragma warning(disable: 4786) /* MS VS 6: truncating debug info after 255 characters */ 0050 #endif 0051 0052 QT_BEGIN_NAMESPACE 0053 0054 class QtEnumPropertyType 0055 { 0056 }; 0057 0058 0059 class QtFlagPropertyType 0060 { 0061 }; 0062 0063 0064 class QtGroupPropertyType 0065 { 0066 }; 0067 0068 QT_END_NAMESPACE 0069 0070 Q_DECLARE_METATYPE(QtEnumPropertyType) 0071 Q_DECLARE_METATYPE(QtFlagPropertyType) 0072 Q_DECLARE_METATYPE(QtGroupPropertyType) 0073 0074 QT_BEGIN_NAMESPACE 0075 0076 /*! 0077 Returns the type id for an enum property. 0078 0079 Note that the property's value type can be retrieved using the 0080 valueType() function (which is QVariant::Int for the enum property 0081 type). 0082 0083 \sa propertyType(), valueType() 0084 */ 0085 int QtVariantPropertyManager::enumTypeId() 0086 { 0087 return qMetaTypeId<QtEnumPropertyType>(); 0088 } 0089 0090 /*! 0091 Returns the type id for a flag property. 0092 0093 Note that the property's value type can be retrieved using the 0094 valueType() function (which is QVariant::Int for the flag property 0095 type). 0096 0097 \sa propertyType(), valueType() 0098 */ 0099 int QtVariantPropertyManager::flagTypeId() 0100 { 0101 return qMetaTypeId<QtFlagPropertyType>(); 0102 } 0103 0104 /*! 0105 Returns the type id for a group property. 0106 0107 Note that the property's value type can be retrieved using the 0108 valueType() function (which is QVariant::Invalid for the group 0109 property type, since it doesn't provide any value). 0110 0111 \sa propertyType(), valueType() 0112 */ 0113 int QtVariantPropertyManager::groupTypeId() 0114 { 0115 return qMetaTypeId<QtGroupPropertyType>(); 0116 } 0117 0118 /*! 0119 Returns the type id for a icon map attribute. 0120 0121 Note that the property's attribute type can be retrieved using the 0122 attributeType() function. 0123 0124 \sa attributeType(), QtEnumPropertyManager::enumIcons() 0125 */ 0126 int QtVariantPropertyManager::iconMapTypeId() 0127 { 0128 return qMetaTypeId<QtIconMap>(); 0129 } 0130 0131 typedef QMap<const QtProperty *, QtProperty *> PropertyMap; 0132 Q_GLOBAL_STATIC(PropertyMap, propertyToWrappedProperty) 0133 0134 static QtProperty *wrappedProperty(QtProperty *property) 0135 { 0136 return propertyToWrappedProperty()->value(property, 0); 0137 } 0138 0139 class QtVariantPropertyPrivate 0140 { 0141 public: 0142 QtVariantPropertyPrivate(QtVariantPropertyManager *m) : manager(m) {} 0143 0144 QtVariantPropertyManager *manager; 0145 }; 0146 0147 /*! 0148 \class QtVariantProperty 0149 \internal 0150 \inmodule QtDesigner 0151 \since 4.4 0152 0153 \brief The QtVariantProperty class is a convenience class handling 0154 QVariant based properties. 0155 0156 QtVariantProperty provides additional API: A property's type, 0157 value type, attribute values and current value can easily be 0158 retrieved using the propertyType(), valueType(), attributeValue() 0159 and value() functions respectively. In addition, the attribute 0160 values and the current value can be set using the corresponding 0161 setValue() and setAttribute() functions. 0162 0163 For example, instead of writing: 0164 0165 \snippet doc/src/snippets/code/tools_shared_qtpropertybrowser_qtvariantproperty.cpp 0 0166 0167 you can write: 0168 0169 \snippet doc/src/snippets/code/tools_shared_qtpropertybrowser_qtvariantproperty.cpp 1 0170 0171 QtVariantProperty instances can only be created by the 0172 QtVariantPropertyManager class. 0173 0174 \sa QtProperty, QtVariantPropertyManager, QtVariantEditorFactory 0175 */ 0176 0177 /*! 0178 Creates a variant property using the given \a manager. 0179 0180 Do not use this constructor to create variant property instances; 0181 use the QtVariantPropertyManager::addProperty() function 0182 instead. This constructor is used internally by the 0183 QtVariantPropertyManager::createProperty() function. 0184 0185 \sa QtVariantPropertyManager 0186 */ 0187 QtVariantProperty::QtVariantProperty(QtVariantPropertyManager *manager) 0188 : QtProperty(manager), d_ptr(new QtVariantPropertyPrivate(manager)) 0189 { 0190 } 0191 0192 /*! 0193 Destroys this property. 0194 0195 \sa QtProperty::~QtProperty() 0196 */ 0197 QtVariantProperty::~QtVariantProperty() 0198 { 0199 } 0200 0201 /*! 0202 Returns the property's current value. 0203 0204 \sa valueType(), setValue() 0205 */ 0206 QVariant QtVariantProperty::value() const 0207 { 0208 return d_ptr->manager->value(this); 0209 } 0210 0211 /*! 0212 Returns this property's value for the specified \a attribute. 0213 0214 QtVariantPropertyManager provides a couple of related functions: 0215 \l{QtVariantPropertyManager::attributes()}{attributes()} and 0216 \l{QtVariantPropertyManager::attributeType()}{attributeType()}. 0217 0218 \sa setAttribute() 0219 */ 0220 QVariant QtVariantProperty::attributeValue(const QString &attribute) const 0221 { 0222 return d_ptr->manager->attributeValue(this, attribute); 0223 } 0224 0225 /*! 0226 Returns the type of this property's value. 0227 0228 \sa propertyType() 0229 */ 0230 int QtVariantProperty::valueType() const 0231 { 0232 return d_ptr->manager->valueType(this); 0233 } 0234 0235 /*! 0236 Returns this property's type. 0237 0238 QtVariantPropertyManager provides several related functions: 0239 \l{QtVariantPropertyManager::enumTypeId()}{enumTypeId()}, 0240 \l{QtVariantPropertyManager::flagTypeId()}{flagTypeId()} and 0241 \l{QtVariantPropertyManager::groupTypeId()}{groupTypeId()}. 0242 0243 \sa valueType() 0244 */ 0245 int QtVariantProperty::propertyType() const 0246 { 0247 return d_ptr->manager->propertyType(this); 0248 } 0249 0250 /*! 0251 Sets the value of this property to \a value. 0252 0253 The specified \a value must be of the type returned by 0254 valueType(), or of a type that can be converted to valueType() 0255 using the QVariant::canConvert() function; otherwise this function 0256 does nothing. 0257 0258 \sa value() 0259 */ 0260 void QtVariantProperty::setValue(const QVariant &value) 0261 { 0262 d_ptr->manager->setValue(this, value); 0263 } 0264 0265 /*! 0266 Sets the \a attribute of property to \a value. 0267 0268 QtVariantPropertyManager provides the related 0269 \l{QtVariantPropertyManager::setAttribute()}{setAttribute()} 0270 function. 0271 0272 \sa attributeValue() 0273 */ 0274 void QtVariantProperty::setAttribute(const QString &attribute, const QVariant &value) 0275 { 0276 d_ptr->manager->setAttribute(this, attribute, value); 0277 } 0278 0279 class QtVariantPropertyManagerPrivate 0280 { 0281 QtVariantPropertyManager *q_ptr; 0282 Q_DECLARE_PUBLIC(QtVariantPropertyManager) 0283 public: 0284 QtVariantPropertyManagerPrivate(); 0285 0286 bool m_creatingProperty; 0287 bool m_creatingSubProperties; 0288 bool m_destroyingSubProperties; 0289 int m_propertyType; 0290 0291 void slotValueChanged(QtProperty *property, int val); 0292 void slotRangeChanged(QtProperty *property, int min, int max); 0293 void slotSingleStepChanged(QtProperty *property, int step); 0294 void slotValueChanged(QtProperty *property, double val); 0295 void slotRangeChanged(QtProperty *property, double min, double max); 0296 void slotSingleStepChanged(QtProperty *property, double step); 0297 void slotDecimalsChanged(QtProperty *property, int prec); 0298 void slotValueChanged(QtProperty *property, bool val); 0299 void slotValueChanged(QtProperty *property, const QString &val); 0300 void slotRegExpChanged(QtProperty *property, const QRegExp ®Exp); 0301 void slotValueChanged(QtProperty *property, const QDate &val); 0302 void slotRangeChanged(QtProperty *property, const QDate &min, const QDate &max); 0303 void slotValueChanged(QtProperty *property, const QTime &val); 0304 void slotValueChanged(QtProperty *property, const QDateTime &val); 0305 void slotValueChanged(QtProperty *property, const QKeySequence &val); 0306 void slotValueChanged(QtProperty *property, const QChar &val); 0307 void slotValueChanged(QtProperty *property, const QLocale &val); 0308 void slotValueChanged(QtProperty *property, const QPoint &val); 0309 void slotValueChanged(QtProperty *property, const QPointF &val); 0310 void slotValueChanged(QtProperty *property, const QSize &val); 0311 void slotRangeChanged(QtProperty *property, const QSize &min, const QSize &max); 0312 void slotValueChanged(QtProperty *property, const QSizeF &val); 0313 void slotRangeChanged(QtProperty *property, const QSizeF &min, const QSizeF &max); 0314 void slotValueChanged(QtProperty *property, const QRect &val); 0315 void slotConstraintChanged(QtProperty *property, const QRect &val); 0316 void slotValueChanged(QtProperty *property, const QRectF &val); 0317 void slotConstraintChanged(QtProperty *property, const QRectF &val); 0318 void slotValueChanged(QtProperty *property, const QColor &val); 0319 void slotEnumChanged(QtProperty *property, int val); 0320 void slotEnumNamesChanged(QtProperty *property, const QStringList &enumNames); 0321 void slotEnumIconsChanged(QtProperty *property, const QMap<int, QIcon> &enumIcons); 0322 void slotValueChanged(QtProperty *property, const QSizePolicy &val); 0323 void slotValueChanged(QtProperty *property, const QFont &val); 0324 void slotValueChanged(QtProperty *property, const QCursor &val); 0325 void slotFlagChanged(QtProperty *property, int val); 0326 void slotFlagNamesChanged(QtProperty *property, const QStringList &flagNames); 0327 void slotPropertyInserted(QtProperty *property, QtProperty *parent, QtProperty *after); 0328 void slotPropertyRemoved(QtProperty *property, QtProperty *parent); 0329 0330 void valueChanged(QtProperty *property, const QVariant &val); 0331 0332 int internalPropertyToType(QtProperty *property) const; 0333 QtVariantProperty *createSubProperty(QtVariantProperty *parent, QtVariantProperty *after, 0334 QtProperty *internal); 0335 void removeSubProperty(QtVariantProperty *property); 0336 0337 QMap<int, QtAbstractPropertyManager *> m_typeToPropertyManager; 0338 QMap<int, QMap<QString, int> > m_typeToAttributeToAttributeType; 0339 0340 QMap<const QtProperty *, QPair<QtVariantProperty *, int> > m_propertyToType; 0341 0342 QMap<int, int> m_typeToValueType; 0343 0344 0345 QMap<QtProperty *, QtVariantProperty *> m_internalToProperty; 0346 0347 const QString m_constraintAttribute; 0348 const QString m_singleStepAttribute; 0349 const QString m_decimalsAttribute; 0350 const QString m_enumIconsAttribute; 0351 const QString m_enumNamesAttribute; 0352 const QString m_flagNamesAttribute; 0353 const QString m_maximumAttribute; 0354 const QString m_minimumAttribute; 0355 const QString m_regExpAttribute; 0356 }; 0357 0358 QtVariantPropertyManagerPrivate::QtVariantPropertyManagerPrivate() : 0359 m_constraintAttribute(QLatin1String("constraint")), 0360 m_singleStepAttribute(QLatin1String("singleStep")), 0361 m_decimalsAttribute(QLatin1String("decimals")), 0362 m_enumIconsAttribute(QLatin1String("enumIcons")), 0363 m_enumNamesAttribute(QLatin1String("enumNames")), 0364 m_flagNamesAttribute(QLatin1String("flagNames")), 0365 m_maximumAttribute(QLatin1String("maximum")), 0366 m_minimumAttribute(QLatin1String("minimum")), 0367 m_regExpAttribute(QLatin1String("regExp")) 0368 { 0369 } 0370 0371 int QtVariantPropertyManagerPrivate::internalPropertyToType(QtProperty *property) const 0372 { 0373 int type = 0; 0374 QtAbstractPropertyManager *internPropertyManager = property->propertyManager(); 0375 if (qobject_cast<QtIntPropertyManager *>(internPropertyManager)) 0376 type = QVariant::Int; 0377 else if (qobject_cast<QtEnumPropertyManager *>(internPropertyManager)) 0378 type = QtVariantPropertyManager::enumTypeId(); 0379 else if (qobject_cast<QtBoolPropertyManager *>(internPropertyManager)) 0380 type = QVariant::Bool; 0381 else if (qobject_cast<QtDoublePropertyManager *>(internPropertyManager)) 0382 type = QVariant::Double; 0383 return type; 0384 } 0385 0386 QtVariantProperty *QtVariantPropertyManagerPrivate::createSubProperty(QtVariantProperty *parent, 0387 QtVariantProperty *after, QtProperty *internal) 0388 { 0389 int type = internalPropertyToType(internal); 0390 if (!type) 0391 return 0; 0392 0393 bool wasCreatingSubProperties = m_creatingSubProperties; 0394 m_creatingSubProperties = true; 0395 0396 QtVariantProperty *varChild = q_ptr->addProperty(type, internal->propertyName()); 0397 0398 m_creatingSubProperties = wasCreatingSubProperties; 0399 0400 varChild->setPropertyName(internal->propertyName()); 0401 varChild->setToolTip(internal->toolTip()); 0402 varChild->setStatusTip(internal->statusTip()); 0403 varChild->setWhatsThis(internal->whatsThis()); 0404 0405 parent->insertSubProperty(varChild, after); 0406 0407 m_internalToProperty[internal] = varChild; 0408 propertyToWrappedProperty()->insert(varChild, internal); 0409 return varChild; 0410 } 0411 0412 void QtVariantPropertyManagerPrivate::removeSubProperty(QtVariantProperty *property) 0413 { 0414 QtProperty *internChild = wrappedProperty(property); 0415 bool wasDestroyingSubProperties = m_destroyingSubProperties; 0416 m_destroyingSubProperties = true; 0417 delete property; 0418 m_destroyingSubProperties = wasDestroyingSubProperties; 0419 m_internalToProperty.remove(internChild); 0420 propertyToWrappedProperty()->remove(property); 0421 } 0422 0423 void QtVariantPropertyManagerPrivate::slotPropertyInserted(QtProperty *property, 0424 QtProperty *parent, QtProperty *after) 0425 { 0426 if (m_creatingProperty) 0427 return; 0428 0429 QtVariantProperty *varParent = m_internalToProperty.value(parent, 0); 0430 if (!varParent) 0431 return; 0432 0433 QtVariantProperty *varAfter = 0; 0434 if (after) { 0435 varAfter = m_internalToProperty.value(after, 0); 0436 if (!varAfter) 0437 return; 0438 } 0439 0440 createSubProperty(varParent, varAfter, property); 0441 } 0442 0443 void QtVariantPropertyManagerPrivate::slotPropertyRemoved(QtProperty *property, QtProperty *parent) 0444 { 0445 Q_UNUSED(parent) 0446 0447 QtVariantProperty *varProperty = m_internalToProperty.value(property, 0); 0448 if (!varProperty) 0449 return; 0450 0451 removeSubProperty(varProperty); 0452 } 0453 0454 void QtVariantPropertyManagerPrivate::valueChanged(QtProperty *property, const QVariant &val) 0455 { 0456 QtVariantProperty *varProp = m_internalToProperty.value(property, 0); 0457 if (!varProp) 0458 return; 0459 Q_EMIT q_ptr->valueChanged(varProp, val); 0460 Q_EMIT q_ptr->propertyChanged(varProp); 0461 } 0462 0463 void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, int val) 0464 { 0465 valueChanged(property, QVariant(val)); 0466 } 0467 0468 void QtVariantPropertyManagerPrivate::slotRangeChanged(QtProperty *property, int min, int max) 0469 { 0470 if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0)) { 0471 Q_EMIT q_ptr->attributeChanged(varProp, m_minimumAttribute, QVariant(min)); 0472 Q_EMIT q_ptr->attributeChanged(varProp, m_maximumAttribute, QVariant(max)); 0473 } 0474 } 0475 0476 void QtVariantPropertyManagerPrivate::slotSingleStepChanged(QtProperty *property, int step) 0477 { 0478 if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0)) 0479 Q_EMIT q_ptr->attributeChanged(varProp, m_singleStepAttribute, QVariant(step)); 0480 } 0481 0482 void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, double val) 0483 { 0484 valueChanged(property, QVariant(val)); 0485 } 0486 0487 void QtVariantPropertyManagerPrivate::slotRangeChanged(QtProperty *property, double min, double max) 0488 { 0489 if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0)) { 0490 Q_EMIT q_ptr->attributeChanged(varProp, m_minimumAttribute, QVariant(min)); 0491 Q_EMIT q_ptr->attributeChanged(varProp, m_maximumAttribute, QVariant(max)); 0492 } 0493 } 0494 0495 void QtVariantPropertyManagerPrivate::slotSingleStepChanged(QtProperty *property, double step) 0496 { 0497 if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0)) 0498 Q_EMIT q_ptr->attributeChanged(varProp, m_singleStepAttribute, QVariant(step)); 0499 } 0500 0501 void QtVariantPropertyManagerPrivate::slotDecimalsChanged(QtProperty *property, int prec) 0502 { 0503 if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0)) 0504 Q_EMIT q_ptr->attributeChanged(varProp, m_decimalsAttribute, QVariant(prec)); 0505 } 0506 0507 void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, bool val) 0508 { 0509 valueChanged(property, QVariant(val)); 0510 } 0511 0512 void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QString &val) 0513 { 0514 valueChanged(property, QVariant(val)); 0515 } 0516 0517 void QtVariantPropertyManagerPrivate::slotRegExpChanged(QtProperty *property, const QRegExp ®Exp) 0518 { 0519 if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0)) 0520 Q_EMIT q_ptr->attributeChanged(varProp, m_regExpAttribute, QVariant(regExp)); 0521 } 0522 0523 void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QDate &val) 0524 { 0525 valueChanged(property, QVariant(val)); 0526 } 0527 0528 void QtVariantPropertyManagerPrivate::slotRangeChanged(QtProperty *property, const QDate &min, const QDate &max) 0529 { 0530 if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0)) { 0531 Q_EMIT q_ptr->attributeChanged(varProp, m_minimumAttribute, QVariant(min)); 0532 Q_EMIT q_ptr->attributeChanged(varProp, m_maximumAttribute, QVariant(max)); 0533 } 0534 } 0535 0536 void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QTime &val) 0537 { 0538 valueChanged(property, QVariant(val)); 0539 } 0540 0541 void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QDateTime &val) 0542 { 0543 valueChanged(property, QVariant(val)); 0544 } 0545 0546 void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QKeySequence &val) 0547 { 0548 QVariant v; 0549 v.setValue(val); 0550 valueChanged(property, v); 0551 } 0552 0553 void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QChar &val) 0554 { 0555 valueChanged(property, QVariant(val)); 0556 } 0557 0558 void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QLocale &val) 0559 { 0560 valueChanged(property, QVariant(val)); 0561 } 0562 0563 void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QPoint &val) 0564 { 0565 valueChanged(property, QVariant(val)); 0566 } 0567 0568 void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QPointF &val) 0569 { 0570 valueChanged(property, QVariant(val)); 0571 } 0572 0573 void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QSize &val) 0574 { 0575 valueChanged(property, QVariant(val)); 0576 } 0577 0578 void QtVariantPropertyManagerPrivate::slotRangeChanged(QtProperty *property, const QSize &min, const QSize &max) 0579 { 0580 if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0)) { 0581 Q_EMIT q_ptr->attributeChanged(varProp, m_minimumAttribute, QVariant(min)); 0582 Q_EMIT q_ptr->attributeChanged(varProp, m_maximumAttribute, QVariant(max)); 0583 } 0584 } 0585 0586 void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QSizeF &val) 0587 { 0588 valueChanged(property, QVariant(val)); 0589 } 0590 0591 void QtVariantPropertyManagerPrivate::slotRangeChanged(QtProperty *property, const QSizeF &min, const QSizeF &max) 0592 { 0593 if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0)) { 0594 Q_EMIT q_ptr->attributeChanged(varProp, m_minimumAttribute, QVariant(min)); 0595 Q_EMIT q_ptr->attributeChanged(varProp, m_maximumAttribute, QVariant(max)); 0596 } 0597 } 0598 0599 void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QRect &val) 0600 { 0601 valueChanged(property, QVariant(val)); 0602 } 0603 0604 void QtVariantPropertyManagerPrivate::slotConstraintChanged(QtProperty *property, const QRect &constraint) 0605 { 0606 if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0)) 0607 Q_EMIT q_ptr->attributeChanged(varProp, m_constraintAttribute, QVariant(constraint)); 0608 } 0609 0610 void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QRectF &val) 0611 { 0612 valueChanged(property, QVariant(val)); 0613 } 0614 0615 void QtVariantPropertyManagerPrivate::slotConstraintChanged(QtProperty *property, const QRectF &constraint) 0616 { 0617 if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0)) 0618 Q_EMIT q_ptr->attributeChanged(varProp, m_constraintAttribute, QVariant(constraint)); 0619 } 0620 0621 void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QColor &val) 0622 { 0623 valueChanged(property, QVariant(val)); 0624 } 0625 0626 void QtVariantPropertyManagerPrivate::slotEnumNamesChanged(QtProperty *property, const QStringList &enumNames) 0627 { 0628 if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0)) 0629 Q_EMIT q_ptr->attributeChanged(varProp, m_enumNamesAttribute, QVariant(enumNames)); 0630 } 0631 0632 void QtVariantPropertyManagerPrivate::slotEnumIconsChanged(QtProperty *property, const QMap<int, QIcon> &enumIcons) 0633 { 0634 if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0)) { 0635 QVariant v; 0636 v.setValue(enumIcons); 0637 Q_EMIT q_ptr->attributeChanged(varProp, m_enumIconsAttribute, v); 0638 } 0639 } 0640 0641 void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QSizePolicy &val) 0642 { 0643 valueChanged(property, QVariant(val)); 0644 } 0645 0646 void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QFont &val) 0647 { 0648 valueChanged(property, QVariant(val)); 0649 } 0650 0651 void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QCursor &val) 0652 { 0653 #ifndef QT_NO_CURSOR 0654 valueChanged(property, QVariant(val)); 0655 #endif 0656 } 0657 0658 void QtVariantPropertyManagerPrivate::slotFlagNamesChanged(QtProperty *property, const QStringList &flagNames) 0659 { 0660 if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0)) 0661 Q_EMIT q_ptr->attributeChanged(varProp, m_flagNamesAttribute, QVariant(flagNames)); 0662 } 0663 0664 /*! 0665 \class QtVariantPropertyManager 0666 \internal 0667 \inmodule QtDesigner 0668 \since 4.4 0669 0670 \brief The QtVariantPropertyManager class provides and manages QVariant based properties. 0671 0672 QtVariantPropertyManager provides the addProperty() function which 0673 creates QtVariantProperty objects. The QtVariantProperty class is 0674 a convenience class handling QVariant based properties inheriting 0675 QtProperty. A QtProperty object created by a 0676 QtVariantPropertyManager instance can be converted into a 0677 QtVariantProperty object using the variantProperty() function. 0678 0679 The property's value can be retrieved using the value(), and set 0680 using the setValue() slot. In addition the property's type, and 0681 the type of its value, can be retrieved using the propertyType() 0682 and valueType() functions respectively. 0683 0684 A property's type is a QVariant::Type enumerator value, and 0685 usually a property's type is the same as its value type. But for 0686 some properties the types differ, for example for enums, flags and 0687 group types in which case QtVariantPropertyManager provides the 0688 enumTypeId(), flagTypeId() and groupTypeId() functions, 0689 respectively, to identify their property type (the value types are 0690 QVariant::Int for the enum and flag types, and QVariant::Invalid 0691 for the group type). 0692 0693 Use the isPropertyTypeSupported() function to check if a particular 0694 property type is supported. The currently supported property types 0695 are: 0696 0697 \table 0698 \header 0699 \li Property Type 0700 \li Property Type Id 0701 \row 0702 \li int 0703 \li QVariant::Int 0704 \row 0705 \li double 0706 \li QVariant::Double 0707 \row 0708 \li bool 0709 \li QVariant::Bool 0710 \row 0711 \li QString 0712 \li QVariant::String 0713 \row 0714 \li QDate 0715 \li QVariant::Date 0716 \row 0717 \li QTime 0718 \li QVariant::Time 0719 \row 0720 \li QDateTime 0721 \li QVariant::DateTime 0722 \row 0723 \li QKeySequence 0724 \li QVariant::KeySequence 0725 \row 0726 \li QChar 0727 \li QVariant::Char 0728 \row 0729 \li QLocale 0730 \li QVariant::Locale 0731 \row 0732 \li QPoint 0733 \li QVariant::Point 0734 \row 0735 \li QPointF 0736 \li QVariant::PointF 0737 \row 0738 \li QSize 0739 \li QVariant::Size 0740 \row 0741 \li QSizeF 0742 \li QVariant::SizeF 0743 \row 0744 \li QRect 0745 \li QVariant::Rect 0746 \row 0747 \li QRectF 0748 \li QVariant::RectF 0749 \row 0750 \li QColor 0751 \li QVariant::Color 0752 \row 0753 \li QSizePolicy 0754 \li QVariant::SizePolicy 0755 \row 0756 \li QFont 0757 \li QVariant::Font 0758 \row 0759 \li QCursor 0760 \li QVariant::Cursor 0761 \row 0762 \li enum 0763 \li enumTypeId() 0764 \row 0765 \li flag 0766 \li flagTypeId() 0767 \row 0768 \li group 0769 \li groupTypeId() 0770 \endtable 0771 0772 Each property type can provide additional attributes, 0773 e.g. QVariant::Int and QVariant::Double provides minimum and 0774 maximum values. The currently supported attributes are: 0775 0776 \table 0777 \header 0778 \li Property Type 0779 \li Attribute Name 0780 \li Attribute Type 0781 \row 0782 \li \c int 0783 \li minimum 0784 \li QVariant::Int 0785 \row 0786 \li 0787 \li maximum 0788 \li QVariant::Int 0789 \row 0790 \li 0791 \li singleStep 0792 \li QVariant::Int 0793 \row 0794 \li \c double 0795 \li minimum 0796 \li QVariant::Double 0797 \row 0798 \li 0799 \li maximum 0800 \li QVariant::Double 0801 \row 0802 \li 0803 \li singleStep 0804 \li QVariant::Double 0805 \row 0806 \li 0807 \li decimals 0808 \li QVariant::Int 0809 \row 0810 \li QString 0811 \li regExp 0812 \li QVariant::RegExp 0813 \row 0814 \li QDate 0815 \li minimum 0816 \li QVariant::Date 0817 \row 0818 \li 0819 \li maximum 0820 \li QVariant::Date 0821 \row 0822 \li QPointF 0823 \li decimals 0824 \li QVariant::Int 0825 \row 0826 \li QSize 0827 \li minimum 0828 \li QVariant::Size 0829 \row 0830 \li 0831 \li maximum 0832 \li QVariant::Size 0833 \row 0834 \li QSizeF 0835 \li minimum 0836 \li QVariant::SizeF 0837 \row 0838 \li 0839 \li maximum 0840 \li QVariant::SizeF 0841 \row 0842 \li 0843 \li decimals 0844 \li QVariant::Int 0845 \row 0846 \li QRect 0847 \li constraint 0848 \li QVariant::Rect 0849 \row 0850 \li QRectF 0851 \li constraint 0852 \li QVariant::RectF 0853 \row 0854 \li 0855 \li decimals 0856 \li QVariant::Int 0857 \row 0858 \li \c enum 0859 \li enumNames 0860 \li QVariant::StringList 0861 \row 0862 \li 0863 \li enumIcons 0864 \li iconMapTypeId() 0865 \row 0866 \li \c flag 0867 \li flagNames 0868 \li QVariant::StringList 0869 \endtable 0870 0871 The attributes for a given property type can be retrieved using 0872 the attributes() function. Each attribute has a value type which 0873 can be retrieved using the attributeType() function, and a value 0874 accessible through the attributeValue() function. In addition, the 0875 value can be set using the setAttribute() slot. 0876 0877 QtVariantManager also provides the valueChanged() signal which is 0878 emitted whenever a property created by this manager change, and 0879 the attributeChanged() signal which is emitted whenever an 0880 attribute of such a property changes. 0881 0882 \sa QtVariantProperty, QtVariantEditorFactory 0883 */ 0884 0885 /*! 0886 \fn void QtVariantPropertyManager::valueChanged(QtProperty *property, const QVariant &value) 0887 0888 This signal is emitted whenever a property created by this manager 0889 changes its value, passing a pointer to the \a property and the 0890 new \a value as parameters. 0891 0892 \sa setValue() 0893 */ 0894 0895 /*! 0896 \fn void QtVariantPropertyManager::attributeChanged(QtProperty *property, 0897 const QString &attribute, const QVariant &value) 0898 0899 This signal is emitted whenever an attribute of a property created 0900 by this manager changes its value, passing a pointer to the \a 0901 property, the \a attribute and the new \a value as parameters. 0902 0903 \sa setAttribute() 0904 */ 0905 0906 /*! 0907 Creates a manager with the given \a parent. 0908 */ 0909 QtVariantPropertyManager::QtVariantPropertyManager(QObject *parent) 0910 : QtAbstractPropertyManager(parent), d_ptr(new QtVariantPropertyManagerPrivate) 0911 { 0912 d_ptr->q_ptr = this; 0913 0914 d_ptr->m_creatingProperty = false; 0915 d_ptr->m_creatingSubProperties = false; 0916 d_ptr->m_destroyingSubProperties = false; 0917 d_ptr->m_propertyType = 0; 0918 0919 // IntPropertyManager 0920 QtIntPropertyManager *intPropertyManager = new QtIntPropertyManager(this); 0921 d_ptr->m_typeToPropertyManager[QVariant::Int] = intPropertyManager; 0922 d_ptr->m_typeToAttributeToAttributeType[QVariant::Int][d_ptr->m_minimumAttribute] = QVariant::Int; 0923 d_ptr->m_typeToAttributeToAttributeType[QVariant::Int][d_ptr->m_maximumAttribute] = QVariant::Int; 0924 d_ptr->m_typeToAttributeToAttributeType[QVariant::Int][d_ptr->m_singleStepAttribute] = QVariant::Int; 0925 d_ptr->m_typeToValueType[QVariant::Int] = QVariant::Int; 0926 connect(intPropertyManager, SIGNAL(valueChanged(QtProperty*,int)), 0927 this, SLOT(slotValueChanged(QtProperty*,int))); 0928 connect(intPropertyManager, SIGNAL(rangeChanged(QtProperty*,int,int)), 0929 this, SLOT(slotRangeChanged(QtProperty*,int,int))); 0930 connect(intPropertyManager, SIGNAL(singleStepChanged(QtProperty*,int)), 0931 this, SLOT(slotSingleStepChanged(QtProperty*,int))); 0932 // DoublePropertyManager 0933 QtDoublePropertyManager *doublePropertyManager = new QtDoublePropertyManager(this); 0934 d_ptr->m_typeToPropertyManager[QVariant::Double] = doublePropertyManager; 0935 d_ptr->m_typeToAttributeToAttributeType[QVariant::Double][d_ptr->m_minimumAttribute] = 0936 QVariant::Double; 0937 d_ptr->m_typeToAttributeToAttributeType[QVariant::Double][d_ptr->m_maximumAttribute] = 0938 QVariant::Double; 0939 d_ptr->m_typeToAttributeToAttributeType[QVariant::Double][d_ptr->m_singleStepAttribute] = 0940 QVariant::Double; 0941 d_ptr->m_typeToAttributeToAttributeType[QVariant::Double][d_ptr->m_decimalsAttribute] = 0942 QVariant::Int; 0943 d_ptr->m_typeToValueType[QVariant::Double] = QVariant::Double; 0944 connect(doublePropertyManager, SIGNAL(valueChanged(QtProperty*,double)), 0945 this, SLOT(slotValueChanged(QtProperty*,double))); 0946 connect(doublePropertyManager, SIGNAL(rangeChanged(QtProperty*,double,double)), 0947 this, SLOT(slotRangeChanged(QtProperty*,double,double))); 0948 connect(doublePropertyManager, SIGNAL(singleStepChanged(QtProperty*,double)), 0949 this, SLOT(slotSingleStepChanged(QtProperty*,double))); 0950 connect(doublePropertyManager, SIGNAL(decimalsChanged(QtProperty*,int)), 0951 this, SLOT(slotDecimalsChanged(QtProperty*,int))); 0952 // BoolPropertyManager 0953 QtBoolPropertyManager *boolPropertyManager = new QtBoolPropertyManager(this); 0954 d_ptr->m_typeToPropertyManager[QVariant::Bool] = boolPropertyManager; 0955 d_ptr->m_typeToValueType[QVariant::Bool] = QVariant::Bool; 0956 connect(boolPropertyManager, SIGNAL(valueChanged(QtProperty*,bool)), 0957 this, SLOT(slotValueChanged(QtProperty*,bool))); 0958 // StringPropertyManager 0959 QtStringPropertyManager *stringPropertyManager = new QtStringPropertyManager(this); 0960 d_ptr->m_typeToPropertyManager[QVariant::String] = stringPropertyManager; 0961 d_ptr->m_typeToValueType[QVariant::String] = QVariant::String; 0962 d_ptr->m_typeToAttributeToAttributeType[QVariant::String][d_ptr->m_regExpAttribute] = 0963 QVariant::RegExp; 0964 connect(stringPropertyManager, SIGNAL(valueChanged(QtProperty*,QString)), 0965 this, SLOT(slotValueChanged(QtProperty*,QString))); 0966 connect(stringPropertyManager, SIGNAL(regExpChanged(QtProperty*,QRegExp)), 0967 this, SLOT(slotRegExpChanged(QtProperty*,QRegExp))); 0968 // DatePropertyManager 0969 QtDatePropertyManager *datePropertyManager = new QtDatePropertyManager(this); 0970 d_ptr->m_typeToPropertyManager[QVariant::Date] = datePropertyManager; 0971 d_ptr->m_typeToValueType[QVariant::Date] = QVariant::Date; 0972 d_ptr->m_typeToAttributeToAttributeType[QVariant::Date][d_ptr->m_minimumAttribute] = 0973 QVariant::Date; 0974 d_ptr->m_typeToAttributeToAttributeType[QVariant::Date][d_ptr->m_maximumAttribute] = 0975 QVariant::Date; 0976 connect(datePropertyManager, SIGNAL(valueChanged(QtProperty*,QDate)), 0977 this, SLOT(slotValueChanged(QtProperty*,QDate))); 0978 connect(datePropertyManager, SIGNAL(rangeChanged(QtProperty*,QDate,QDate)), 0979 this, SLOT(slotRangeChanged(QtProperty*,QDate,QDate))); 0980 // TimePropertyManager 0981 QtTimePropertyManager *timePropertyManager = new QtTimePropertyManager(this); 0982 d_ptr->m_typeToPropertyManager[QVariant::Time] = timePropertyManager; 0983 d_ptr->m_typeToValueType[QVariant::Time] = QVariant::Time; 0984 connect(timePropertyManager, SIGNAL(valueChanged(QtProperty*,QTime)), 0985 this, SLOT(slotValueChanged(QtProperty*,QTime))); 0986 // DateTimePropertyManager 0987 QtDateTimePropertyManager *dateTimePropertyManager = new QtDateTimePropertyManager(this); 0988 d_ptr->m_typeToPropertyManager[QVariant::DateTime] = dateTimePropertyManager; 0989 d_ptr->m_typeToValueType[QVariant::DateTime] = QVariant::DateTime; 0990 connect(dateTimePropertyManager, SIGNAL(valueChanged(QtProperty*,QDateTime)), 0991 this, SLOT(slotValueChanged(QtProperty*,QDateTime))); 0992 // KeySequencePropertyManager 0993 QtKeySequencePropertyManager *keySequencePropertyManager = new QtKeySequencePropertyManager(this); 0994 d_ptr->m_typeToPropertyManager[QVariant::KeySequence] = keySequencePropertyManager; 0995 d_ptr->m_typeToValueType[QVariant::KeySequence] = QVariant::KeySequence; 0996 connect(keySequencePropertyManager, SIGNAL(valueChanged(QtProperty*,QKeySequence)), 0997 this, SLOT(slotValueChanged(QtProperty*,QKeySequence))); 0998 // CharPropertyManager 0999 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 */ 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 */ 1241 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 */ 1255 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 */ 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 */ 1302 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 */ 1365 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 */ 1376 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 */ 1388 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 */ 1406 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 */ 1505 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 */ 1524 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 */ 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 */ 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 */ 1742 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 */ 1752 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 */ 1761 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 */ 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 QList<QtProperty *> 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 */ 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 */ 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 */ 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 */ 1985 QtVariantEditorFactory::~QtVariantEditorFactory() 1986 { 1987 } 1988 1989 /*! 1990 \internal 1991 1992 Reimplemented from the QtAbstractEditorFactory class. 1993 */ 1994 void QtVariantEditorFactory::connectPropertyManager(QtVariantPropertyManager *manager) 1995 { 1996 const QList<QtIntPropertyManager *> intPropertyManagers = manager->findChildren<QtIntPropertyManager *>(); 1997 for (QtIntPropertyManager *manager : intPropertyManagers) 1998 d_ptr->m_spinBoxFactory->addPropertyManager(manager); 1999 2000 const QList<QtDoublePropertyManager *> doublePropertyManagers = manager->findChildren<QtDoublePropertyManager *>(); 2001 for (QtDoublePropertyManager *manager : doublePropertyManagers) 2002 d_ptr->m_doubleSpinBoxFactory->addPropertyManager(manager); 2003 2004 const QList<QtBoolPropertyManager *> boolPropertyManagers = manager->findChildren<QtBoolPropertyManager *>(); 2005 for (QtBoolPropertyManager *manager : boolPropertyManagers) 2006 d_ptr->m_checkBoxFactory->addPropertyManager(manager); 2007 2008 const QList<QtStringPropertyManager *> stringPropertyManagers = manager->findChildren<QtStringPropertyManager *>(); 2009 for (QtStringPropertyManager *manager : stringPropertyManagers) 2010 d_ptr->m_lineEditFactory->addPropertyManager(manager); 2011 2012 const QList<QtDatePropertyManager *> datePropertyManagers = manager->findChildren<QtDatePropertyManager *>(); 2013 for (QtDatePropertyManager *manager : datePropertyManagers) 2014 d_ptr->m_dateEditFactory->addPropertyManager(manager); 2015 2016 const QList<QtTimePropertyManager *> timePropertyManagers = manager->findChildren<QtTimePropertyManager *>(); 2017 for (QtTimePropertyManager *manager : timePropertyManagers) 2018 d_ptr->m_timeEditFactory->addPropertyManager(manager); 2019 2020 const QList<QtDateTimePropertyManager *> dateTimePropertyManagers = manager->findChildren<QtDateTimePropertyManager *>(); 2021 for (QtDateTimePropertyManager *manager : dateTimePropertyManagers) 2022 d_ptr->m_dateTimeEditFactory->addPropertyManager(manager); 2023 2024 const QList<QtKeySequencePropertyManager *> keySequencePropertyManagers = manager->findChildren<QtKeySequencePropertyManager *>(); 2025 for (QtKeySequencePropertyManager *manager : keySequencePropertyManagers) 2026 d_ptr->m_keySequenceEditorFactory->addPropertyManager(manager); 2027 2028 const QList<QtCharPropertyManager *> charPropertyManagers = manager->findChildren<QtCharPropertyManager *>(); 2029 for (QtCharPropertyManager *manager : charPropertyManagers) 2030 d_ptr->m_charEditorFactory->addPropertyManager(manager); 2031 2032 const QList<QtLocalePropertyManager *> localePropertyManagers = manager->findChildren<QtLocalePropertyManager *>(); 2033 for (QtLocalePropertyManager *manager : localePropertyManagers) 2034 d_ptr->m_comboBoxFactory->addPropertyManager(manager->subEnumPropertyManager()); 2035 2036 const QList<QtPointPropertyManager *> pointPropertyManagers = manager->findChildren<QtPointPropertyManager *>(); 2037 for (QtPointPropertyManager *manager : pointPropertyManagers) 2038 d_ptr->m_spinBoxFactory->addPropertyManager(manager->subIntPropertyManager()); 2039 2040 const QList<QtPointFPropertyManager *> pointFPropertyManagers = manager->findChildren<QtPointFPropertyManager *>(); 2041 for (QtPointFPropertyManager *manager : pointFPropertyManagers) 2042 d_ptr->m_doubleSpinBoxFactory->addPropertyManager(manager->subDoublePropertyManager()); 2043 2044 const QList<QtSizePropertyManager *> sizePropertyManagers = manager->findChildren<QtSizePropertyManager *>(); 2045 for (QtSizePropertyManager *manager : sizePropertyManagers) 2046 d_ptr->m_spinBoxFactory->addPropertyManager(manager->subIntPropertyManager()); 2047 2048 const QList<QtSizeFPropertyManager *> sizeFPropertyManagers = manager->findChildren<QtSizeFPropertyManager *>(); 2049 for (QtSizeFPropertyManager *manager : sizeFPropertyManagers) 2050 d_ptr->m_doubleSpinBoxFactory->addPropertyManager(manager->subDoublePropertyManager()); 2051 2052 const QList<QtRectPropertyManager *> rectPropertyManagers = manager->findChildren<QtRectPropertyManager *>(); 2053 for (QtRectPropertyManager *manager : rectPropertyManagers) 2054 d_ptr->m_spinBoxFactory->addPropertyManager(manager->subIntPropertyManager()); 2055 2056 const QList<QtRectFPropertyManager *> rectFPropertyManagers = manager->findChildren<QtRectFPropertyManager *>(); 2057 for (QtRectFPropertyManager *manager : rectFPropertyManagers) 2058 d_ptr->m_doubleSpinBoxFactory->addPropertyManager(manager->subDoublePropertyManager()); 2059 2060 const QList<QtColorPropertyManager *> 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 QList<QtEnumPropertyManager *> enumPropertyManagers = manager->findChildren<QtEnumPropertyManager *>(); 2067 for (QtEnumPropertyManager *manager : enumPropertyManagers) 2068 d_ptr->m_comboBoxFactory->addPropertyManager(manager); 2069 2070 const QList<QtSizePolicyPropertyManager *> 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 QList<QtFontPropertyManager *> 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 QList<QtCursorPropertyManager *> cursorPropertyManagers = manager->findChildren<QtCursorPropertyManager *>(); 2085 for (QtCursorPropertyManager *manager : cursorPropertyManagers) 2086 d_ptr->m_cursorEditorFactory->addPropertyManager(manager); 2087 2088 const QList<QtFlagPropertyManager *> 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 */ 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 */ 2113 void QtVariantEditorFactory::disconnectPropertyManager(QtVariantPropertyManager *manager) 2114 { 2115 const QList<QtIntPropertyManager *> intPropertyManagers = manager->findChildren<QtIntPropertyManager *>(); 2116 for (QtIntPropertyManager *manager : intPropertyManagers) 2117 d_ptr->m_spinBoxFactory->removePropertyManager(manager); 2118 2119 const QList<QtDoublePropertyManager *> doublePropertyManagers = manager->findChildren<QtDoublePropertyManager *>(); 2120 for (QtDoublePropertyManager *manager : doublePropertyManagers) 2121 d_ptr->m_doubleSpinBoxFactory->removePropertyManager(manager); 2122 2123 const QList<QtBoolPropertyManager *> boolPropertyManagers = manager->findChildren<QtBoolPropertyManager *>(); 2124 for (QtBoolPropertyManager *manager : boolPropertyManagers) 2125 d_ptr->m_checkBoxFactory->removePropertyManager(manager); 2126 2127 const QList<QtStringPropertyManager *> stringPropertyManagers = manager->findChildren<QtStringPropertyManager *>(); 2128 for (QtStringPropertyManager *manager : stringPropertyManagers) 2129 d_ptr->m_lineEditFactory->removePropertyManager(manager); 2130 2131 const QList<QtDatePropertyManager *> datePropertyManagers = manager->findChildren<QtDatePropertyManager *>(); 2132 for (QtDatePropertyManager *manager : datePropertyManagers) 2133 d_ptr->m_dateEditFactory->removePropertyManager(manager); 2134 2135 const QList<QtTimePropertyManager *> timePropertyManagers = manager->findChildren<QtTimePropertyManager *>(); 2136 for (QtTimePropertyManager *manager : timePropertyManagers) 2137 d_ptr->m_timeEditFactory->removePropertyManager(manager); 2138 2139 const QList<QtDateTimePropertyManager *> dateTimePropertyManagers = manager->findChildren<QtDateTimePropertyManager *>(); 2140 for (QtDateTimePropertyManager *manager : dateTimePropertyManagers) 2141 d_ptr->m_dateTimeEditFactory->removePropertyManager(manager); 2142 2143 const QList<QtKeySequencePropertyManager *> keySequencePropertyManagers = manager->findChildren<QtKeySequencePropertyManager *>(); 2144 for (QtKeySequencePropertyManager *manager : keySequencePropertyManagers) 2145 d_ptr->m_keySequenceEditorFactory->removePropertyManager(manager); 2146 2147 const QList<QtCharPropertyManager *> charPropertyManagers = manager->findChildren<QtCharPropertyManager *>(); 2148 for (QtCharPropertyManager *manager : charPropertyManagers) 2149 d_ptr->m_charEditorFactory->removePropertyManager(manager); 2150 2151 const QList<QtLocalePropertyManager *> localePropertyManagers = manager->findChildren<QtLocalePropertyManager *>(); 2152 for (QtLocalePropertyManager *manager : localePropertyManagers) 2153 d_ptr->m_comboBoxFactory->removePropertyManager(manager->subEnumPropertyManager()); 2154 2155 const QList<QtPointPropertyManager *> pointPropertyManagers = manager->findChildren<QtPointPropertyManager *>(); 2156 for (QtPointPropertyManager *manager : pointPropertyManagers) 2157 d_ptr->m_spinBoxFactory->removePropertyManager(manager->subIntPropertyManager()); 2158 2159 const QList<QtPointFPropertyManager *> pointFPropertyManagers = manager->findChildren<QtPointFPropertyManager *>(); 2160 for (QtPointFPropertyManager *manager : pointFPropertyManagers) 2161 d_ptr->m_doubleSpinBoxFactory->removePropertyManager(manager->subDoublePropertyManager()); 2162 2163 const QList<QtSizePropertyManager *> sizePropertyManagers = manager->findChildren<QtSizePropertyManager *>(); 2164 for (QtSizePropertyManager *manager : sizePropertyManagers) 2165 d_ptr->m_spinBoxFactory->removePropertyManager(manager->subIntPropertyManager()); 2166 2167 const QList<QtSizeFPropertyManager *> sizeFPropertyManagers = manager->findChildren<QtSizeFPropertyManager *>(); 2168 for (QtSizeFPropertyManager *manager : sizeFPropertyManagers) 2169 d_ptr->m_doubleSpinBoxFactory->removePropertyManager(manager->subDoublePropertyManager()); 2170 2171 const QList<QtRectPropertyManager *> rectPropertyManagers = manager->findChildren<QtRectPropertyManager *>(); 2172 for (QtRectPropertyManager *manager : rectPropertyManagers) 2173 d_ptr->m_spinBoxFactory->removePropertyManager(manager->subIntPropertyManager()); 2174 2175 const QList<QtRectFPropertyManager *> rectFPropertyManagers = manager->findChildren<QtRectFPropertyManager *>(); 2176 for (QtRectFPropertyManager *manager : rectFPropertyManagers) 2177 d_ptr->m_doubleSpinBoxFactory->removePropertyManager(manager->subDoublePropertyManager()); 2178 2179 const QList<QtColorPropertyManager *> 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 QList<QtEnumPropertyManager *> enumPropertyManagers = manager->findChildren<QtEnumPropertyManager *>(); 2186 for (QtEnumPropertyManager *manager : enumPropertyManagers) 2187 d_ptr->m_comboBoxFactory->removePropertyManager(manager); 2188 2189 const QList<QtSizePolicyPropertyManager *> 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 QList<QtFontPropertyManager *> 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 QList<QtCursorPropertyManager *> cursorPropertyManagers = manager->findChildren<QtCursorPropertyManager *>(); 2204 for (QtCursorPropertyManager *manager : cursorPropertyManagers) 2205 d_ptr->m_cursorEditorFactory->removePropertyManager(manager); 2206 2207 const QList<QtFlagPropertyManager *> 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"