File indexing completed on 2024-05-12 04:35:12

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 "qtpropertymanager.h"
0041 #include "qtpropertybrowserutils_p.h"
0042 #include <QtCore/QDateTime>
0043 #include <QtCore/QLocale>
0044 #include <QtCore/QMap>
0045 #include <QtCore/QTimer>
0046 #include <QtGui/QIcon>
0047 #include <QtCore/QMetaEnum>
0048 #include <QtGui/QFontDatabase>
0049 #include <QtWidgets/QStyleOption>
0050 #include <QtWidgets/QStyle>
0051 #include <QtWidgets/QApplication>
0052 #include <QtGui/QPainter>
0053 #include <QtWidgets/QLabel>
0054 
0055 #include <limits>
0056 #include <limits.h>
0057 #include <float.h>
0058 
0059 #if defined(Q_CC_MSVC)
0060 #    pragma warning(disable: 4786) /* MS VS 6: truncating debug info after 255 characters */
0061 #endif
0062 
0063 QT_BEGIN_NAMESPACE
0064 
0065 template <class PrivateData, class Value>
0066 static void setSimpleMinimumData(PrivateData *data, const Value &minVal)
0067 {
0068     data->minVal = minVal;
0069     if (data->maxVal < data->minVal)
0070         data->maxVal = data->minVal;
0071 
0072     if (data->val < data->minVal)
0073         data->val = data->minVal;
0074 }
0075 
0076 template <class PrivateData, class Value>
0077 static void setSimpleMaximumData(PrivateData *data, const Value &maxVal)
0078 {
0079     data->maxVal = maxVal;
0080     if (data->minVal > data->maxVal)
0081         data->minVal = data->maxVal;
0082 
0083     if (data->val > data->maxVal)
0084         data->val = data->maxVal;
0085 }
0086 
0087 template <class PrivateData, class Value>
0088 static void setSizeMinimumData(PrivateData *data, const Value &newMinVal)
0089 {
0090     data->minVal = newMinVal;
0091     if (data->maxVal.width() < data->minVal.width())
0092         data->maxVal.setWidth(data->minVal.width());
0093     if (data->maxVal.height() < data->minVal.height())
0094         data->maxVal.setHeight(data->minVal.height());
0095 
0096     if (data->val.width() < data->minVal.width())
0097         data->val.setWidth(data->minVal.width());
0098     if (data->val.height() < data->minVal.height())
0099         data->val.setHeight(data->minVal.height());
0100 }
0101 
0102 template <class PrivateData, class Value>
0103 static void setSizeMaximumData(PrivateData *data, const Value &newMaxVal)
0104 {
0105     data->maxVal = newMaxVal;
0106     if (data->minVal.width() > data->maxVal.width())
0107         data->minVal.setWidth(data->maxVal.width());
0108     if (data->minVal.height() > data->maxVal.height())
0109         data->minVal.setHeight(data->maxVal.height());
0110 
0111     if (data->val.width() > data->maxVal.width())
0112         data->val.setWidth(data->maxVal.width());
0113     if (data->val.height() > data->maxVal.height())
0114         data->val.setHeight(data->maxVal.height());
0115 }
0116 
0117 template <class SizeValue>
0118 static SizeValue qBoundSize(const SizeValue &minVal, const SizeValue &val, const SizeValue &maxVal)
0119 {
0120     SizeValue croppedVal = val;
0121     if (minVal.width() > val.width())
0122         croppedVal.setWidth(minVal.width());
0123     else if (maxVal.width() < val.width())
0124         croppedVal.setWidth(maxVal.width());
0125 
0126     if (minVal.height() > val.height())
0127         croppedVal.setHeight(minVal.height());
0128     else if (maxVal.height() < val.height())
0129         croppedVal.setHeight(maxVal.height());
0130 
0131     return croppedVal;
0132 }
0133 
0134 // Match the exact signature of qBound for VS 6.
0135 QSize qBound(QSize minVal, QSize val, QSize maxVal)
0136 {
0137     return qBoundSize(minVal, val, maxVal);
0138 }
0139 
0140 QSizeF qBound(QSizeF minVal, QSizeF val, QSizeF maxVal)
0141 {
0142     return qBoundSize(minVal, val, maxVal);
0143 }
0144 
0145 namespace {
0146 
0147 namespace {
0148 template <class Value>
0149 void orderBorders(Value &minVal, Value &maxVal)
0150 {
0151     if (minVal > maxVal)
0152         qSwap(minVal, maxVal);
0153 }
0154 
0155 template <class Value>
0156 static void orderSizeBorders(Value &minVal, Value &maxVal)
0157 {
0158     Value fromSize = minVal;
0159     Value toSize = maxVal;
0160     if (fromSize.width() > toSize.width()) {
0161         fromSize.setWidth(maxVal.width());
0162         toSize.setWidth(minVal.width());
0163     }
0164     if (fromSize.height() > toSize.height()) {
0165         fromSize.setHeight(maxVal.height());
0166         toSize.setHeight(minVal.height());
0167     }
0168     minVal = fromSize;
0169     maxVal = toSize;
0170 }
0171 
0172 void orderBorders(QSize &minVal, QSize &maxVal)
0173 {
0174     orderSizeBorders(minVal, maxVal);
0175 }
0176 
0177 void orderBorders(QSizeF &minVal, QSizeF &maxVal)
0178 {
0179     orderSizeBorders(minVal, maxVal);
0180 }
0181 
0182 }
0183 }
0184 ////////
0185 
0186 template <class Value, class PrivateData>
0187 static Value getData(const QMap<const QtProperty *, PrivateData> &propertyMap,
0188             Value PrivateData::*data,
0189             const QtProperty *property, const Value &defaultValue = Value())
0190 {
0191     const auto it = propertyMap.constFind(property);
0192     if (it == propertyMap.constEnd())
0193         return defaultValue;
0194     return it.value().*data;
0195 }
0196 
0197 template <class Value, class PrivateData>
0198 static Value getValue(const QMap<const QtProperty *, PrivateData> &propertyMap,
0199             const QtProperty *property, const Value &defaultValue = Value())
0200 {
0201     return getData<Value>(propertyMap, &PrivateData::val, property, defaultValue);
0202 }
0203 
0204 template <class Value, class PrivateData>
0205 static Value getMinimum(const QMap<const QtProperty *, PrivateData> &propertyMap,
0206             const QtProperty *property, const Value &defaultValue = Value())
0207 {
0208     return getData<Value>(propertyMap, &PrivateData::minVal, property, defaultValue);
0209 }
0210 
0211 template <class Value, class PrivateData>
0212 static Value getMaximum(const QMap<const QtProperty *, PrivateData> &propertyMap,
0213             const QtProperty *property, const Value &defaultValue = Value())
0214 {
0215     return getData<Value>(propertyMap, &PrivateData::maxVal, property, defaultValue);
0216 }
0217 
0218 template <class ValueChangeParameter, class Value, class PropertyManager>
0219 static void setSimpleValue(QMap<const QtProperty *, Value> &propertyMap,
0220             PropertyManager *manager,
0221             void (PropertyManager::*propertyChangedSignal)(QtProperty *),
0222             void (PropertyManager::*valueChangedSignal)(QtProperty *, ValueChangeParameter),
0223             QtProperty *property, const Value &val)
0224 {
0225     const auto it = propertyMap.find(property);
0226     if (it == propertyMap.end())
0227         return;
0228 
0229     if (it.value() == val)
0230         return;
0231 
0232     it.value() = val;
0233 
0234     Q_EMIT (manager->*propertyChangedSignal)(property);
0235     Q_EMIT (manager->*valueChangedSignal)(property, val);
0236 }
0237 
0238 template <class ValueChangeParameter, class PropertyManagerPrivate, class PropertyManager, class Value>
0239 static void setValueInRange(PropertyManager *manager, PropertyManagerPrivate *managerPrivate,
0240             void (PropertyManager::*propertyChangedSignal)(QtProperty *),
0241             void (PropertyManager::*valueChangedSignal)(QtProperty *, ValueChangeParameter),
0242             QtProperty *property, const Value &val,
0243             void (PropertyManagerPrivate::*setSubPropertyValue)(QtProperty *, ValueChangeParameter))
0244 {
0245     const auto it = managerPrivate->m_values.find(property);
0246     if (it == managerPrivate->m_values.end())
0247         return;
0248 
0249     auto &data = it.value();
0250 
0251     if (data.val == val)
0252         return;
0253 
0254     const Value oldVal = data.val;
0255 
0256     data.val = qBound(data.minVal, val, data.maxVal);
0257 
0258     if (data.val == oldVal)
0259         return;
0260 
0261     if (setSubPropertyValue)
0262         (managerPrivate->*setSubPropertyValue)(property, data.val);
0263 
0264     Q_EMIT (manager->*propertyChangedSignal)(property);
0265     Q_EMIT (manager->*valueChangedSignal)(property, data.val);
0266 }
0267 
0268 template <class ValueChangeParameter, class PropertyManagerPrivate, class PropertyManager, class Value>
0269 static void setBorderValues(PropertyManager *manager, PropertyManagerPrivate *managerPrivate,
0270             void (PropertyManager::*propertyChangedSignal)(QtProperty *),
0271             void (PropertyManager::*valueChangedSignal)(QtProperty *, ValueChangeParameter),
0272             void (PropertyManager::*rangeChangedSignal)(QtProperty *, ValueChangeParameter, ValueChangeParameter),
0273             QtProperty *property, const Value &minVal, const Value &maxVal,
0274             void (PropertyManagerPrivate::*setSubPropertyRange)(QtProperty *,
0275                     ValueChangeParameter, ValueChangeParameter, ValueChangeParameter))
0276 {
0277     const auto it = managerPrivate->m_values.find(property);
0278     if (it == managerPrivate->m_values.end())
0279         return;
0280 
0281     Value fromVal = minVal;
0282     Value toVal = maxVal;
0283     orderBorders(fromVal, toVal);
0284 
0285     auto &data = it.value();
0286 
0287     if (data.minVal == fromVal && data.maxVal == toVal)
0288         return;
0289 
0290     const Value oldVal = data.val;
0291 
0292     data.setMinimumValue(fromVal);
0293     data.setMaximumValue(toVal);
0294 
0295     Q_EMIT (manager->*rangeChangedSignal)(property, data.minVal, data.maxVal);
0296 
0297     if (setSubPropertyRange)
0298         (managerPrivate->*setSubPropertyRange)(property, data.minVal, data.maxVal, data.val);
0299 
0300     if (data.val == oldVal)
0301         return;
0302 
0303     Q_EMIT (manager->*propertyChangedSignal)(property);
0304     Q_EMIT (manager->*valueChangedSignal)(property, data.val);
0305 }
0306 
0307 template <class ValueChangeParameter, class PropertyManagerPrivate, class PropertyManager, class Value, class PrivateData>
0308 static void setBorderValue(PropertyManager *manager, PropertyManagerPrivate *managerPrivate,
0309             void (PropertyManager::*propertyChangedSignal)(QtProperty *),
0310             void (PropertyManager::*valueChangedSignal)(QtProperty *, ValueChangeParameter),
0311             void (PropertyManager::*rangeChangedSignal)(QtProperty *, ValueChangeParameter, ValueChangeParameter),
0312             QtProperty *property,
0313             Value (PrivateData::*getRangeVal)() const,
0314             void (PrivateData::*setRangeVal)(ValueChangeParameter), const Value &borderVal,
0315             void (PropertyManagerPrivate::*setSubPropertyRange)(QtProperty *,
0316                     ValueChangeParameter, ValueChangeParameter, ValueChangeParameter))
0317 {
0318     const auto it = managerPrivate->m_values.find(property);
0319     if (it == managerPrivate->m_values.end())
0320         return;
0321 
0322     PrivateData &data = it.value();
0323 
0324     if ((data.*getRangeVal)() == borderVal)
0325         return;
0326 
0327     const Value oldVal = data.val;
0328 
0329     (data.*setRangeVal)(borderVal);
0330 
0331     Q_EMIT (manager->*rangeChangedSignal)(property, data.minVal, data.maxVal);
0332 
0333     if (setSubPropertyRange)
0334         (managerPrivate->*setSubPropertyRange)(property, data.minVal, data.maxVal, data.val);
0335 
0336     if (data.val == oldVal)
0337         return;
0338 
0339     Q_EMIT (manager->*propertyChangedSignal)(property);
0340     Q_EMIT (manager->*valueChangedSignal)(property, data.val);
0341 }
0342 
0343 template <class ValueChangeParameter, class PropertyManagerPrivate, class PropertyManager, class Value, class PrivateData>
0344 static void setMinimumValue(PropertyManager *manager, PropertyManagerPrivate *managerPrivate,
0345             void (PropertyManager::*propertyChangedSignal)(QtProperty *),
0346             void (PropertyManager::*valueChangedSignal)(QtProperty *, ValueChangeParameter),
0347             void (PropertyManager::*rangeChangedSignal)(QtProperty *, ValueChangeParameter, ValueChangeParameter),
0348             QtProperty *property, const Value &minVal)
0349 {
0350     void (PropertyManagerPrivate::*setSubPropertyRange)(QtProperty *,
0351                     ValueChangeParameter, ValueChangeParameter, ValueChangeParameter) = 0;
0352     setBorderValue<ValueChangeParameter, PropertyManagerPrivate, PropertyManager, Value, PrivateData>(manager, managerPrivate,
0353             propertyChangedSignal, valueChangedSignal, rangeChangedSignal,
0354             property, &PropertyManagerPrivate::Data::minimumValue, &PropertyManagerPrivate::Data::setMinimumValue, minVal, setSubPropertyRange);
0355 }
0356 
0357 template <class ValueChangeParameter, class PropertyManagerPrivate, class PropertyManager, class Value, class PrivateData>
0358 static void setMaximumValue(PropertyManager *manager, PropertyManagerPrivate *managerPrivate,
0359             void (PropertyManager::*propertyChangedSignal)(QtProperty *),
0360             void (PropertyManager::*valueChangedSignal)(QtProperty *, ValueChangeParameter),
0361             void (PropertyManager::*rangeChangedSignal)(QtProperty *, ValueChangeParameter, ValueChangeParameter),
0362             QtProperty *property, const Value &maxVal)
0363 {
0364     void (PropertyManagerPrivate::*setSubPropertyRange)(QtProperty *,
0365                     ValueChangeParameter, ValueChangeParameter, ValueChangeParameter) = 0;
0366     setBorderValue<ValueChangeParameter, PropertyManagerPrivate, PropertyManager, Value, PrivateData>(manager, managerPrivate,
0367             propertyChangedSignal, valueChangedSignal, rangeChangedSignal,
0368             property, &PropertyManagerPrivate::Data::maximumValue, &PropertyManagerPrivate::Data::setMaximumValue, maxVal, setSubPropertyRange);
0369 }
0370 
0371 class QtMetaEnumWrapper : public QObject
0372 {
0373     Q_OBJECT
0374     Q_PROPERTY(QSizePolicy::Policy policy READ policy)
0375 public:
0376     QSizePolicy::Policy policy() const { return QSizePolicy::Ignored; }
0377 private:
0378     QtMetaEnumWrapper(QObject *parent) : QObject(parent) {}
0379 };
0380 
0381 class QtMetaEnumProvider
0382 {
0383 public:
0384     QtMetaEnumProvider();
0385 
0386     QStringList policyEnumNames() const { return m_policyEnumNames; }
0387     QStringList languageEnumNames() const { return m_languageEnumNames; }
0388     QStringList countryEnumNames(QLocale::Language language) const { return m_countryEnumNames.value(language); }
0389 
0390     QSizePolicy::Policy indexToSizePolicy(int index) const;
0391     int sizePolicyToIndex(QSizePolicy::Policy policy) const;
0392 
0393     void indexToLocale(int languageIndex, int countryIndex, QLocale::Language *language, QLocale::Country *country) const;
0394     void localeToIndex(QLocale::Language language, QLocale::Country country, int *languageIndex, int *countryIndex) const;
0395 
0396 private:
0397     void initLocale();
0398 
0399     QStringList m_policyEnumNames;
0400     QStringList m_languageEnumNames;
0401     QMap<QLocale::Language, QStringList> m_countryEnumNames;
0402     QMap<int, QLocale::Language> m_indexToLanguage;
0403     QMap<QLocale::Language, int> m_languageToIndex;
0404     QMap<int, QMap<int, QLocale::Country> > m_indexToCountry;
0405     QMap<QLocale::Language, QMap<QLocale::Country, int> > m_countryToIndex;
0406     QMetaEnum m_policyEnum;
0407 };
0408 
0409 static QList<QLocale::Country> sortCountries(const QList<QLocale::Country> &countries)
0410 {
0411     QMultiMap<QString, QLocale::Country> nameToCountry;
0412     for (QLocale::Country country : countries)
0413         nameToCountry.insert(QLocale::countryToString(country), country);
0414     return nameToCountry.values();
0415 }
0416 
0417 void QtMetaEnumProvider::initLocale()
0418 {
0419     QMultiMap<QString, QLocale::Language> nameToLanguage;
0420     for (int l = QLocale::C, last = QLocale::LastLanguage; l <= last; ++l) {
0421         const QLocale::Language language = static_cast<QLocale::Language>(l);
0422         QLocale locale(language);
0423         if (locale.language() == language)
0424             nameToLanguage.insert(QLocale::languageToString(language), language);
0425     }
0426 
0427     const QLocale system = QLocale::system();
0428     if (!nameToLanguage.contains(QLocale::languageToString(system.language())))
0429         nameToLanguage.insert(QLocale::languageToString(system.language()), system.language());
0430 
0431     const QList<QLocale::Language> languages = nameToLanguage.values();
0432     for (QLocale::Language language : languages) {
0433         QList<QLocale::Country> countries;
0434         countries = QLocale::countriesForLanguage(language);
0435         if (countries.isEmpty() && language == system.language())
0436             countries << system.country();
0437 
0438         if (!countries.isEmpty() && !m_languageToIndex.contains(language)) {
0439             countries = sortCountries(countries);
0440             int langIdx = m_languageEnumNames.count();
0441             m_indexToLanguage[langIdx] = language;
0442             m_languageToIndex[language] = langIdx;
0443             QStringList countryNames;
0444             int countryIdx = 0;
0445             for (QLocale::Country country : qAsConst(countries)) {
0446                 countryNames << QLocale::countryToString(country);
0447                 m_indexToCountry[langIdx][countryIdx] = country;
0448                 m_countryToIndex[language][country] = countryIdx;
0449                 ++countryIdx;
0450             }
0451             m_languageEnumNames << QLocale::languageToString(language);
0452             m_countryEnumNames[language] = countryNames;
0453         }
0454     }
0455 }
0456 
0457 QtMetaEnumProvider::QtMetaEnumProvider()
0458 {
0459     QMetaProperty p;
0460 
0461     p = QtMetaEnumWrapper::staticMetaObject.property(
0462                 QtMetaEnumWrapper::staticMetaObject.propertyOffset() + 0);
0463     m_policyEnum = p.enumerator();
0464     const int keyCount = m_policyEnum.keyCount();
0465     for (int i = 0; i < keyCount; i++)
0466         m_policyEnumNames << QLatin1String(m_policyEnum.key(i));
0467 
0468     initLocale();
0469 }
0470 
0471 QSizePolicy::Policy QtMetaEnumProvider::indexToSizePolicy(int index) const
0472 {
0473     return static_cast<QSizePolicy::Policy>(m_policyEnum.value(index));
0474 }
0475 
0476 int QtMetaEnumProvider::sizePolicyToIndex(QSizePolicy::Policy policy) const
0477 {
0478      const int keyCount = m_policyEnum.keyCount();
0479     for (int i = 0; i < keyCount; i++)
0480         if (indexToSizePolicy(i) == policy)
0481             return i;
0482     return -1;
0483 }
0484 
0485 void QtMetaEnumProvider::indexToLocale(int languageIndex, int countryIndex, QLocale::Language *language, QLocale::Country *country) const
0486 {
0487     QLocale::Language l = QLocale::C;
0488     QLocale::Country c = QLocale::AnyCountry;
0489     if (m_indexToLanguage.contains(languageIndex)) {
0490         l = m_indexToLanguage[languageIndex];
0491         if (m_indexToCountry.contains(languageIndex) && m_indexToCountry[languageIndex].contains(countryIndex))
0492             c = m_indexToCountry[languageIndex][countryIndex];
0493     }
0494     if (language)
0495         *language = l;
0496     if (country)
0497         *country = c;
0498 }
0499 
0500 void QtMetaEnumProvider::localeToIndex(QLocale::Language language, QLocale::Country country, int *languageIndex, int *countryIndex) const
0501 {
0502     int l = -1;
0503     int c = -1;
0504     if (m_languageToIndex.contains(language)) {
0505         l = m_languageToIndex[language];
0506         if (m_countryToIndex.contains(language) && m_countryToIndex[language].contains(country))
0507             c = m_countryToIndex[language][country];
0508     }
0509 
0510     if (languageIndex)
0511         *languageIndex = l;
0512     if (countryIndex)
0513         *countryIndex = c;
0514 }
0515 
0516 Q_GLOBAL_STATIC(QtMetaEnumProvider, metaEnumProvider)
0517 
0518 // QtGroupPropertyManager
0519 
0520 /*!
0521     \class QtGroupPropertyManager
0522     \internal
0523     \inmodule QtDesigner
0524     \since 4.4
0525 
0526     \brief The QtGroupPropertyManager provides and manages group properties.
0527 
0528     This class is intended to provide a grouping element without any value.
0529 
0530     \sa QtAbstractPropertyManager
0531 */
0532 
0533 /*!
0534     Creates a manager with the given \a parent.
0535 */
0536 QtGroupPropertyManager::QtGroupPropertyManager(QObject *parent)
0537     : QtAbstractPropertyManager(parent)
0538 {
0539 
0540 }
0541 
0542 /*!
0543     Destroys this manager, and all the properties it has created.
0544 */
0545 QtGroupPropertyManager::~QtGroupPropertyManager()
0546 {
0547 
0548 }
0549 
0550 /*!
0551     \reimp
0552 */
0553 bool QtGroupPropertyManager::hasValue(const QtProperty *property) const
0554 {
0555     Q_UNUSED(property)
0556     return false;
0557 }
0558 
0559 /*!
0560     \reimp
0561 */
0562 void QtGroupPropertyManager::initializeProperty(QtProperty *property)
0563 {
0564     Q_UNUSED(property)
0565 }
0566 
0567 /*!
0568     \reimp
0569 */
0570 void QtGroupPropertyManager::uninitializeProperty(QtProperty *property)
0571 {
0572     Q_UNUSED(property)
0573 }
0574 
0575 // QtIntPropertyManager
0576 
0577 class QtIntPropertyManagerPrivate
0578 {
0579     QtIntPropertyManager *q_ptr;
0580     Q_DECLARE_PUBLIC(QtIntPropertyManager)
0581 public:
0582 
0583     struct Data
0584     {
0585         int val{0};
0586         int minVal{-INT_MAX};
0587         int maxVal{INT_MAX};
0588         int singleStep{1};
0589         int minimumValue() const { return minVal; }
0590         int maximumValue() const { return maxVal; }
0591         void setMinimumValue(int newMinVal) { setSimpleMinimumData(this, newMinVal); }
0592         void setMaximumValue(int newMaxVal) { setSimpleMaximumData(this, newMaxVal); }
0593     };
0594 
0595     typedef QMap<const QtProperty *, Data> PropertyValueMap;
0596     PropertyValueMap m_values;
0597 };
0598 
0599 /*!
0600     \class QtIntPropertyManager
0601     \internal
0602     \inmodule QtDesigner
0603     \since 4.4
0604 
0605     \brief The QtIntPropertyManager provides and manages int properties.
0606 
0607     An int property has a current value, and a range specifying the
0608     valid values. The range is defined by a minimum and a maximum
0609     value.
0610 
0611     The property's value and range can be retrieved using the value(),
0612     minimum() and maximum() functions, and can be set using the
0613     setValue(), setMinimum() and setMaximum() slots. Alternatively,
0614     the range can be defined in one go using the setRange() slot.
0615 
0616     In addition, QtIntPropertyManager provides the valueChanged() signal which
0617     is emitted whenever a property created by this manager changes,
0618     and the rangeChanged() signal which is emitted whenever such a
0619     property changes its range of valid values.
0620 
0621     \sa QtAbstractPropertyManager, QtSpinBoxFactory, QtSliderFactory, QtScrollBarFactory
0622 */
0623 
0624 /*!
0625     \fn void QtIntPropertyManager::valueChanged(QtProperty *property, int value)
0626 
0627     This signal is emitted whenever a property created by this manager
0628     changes its value, passing a pointer to the \a property and the new
0629     \a value as parameters.
0630 
0631     \sa setValue()
0632 */
0633 
0634 /*!
0635     \fn void QtIntPropertyManager::rangeChanged(QtProperty *property, int minimum, int maximum)
0636 
0637     This signal is emitted whenever a property created by this manager
0638     changes its range of valid values, passing a pointer to the
0639     \a property and the new \a minimum and \a maximum values.
0640 
0641     \sa setRange()
0642 */
0643 
0644 /*!
0645     \fn void QtIntPropertyManager::singleStepChanged(QtProperty *property, int step)
0646 
0647     This signal is emitted whenever a property created by this manager
0648     changes its single step property, passing a pointer to the
0649     \a property and the new \a step value
0650 
0651     \sa setSingleStep()
0652 */
0653 
0654 /*!
0655     Creates a manager with the given \a parent.
0656 */
0657 QtIntPropertyManager::QtIntPropertyManager(QObject *parent)
0658     : QtAbstractPropertyManager(parent), d_ptr(new QtIntPropertyManagerPrivate)
0659 {
0660     d_ptr->q_ptr = this;
0661 }
0662 
0663 /*!
0664     Destroys this manager, and all the properties it has created.
0665 */
0666 QtIntPropertyManager::~QtIntPropertyManager()
0667 {
0668     clear();
0669 }
0670 
0671 /*!
0672     Returns the given \a property's value.
0673 
0674     If the given property is not managed by this manager, this
0675     function returns 0.
0676 
0677     \sa setValue()
0678 */
0679 int QtIntPropertyManager::value(const QtProperty *property) const
0680 {
0681     return getValue<int>(d_ptr->m_values, property, 0);
0682 }
0683 
0684 /*!
0685     Returns the given \a property's minimum value.
0686 
0687     \sa setMinimum(), maximum(), setRange()
0688 */
0689 int QtIntPropertyManager::minimum(const QtProperty *property) const
0690 {
0691     return getMinimum<int>(d_ptr->m_values, property, 0);
0692 }
0693 
0694 /*!
0695     Returns the given \a property's maximum value.
0696 
0697     \sa setMaximum(), minimum(), setRange()
0698 */
0699 int QtIntPropertyManager::maximum(const QtProperty *property) const
0700 {
0701     return getMaximum<int>(d_ptr->m_values, property, 0);
0702 }
0703 
0704 /*!
0705     Returns the given \a property's step value.
0706 
0707     The step is typically used to increment or decrement a property value while pressing an arrow key.
0708 
0709     \sa setSingleStep()
0710 */
0711 int QtIntPropertyManager::singleStep(const QtProperty *property) const
0712 {
0713     return getData<int>(d_ptr->m_values, &QtIntPropertyManagerPrivate::Data::singleStep, property, 0);
0714 }
0715 
0716 /*!
0717     \reimp
0718 */
0719 QString QtIntPropertyManager::valueText(const QtProperty *property) const
0720 {
0721     const QtIntPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
0722     if (it == d_ptr->m_values.constEnd())
0723         return QString();
0724     return QString::number(it.value().val);
0725 }
0726 
0727 /*!
0728     \fn void QtIntPropertyManager::setValue(QtProperty *property, int value)
0729 
0730     Sets the value of the given \a property to \a value.
0731 
0732     If the specified \a value is not valid according to the given \a
0733     property's range, the \a value is adjusted to the nearest valid
0734     value within the range.
0735 
0736     \sa value(), setRange(), valueChanged()
0737 */
0738 void QtIntPropertyManager::setValue(QtProperty *property, int val)
0739 {
0740     void (QtIntPropertyManagerPrivate::*setSubPropertyValue)(QtProperty *, int) = 0;
0741     setValueInRange<int, QtIntPropertyManagerPrivate, QtIntPropertyManager, int>(this, d_ptr.data(),
0742                 &QtIntPropertyManager::propertyChanged,
0743                 &QtIntPropertyManager::valueChanged,
0744                 property, val, setSubPropertyValue);
0745 }
0746 
0747 /*!
0748     Sets the minimum value for the given \a property to \a minVal.
0749 
0750     When setting the minimum value, the maximum and current values are
0751     adjusted if necessary (ensuring that the range remains valid and
0752     that the current value is within the range).
0753 
0754     \sa minimum(), setRange(), rangeChanged()
0755 */
0756 void QtIntPropertyManager::setMinimum(QtProperty *property, int minVal)
0757 {
0758     setMinimumValue<int, QtIntPropertyManagerPrivate, QtIntPropertyManager, int, QtIntPropertyManagerPrivate::Data>(this, d_ptr.data(),
0759                 &QtIntPropertyManager::propertyChanged,
0760                 &QtIntPropertyManager::valueChanged,
0761                 &QtIntPropertyManager::rangeChanged,
0762                 property, minVal);
0763 }
0764 
0765 /*!
0766     Sets the maximum value for the given \a property to \a maxVal.
0767 
0768     When setting maximum value, the minimum and current values are
0769     adjusted if necessary (ensuring that the range remains valid and
0770     that the current value is within the range).
0771 
0772     \sa maximum(), setRange(), rangeChanged()
0773 */
0774 void QtIntPropertyManager::setMaximum(QtProperty *property, int maxVal)
0775 {
0776     setMaximumValue<int, QtIntPropertyManagerPrivate, QtIntPropertyManager, int, QtIntPropertyManagerPrivate::Data>(this, d_ptr.data(),
0777                 &QtIntPropertyManager::propertyChanged,
0778                 &QtIntPropertyManager::valueChanged,
0779                 &QtIntPropertyManager::rangeChanged,
0780                 property, maxVal);
0781 }
0782 
0783 /*!
0784     \fn void QtIntPropertyManager::setRange(QtProperty *property, int minimum, int maximum)
0785 
0786     Sets the range of valid values.
0787 
0788     This is a convenience function defining the range of valid values
0789     in one go; setting the \a minimum and \a maximum values for the
0790     given \a property with a single function call.
0791 
0792     When setting a new range, the current value is adjusted if
0793     necessary (ensuring that the value remains within range).
0794 
0795     \sa setMinimum(), setMaximum(), rangeChanged()
0796 */
0797 void QtIntPropertyManager::setRange(QtProperty *property, int minVal, int maxVal)
0798 {
0799     void (QtIntPropertyManagerPrivate::*setSubPropertyRange)(QtProperty *, int, int, int) = 0;
0800     setBorderValues<int, QtIntPropertyManagerPrivate, QtIntPropertyManager, int>(this, d_ptr.data(),
0801                 &QtIntPropertyManager::propertyChanged,
0802                 &QtIntPropertyManager::valueChanged,
0803                 &QtIntPropertyManager::rangeChanged,
0804                 property, minVal, maxVal, setSubPropertyRange);
0805 }
0806 
0807 /*!
0808     Sets the step value for the given \a property to \a step.
0809 
0810     The step is typically used to increment or decrement a property value while pressing an arrow key.
0811 
0812     \sa singleStep()
0813 */
0814 void QtIntPropertyManager::setSingleStep(QtProperty *property, int step)
0815 {
0816     const QtIntPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
0817     if (it == d_ptr->m_values.end())
0818         return;
0819 
0820     QtIntPropertyManagerPrivate::Data data = it.value();
0821 
0822     if (step < 0)
0823         step = 0;
0824 
0825     if (data.singleStep == step)
0826         return;
0827 
0828     data.singleStep = step;
0829 
0830     it.value() = data;
0831 
0832     Q_EMIT singleStepChanged(property, data.singleStep);
0833 }
0834 
0835 /*!
0836     \reimp
0837 */
0838 void QtIntPropertyManager::initializeProperty(QtProperty *property)
0839 {
0840     d_ptr->m_values[property] = QtIntPropertyManagerPrivate::Data();
0841 }
0842 
0843 /*!
0844     \reimp
0845 */
0846 void QtIntPropertyManager::uninitializeProperty(QtProperty *property)
0847 {
0848     d_ptr->m_values.remove(property);
0849 }
0850 
0851 // QtDoublePropertyManager
0852 
0853 class QtDoublePropertyManagerPrivate
0854 {
0855     QtDoublePropertyManager *q_ptr;
0856     Q_DECLARE_PUBLIC(QtDoublePropertyManager)
0857 public:
0858 
0859     struct Data
0860     {
0861         double val{0};
0862         double minVal{-DBL_MAX};
0863         double maxVal{DBL_MAX};
0864         double singleStep{1};
0865         int decimals{2};
0866         double minimumValue() const { return minVal; }
0867         double maximumValue() const { return maxVal; }
0868         void setMinimumValue(double newMinVal) { setSimpleMinimumData(this, newMinVal); }
0869         void setMaximumValue(double newMaxVal) { setSimpleMaximumData(this, newMaxVal); }
0870     };
0871 
0872     typedef QMap<const QtProperty *, Data> PropertyValueMap;
0873     PropertyValueMap m_values;
0874 };
0875 
0876 /*!
0877     \class QtDoublePropertyManager
0878     \internal
0879     \inmodule QtDesigner
0880     \since 4.4
0881 
0882     \brief The QtDoublePropertyManager provides and manages double properties.
0883 
0884     A double property has a current value, and a range specifying the
0885     valid values. The range is defined by a minimum and a maximum
0886     value.
0887 
0888     The property's value and range can be retrieved using the value(),
0889     minimum() and maximum() functions, and can be set using the
0890     setValue(), setMinimum() and setMaximum() slots.
0891     Alternatively, the range can be defined in one go using the
0892     setRange() slot.
0893 
0894     In addition, QtDoublePropertyManager provides the valueChanged() signal
0895     which is emitted whenever a property created by this manager
0896     changes, and the rangeChanged() signal which is emitted whenever
0897     such a property changes its range of valid values.
0898 
0899     \sa QtAbstractPropertyManager, QtDoubleSpinBoxFactory
0900 */
0901 
0902 /*!
0903     \fn void QtDoublePropertyManager::valueChanged(QtProperty *property, double value)
0904 
0905     This signal is emitted whenever a property created by this manager
0906     changes its value, passing a pointer to the \a property and the new
0907     \a value as parameters.
0908 
0909     \sa setValue()
0910 */
0911 
0912 /*!
0913     \fn void QtDoublePropertyManager::rangeChanged(QtProperty *property, double minimum, double maximum)
0914 
0915     This signal is emitted whenever a property created by this manager
0916     changes its range of valid values, passing a pointer to the
0917     \a property and the new \a minimum and \a maximum values
0918 
0919     \sa setRange()
0920 */
0921 
0922 /*!
0923     \fn void QtDoublePropertyManager::decimalsChanged(QtProperty *property, int prec)
0924 
0925     This signal is emitted whenever a property created by this manager
0926     changes its precision of value, passing a pointer to the
0927     \a property and the new \a prec value
0928 
0929     \sa setDecimals()
0930 */
0931 
0932 /*!
0933     \fn void QtDoublePropertyManager::singleStepChanged(QtProperty *property, double step)
0934 
0935     This signal is emitted whenever a property created by this manager
0936     changes its single step property, passing a pointer to the
0937     \a property and the new \a step value
0938 
0939     \sa setSingleStep()
0940 */
0941 
0942 /*!
0943     Creates a manager with the given \a parent.
0944 */
0945 QtDoublePropertyManager::QtDoublePropertyManager(QObject *parent)
0946     : QtAbstractPropertyManager(parent), d_ptr(new QtDoublePropertyManagerPrivate)
0947 {
0948     d_ptr->q_ptr = this;
0949 }
0950 
0951 /*!
0952     Destroys  this manager, and all the properties it has created.
0953 */
0954 QtDoublePropertyManager::~QtDoublePropertyManager()
0955 {
0956     clear();
0957 }
0958 
0959 /*!
0960     Returns the given \a property's value.
0961 
0962     If the given property is not managed by this manager, this
0963     function returns 0.
0964 
0965     \sa setValue()
0966 */
0967 double QtDoublePropertyManager::value(const QtProperty *property) const
0968 {
0969     return getValue<double>(d_ptr->m_values, property, 0.0);
0970 }
0971 
0972 /*!
0973     Returns the given \a property's minimum value.
0974 
0975     \sa maximum(), setRange()
0976 */
0977 double QtDoublePropertyManager::minimum(const QtProperty *property) const
0978 {
0979     return getMinimum<double>(d_ptr->m_values, property, 0.0);
0980 }
0981 
0982 /*!
0983     Returns the given \a property's maximum value.
0984 
0985     \sa minimum(), setRange()
0986 */
0987 double QtDoublePropertyManager::maximum(const QtProperty *property) const
0988 {
0989     return getMaximum<double>(d_ptr->m_values, property, 0.0);
0990 }
0991 
0992 /*!
0993     Returns the given \a property's step value.
0994 
0995     The step is typically used to increment or decrement a property value while pressing an arrow key.
0996 
0997     \sa setSingleStep()
0998 */
0999 double QtDoublePropertyManager::singleStep(const QtProperty *property) const
1000 {
1001     return getData<double>(d_ptr->m_values, &QtDoublePropertyManagerPrivate::Data::singleStep, property, 0);
1002 }
1003 
1004 /*!
1005     Returns the given \a property's precision, in decimals.
1006 
1007     \sa setDecimals()
1008 */
1009 int QtDoublePropertyManager::decimals(const QtProperty *property) const
1010 {
1011     return getData<int>(d_ptr->m_values, &QtDoublePropertyManagerPrivate::Data::decimals, property, 0);
1012 }
1013 
1014 /*!
1015     \reimp
1016 */
1017 QString QtDoublePropertyManager::valueText(const QtProperty *property) const
1018 {
1019     const QtDoublePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
1020     if (it == d_ptr->m_values.constEnd())
1021         return QString();
1022     return QString::number(it.value().val, 'f', it.value().decimals);
1023 }
1024 
1025 /*!
1026     \fn void QtDoublePropertyManager::setValue(QtProperty *property, double value)
1027 
1028     Sets the value of the given \a property to \a value.
1029 
1030     If the specified \a value is not valid according to the given
1031     \a property's range, the \a value is adjusted to the nearest valid value
1032     within the range.
1033 
1034     \sa value(), setRange(), valueChanged()
1035 */
1036 void QtDoublePropertyManager::setValue(QtProperty *property, double val)
1037 {
1038     void (QtDoublePropertyManagerPrivate::*setSubPropertyValue)(QtProperty *, double) = 0;
1039     setValueInRange<double, QtDoublePropertyManagerPrivate, QtDoublePropertyManager, double>(this, d_ptr.data(),
1040                 &QtDoublePropertyManager::propertyChanged,
1041                 &QtDoublePropertyManager::valueChanged,
1042                 property, val, setSubPropertyValue);
1043 }
1044 
1045 /*!
1046     Sets the step value for the given \a property to \a step.
1047 
1048     The step is typically used to increment or decrement a property value while pressing an arrow key.
1049 
1050     \sa singleStep()
1051 */
1052 void QtDoublePropertyManager::setSingleStep(QtProperty *property, double step)
1053 {
1054     const QtDoublePropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
1055     if (it == d_ptr->m_values.end())
1056         return;
1057 
1058     QtDoublePropertyManagerPrivate::Data data = it.value();
1059 
1060     if (step < 0)
1061         step = 0;
1062 
1063     if (data.singleStep == step)
1064         return;
1065 
1066     data.singleStep = step;
1067 
1068     it.value() = data;
1069 
1070     Q_EMIT singleStepChanged(property, data.singleStep);
1071 }
1072 
1073 /*!
1074     \fn void QtDoublePropertyManager::setDecimals(QtProperty *property, int prec)
1075 
1076     Sets the precision of the given \a property to \a prec.
1077 
1078     The valid decimal range is 0-13. The default is 2.
1079 
1080     \sa decimals()
1081 */
1082 void QtDoublePropertyManager::setDecimals(QtProperty *property, int prec)
1083 {
1084     const QtDoublePropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
1085     if (it == d_ptr->m_values.end())
1086         return;
1087 
1088     QtDoublePropertyManagerPrivate::Data data = it.value();
1089 
1090     if (prec > 13)
1091         prec = 13;
1092     else if (prec < 0)
1093         prec = 0;
1094 
1095     if (data.decimals == prec)
1096         return;
1097 
1098     data.decimals = prec;
1099 
1100     it.value() = data;
1101 
1102     Q_EMIT decimalsChanged(property, data.decimals);
1103 }
1104 
1105 /*!
1106     Sets the minimum value for the given \a property to \a minVal.
1107 
1108     When setting the minimum value, the maximum and current values are
1109     adjusted if necessary (ensuring that the range remains valid and
1110     that the current value is within in the range).
1111 
1112     \sa minimum(), setRange(), rangeChanged()
1113 */
1114 void QtDoublePropertyManager::setMinimum(QtProperty *property, double minVal)
1115 {
1116     setMinimumValue<double, QtDoublePropertyManagerPrivate, QtDoublePropertyManager, double, QtDoublePropertyManagerPrivate::Data>(this, d_ptr.data(),
1117                 &QtDoublePropertyManager::propertyChanged,
1118                 &QtDoublePropertyManager::valueChanged,
1119                 &QtDoublePropertyManager::rangeChanged,
1120                 property, minVal);
1121 }
1122 
1123 /*!
1124     Sets the maximum value for the given \a property to \a maxVal.
1125 
1126     When setting the maximum value, the minimum and current values are
1127     adjusted if necessary (ensuring that the range remains valid and
1128     that the current value is within in the range).
1129 
1130     \sa maximum(), setRange(), rangeChanged()
1131 */
1132 void QtDoublePropertyManager::setMaximum(QtProperty *property, double maxVal)
1133 {
1134     setMaximumValue<double, QtDoublePropertyManagerPrivate, QtDoublePropertyManager, double, QtDoublePropertyManagerPrivate::Data>(this, d_ptr.data(),
1135                 &QtDoublePropertyManager::propertyChanged,
1136                 &QtDoublePropertyManager::valueChanged,
1137                 &QtDoublePropertyManager::rangeChanged,
1138                 property, maxVal);
1139 }
1140 
1141 /*!
1142     \fn void QtDoublePropertyManager::setRange(QtProperty *property, double minimum, double maximum)
1143 
1144     Sets the range of valid values.
1145 
1146     This is a convenience function defining the range of valid values
1147     in one go; setting the \a minimum and \a maximum values for the
1148     given \a property with a single function call.
1149 
1150     When setting a new range, the current value is adjusted if
1151     necessary (ensuring that the value remains within range).
1152 
1153     \sa setMinimum(), setMaximum(), rangeChanged()
1154 */
1155 void QtDoublePropertyManager::setRange(QtProperty *property, double minVal, double maxVal)
1156 {
1157     void (QtDoublePropertyManagerPrivate::*setSubPropertyRange)(QtProperty *, double, double, double) = 0;
1158     setBorderValues<double, QtDoublePropertyManagerPrivate, QtDoublePropertyManager, double>(this, d_ptr.data(),
1159                 &QtDoublePropertyManager::propertyChanged,
1160                 &QtDoublePropertyManager::valueChanged,
1161                 &QtDoublePropertyManager::rangeChanged,
1162                 property, minVal, maxVal, setSubPropertyRange);
1163 }
1164 
1165 /*!
1166     \reimp
1167 */
1168 void QtDoublePropertyManager::initializeProperty(QtProperty *property)
1169 {
1170     d_ptr->m_values[property] = QtDoublePropertyManagerPrivate::Data();
1171 }
1172 
1173 /*!
1174     \reimp
1175 */
1176 void QtDoublePropertyManager::uninitializeProperty(QtProperty *property)
1177 {
1178     d_ptr->m_values.remove(property);
1179 }
1180 
1181 // QtStringPropertyManager
1182 
1183 class QtStringPropertyManagerPrivate
1184 {
1185     QtStringPropertyManager *q_ptr;
1186     Q_DECLARE_PUBLIC(QtStringPropertyManager)
1187 public:
1188 
1189     struct Data
1190     {
1191         Data() : regExp(QString(QLatin1Char('*')),  Qt::CaseSensitive, QRegExp::Wildcard)
1192         {
1193         }
1194         QString val;
1195         QRegExp regExp;
1196     };
1197 
1198     typedef QMap<const QtProperty *, Data> PropertyValueMap;
1199     QMap<const QtProperty *, Data> m_values;
1200 };
1201 
1202 /*!
1203     \class QtStringPropertyManager
1204     \internal
1205     \inmodule QtDesigner
1206     \since 4.4
1207 
1208     \brief The QtStringPropertyManager provides and manages QString properties.
1209 
1210     A string property's value can be retrieved using the value()
1211     function, and set using the setValue() slot.
1212 
1213     The current value can be checked against a regular expression. To
1214     set the regular expression use the setRegExp() slot, use the
1215     regExp() function to retrieve the currently set expression.
1216 
1217     In addition, QtStringPropertyManager provides the valueChanged() signal
1218     which is emitted whenever a property created by this manager
1219     changes, and the regExpChanged() signal which is emitted whenever
1220     such a property changes its currently set regular expression.
1221 
1222     \sa QtAbstractPropertyManager, QtLineEditFactory
1223 */
1224 
1225 /*!
1226     \fn void QtStringPropertyManager::valueChanged(QtProperty *property, const QString &value)
1227 
1228     This signal is emitted whenever a property created by this manager
1229     changes its value, passing a pointer to the \a property and the
1230     new \a value as parameters.
1231 
1232     \sa setValue()
1233 */
1234 
1235 /*!
1236     \fn void QtStringPropertyManager::regExpChanged(QtProperty *property, const QRegExp &regExp)
1237 
1238     This signal is emitted whenever a property created by this manager
1239     changes its currenlty set regular expression, passing a pointer to
1240     the \a property and the new \a regExp as parameters.
1241 
1242     \sa setRegExp()
1243 */
1244 
1245 /*!
1246     Creates a manager with the given \a parent.
1247 */
1248 QtStringPropertyManager::QtStringPropertyManager(QObject *parent)
1249     : QtAbstractPropertyManager(parent), d_ptr(new QtStringPropertyManagerPrivate)
1250 {
1251     d_ptr->q_ptr = this;
1252 }
1253 
1254 /*!
1255     Destroys this manager, and all the properties it has created.
1256 */
1257 QtStringPropertyManager::~QtStringPropertyManager()
1258 {
1259     clear();
1260 }
1261 
1262 /*!
1263     Returns the given \a property's value.
1264 
1265     If the given property is not managed by this manager, this
1266     function returns an empty string.
1267 
1268     \sa setValue()
1269 */
1270 QString QtStringPropertyManager::value(const QtProperty *property) const
1271 {
1272     return getValue<QString>(d_ptr->m_values, property);
1273 }
1274 
1275 /*!
1276     Returns the given \a property's currently set regular expression.
1277 
1278     If the given \a property is not managed by this manager, this
1279     function returns an empty expression.
1280 
1281     \sa setRegExp()
1282 */
1283 QRegExp QtStringPropertyManager::regExp(const QtProperty *property) const
1284 {
1285     return getData<QRegExp>(d_ptr->m_values, &QtStringPropertyManagerPrivate::Data::regExp, property, QRegExp());
1286 }
1287 
1288 /*!
1289     \reimp
1290 */
1291 QString QtStringPropertyManager::valueText(const QtProperty *property) const
1292 {
1293     const QtStringPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
1294     if (it == d_ptr->m_values.constEnd())
1295         return QString();
1296     return it.value().val;
1297 }
1298 
1299 /*!
1300     \fn void QtStringPropertyManager::setValue(QtProperty *property, const QString &value)
1301 
1302     Sets the value of the given \a property to \a value.
1303 
1304     If the specified \a value doesn't match the given \a property's
1305     regular expression, this function does nothing.
1306 
1307     \sa value(), setRegExp(), valueChanged()
1308 */
1309 void QtStringPropertyManager::setValue(QtProperty *property, const QString &val)
1310 {
1311     const QtStringPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
1312     if (it == d_ptr->m_values.end())
1313         return;
1314 
1315     QtStringPropertyManagerPrivate::Data data = it.value();
1316 
1317     if (data.val == val)
1318         return;
1319 
1320     if (data.regExp.isValid() && !data.regExp.exactMatch(val))
1321         return;
1322 
1323     data.val = val;
1324 
1325     it.value() = data;
1326 
1327     Q_EMIT propertyChanged(property);
1328     Q_EMIT valueChanged(property, data.val);
1329 }
1330 
1331 /*!
1332     Sets the regular expression of the given \a property to \a regExp.
1333 
1334     \sa regExp(), setValue(), regExpChanged()
1335 */
1336 void QtStringPropertyManager::setRegExp(QtProperty *property, const QRegExp &regExp)
1337 {
1338     const QtStringPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
1339     if (it == d_ptr->m_values.end())
1340         return;
1341 
1342     QtStringPropertyManagerPrivate::Data data = it.value() ;
1343 
1344     if (data.regExp == regExp)
1345         return;
1346 
1347     data.regExp = regExp;
1348 
1349     it.value() = data;
1350 
1351     Q_EMIT regExpChanged(property, data.regExp);
1352 }
1353 
1354 /*!
1355     \reimp
1356 */
1357 void QtStringPropertyManager::initializeProperty(QtProperty *property)
1358 {
1359     d_ptr->m_values[property] = QtStringPropertyManagerPrivate::Data();
1360 }
1361 
1362 /*!
1363     \reimp
1364 */
1365 void QtStringPropertyManager::uninitializeProperty(QtProperty *property)
1366 {
1367     d_ptr->m_values.remove(property);
1368 }
1369 
1370 // QtBoolPropertyManager
1371 //     Return an icon containing a check box indicator
1372 static QIcon drawCheckBox(bool value)
1373 {
1374     QStyleOptionButton opt;
1375     opt.state |= value ? QStyle::State_On : QStyle::State_Off;
1376     opt.state |= QStyle::State_Enabled;
1377     const QStyle *style = QApplication::style();
1378     // Figure out size of an indicator and make sure it is not scaled down in a list view item
1379     // by making the pixmap as big as a list view icon and centering the indicator in it.
1380     // (if it is smaller, it can't be helped)
1381     const int indicatorWidth = style->pixelMetric(QStyle::PM_IndicatorWidth, &opt);
1382     const int indicatorHeight = style->pixelMetric(QStyle::PM_IndicatorHeight, &opt);
1383     const int listViewIconSize = indicatorWidth;
1384     const int pixmapWidth = indicatorWidth;
1385     const int pixmapHeight = qMax(indicatorHeight, listViewIconSize);
1386 
1387     opt.rect = QRect(0, 0, indicatorWidth, indicatorHeight);
1388     QPixmap pixmap = QPixmap(pixmapWidth, pixmapHeight);
1389     pixmap.fill(Qt::transparent);
1390     {
1391         // Center?
1392         const int xoff = (pixmapWidth  > indicatorWidth)  ? (pixmapWidth  - indicatorWidth)  / 2 : 0;
1393         const int yoff = (pixmapHeight > indicatorHeight) ? (pixmapHeight - indicatorHeight) / 2 : 0;
1394         QPainter painter(&pixmap);
1395         painter.translate(xoff, yoff);
1396         style->drawPrimitive(QStyle::PE_IndicatorCheckBox, &opt, &painter);
1397     }
1398     return QIcon(pixmap);
1399 }
1400 
1401 class QtBoolPropertyManagerPrivate
1402 {
1403     QtBoolPropertyManager *q_ptr;
1404     Q_DECLARE_PUBLIC(QtBoolPropertyManager)
1405 public:
1406     QtBoolPropertyManagerPrivate();
1407 
1408     QMap<const QtProperty *, bool> m_values;
1409     const QIcon m_checkedIcon;
1410     const QIcon m_uncheckedIcon;
1411 };
1412 
1413 QtBoolPropertyManagerPrivate::QtBoolPropertyManagerPrivate() :
1414     m_checkedIcon(drawCheckBox(true)),
1415     m_uncheckedIcon(drawCheckBox(false))
1416 {
1417 }
1418 
1419 /*!
1420     \class QtBoolPropertyManager
1421     \internal
1422     \inmodule QtDesigner
1423     \since 4.4
1424 
1425     \brief The QtBoolPropertyManager class provides and manages boolean properties.
1426 
1427     The property's value can be retrieved using the value() function,
1428     and set using the setValue() slot.
1429 
1430     In addition, QtBoolPropertyManager provides the valueChanged() signal
1431     which is emitted whenever a property created by this manager
1432     changes.
1433 
1434     \sa QtAbstractPropertyManager, QtCheckBoxFactory
1435 */
1436 
1437 /*!
1438     \fn void QtBoolPropertyManager::valueChanged(QtProperty *property, bool value)
1439 
1440     This signal is emitted whenever a property created by this manager
1441     changes its value, passing a pointer to the \a property and the
1442     new \a value as parameters.
1443 */
1444 
1445 /*!
1446     Creates a manager with the given \a parent.
1447 */
1448 QtBoolPropertyManager::QtBoolPropertyManager(QObject *parent)
1449     : QtAbstractPropertyManager(parent), d_ptr(new QtBoolPropertyManagerPrivate)
1450 {
1451     d_ptr->q_ptr = this;
1452 }
1453 
1454 /*!
1455     Destroys this manager, and all the properties it has created.
1456 */
1457 QtBoolPropertyManager::~QtBoolPropertyManager()
1458 {
1459     clear();
1460 }
1461 
1462 /*!
1463     Returns the given \a property's value.
1464 
1465     If the given \a property is not managed by \e this manager, this
1466     function returns false.
1467 
1468     \sa setValue()
1469 */
1470 bool QtBoolPropertyManager::value(const QtProperty *property) const
1471 {
1472     return d_ptr->m_values.value(property, false);
1473 }
1474 
1475 /*!
1476     \reimp
1477 */
1478 QString QtBoolPropertyManager::valueText(const QtProperty *property) const
1479 {
1480     const QMap<const QtProperty *, bool>::const_iterator it = d_ptr->m_values.constFind(property);
1481     if (it == d_ptr->m_values.constEnd())
1482         return QString();
1483 
1484     static const QString trueText = tr("True");
1485     static const QString falseText = tr("False");
1486     return it.value() ? trueText : falseText;
1487 }
1488 
1489 /*!
1490     \reimp
1491 */
1492 QIcon QtBoolPropertyManager::valueIcon(const QtProperty *property) const
1493 {
1494     const QMap<const QtProperty *, bool>::const_iterator it = d_ptr->m_values.constFind(property);
1495     if (it == d_ptr->m_values.constEnd())
1496         return QIcon();
1497 
1498     return it.value() ? d_ptr->m_checkedIcon : d_ptr->m_uncheckedIcon;
1499 }
1500 
1501 /*!
1502     \fn void QtBoolPropertyManager::setValue(QtProperty *property, bool value)
1503 
1504     Sets the value of the given \a property to \a value.
1505 
1506     \sa value()
1507 */
1508 void QtBoolPropertyManager::setValue(QtProperty *property, bool val)
1509 {
1510     setSimpleValue<bool, bool, QtBoolPropertyManager>(d_ptr->m_values, this,
1511                 &QtBoolPropertyManager::propertyChanged,
1512                 &QtBoolPropertyManager::valueChanged,
1513                 property, val);
1514 }
1515 
1516 /*!
1517     \reimp
1518 */
1519 void QtBoolPropertyManager::initializeProperty(QtProperty *property)
1520 {
1521     d_ptr->m_values[property] = false;
1522 }
1523 
1524 /*!
1525     \reimp
1526 */
1527 void QtBoolPropertyManager::uninitializeProperty(QtProperty *property)
1528 {
1529     d_ptr->m_values.remove(property);
1530 }
1531 
1532 // QtDatePropertyManager
1533 
1534 class QtDatePropertyManagerPrivate
1535 {
1536     QtDatePropertyManager *q_ptr;
1537     Q_DECLARE_PUBLIC(QtDatePropertyManager)
1538 public:
1539     explicit QtDatePropertyManagerPrivate(QtDatePropertyManager *q);
1540 
1541     struct Data
1542     {
1543         QDate val{QDate::currentDate()};
1544         QDate minVal{QDate(1752, 9, 14)};
1545         QDate maxVal{QDate(9999, 12, 31)};
1546         QDate minimumValue() const { return minVal; }
1547         QDate maximumValue() const { return maxVal; }
1548         void setMinimumValue(const QDate &newMinVal) { setSimpleMinimumData(this, newMinVal); }
1549         void setMaximumValue(const QDate &newMaxVal) { setSimpleMaximumData(this, newMaxVal); }
1550     };
1551 
1552     QString m_format;
1553 
1554     typedef QMap<const QtProperty *, Data> PropertyValueMap;
1555     QMap<const QtProperty *, Data> m_values;
1556 };
1557 
1558 QtDatePropertyManagerPrivate::QtDatePropertyManagerPrivate(QtDatePropertyManager *q) :
1559     q_ptr(q),
1560     m_format(QtPropertyBrowserUtils::dateFormat())
1561 {
1562 }
1563 
1564 /*!
1565     \class QtDatePropertyManager
1566     \internal
1567     \inmodule QtDesigner
1568     \since 4.4
1569 
1570     \brief The QtDatePropertyManager provides and manages QDate properties.
1571 
1572     A date property has a current value, and a range specifying the
1573     valid dates. The range is defined by a minimum and a maximum
1574     value.
1575 
1576     The property's values can be retrieved using the minimum(),
1577     maximum() and value() functions, and can be set using the
1578     setMinimum(), setMaximum() and setValue() slots. Alternatively,
1579     the range can be defined in one go using the setRange() slot.
1580 
1581     In addition, QtDatePropertyManager provides the valueChanged() signal
1582     which is emitted whenever a property created by this manager
1583     changes, and the rangeChanged() signal which is emitted whenever
1584     such a property changes its range of valid dates.
1585 
1586     \sa QtAbstractPropertyManager, QtDateEditFactory, QtDateTimePropertyManager
1587 */
1588 
1589 /*!
1590     \fn void QtDatePropertyManager::valueChanged(QtProperty *property, const QDate &value)
1591 
1592     This signal is emitted whenever a property created by this manager
1593     changes its value, passing a pointer to the \a property and the new
1594     \a value as parameters.
1595 
1596     \sa setValue()
1597 */
1598 
1599 /*!
1600     \fn void QtDatePropertyManager::rangeChanged(QtProperty *property, const QDate &minimum, const QDate &maximum)
1601 
1602     This signal is emitted whenever a property created by this manager
1603     changes its range of valid dates, passing a pointer to the \a
1604     property and the new \a minimum and \a maximum dates.
1605 
1606     \sa setRange()
1607 */
1608 
1609 /*!
1610     Creates a manager with the given \a parent.
1611 */
1612 QtDatePropertyManager::QtDatePropertyManager(QObject *parent)
1613     : QtAbstractPropertyManager(parent), d_ptr(new QtDatePropertyManagerPrivate(this))
1614 {
1615 }
1616 
1617 /*!
1618     Destroys this manager, and all the properties it has created.
1619 */
1620 QtDatePropertyManager::~QtDatePropertyManager()
1621 {
1622     clear();
1623 }
1624 
1625 /*!
1626     Returns the given \a property's value.
1627 
1628     If the given \a property is not managed by \e this manager, this
1629     function returns an invalid date.
1630 
1631     \sa setValue()
1632 */
1633 QDate QtDatePropertyManager::value(const QtProperty *property) const
1634 {
1635     return getValue<QDate>(d_ptr->m_values, property);
1636 }
1637 
1638 /*!
1639     Returns the given \a  property's  minimum date.
1640 
1641     \sa maximum(), setRange()
1642 */
1643 QDate QtDatePropertyManager::minimum(const QtProperty *property) const
1644 {
1645     return getMinimum<QDate>(d_ptr->m_values, property);
1646 }
1647 
1648 /*!
1649     Returns the given \a property's maximum date.
1650 
1651     \sa minimum(), setRange()
1652 */
1653 QDate QtDatePropertyManager::maximum(const QtProperty *property) const
1654 {
1655     return getMaximum<QDate>(d_ptr->m_values, property);
1656 }
1657 
1658 /*!
1659     \reimp
1660 */
1661 QString QtDatePropertyManager::valueText(const QtProperty *property) const
1662 {
1663     const QtDatePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
1664     if (it == d_ptr->m_values.constEnd())
1665         return QString();
1666     return it.value().val.toString(d_ptr->m_format);
1667 }
1668 
1669 /*!
1670     \fn void QtDatePropertyManager::setValue(QtProperty *property, const QDate &value)
1671 
1672     Sets the value of the given \a property to \a value.
1673 
1674     If the specified \a value is not a valid date according to the
1675     given \a property's range, the value is adjusted to the nearest
1676     valid value within the range.
1677 
1678     \sa value(), setRange(), valueChanged()
1679 */
1680 void QtDatePropertyManager::setValue(QtProperty *property, const QDate &val)
1681 {
1682     void (QtDatePropertyManagerPrivate::*setSubPropertyValue)(QtProperty *, const QDate &) = 0;
1683     setValueInRange<const QDate &, QtDatePropertyManagerPrivate, QtDatePropertyManager, const QDate>(this, d_ptr.data(),
1684                 &QtDatePropertyManager::propertyChanged,
1685                 &QtDatePropertyManager::valueChanged,
1686                 property, val, setSubPropertyValue);
1687 }
1688 
1689 /*!
1690     Sets the minimum value for the given \a property to \a minVal.
1691 
1692     When setting the minimum value, the maximum and current values are
1693     adjusted if necessary (ensuring that the range remains valid and
1694     that the current value is within in the range).
1695 
1696     \sa minimum(), setRange()
1697 */
1698 void QtDatePropertyManager::setMinimum(QtProperty *property, const QDate &minVal)
1699 {
1700     setMinimumValue<const QDate &, QtDatePropertyManagerPrivate, QtDatePropertyManager, QDate, QtDatePropertyManagerPrivate::Data>(this, d_ptr.data(),
1701                 &QtDatePropertyManager::propertyChanged,
1702                 &QtDatePropertyManager::valueChanged,
1703                 &QtDatePropertyManager::rangeChanged,
1704                 property, minVal);
1705 }
1706 
1707 /*!
1708     Sets the maximum value for the given \a property to \a maxVal.
1709 
1710     When setting the maximum value, the minimum and current
1711     values are adjusted if necessary (ensuring that the range remains
1712     valid and that the current value is within in the range).
1713 
1714     \sa maximum(), setRange()
1715 */
1716 void QtDatePropertyManager::setMaximum(QtProperty *property, const QDate &maxVal)
1717 {
1718     setMaximumValue<const QDate &, QtDatePropertyManagerPrivate, QtDatePropertyManager, QDate, QtDatePropertyManagerPrivate::Data>(this, d_ptr.data(),
1719                 &QtDatePropertyManager::propertyChanged,
1720                 &QtDatePropertyManager::valueChanged,
1721                 &QtDatePropertyManager::rangeChanged,
1722                 property, maxVal);
1723 }
1724 
1725 /*!
1726     \fn void QtDatePropertyManager::setRange(QtProperty *property, const QDate &minimum, const QDate &maximum)
1727 
1728     Sets the range of valid dates.
1729 
1730     This is a convenience function defining the range of valid dates
1731     in one go; setting the \a minimum and \a maximum values for the
1732     given \a property with a single function call.
1733 
1734     When setting a new date range, the current value is adjusted if
1735     necessary (ensuring that the value remains in date range).
1736 
1737     \sa setMinimum(), setMaximum(), rangeChanged()
1738 */
1739 void QtDatePropertyManager::setRange(QtProperty *property, const QDate &minVal, const QDate &maxVal)
1740 {
1741     void (QtDatePropertyManagerPrivate::*setSubPropertyRange)(QtProperty *, const QDate &,
1742           const QDate &, const QDate &) = 0;
1743     setBorderValues<const QDate &, QtDatePropertyManagerPrivate, QtDatePropertyManager, QDate>(this, d_ptr.data(),
1744                 &QtDatePropertyManager::propertyChanged,
1745                 &QtDatePropertyManager::valueChanged,
1746                 &QtDatePropertyManager::rangeChanged,
1747                 property, minVal, maxVal, setSubPropertyRange);
1748 }
1749 
1750 /*!
1751     \reimp
1752 */
1753 void QtDatePropertyManager::initializeProperty(QtProperty *property)
1754 {
1755     d_ptr->m_values[property] = QtDatePropertyManagerPrivate::Data();
1756 }
1757 
1758 /*!
1759     \reimp
1760 */
1761 void QtDatePropertyManager::uninitializeProperty(QtProperty *property)
1762 {
1763     d_ptr->m_values.remove(property);
1764 }
1765 
1766 // QtTimePropertyManager
1767 
1768 class QtTimePropertyManagerPrivate
1769 {
1770     QtTimePropertyManager *q_ptr;
1771     Q_DECLARE_PUBLIC(QtTimePropertyManager)
1772 public:
1773     explicit QtTimePropertyManagerPrivate(QtTimePropertyManager *q);
1774 
1775     const QString m_format;
1776 
1777     typedef QMap<const QtProperty *, QTime> PropertyValueMap;
1778     PropertyValueMap m_values;
1779 };
1780 
1781 QtTimePropertyManagerPrivate::QtTimePropertyManagerPrivate(QtTimePropertyManager *q) :
1782     q_ptr(q),
1783     m_format(QtPropertyBrowserUtils::timeFormat())
1784 {
1785 }
1786 
1787 /*!
1788     \class QtTimePropertyManager
1789     \internal
1790     \inmodule QtDesigner
1791     \since 4.4
1792 
1793     \brief The QtTimePropertyManager provides and manages QTime properties.
1794 
1795     A time property's value can be retrieved using the value()
1796     function, and set using the setValue() slot.
1797 
1798     In addition, QtTimePropertyManager provides the valueChanged() signal
1799     which is emitted whenever a property created by this manager
1800     changes.
1801 
1802     \sa QtAbstractPropertyManager, QtTimeEditFactory
1803 */
1804 
1805 /*!
1806     \fn void QtTimePropertyManager::valueChanged(QtProperty *property, const QTime &value)
1807 
1808     This signal is emitted whenever a property created by this manager
1809     changes its value, passing a pointer to the \a property and the
1810     new \a value as parameters.
1811 
1812     \sa setValue()
1813 */
1814 
1815 /*!
1816     Creates a manager with the given \a parent.
1817 */
1818 QtTimePropertyManager::QtTimePropertyManager(QObject *parent)
1819     : QtAbstractPropertyManager(parent), d_ptr(new QtTimePropertyManagerPrivate(this))
1820 {
1821 }
1822 
1823 /*!
1824     Destroys this manager, and all the properties it has created.
1825 */
1826 QtTimePropertyManager::~QtTimePropertyManager()
1827 {
1828     clear();
1829 }
1830 
1831 /*!
1832     Returns the given \a property's value.
1833 
1834     If the given property is not managed by this manager, this
1835     function returns an invalid time object.
1836 
1837     \sa setValue()
1838 */
1839 QTime QtTimePropertyManager::value(const QtProperty *property) const
1840 {
1841     return d_ptr->m_values.value(property, QTime());
1842 }
1843 
1844 /*!
1845     \reimp
1846 */
1847 QString QtTimePropertyManager::valueText(const QtProperty *property) const
1848 {
1849    const QtTimePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
1850     if (it == d_ptr->m_values.constEnd())
1851         return QString();
1852     return it.value().toString(d_ptr->m_format);
1853 }
1854 
1855 /*!
1856     \fn void QtTimePropertyManager::setValue(QtProperty *property, const QTime &value)
1857 
1858     Sets the value of the given \a property to \a value.
1859 
1860     \sa value(), valueChanged()
1861 */
1862 void QtTimePropertyManager::setValue(QtProperty *property, const QTime &val)
1863 {
1864     setSimpleValue<const QTime &, QTime, QtTimePropertyManager>(d_ptr->m_values, this,
1865                 &QtTimePropertyManager::propertyChanged,
1866                 &QtTimePropertyManager::valueChanged,
1867                 property, val);
1868 }
1869 
1870 /*!
1871     \reimp
1872 */
1873 void QtTimePropertyManager::initializeProperty(QtProperty *property)
1874 {
1875     d_ptr->m_values[property] = QTime::currentTime();
1876 }
1877 
1878 /*!
1879     \reimp
1880 */
1881 void QtTimePropertyManager::uninitializeProperty(QtProperty *property)
1882 {
1883     d_ptr->m_values.remove(property);
1884 }
1885 
1886 // QtDateTimePropertyManager
1887 
1888 class QtDateTimePropertyManagerPrivate
1889 {
1890     QtDateTimePropertyManager *q_ptr;
1891     Q_DECLARE_PUBLIC(QtDateTimePropertyManager)
1892 public:
1893     explicit QtDateTimePropertyManagerPrivate(QtDateTimePropertyManager *q);
1894 
1895     const QString m_format;
1896 
1897     typedef QMap<const QtProperty *, QDateTime> PropertyValueMap;
1898     PropertyValueMap m_values;
1899 };
1900 
1901 QtDateTimePropertyManagerPrivate::QtDateTimePropertyManagerPrivate(QtDateTimePropertyManager *q) :
1902     q_ptr(q),
1903     m_format(QtPropertyBrowserUtils::dateTimeFormat())
1904 {
1905 }
1906 
1907 /*! \class QtDateTimePropertyManager
1908     \internal
1909     \inmodule QtDesigner
1910     \since 4.4
1911 
1912     \brief The QtDateTimePropertyManager provides and manages QDateTime properties.
1913 
1914     A date and time property has a current value which can be
1915     retrieved using the value() function, and set using the setValue()
1916     slot. In addition, QtDateTimePropertyManager provides the
1917     valueChanged() signal which is emitted whenever a property created
1918     by this manager changes.
1919 
1920     \sa QtAbstractPropertyManager, QtDateTimeEditFactory, QtDatePropertyManager
1921 */
1922 
1923 /*!
1924     \fn void QtDateTimePropertyManager::valueChanged(QtProperty *property, const QDateTime &value)
1925 
1926     This signal is emitted whenever a property created by this manager
1927     changes its value, passing a pointer to the \a property and the new
1928     \a value as parameters.
1929 */
1930 
1931 /*!
1932     Creates a manager with the given \a parent.
1933 */
1934 QtDateTimePropertyManager::QtDateTimePropertyManager(QObject *parent)
1935     : QtAbstractPropertyManager(parent), d_ptr(new QtDateTimePropertyManagerPrivate(this))
1936 {
1937 }
1938 
1939 /*!
1940     Destroys this manager, and all the properties it has created.
1941 */
1942 QtDateTimePropertyManager::~QtDateTimePropertyManager()
1943 {
1944     clear();
1945 }
1946 
1947 /*!
1948     Returns the given \a property's value.
1949 
1950     If the given \a property is not managed by this manager, this
1951     function returns an invalid QDateTime object.
1952 
1953     \sa setValue()
1954 */
1955 QDateTime QtDateTimePropertyManager::value(const QtProperty *property) const
1956 {
1957     return d_ptr->m_values.value(property, QDateTime());
1958 }
1959 
1960 /*!
1961     \reimp
1962 */
1963 QString QtDateTimePropertyManager::valueText(const QtProperty *property) const
1964 {
1965    const QtDateTimePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
1966     if (it == d_ptr->m_values.constEnd())
1967         return QString();
1968     return it.value().toString(d_ptr->m_format);
1969 }
1970 
1971 /*!
1972     \fn void QtDateTimePropertyManager::setValue(QtProperty *property, const QDateTime &value)
1973 
1974     Sets the value of the given \a property to \a value.
1975 
1976     \sa value(), valueChanged()
1977 */
1978 void QtDateTimePropertyManager::setValue(QtProperty *property, const QDateTime &val)
1979 {
1980     setSimpleValue<const QDateTime &, QDateTime, QtDateTimePropertyManager>(d_ptr->m_values, this,
1981                 &QtDateTimePropertyManager::propertyChanged,
1982                 &QtDateTimePropertyManager::valueChanged,
1983                 property, val);
1984 }
1985 
1986 /*!
1987     \reimp
1988 */
1989 void QtDateTimePropertyManager::initializeProperty(QtProperty *property)
1990 {
1991     d_ptr->m_values[property] = QDateTime::currentDateTime();
1992 }
1993 
1994 /*!
1995     \reimp
1996 */
1997 void QtDateTimePropertyManager::uninitializeProperty(QtProperty *property)
1998 {
1999     d_ptr->m_values.remove(property);
2000 }
2001 
2002 // QtKeySequencePropertyManager
2003 
2004 class QtKeySequencePropertyManagerPrivate
2005 {
2006     QtKeySequencePropertyManager *q_ptr;
2007     Q_DECLARE_PUBLIC(QtKeySequencePropertyManager)
2008 public:
2009 
2010     QString m_format;
2011 
2012     typedef QMap<const QtProperty *, QKeySequence> PropertyValueMap;
2013     PropertyValueMap m_values;
2014 };
2015 
2016 /*! \class QtKeySequencePropertyManager
2017     \internal
2018     \inmodule QtDesigner
2019     \since 4.4
2020 
2021     \brief The QtKeySequencePropertyManager provides and manages QKeySequence properties.
2022 
2023     A key sequence's value can be retrieved using the value()
2024     function, and set using the setValue() slot.
2025 
2026     In addition, QtKeySequencePropertyManager provides the valueChanged() signal
2027     which is emitted whenever a property created by this manager
2028     changes.
2029 
2030     \sa QtAbstractPropertyManager
2031 */
2032 
2033 /*!
2034     \fn void QtKeySequencePropertyManager::valueChanged(QtProperty *property, const QKeySequence &value)
2035 
2036     This signal is emitted whenever a property created by this manager
2037     changes its value, passing a pointer to the \a property and the new
2038     \a value as parameters.
2039 */
2040 
2041 /*!
2042     Creates a manager with the given \a parent.
2043 */
2044 QtKeySequencePropertyManager::QtKeySequencePropertyManager(QObject *parent)
2045     : QtAbstractPropertyManager(parent), d_ptr(new QtKeySequencePropertyManagerPrivate)
2046 {
2047     d_ptr->q_ptr = this;
2048 }
2049 
2050 /*!
2051     Destroys this manager, and all the properties it has created.
2052 */
2053 QtKeySequencePropertyManager::~QtKeySequencePropertyManager()
2054 {
2055     clear();
2056 }
2057 
2058 /*!
2059     Returns the given \a property's value.
2060 
2061     If the given \a property is not managed by this manager, this
2062     function returns an empty QKeySequence object.
2063 
2064     \sa setValue()
2065 */
2066 QKeySequence QtKeySequencePropertyManager::value(const QtProperty *property) const
2067 {
2068     return d_ptr->m_values.value(property, QKeySequence());
2069 }
2070 
2071 /*!
2072     \reimp
2073 */
2074 QString QtKeySequencePropertyManager::valueText(const QtProperty *property) const
2075 {
2076     const QtKeySequencePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
2077     if (it == d_ptr->m_values.constEnd())
2078         return QString();
2079     return it.value().toString(QKeySequence::NativeText);
2080 }
2081 
2082 /*!
2083     \fn void QtKeySequencePropertyManager::setValue(QtProperty *property, const QKeySequence &value)
2084 
2085     Sets the value of the given \a property to \a value.
2086 
2087     \sa value(), valueChanged()
2088 */
2089 void QtKeySequencePropertyManager::setValue(QtProperty *property, const QKeySequence &val)
2090 {
2091     setSimpleValue<const QKeySequence &, QKeySequence, QtKeySequencePropertyManager>(d_ptr->m_values, this,
2092                 &QtKeySequencePropertyManager::propertyChanged,
2093                 &QtKeySequencePropertyManager::valueChanged,
2094                 property, val);
2095 }
2096 
2097 /*!
2098     \reimp
2099 */
2100 void QtKeySequencePropertyManager::initializeProperty(QtProperty *property)
2101 {
2102     d_ptr->m_values[property] = QKeySequence();
2103 }
2104 
2105 /*!
2106     \reimp
2107 */
2108 void QtKeySequencePropertyManager::uninitializeProperty(QtProperty *property)
2109 {
2110     d_ptr->m_values.remove(property);
2111 }
2112 
2113 // QtCharPropertyManager
2114 
2115 class QtCharPropertyManagerPrivate
2116 {
2117     QtCharPropertyManager *q_ptr;
2118     Q_DECLARE_PUBLIC(QtCharPropertyManager)
2119 public:
2120 
2121     typedef QMap<const QtProperty *, QChar> PropertyValueMap;
2122     PropertyValueMap m_values;
2123 };
2124 
2125 /*! \class QtCharPropertyManager
2126     \internal
2127     \inmodule QtDesigner
2128     \since 4.4
2129 
2130     \brief The QtCharPropertyManager provides and manages QChar properties.
2131 
2132     A char's value can be retrieved using the value()
2133     function, and set using the setValue() slot.
2134 
2135     In addition, QtCharPropertyManager provides the valueChanged() signal
2136     which is emitted whenever a property created by this manager
2137     changes.
2138 
2139     \sa QtAbstractPropertyManager
2140 */
2141 
2142 /*!
2143     \fn void QtCharPropertyManager::valueChanged(QtProperty *property, const QChar &value)
2144 
2145     This signal is emitted whenever a property created by this manager
2146     changes its value, passing a pointer to the \a property and the new
2147     \a value as parameters.
2148 */
2149 
2150 /*!
2151     Creates a manager with the given \a parent.
2152 */
2153 QtCharPropertyManager::QtCharPropertyManager(QObject *parent)
2154     : QtAbstractPropertyManager(parent), d_ptr(new QtCharPropertyManagerPrivate)
2155 {
2156     d_ptr->q_ptr = this;
2157 }
2158 
2159 /*!
2160     Destroys this manager, and all the properties it has created.
2161 */
2162 QtCharPropertyManager::~QtCharPropertyManager()
2163 {
2164     clear();
2165 }
2166 
2167 /*!
2168     Returns the given \a property's value.
2169 
2170     If the given \a property is not managed by this manager, this
2171     function returns an null QChar object.
2172 
2173     \sa setValue()
2174 */
2175 QChar QtCharPropertyManager::value(const QtProperty *property) const
2176 {
2177     return d_ptr->m_values.value(property, QChar());
2178 }
2179 
2180 /*!
2181     \reimp
2182 */
2183 QString QtCharPropertyManager::valueText(const QtProperty *property) const
2184 {
2185    const QtCharPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
2186     if (it == d_ptr->m_values.constEnd())
2187         return QString();
2188     const QChar c = it.value();
2189     return c.isNull() ? QString() : QString(c);
2190 }
2191 
2192 /*!
2193     \fn void QtCharPropertyManager::setValue(QtProperty *property, const QChar &value)
2194 
2195     Sets the value of the given \a property to \a value.
2196 
2197     \sa value(), valueChanged()
2198 */
2199 void QtCharPropertyManager::setValue(QtProperty *property, const QChar &val)
2200 {
2201     setSimpleValue<const QChar &, QChar, QtCharPropertyManager>(d_ptr->m_values, this,
2202                 &QtCharPropertyManager::propertyChanged,
2203                 &QtCharPropertyManager::valueChanged,
2204                 property, val);
2205 }
2206 
2207 /*!
2208     \reimp
2209 */
2210 void QtCharPropertyManager::initializeProperty(QtProperty *property)
2211 {
2212     d_ptr->m_values[property] = QChar();
2213 }
2214 
2215 /*!
2216     \reimp
2217 */
2218 void QtCharPropertyManager::uninitializeProperty(QtProperty *property)
2219 {
2220     d_ptr->m_values.remove(property);
2221 }
2222 
2223 // QtLocalePropertyManager
2224 
2225 class QtLocalePropertyManagerPrivate
2226 {
2227     QtLocalePropertyManager *q_ptr;
2228     Q_DECLARE_PUBLIC(QtLocalePropertyManager)
2229 public:
2230 
2231     QtLocalePropertyManagerPrivate();
2232 
2233     void slotEnumChanged(QtProperty *property, int value);
2234     void slotPropertyDestroyed(QtProperty *property);
2235 
2236     typedef QMap<const QtProperty *, QLocale> PropertyValueMap;
2237     PropertyValueMap m_values;
2238 
2239     QtEnumPropertyManager *m_enumPropertyManager;
2240 
2241     QMap<const QtProperty *, QtProperty *> m_propertyToLanguage;
2242     QMap<const QtProperty *, QtProperty *> m_propertyToCountry;
2243 
2244     QMap<const QtProperty *, QtProperty *> m_languageToProperty;
2245     QMap<const QtProperty *, QtProperty *> m_countryToProperty;
2246 };
2247 
2248 QtLocalePropertyManagerPrivate::QtLocalePropertyManagerPrivate()
2249 {
2250 }
2251 
2252 void QtLocalePropertyManagerPrivate::slotEnumChanged(QtProperty *property, int value)
2253 {
2254     if (QtProperty *prop = m_languageToProperty.value(property, 0)) {
2255         const QLocale loc = m_values[prop];
2256         QLocale::Language newLanguage = loc.language();
2257         QLocale::Country newCountry = loc.country();
2258         metaEnumProvider()->indexToLocale(value, 0, &newLanguage, 0);
2259         QLocale newLoc(newLanguage, newCountry);
2260         q_ptr->setValue(prop, newLoc);
2261     } else if (QtProperty *prop = m_countryToProperty.value(property, 0)) {
2262         const QLocale loc = m_values[prop];
2263         QLocale::Language newLanguage = loc.language();
2264         QLocale::Country newCountry = loc.country();
2265         metaEnumProvider()->indexToLocale(m_enumPropertyManager->value(m_propertyToLanguage.value(prop)), value, &newLanguage, &newCountry);
2266         QLocale newLoc(newLanguage, newCountry);
2267         q_ptr->setValue(prop, newLoc);
2268     }
2269 }
2270 
2271 void QtLocalePropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
2272 {
2273     if (QtProperty *subProp = m_languageToProperty.value(property, 0)) {
2274         m_propertyToLanguage[subProp] = 0;
2275         m_languageToProperty.remove(property);
2276     } else if (QtProperty *subProp = m_countryToProperty.value(property, 0)) {
2277         m_propertyToCountry[subProp] = 0;
2278         m_countryToProperty.remove(property);
2279     }
2280 }
2281 
2282 /*!
2283     \class QtLocalePropertyManager
2284     \internal
2285     \inmodule QtDesigner
2286     \since 4.4
2287 
2288     \brief The QtLocalePropertyManager provides and manages QLocale properties.
2289 
2290     A locale property has nested \e language and \e country
2291     subproperties. The top-level property's value can be retrieved
2292     using the value() function, and set using the setValue() slot.
2293 
2294     The subproperties are created by QtEnumPropertyManager object.
2295     These submanager can be retrieved using the subEnumPropertyManager()
2296     function. In order to provide editing widgets for the subproperties
2297     in a property browser widget, this manager must be associated with editor factory.
2298 
2299     In addition, QtLocalePropertyManager provides the valueChanged()
2300     signal which is emitted whenever a property created by this
2301     manager changes.
2302 
2303     \sa QtAbstractPropertyManager, QtEnumPropertyManager
2304 */
2305 
2306 /*!
2307     \fn void QtLocalePropertyManager::valueChanged(QtProperty *property, const QLocale &value)
2308 
2309     This signal is emitted whenever a property created by this manager
2310     changes its value, passing a pointer to the \a property and the
2311     new \a value as parameters.
2312 
2313     \sa setValue()
2314 */
2315 
2316 /*!
2317     Creates a manager with the given \a parent.
2318 */
2319 QtLocalePropertyManager::QtLocalePropertyManager(QObject *parent)
2320     : QtAbstractPropertyManager(parent), d_ptr(new QtLocalePropertyManagerPrivate)
2321 {
2322     d_ptr->q_ptr = this;
2323 
2324     d_ptr->m_enumPropertyManager = new QtEnumPropertyManager(this);
2325     connect(d_ptr->m_enumPropertyManager, SIGNAL(valueChanged(QtProperty*,int)),
2326                 this, SLOT(slotEnumChanged(QtProperty*,int)));
2327 
2328     connect(d_ptr->m_enumPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
2329                 this, SLOT(slotPropertyDestroyed(QtProperty*)));
2330 }
2331 
2332 /*!
2333     Destroys this manager, and all the properties it has created.
2334 */
2335 QtLocalePropertyManager::~QtLocalePropertyManager()
2336 {
2337     clear();
2338 }
2339 
2340 /*!
2341     Returns the manager that creates the nested \e language
2342     and \e country subproperties.
2343 
2344     In order to provide editing widgets for the mentioned subproperties
2345     in a property browser widget, this manager must be associated with
2346     an editor factory.
2347 
2348     \sa QtAbstractPropertyBrowser::setFactoryForManager()
2349 */
2350 QtEnumPropertyManager *QtLocalePropertyManager::subEnumPropertyManager() const
2351 {
2352     return d_ptr->m_enumPropertyManager;
2353 }
2354 
2355 /*!
2356     Returns the given \a property's value.
2357 
2358     If the given property is not managed by this manager, this
2359     function returns the default locale.
2360 
2361     \sa setValue()
2362 */
2363 QLocale QtLocalePropertyManager::value(const QtProperty *property) const
2364 {
2365     return d_ptr->m_values.value(property, QLocale());
2366 }
2367 
2368 /*!
2369     \reimp
2370 */
2371 QString QtLocalePropertyManager::valueText(const QtProperty *property) const
2372 {
2373     const QtLocalePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
2374     if (it == d_ptr->m_values.constEnd())
2375         return QString();
2376 
2377     const QLocale loc = it.value();
2378 
2379     int langIdx = 0;
2380     int countryIdx = 0;
2381     const QtMetaEnumProvider *me = metaEnumProvider();
2382     me->localeToIndex(loc.language(), loc.country(), &langIdx, &countryIdx);
2383     if (langIdx < 0) {
2384         qWarning("QtLocalePropertyManager::valueText: Unknown language %d", loc.language());
2385         return tr("<Invalid>");
2386     }
2387     const QString languageName = me->languageEnumNames().at(langIdx);
2388     if (countryIdx < 0) {
2389         qWarning("QtLocalePropertyManager::valueText: Unknown country %d for %s", loc.country(), qPrintable(languageName));
2390         return languageName;
2391     }
2392     const QString countryName = me->countryEnumNames(loc.language()).at(countryIdx);
2393     return tr("%1, %2").arg(languageName, countryName);
2394 }
2395 
2396 /*!
2397     \fn void QtLocalePropertyManager::setValue(QtProperty *property, const QLocale &value)
2398 
2399     Sets the value of the given \a property to \a value. Nested
2400     properties are updated automatically.
2401 
2402     \sa value(), valueChanged()
2403 */
2404 void QtLocalePropertyManager::setValue(QtProperty *property, const QLocale &val)
2405 {
2406     const QtLocalePropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
2407     if (it == d_ptr->m_values.end())
2408         return;
2409 
2410     const QLocale loc = it.value();
2411     if (loc == val)
2412         return;
2413 
2414     it.value() = val;
2415 
2416     int langIdx = 0;
2417     int countryIdx = 0;
2418     metaEnumProvider()->localeToIndex(val.language(), val.country(), &langIdx, &countryIdx);
2419     if (loc.language() != val.language()) {
2420         d_ptr->m_enumPropertyManager->setValue(d_ptr->m_propertyToLanguage.value(property), langIdx);
2421         d_ptr->m_enumPropertyManager->setEnumNames(d_ptr->m_propertyToCountry.value(property),
2422                     metaEnumProvider()->countryEnumNames(val.language()));
2423     }
2424     d_ptr->m_enumPropertyManager->setValue(d_ptr->m_propertyToCountry.value(property), countryIdx);
2425 
2426     Q_EMIT propertyChanged(property);
2427     Q_EMIT valueChanged(property, val);
2428 }
2429 
2430 /*!
2431     \reimp
2432 */
2433 void QtLocalePropertyManager::initializeProperty(QtProperty *property)
2434 {
2435     QLocale val;
2436     d_ptr->m_values[property] = val;
2437 
2438     int langIdx = 0;
2439     int countryIdx = 0;
2440     metaEnumProvider()->localeToIndex(val.language(), val.country(), &langIdx, &countryIdx);
2441 
2442     QtProperty *languageProp = d_ptr->m_enumPropertyManager->addProperty();
2443     languageProp->setPropertyName(tr("Language"));
2444     d_ptr->m_enumPropertyManager->setEnumNames(languageProp, metaEnumProvider()->languageEnumNames());
2445     d_ptr->m_enumPropertyManager->setValue(languageProp, langIdx);
2446     d_ptr->m_propertyToLanguage[property] = languageProp;
2447     d_ptr->m_languageToProperty[languageProp] = property;
2448     property->addSubProperty(languageProp);
2449 
2450     QtProperty *countryProp = d_ptr->m_enumPropertyManager->addProperty();
2451     countryProp->setPropertyName(tr("Country"));
2452     d_ptr->m_enumPropertyManager->setEnumNames(countryProp, metaEnumProvider()->countryEnumNames(val.language()));
2453     d_ptr->m_enumPropertyManager->setValue(countryProp, countryIdx);
2454     d_ptr->m_propertyToCountry[property] = countryProp;
2455     d_ptr->m_countryToProperty[countryProp] = property;
2456     property->addSubProperty(countryProp);
2457 }
2458 
2459 /*!
2460     \reimp
2461 */
2462 void QtLocalePropertyManager::uninitializeProperty(QtProperty *property)
2463 {
2464     QtProperty *languageProp = d_ptr->m_propertyToLanguage[property];
2465     if (languageProp) {
2466         d_ptr->m_languageToProperty.remove(languageProp);
2467         delete languageProp;
2468     }
2469     d_ptr->m_propertyToLanguage.remove(property);
2470 
2471     QtProperty *countryProp = d_ptr->m_propertyToCountry[property];
2472     if (countryProp) {
2473         d_ptr->m_countryToProperty.remove(countryProp);
2474         delete countryProp;
2475     }
2476     d_ptr->m_propertyToCountry.remove(property);
2477 
2478     d_ptr->m_values.remove(property);
2479 }
2480 
2481 // QtPointPropertyManager
2482 
2483 class QtPointPropertyManagerPrivate
2484 {
2485     QtPointPropertyManager *q_ptr;
2486     Q_DECLARE_PUBLIC(QtPointPropertyManager)
2487 public:
2488 
2489     void slotIntChanged(QtProperty *property, int value);
2490     void slotPropertyDestroyed(QtProperty *property);
2491 
2492     typedef QMap<const QtProperty *, QPoint> PropertyValueMap;
2493     PropertyValueMap m_values;
2494 
2495     QtIntPropertyManager *m_intPropertyManager;
2496 
2497     QMap<const QtProperty *, QtProperty *> m_propertyToX;
2498     QMap<const QtProperty *, QtProperty *> m_propertyToY;
2499 
2500     QMap<const QtProperty *, QtProperty *> m_xToProperty;
2501     QMap<const QtProperty *, QtProperty *> m_yToProperty;
2502 };
2503 
2504 void QtPointPropertyManagerPrivate::slotIntChanged(QtProperty *property, int value)
2505 {
2506     if (QtProperty *xprop = m_xToProperty.value(property, 0)) {
2507         QPoint p = m_values[xprop];
2508         p.setX(value);
2509         q_ptr->setValue(xprop, p);
2510     } else if (QtProperty *yprop = m_yToProperty.value(property, 0)) {
2511         QPoint p = m_values[yprop];
2512         p.setY(value);
2513         q_ptr->setValue(yprop, p);
2514     }
2515 }
2516 
2517 void QtPointPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
2518 {
2519     if (QtProperty *pointProp = m_xToProperty.value(property, 0)) {
2520         m_propertyToX[pointProp] = 0;
2521         m_xToProperty.remove(property);
2522     } else if (QtProperty *pointProp = m_yToProperty.value(property, 0)) {
2523         m_propertyToY[pointProp] = 0;
2524         m_yToProperty.remove(property);
2525     }
2526 }
2527 
2528 /*! \class QtPointPropertyManager
2529     \internal
2530     \inmodule QtDesigner
2531     \since 4.4
2532 
2533     \brief The QtPointPropertyManager provides and manages QPoint properties.
2534 
2535     A point property has nested \e x and \e y subproperties. The
2536     top-level property's value can be retrieved using the value()
2537     function, and set using the setValue() slot.
2538 
2539     The subproperties are created by a QtIntPropertyManager object. This
2540     manager can be retrieved using the subIntPropertyManager() function. In
2541     order to provide editing widgets for the subproperties in a
2542     property browser widget, this manager must be associated with an
2543     editor factory.
2544 
2545     In addition, QtPointPropertyManager provides the valueChanged() signal which
2546     is emitted whenever a property created by this manager changes.
2547 
2548     \sa QtAbstractPropertyManager, QtIntPropertyManager, QtPointFPropertyManager
2549 */
2550 
2551 /*!
2552     \fn void QtPointPropertyManager::valueChanged(QtProperty *property, const QPoint &value)
2553 
2554     This signal is emitted whenever a property created by this manager
2555     changes its value, passing a pointer to the \a property and the
2556     new \a value as parameters.
2557 
2558     \sa setValue()
2559 */
2560 
2561 /*!
2562     Creates a manager with the given \a parent.
2563 */
2564 QtPointPropertyManager::QtPointPropertyManager(QObject *parent)
2565     : QtAbstractPropertyManager(parent), d_ptr(new QtPointPropertyManagerPrivate)
2566 {
2567     d_ptr->q_ptr = this;
2568 
2569     d_ptr->m_intPropertyManager = new QtIntPropertyManager(this);
2570     connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty*,int)),
2571                 this, SLOT(slotIntChanged(QtProperty*,int)));
2572     connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
2573                 this, SLOT(slotPropertyDestroyed(QtProperty*)));
2574 }
2575 
2576 /*!
2577     Destroys this manager, and all the properties it has created.
2578 */
2579 QtPointPropertyManager::~QtPointPropertyManager()
2580 {
2581     clear();
2582 }
2583 
2584 /*!
2585     Returns the manager that creates the nested \e x and \e y
2586     subproperties.
2587 
2588     In order to provide editing widgets for the subproperties in a
2589     property browser widget, this manager must be associated with an
2590     editor factory.
2591 
2592     \sa QtAbstractPropertyBrowser::setFactoryForManager()
2593 */
2594 QtIntPropertyManager *QtPointPropertyManager::subIntPropertyManager() const
2595 {
2596     return d_ptr->m_intPropertyManager;
2597 }
2598 
2599 /*!
2600     Returns the given \a property's value.
2601 
2602     If the given \a property is not managed by this manager, this
2603     function returns a point with coordinates (0, 0).
2604 
2605     \sa setValue()
2606 */
2607 QPoint QtPointPropertyManager::value(const QtProperty *property) const
2608 {
2609     return d_ptr->m_values.value(property, QPoint());
2610 }
2611 
2612 /*!
2613     \reimp
2614 */
2615 QString QtPointPropertyManager::valueText(const QtProperty *property) const
2616 {
2617     const QtPointPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
2618     if (it == d_ptr->m_values.constEnd())
2619         return QString();
2620     const QPoint v = it.value();
2621     return tr("(%1, %2)").arg(QString::number(v.x()))
2622                          .arg(QString::number(v.y()));
2623 }
2624 
2625 /*!
2626     \fn void QtPointPropertyManager::setValue(QtProperty *property, const QPoint &value)
2627 
2628     Sets the value of the given \a property to \a value. Nested
2629     properties are updated automatically.
2630 
2631     \sa value(), valueChanged()
2632 */
2633 void QtPointPropertyManager::setValue(QtProperty *property, const QPoint &val)
2634 {
2635     const QtPointPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
2636     if (it == d_ptr->m_values.end())
2637         return;
2638 
2639     if (it.value() == val)
2640         return;
2641 
2642     it.value() = val;
2643     d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToX[property], val.x());
2644     d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToY[property], val.y());
2645 
2646     Q_EMIT propertyChanged(property);
2647     Q_EMIT valueChanged(property, val);
2648 }
2649 
2650 /*!
2651     \reimp
2652 */
2653 void QtPointPropertyManager::initializeProperty(QtProperty *property)
2654 {
2655     d_ptr->m_values[property] = QPoint(0, 0);
2656 
2657     QtProperty *xProp = d_ptr->m_intPropertyManager->addProperty();
2658     xProp->setPropertyName(tr("X"));
2659     d_ptr->m_intPropertyManager->setValue(xProp, 0);
2660     d_ptr->m_propertyToX[property] = xProp;
2661     d_ptr->m_xToProperty[xProp] = property;
2662     property->addSubProperty(xProp);
2663 
2664     QtProperty *yProp = d_ptr->m_intPropertyManager->addProperty();
2665     yProp->setPropertyName(tr("Y"));
2666     d_ptr->m_intPropertyManager->setValue(yProp, 0);
2667     d_ptr->m_propertyToY[property] = yProp;
2668     d_ptr->m_yToProperty[yProp] = property;
2669     property->addSubProperty(yProp);
2670 }
2671 
2672 /*!
2673     \reimp
2674 */
2675 void QtPointPropertyManager::uninitializeProperty(QtProperty *property)
2676 {
2677     QtProperty *xProp = d_ptr->m_propertyToX[property];
2678     if (xProp) {
2679         d_ptr->m_xToProperty.remove(xProp);
2680         delete xProp;
2681     }
2682     d_ptr->m_propertyToX.remove(property);
2683 
2684     QtProperty *yProp = d_ptr->m_propertyToY[property];
2685     if (yProp) {
2686         d_ptr->m_yToProperty.remove(yProp);
2687         delete yProp;
2688     }
2689     d_ptr->m_propertyToY.remove(property);
2690 
2691     d_ptr->m_values.remove(property);
2692 }
2693 
2694 // QtPointFPropertyManager
2695 
2696 class QtPointFPropertyManagerPrivate
2697 {
2698     QtPointFPropertyManager *q_ptr;
2699     Q_DECLARE_PUBLIC(QtPointFPropertyManager)
2700 public:
2701 
2702     struct Data
2703     {
2704         QPointF val;
2705         int decimals{2};
2706     };
2707 
2708     void slotDoubleChanged(QtProperty *property, double value);
2709     void slotPropertyDestroyed(QtProperty *property);
2710 
2711     typedef QMap<const QtProperty *, Data> PropertyValueMap;
2712     PropertyValueMap m_values;
2713 
2714     QtDoublePropertyManager *m_doublePropertyManager;
2715 
2716     QMap<const QtProperty *, QtProperty *> m_propertyToX;
2717     QMap<const QtProperty *, QtProperty *> m_propertyToY;
2718 
2719     QMap<const QtProperty *, QtProperty *> m_xToProperty;
2720     QMap<const QtProperty *, QtProperty *> m_yToProperty;
2721 };
2722 
2723 void QtPointFPropertyManagerPrivate::slotDoubleChanged(QtProperty *property, double value)
2724 {
2725     if (QtProperty *prop = m_xToProperty.value(property, 0)) {
2726         QPointF p = m_values[prop].val;
2727         p.setX(value);
2728         q_ptr->setValue(prop, p);
2729     } else if (QtProperty *prop = m_yToProperty.value(property, 0)) {
2730         QPointF p = m_values[prop].val;
2731         p.setY(value);
2732         q_ptr->setValue(prop, p);
2733     }
2734 }
2735 
2736 void QtPointFPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
2737 {
2738     if (QtProperty *pointProp  = m_xToProperty.value(property, 0)) {
2739         m_propertyToX[pointProp] = 0;
2740         m_xToProperty.remove(property);
2741     } else if (QtProperty *pointProp = m_yToProperty.value(property, 0)) {
2742         m_propertyToY[pointProp] = 0;
2743         m_yToProperty.remove(property);
2744     }
2745 }
2746 
2747 /*! \class QtPointFPropertyManager
2748     \internal
2749     \inmodule QtDesigner
2750     \since 4.4
2751 
2752     \brief The QtPointFPropertyManager provides and manages QPointF properties.
2753 
2754     A point property has nested \e x and \e y subproperties. The
2755     top-level property's value can be retrieved using the value()
2756     function, and set using the setValue() slot.
2757 
2758     The subproperties are created by a QtDoublePropertyManager object. This
2759     manager can be retrieved using the subDoublePropertyManager() function. In
2760     order to provide editing widgets for the subproperties in a
2761     property browser widget, this manager must be associated with an
2762     editor factory.
2763 
2764     In addition, QtPointFPropertyManager provides the valueChanged() signal which
2765     is emitted whenever a property created by this manager changes.
2766 
2767     \sa QtAbstractPropertyManager, QtDoublePropertyManager, QtPointPropertyManager
2768 */
2769 
2770 /*!
2771     \fn void QtPointFPropertyManager::valueChanged(QtProperty *property, const QPointF &value)
2772 
2773     This signal is emitted whenever a property created by this manager
2774     changes its value, passing a pointer to the \a property and the
2775     new \a value as parameters.
2776 
2777     \sa setValue()
2778 */
2779 
2780 /*!
2781     \fn void QtPointFPropertyManager::decimalsChanged(QtProperty *property, int prec)
2782 
2783     This signal is emitted whenever a property created by this manager
2784     changes its precision of value, passing a pointer to the
2785     \a property and the new \a prec value
2786 
2787     \sa setDecimals()
2788 */
2789 
2790 /*!
2791     Creates a manager with the given \a parent.
2792 */
2793 QtPointFPropertyManager::QtPointFPropertyManager(QObject *parent)
2794     : QtAbstractPropertyManager(parent), d_ptr(new QtPointFPropertyManagerPrivate)
2795 {
2796     d_ptr->q_ptr = this;
2797 
2798     d_ptr->m_doublePropertyManager = new QtDoublePropertyManager(this);
2799     connect(d_ptr->m_doublePropertyManager, SIGNAL(valueChanged(QtProperty*,double)),
2800                 this, SLOT(slotDoubleChanged(QtProperty*,double)));
2801     connect(d_ptr->m_doublePropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
2802                 this, SLOT(slotPropertyDestroyed(QtProperty*)));
2803 }
2804 
2805 /*!
2806     Destroys this manager, and all the properties it has created.
2807 */
2808 QtPointFPropertyManager::~QtPointFPropertyManager()
2809 {
2810     clear();
2811 }
2812 
2813 /*!
2814     Returns the manager that creates the nested \e x and \e y
2815     subproperties.
2816 
2817     In order to provide editing widgets for the subproperties in a
2818     property browser widget, this manager must be associated with an
2819     editor factory.
2820 
2821     \sa QtAbstractPropertyBrowser::setFactoryForManager()
2822 */
2823 QtDoublePropertyManager *QtPointFPropertyManager::subDoublePropertyManager() const
2824 {
2825     return d_ptr->m_doublePropertyManager;
2826 }
2827 
2828 /*!
2829     Returns the given \a property's value.
2830 
2831     If the given \a property is not managed by this manager, this
2832     function returns a point with coordinates (0, 0).
2833 
2834     \sa setValue()
2835 */
2836 QPointF QtPointFPropertyManager::value(const QtProperty *property) const
2837 {
2838     return getValue<QPointF>(d_ptr->m_values, property);
2839 }
2840 
2841 /*!
2842     Returns the given \a property's precision, in decimals.
2843 
2844     \sa setDecimals()
2845 */
2846 int QtPointFPropertyManager::decimals(const QtProperty *property) const
2847 {
2848     return getData<int>(d_ptr->m_values, &QtPointFPropertyManagerPrivate::Data::decimals, property, 0);
2849 }
2850 
2851 /*!
2852     \reimp
2853 */
2854 QString QtPointFPropertyManager::valueText(const QtProperty *property) const
2855 {
2856     const QtPointFPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
2857     if (it == d_ptr->m_values.constEnd())
2858         return QString();
2859     const QPointF v = it.value().val;
2860     const int dec =  it.value().decimals;
2861     return tr("(%1, %2)").arg(QString::number(v.x(), 'f', dec))
2862                          .arg(QString::number(v.y(), 'f', dec));
2863 }
2864 
2865 /*!
2866     \fn void QtPointFPropertyManager::setValue(QtProperty *property, const QPointF &value)
2867 
2868     Sets the value of the given \a property to \a value. Nested
2869     properties are updated automatically.
2870 
2871     \sa value(), valueChanged()
2872 */
2873 void QtPointFPropertyManager::setValue(QtProperty *property, const QPointF &val)
2874 {
2875     const QtPointFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
2876     if (it == d_ptr->m_values.end())
2877         return;
2878 
2879     if (it.value().val == val)
2880         return;
2881 
2882     it.value().val = val;
2883     d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToX[property], val.x());
2884     d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToY[property], val.y());
2885 
2886     Q_EMIT propertyChanged(property);
2887     Q_EMIT valueChanged(property, val);
2888 }
2889 
2890 /*!
2891     \fn void QtPointFPropertyManager::setDecimals(QtProperty *property, int prec)
2892 
2893     Sets the precision of the given \a property to \a prec.
2894 
2895     The valid decimal range is 0-13. The default is 2.
2896 
2897     \sa decimals()
2898 */
2899 void QtPointFPropertyManager::setDecimals(QtProperty *property, int prec)
2900 {
2901     const QtPointFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
2902     if (it == d_ptr->m_values.end())
2903         return;
2904 
2905     QtPointFPropertyManagerPrivate::Data data = it.value();
2906 
2907     if (prec > 13)
2908         prec = 13;
2909     else if (prec < 0)
2910         prec = 0;
2911 
2912     if (data.decimals == prec)
2913         return;
2914 
2915     data.decimals = prec;
2916     d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToX[property], prec);
2917     d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToY[property], prec);
2918 
2919     it.value() = data;
2920 
2921     Q_EMIT decimalsChanged(property, data.decimals);
2922 }
2923 
2924 /*!
2925     \reimp
2926 */
2927 void QtPointFPropertyManager::initializeProperty(QtProperty *property)
2928 {
2929     d_ptr->m_values[property] = QtPointFPropertyManagerPrivate::Data();
2930 
2931     QtProperty *xProp = d_ptr->m_doublePropertyManager->addProperty();
2932     xProp->setPropertyName(tr("X"));
2933     d_ptr->m_doublePropertyManager->setDecimals(xProp, decimals(property));
2934     d_ptr->m_doublePropertyManager->setValue(xProp, 0);
2935     d_ptr->m_propertyToX[property] = xProp;
2936     d_ptr->m_xToProperty[xProp] = property;
2937     property->addSubProperty(xProp);
2938 
2939     QtProperty *yProp = d_ptr->m_doublePropertyManager->addProperty();
2940     yProp->setPropertyName(tr("Y"));
2941     d_ptr->m_doublePropertyManager->setDecimals(yProp, decimals(property));
2942     d_ptr->m_doublePropertyManager->setValue(yProp, 0);
2943     d_ptr->m_propertyToY[property] = yProp;
2944     d_ptr->m_yToProperty[yProp] = property;
2945     property->addSubProperty(yProp);
2946 }
2947 
2948 /*!
2949     \reimp
2950 */
2951 void QtPointFPropertyManager::uninitializeProperty(QtProperty *property)
2952 {
2953     QtProperty *xProp = d_ptr->m_propertyToX[property];
2954     if (xProp) {
2955         d_ptr->m_xToProperty.remove(xProp);
2956         delete xProp;
2957     }
2958     d_ptr->m_propertyToX.remove(property);
2959 
2960     QtProperty *yProp = d_ptr->m_propertyToY[property];
2961     if (yProp) {
2962         d_ptr->m_yToProperty.remove(yProp);
2963         delete yProp;
2964     }
2965     d_ptr->m_propertyToY.remove(property);
2966 
2967     d_ptr->m_values.remove(property);
2968 }
2969 
2970 // QtSizePropertyManager
2971 
2972 class QtSizePropertyManagerPrivate
2973 {
2974     QtSizePropertyManager *q_ptr;
2975     Q_DECLARE_PUBLIC(QtSizePropertyManager)
2976 public:
2977 
2978     void slotIntChanged(QtProperty *property, int value);
2979     void slotPropertyDestroyed(QtProperty *property);
2980     void setValue(QtProperty *property, const QSize &val);
2981     void setRange(QtProperty *property,
2982                 const QSize &minVal, const QSize &maxVal, const QSize &val);
2983 
2984     struct Data
2985     {
2986         QSize val{0, 0};
2987         QSize minVal{0, 0};
2988         QSize maxVal{INT_MAX, INT_MAX};
2989         QSize minimumValue() const { return minVal; }
2990         QSize maximumValue() const { return maxVal; }
2991         void setMinimumValue(const QSize &newMinVal) { setSizeMinimumData(this, newMinVal); }
2992         void setMaximumValue(const QSize &newMaxVal) { setSizeMaximumData(this, newMaxVal); }
2993     };
2994 
2995     typedef QMap<const QtProperty *, Data> PropertyValueMap;
2996     PropertyValueMap m_values;
2997 
2998     QtIntPropertyManager *m_intPropertyManager;
2999 
3000     QMap<const QtProperty *, QtProperty *> m_propertyToW;
3001     QMap<const QtProperty *, QtProperty *> m_propertyToH;
3002 
3003     QMap<const QtProperty *, QtProperty *> m_wToProperty;
3004     QMap<const QtProperty *, QtProperty *> m_hToProperty;
3005 };
3006 
3007 void QtSizePropertyManagerPrivate::slotIntChanged(QtProperty *property, int value)
3008 {
3009     if (QtProperty *prop = m_wToProperty.value(property, 0)) {
3010         QSize s = m_values[prop].val;
3011         s.setWidth(value);
3012         q_ptr->setValue(prop, s);
3013     } else if (QtProperty *prop = m_hToProperty.value(property, 0)) {
3014         QSize s = m_values[prop].val;
3015         s.setHeight(value);
3016         q_ptr->setValue(prop, s);
3017     }
3018 }
3019 
3020 void QtSizePropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
3021 {
3022     if (QtProperty *pointProp = m_wToProperty.value(property, 0)) {
3023         m_propertyToW[pointProp] = 0;
3024         m_wToProperty.remove(property);
3025     } else if (QtProperty *pointProp = m_hToProperty.value(property, 0)) {
3026         m_propertyToH[pointProp] = 0;
3027         m_hToProperty.remove(property);
3028     }
3029 }
3030 
3031 void QtSizePropertyManagerPrivate::setValue(QtProperty *property, const QSize &val)
3032 {
3033     m_intPropertyManager->setValue(m_propertyToW.value(property), val.width());
3034     m_intPropertyManager->setValue(m_propertyToH.value(property), val.height());
3035 }
3036 
3037 void QtSizePropertyManagerPrivate::setRange(QtProperty *property,
3038                 const QSize &minVal, const QSize &maxVal, const QSize &val)
3039 {
3040     QtProperty *wProperty = m_propertyToW.value(property);
3041     QtProperty *hProperty = m_propertyToH.value(property);
3042     m_intPropertyManager->setRange(wProperty, minVal.width(), maxVal.width());
3043     m_intPropertyManager->setValue(wProperty, val.width());
3044     m_intPropertyManager->setRange(hProperty, minVal.height(), maxVal.height());
3045     m_intPropertyManager->setValue(hProperty, val.height());
3046 }
3047 
3048 /*!
3049     \class QtSizePropertyManager
3050     \internal
3051     \inmodule QtDesigner
3052     \since 4.4
3053 
3054     \brief The QtSizePropertyManager provides and manages QSize properties.
3055 
3056     A size property has nested \e width and \e height
3057     subproperties. The top-level property's value can be retrieved
3058     using the value() function, and set using the setValue() slot.
3059 
3060     The subproperties are created by a QtIntPropertyManager object. This
3061     manager can be retrieved using the subIntPropertyManager() function. In
3062     order to provide editing widgets for the subproperties in a
3063     property browser widget, this manager must be associated with an
3064     editor factory.
3065 
3066     A size property also has a range of valid values defined by a
3067     minimum size and a maximum size. These sizes can be retrieved
3068     using the minimum() and the maximum() functions, and set using the
3069     setMinimum() and setMaximum() slots. Alternatively, the range can
3070     be defined in one go using the setRange() slot.
3071 
3072     In addition, QtSizePropertyManager provides the valueChanged() signal
3073     which is emitted whenever a property created by this manager
3074     changes, and the rangeChanged() signal which is emitted whenever
3075     such a property changes its range of valid sizes.
3076 
3077     \sa QtAbstractPropertyManager, QtIntPropertyManager, QtSizeFPropertyManager
3078 */
3079 
3080 /*!
3081     \fn void QtSizePropertyManager::valueChanged(QtProperty *property, const QSize &value)
3082 
3083     This signal is emitted whenever a property created by this manager
3084     changes its value, passing a pointer to the \a property and the new
3085     \a value as parameters.
3086 
3087     \sa setValue()
3088 */
3089 
3090 /*!
3091     \fn void QtSizePropertyManager::rangeChanged(QtProperty *property, const QSize &minimum, const QSize &maximum)
3092 
3093     This signal is emitted whenever a property created by this manager
3094     changes its range of valid sizes, passing a pointer to the \a
3095     property and the new \a minimum and \a maximum sizes.
3096 
3097     \sa setRange()
3098 */
3099 
3100 /*!
3101     Creates a manager with the given \a parent.
3102 */
3103 QtSizePropertyManager::QtSizePropertyManager(QObject *parent)
3104     : QtAbstractPropertyManager(parent), d_ptr(new QtSizePropertyManagerPrivate)
3105 {
3106     d_ptr->q_ptr = this;
3107 
3108     d_ptr->m_intPropertyManager = new QtIntPropertyManager(this);
3109     connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty*,int)),
3110                 this, SLOT(slotIntChanged(QtProperty*,int)));
3111     connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
3112                 this, SLOT(slotPropertyDestroyed(QtProperty*)));
3113 }
3114 
3115 /*!
3116     Destroys this manager, and all the properties it has created.
3117 */
3118 QtSizePropertyManager::~QtSizePropertyManager()
3119 {
3120     clear();
3121 }
3122 
3123 /*!
3124     Returns the manager that creates the nested \e width and \e height
3125     subproperties.
3126 
3127     In order to provide editing widgets for the \e width and \e height
3128     properties in a property browser widget, this manager must be
3129     associated with an editor factory.
3130 
3131     \sa QtAbstractPropertyBrowser::setFactoryForManager()
3132 */
3133 QtIntPropertyManager *QtSizePropertyManager::subIntPropertyManager() const
3134 {
3135     return d_ptr->m_intPropertyManager;
3136 }
3137 
3138 /*!
3139     Returns the given \a property's value.
3140 
3141     If the given \a property is not managed by this manager, this
3142     function returns an invalid size
3143 
3144     \sa setValue()
3145 */
3146 QSize QtSizePropertyManager::value(const QtProperty *property) const
3147 {
3148     return getValue<QSize>(d_ptr->m_values, property);
3149 }
3150 
3151 /*!
3152     Returns the given \a property's minimum size value.
3153 
3154     \sa setMinimum(), maximum(), setRange()
3155 */
3156 QSize QtSizePropertyManager::minimum(const QtProperty *property) const
3157 {
3158     return getMinimum<QSize>(d_ptr->m_values, property);
3159 }
3160 
3161 /*!
3162     Returns the given \a property's maximum size value.
3163 
3164     \sa setMaximum(), minimum(), setRange()
3165 */
3166 QSize QtSizePropertyManager::maximum(const QtProperty *property) const
3167 {
3168     return getMaximum<QSize>(d_ptr->m_values, property);
3169 }
3170 
3171 /*!
3172     \reimp
3173 */
3174 QString QtSizePropertyManager::valueText(const QtProperty *property) const
3175 {
3176     const QtSizePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
3177     if (it == d_ptr->m_values.constEnd())
3178         return QString();
3179     const QSize v = it.value().val;
3180     return tr("%1 x %2").arg(QString::number(v.width()))
3181                         .arg(QString::number(v.height()));
3182 }
3183 
3184 /*!
3185     \fn void QtSizePropertyManager::setValue(QtProperty *property, const QSize &value)
3186 
3187     Sets the value of the given \a property to \a value.
3188 
3189     If the specified \a value is not valid according to the given \a
3190     property's size range, the \a value is adjusted to the nearest
3191     valid value within the size range.
3192 
3193     \sa value(), setRange(), valueChanged()
3194 */
3195 void QtSizePropertyManager::setValue(QtProperty *property, const QSize &val)
3196 {
3197     setValueInRange<const QSize &, QtSizePropertyManagerPrivate, QtSizePropertyManager, const QSize>(this, d_ptr.data(),
3198                 &QtSizePropertyManager::propertyChanged,
3199                 &QtSizePropertyManager::valueChanged,
3200                 property, val, &QtSizePropertyManagerPrivate::setValue);
3201 }
3202 
3203 /*!
3204     Sets the minimum size value for the given \a property to \a minVal.
3205 
3206     When setting the minimum size value, the maximum and current
3207     values are adjusted if necessary (ensuring that the size range
3208     remains valid and that the current value is within the range).
3209 
3210     \sa minimum(), setRange(), rangeChanged()
3211 */
3212 void QtSizePropertyManager::setMinimum(QtProperty *property, const QSize &minVal)
3213 {
3214     setBorderValue<const QSize &, QtSizePropertyManagerPrivate, QtSizePropertyManager, QSize, QtSizePropertyManagerPrivate::Data>(this, d_ptr.data(),
3215                 &QtSizePropertyManager::propertyChanged,
3216                 &QtSizePropertyManager::valueChanged,
3217                 &QtSizePropertyManager::rangeChanged,
3218                 property,
3219                 &QtSizePropertyManagerPrivate::Data::minimumValue,
3220                 &QtSizePropertyManagerPrivate::Data::setMinimumValue,
3221                 minVal, &QtSizePropertyManagerPrivate::setRange);
3222 }
3223 
3224 /*!
3225     Sets the maximum size value for the given \a property to \a maxVal.
3226 
3227     When setting the maximum size value, the minimum and current
3228     values are adjusted if necessary (ensuring that the size range
3229     remains valid and that the current value is within the range).
3230 
3231     \sa maximum(), setRange(), rangeChanged()
3232 */
3233 void QtSizePropertyManager::setMaximum(QtProperty *property, const QSize &maxVal)
3234 {
3235     setBorderValue<const QSize &, QtSizePropertyManagerPrivate, QtSizePropertyManager, QSize, QtSizePropertyManagerPrivate::Data>(this, d_ptr.data(),
3236                 &QtSizePropertyManager::propertyChanged,
3237                 &QtSizePropertyManager::valueChanged,
3238                 &QtSizePropertyManager::rangeChanged,
3239                 property,
3240                 &QtSizePropertyManagerPrivate::Data::maximumValue,
3241                 &QtSizePropertyManagerPrivate::Data::setMaximumValue,
3242                 maxVal, &QtSizePropertyManagerPrivate::setRange);
3243 }
3244 
3245 /*!
3246     \fn void QtSizePropertyManager::setRange(QtProperty *property, const QSize &minimum, const QSize &maximum)
3247 
3248     Sets the range of valid values.
3249 
3250     This is a convenience function defining the range of valid values
3251     in one go; setting the \a minimum and \a maximum values for the
3252     given \a property with a single function call.
3253 
3254     When setting a new range, the current value is adjusted if
3255     necessary (ensuring that the value remains within the range).
3256 
3257     \sa setMinimum(), setMaximum(), rangeChanged()
3258 */
3259 void QtSizePropertyManager::setRange(QtProperty *property, const QSize &minVal, const QSize &maxVal)
3260 {
3261     setBorderValues<const QSize &, QtSizePropertyManagerPrivate, QtSizePropertyManager, QSize>(this, d_ptr.data(),
3262                 &QtSizePropertyManager::propertyChanged,
3263                 &QtSizePropertyManager::valueChanged,
3264                 &QtSizePropertyManager::rangeChanged,
3265                 property, minVal, maxVal, &QtSizePropertyManagerPrivate::setRange);
3266 }
3267 
3268 /*!
3269     \reimp
3270 */
3271 void QtSizePropertyManager::initializeProperty(QtProperty *property)
3272 {
3273     d_ptr->m_values[property] = QtSizePropertyManagerPrivate::Data();
3274 
3275     QtProperty *wProp = d_ptr->m_intPropertyManager->addProperty();
3276     wProp->setPropertyName(tr("Width"));
3277     d_ptr->m_intPropertyManager->setValue(wProp, 0);
3278     d_ptr->m_intPropertyManager->setMinimum(wProp, 0);
3279     d_ptr->m_propertyToW[property] = wProp;
3280     d_ptr->m_wToProperty[wProp] = property;
3281     property->addSubProperty(wProp);
3282 
3283     QtProperty *hProp = d_ptr->m_intPropertyManager->addProperty();
3284     hProp->setPropertyName(tr("Height"));
3285     d_ptr->m_intPropertyManager->setValue(hProp, 0);
3286     d_ptr->m_intPropertyManager->setMinimum(hProp, 0);
3287     d_ptr->m_propertyToH[property] = hProp;
3288     d_ptr->m_hToProperty[hProp] = property;
3289     property->addSubProperty(hProp);
3290 }
3291 
3292 /*!
3293     \reimp
3294 */
3295 void QtSizePropertyManager::uninitializeProperty(QtProperty *property)
3296 {
3297     QtProperty *wProp = d_ptr->m_propertyToW[property];
3298     if (wProp) {
3299         d_ptr->m_wToProperty.remove(wProp);
3300         delete wProp;
3301     }
3302     d_ptr->m_propertyToW.remove(property);
3303 
3304     QtProperty *hProp = d_ptr->m_propertyToH[property];
3305     if (hProp) {
3306         d_ptr->m_hToProperty.remove(hProp);
3307         delete hProp;
3308     }
3309     d_ptr->m_propertyToH.remove(property);
3310 
3311     d_ptr->m_values.remove(property);
3312 }
3313 
3314 // QtSizeFPropertyManager
3315 
3316 class QtSizeFPropertyManagerPrivate
3317 {
3318     QtSizeFPropertyManager *q_ptr;
3319     Q_DECLARE_PUBLIC(QtSizeFPropertyManager)
3320 public:
3321 
3322     void slotDoubleChanged(QtProperty *property, double value);
3323     void slotPropertyDestroyed(QtProperty *property);
3324     void setValue(QtProperty *property, const QSizeF &val);
3325     void setRange(QtProperty *property,
3326                 const QSizeF &minVal, const QSizeF &maxVal, const QSizeF &val);
3327 
3328     struct Data
3329     {
3330         QSizeF val{0, 0};
3331         QSizeF minVal{0, 0};
3332         QSizeF maxVal{std::numeric_limits<qreal>::max(), std::numeric_limits<qreal>::max()};
3333         int decimals{2};
3334         QSizeF minimumValue() const { return minVal; }
3335         QSizeF maximumValue() const { return maxVal; }
3336         void setMinimumValue(const QSizeF &newMinVal) { setSizeMinimumData(this, newMinVal); }
3337         void setMaximumValue(const QSizeF &newMaxVal) { setSizeMaximumData(this, newMaxVal); }
3338     };
3339 
3340     typedef QMap<const QtProperty *, Data> PropertyValueMap;
3341     PropertyValueMap m_values;
3342 
3343     QtDoublePropertyManager *m_doublePropertyManager;
3344 
3345     QMap<const QtProperty *, QtProperty *> m_propertyToW;
3346     QMap<const QtProperty *, QtProperty *> m_propertyToH;
3347 
3348     QMap<const QtProperty *, QtProperty *> m_wToProperty;
3349     QMap<const QtProperty *, QtProperty *> m_hToProperty;
3350 };
3351 
3352 void QtSizeFPropertyManagerPrivate::slotDoubleChanged(QtProperty *property, double value)
3353 {
3354     if (QtProperty *prop = m_wToProperty.value(property, 0)) {
3355         QSizeF s = m_values[prop].val;
3356         s.setWidth(value);
3357         q_ptr->setValue(prop, s);
3358     } else if (QtProperty *prop = m_hToProperty.value(property, 0)) {
3359         QSizeF s = m_values[prop].val;
3360         s.setHeight(value);
3361         q_ptr->setValue(prop, s);
3362     }
3363 }
3364 
3365 void QtSizeFPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
3366 {
3367     if (QtProperty *pointProp = m_wToProperty.value(property, 0)) {
3368         m_propertyToW[pointProp] = 0;
3369         m_wToProperty.remove(property);
3370     } else if (QtProperty *pointProp = m_hToProperty.value(property, 0)) {
3371         m_propertyToH[pointProp] = 0;
3372         m_hToProperty.remove(property);
3373     }
3374 }
3375 
3376 void QtSizeFPropertyManagerPrivate::setValue(QtProperty *property, const QSizeF &val)
3377 {
3378     m_doublePropertyManager->setValue(m_propertyToW.value(property), val.width());
3379     m_doublePropertyManager->setValue(m_propertyToH.value(property), val.height());
3380 }
3381 
3382 void QtSizeFPropertyManagerPrivate::setRange(QtProperty *property,
3383                 const QSizeF &minVal, const QSizeF &maxVal, const QSizeF &val)
3384 {
3385     m_doublePropertyManager->setRange(m_propertyToW[property], minVal.width(), maxVal.width());
3386     m_doublePropertyManager->setValue(m_propertyToW[property], val.width());
3387     m_doublePropertyManager->setRange(m_propertyToH[property], minVal.height(), maxVal.height());
3388     m_doublePropertyManager->setValue(m_propertyToH[property], val.height());
3389 }
3390 
3391 /*!
3392     \class QtSizeFPropertyManager
3393     \internal
3394     \inmodule QtDesigner
3395     \since 4.4
3396 
3397     \brief The QtSizeFPropertyManager provides and manages QSizeF properties.
3398 
3399     A size property has nested \e width and \e height
3400     subproperties. The top-level property's value can be retrieved
3401     using the value() function, and set using the setValue() slot.
3402 
3403     The subproperties are created by a QtDoublePropertyManager object. This
3404     manager can be retrieved using the subDoublePropertyManager() function. In
3405     order to provide editing widgets for the subproperties in a
3406     property browser widget, this manager must be associated with an
3407     editor factory.
3408 
3409     A size property also has a range of valid values defined by a
3410     minimum size and a maximum size. These sizes can be retrieved
3411     using the minimum() and the maximum() functions, and set using the
3412     setMinimum() and setMaximum() slots. Alternatively, the range can
3413     be defined in one go using the setRange() slot.
3414 
3415     In addition, QtSizeFPropertyManager provides the valueChanged() signal
3416     which is emitted whenever a property created by this manager
3417     changes, and the rangeChanged() signal which is emitted whenever
3418     such a property changes its range of valid sizes.
3419 
3420     \sa QtAbstractPropertyManager, QtDoublePropertyManager, QtSizePropertyManager
3421 */
3422 
3423 /*!
3424     \fn void QtSizeFPropertyManager::valueChanged(QtProperty *property, const QSizeF &value)
3425 
3426     This signal is emitted whenever a property created by this manager
3427     changes its value, passing a pointer to the \a property and the new
3428     \a value as parameters.
3429 
3430     \sa setValue()
3431 */
3432 
3433 /*!
3434     \fn void QtSizeFPropertyManager::rangeChanged(QtProperty *property, const QSizeF &minimum, const QSizeF &maximum)
3435 
3436     This signal is emitted whenever a property created by this manager
3437     changes its range of valid sizes, passing a pointer to the \a
3438     property and the new \a minimum and \a maximum sizes.
3439 
3440     \sa setRange()
3441 */
3442 
3443 /*!
3444     \fn void QtSizeFPropertyManager::decimalsChanged(QtProperty *property, int prec)
3445 
3446     This signal is emitted whenever a property created by this manager
3447     changes its precision of value, passing a pointer to the
3448     \a property and the new \a prec value
3449 
3450     \sa setDecimals()
3451 */
3452 
3453 /*!
3454     Creates a manager with the given \a parent.
3455 */
3456 QtSizeFPropertyManager::QtSizeFPropertyManager(QObject *parent)
3457     : QtAbstractPropertyManager(parent), d_ptr(new QtSizeFPropertyManagerPrivate)
3458 {
3459     d_ptr->q_ptr = this;
3460 
3461     d_ptr->m_doublePropertyManager = new QtDoublePropertyManager(this);
3462     connect(d_ptr->m_doublePropertyManager, SIGNAL(valueChanged(QtProperty*,double)),
3463                 this, SLOT(slotDoubleChanged(QtProperty*,double)));
3464     connect(d_ptr->m_doublePropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
3465                 this, SLOT(slotPropertyDestroyed(QtProperty*)));
3466 }
3467 
3468 /*!
3469     Destroys this manager, and all the properties it has created.
3470 */
3471 QtSizeFPropertyManager::~QtSizeFPropertyManager()
3472 {
3473     clear();
3474 }
3475 
3476 /*!
3477     Returns the manager that creates the nested \e width and \e height
3478     subproperties.
3479 
3480     In order to provide editing widgets for the \e width and \e height
3481     properties in a property browser widget, this manager must be
3482     associated with an editor factory.
3483 
3484     \sa QtAbstractPropertyBrowser::setFactoryForManager()
3485 */
3486 QtDoublePropertyManager *QtSizeFPropertyManager::subDoublePropertyManager() const
3487 {
3488     return d_ptr->m_doublePropertyManager;
3489 }
3490 
3491 /*!
3492     Returns the given \a property's value.
3493 
3494     If the given \a property is not managed by this manager, this
3495     function returns an invalid size
3496 
3497     \sa setValue()
3498 */
3499 QSizeF QtSizeFPropertyManager::value(const QtProperty *property) const
3500 {
3501     return getValue<QSizeF>(d_ptr->m_values, property);
3502 }
3503 
3504 /*!
3505     Returns the given \a property's precision, in decimals.
3506 
3507     \sa setDecimals()
3508 */
3509 int QtSizeFPropertyManager::decimals(const QtProperty *property) const
3510 {
3511     return getData<int>(d_ptr->m_values, &QtSizeFPropertyManagerPrivate::Data::decimals, property, 0);
3512 }
3513 
3514 /*!
3515     Returns the given \a property's minimum size value.
3516 
3517     \sa setMinimum(), maximum(), setRange()
3518 */
3519 QSizeF QtSizeFPropertyManager::minimum(const QtProperty *property) const
3520 {
3521     return getMinimum<QSizeF>(d_ptr->m_values, property);
3522 }
3523 
3524 /*!
3525     Returns the given \a property's maximum size value.
3526 
3527     \sa setMaximum(), minimum(), setRange()
3528 */
3529 QSizeF QtSizeFPropertyManager::maximum(const QtProperty *property) const
3530 {
3531     return getMaximum<QSizeF>(d_ptr->m_values, property);
3532 }
3533 
3534 /*!
3535     \reimp
3536 */
3537 QString QtSizeFPropertyManager::valueText(const QtProperty *property) const
3538 {
3539     const QtSizeFPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
3540     if (it == d_ptr->m_values.constEnd())
3541         return QString();
3542     const QSizeF v = it.value().val;
3543     const int dec = it.value().decimals;
3544     return tr("%1 x %2").arg(QString::number(v.width(), 'f', dec))
3545                         .arg(QString::number(v.height(), 'f', dec));
3546 }
3547 
3548 /*!
3549     \fn void QtSizeFPropertyManager::setValue(QtProperty *property, const QSizeF &value)
3550 
3551     Sets the value of the given \a property to \a value.
3552 
3553     If the specified \a value is not valid according to the given \a
3554     property's size range, the \a value is adjusted to the nearest
3555     valid value within the size range.
3556 
3557     \sa value(), setRange(), valueChanged()
3558 */
3559 void QtSizeFPropertyManager::setValue(QtProperty *property, const QSizeF &val)
3560 {
3561     setValueInRange<const QSizeF &, QtSizeFPropertyManagerPrivate, QtSizeFPropertyManager, QSizeF>(this, d_ptr.data(),
3562                 &QtSizeFPropertyManager::propertyChanged,
3563                 &QtSizeFPropertyManager::valueChanged,
3564                 property, val, &QtSizeFPropertyManagerPrivate::setValue);
3565 }
3566 
3567 /*!
3568     \fn void QtSizeFPropertyManager::setDecimals(QtProperty *property, int prec)
3569 
3570     Sets the precision of the given \a property to \a prec.
3571 
3572     The valid decimal range is 0-13. The default is 2.
3573 
3574     \sa decimals()
3575 */
3576 void QtSizeFPropertyManager::setDecimals(QtProperty *property, int prec)
3577 {
3578     const QtSizeFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
3579     if (it == d_ptr->m_values.end())
3580         return;
3581 
3582     QtSizeFPropertyManagerPrivate::Data data = it.value();
3583 
3584     if (prec > 13)
3585         prec = 13;
3586     else if (prec < 0)
3587         prec = 0;
3588 
3589     if (data.decimals == prec)
3590         return;
3591 
3592     data.decimals = prec;
3593     d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToW[property], prec);
3594     d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToH[property], prec);
3595 
3596     it.value() = data;
3597 
3598     Q_EMIT decimalsChanged(property, data.decimals);
3599 }
3600 
3601 /*!
3602     Sets the minimum size value for the given \a property to \a minVal.
3603 
3604     When setting the minimum size value, the maximum and current
3605     values are adjusted if necessary (ensuring that the size range
3606     remains valid and that the current value is within the range).
3607 
3608     \sa minimum(), setRange(), rangeChanged()
3609 */
3610 void QtSizeFPropertyManager::setMinimum(QtProperty *property, const QSizeF &minVal)
3611 {
3612     setBorderValue<const QSizeF &, QtSizeFPropertyManagerPrivate, QtSizeFPropertyManager, QSizeF, QtSizeFPropertyManagerPrivate::Data>(this, d_ptr.data(),
3613                 &QtSizeFPropertyManager::propertyChanged,
3614                 &QtSizeFPropertyManager::valueChanged,
3615                 &QtSizeFPropertyManager::rangeChanged,
3616                 property,
3617                 &QtSizeFPropertyManagerPrivate::Data::minimumValue,
3618                 &QtSizeFPropertyManagerPrivate::Data::setMinimumValue,
3619                 minVal, &QtSizeFPropertyManagerPrivate::setRange);
3620 }
3621 
3622 /*!
3623     Sets the maximum size value for the given \a property to \a maxVal.
3624 
3625     When setting the maximum size value, the minimum and current
3626     values are adjusted if necessary (ensuring that the size range
3627     remains valid and that the current value is within the range).
3628 
3629     \sa maximum(), setRange(), rangeChanged()
3630 */
3631 void QtSizeFPropertyManager::setMaximum(QtProperty *property, const QSizeF &maxVal)
3632 {
3633     setBorderValue<const QSizeF &, QtSizeFPropertyManagerPrivate, QtSizeFPropertyManager, QSizeF, QtSizeFPropertyManagerPrivate::Data>(this, d_ptr.data(),
3634                 &QtSizeFPropertyManager::propertyChanged,
3635                 &QtSizeFPropertyManager::valueChanged,
3636                 &QtSizeFPropertyManager::rangeChanged,
3637                 property,
3638                 &QtSizeFPropertyManagerPrivate::Data::maximumValue,
3639                 &QtSizeFPropertyManagerPrivate::Data::setMaximumValue,
3640                 maxVal, &QtSizeFPropertyManagerPrivate::setRange);
3641 }
3642 
3643 /*!
3644     \fn void QtSizeFPropertyManager::setRange(QtProperty *property, const QSizeF &minimum, const QSizeF &maximum)
3645 
3646     Sets the range of valid values.
3647 
3648     This is a convenience function defining the range of valid values
3649     in one go; setting the \a minimum and \a maximum values for the
3650     given \a property with a single function call.
3651 
3652     When setting a new range, the current value is adjusted if
3653     necessary (ensuring that the value remains within the range).
3654 
3655     \sa setMinimum(), setMaximum(), rangeChanged()
3656 */
3657 void QtSizeFPropertyManager::setRange(QtProperty *property, const QSizeF &minVal, const QSizeF &maxVal)
3658 {
3659     setBorderValues<const QSizeF &, QtSizeFPropertyManagerPrivate, QtSizeFPropertyManager, QSizeF>(this, d_ptr.data(),
3660                 &QtSizeFPropertyManager::propertyChanged,
3661                 &QtSizeFPropertyManager::valueChanged,
3662                 &QtSizeFPropertyManager::rangeChanged,
3663                 property, minVal, maxVal, &QtSizeFPropertyManagerPrivate::setRange);
3664 }
3665 
3666 /*!
3667     \reimp
3668 */
3669 void QtSizeFPropertyManager::initializeProperty(QtProperty *property)
3670 {
3671     d_ptr->m_values[property] = QtSizeFPropertyManagerPrivate::Data();
3672 
3673     QtProperty *wProp = d_ptr->m_doublePropertyManager->addProperty();
3674     wProp->setPropertyName(tr("Width"));
3675     d_ptr->m_doublePropertyManager->setDecimals(wProp, decimals(property));
3676     d_ptr->m_doublePropertyManager->setValue(wProp, 0);
3677     d_ptr->m_doublePropertyManager->setMinimum(wProp, 0);
3678     d_ptr->m_propertyToW[property] = wProp;
3679     d_ptr->m_wToProperty[wProp] = property;
3680     property->addSubProperty(wProp);
3681 
3682     QtProperty *hProp = d_ptr->m_doublePropertyManager->addProperty();
3683     hProp->setPropertyName(tr("Height"));
3684     d_ptr->m_doublePropertyManager->setDecimals(hProp, decimals(property));
3685     d_ptr->m_doublePropertyManager->setValue(hProp, 0);
3686     d_ptr->m_doublePropertyManager->setMinimum(hProp, 0);
3687     d_ptr->m_propertyToH[property] = hProp;
3688     d_ptr->m_hToProperty[hProp] = property;
3689     property->addSubProperty(hProp);
3690 }
3691 
3692 /*!
3693     \reimp
3694 */
3695 void QtSizeFPropertyManager::uninitializeProperty(QtProperty *property)
3696 {
3697     QtProperty *wProp = d_ptr->m_propertyToW[property];
3698     if (wProp) {
3699         d_ptr->m_wToProperty.remove(wProp);
3700         delete wProp;
3701     }
3702     d_ptr->m_propertyToW.remove(property);
3703 
3704     QtProperty *hProp = d_ptr->m_propertyToH[property];
3705     if (hProp) {
3706         d_ptr->m_hToProperty.remove(hProp);
3707         delete hProp;
3708     }
3709     d_ptr->m_propertyToH.remove(property);
3710 
3711     d_ptr->m_values.remove(property);
3712 }
3713 
3714 // QtRectPropertyManager
3715 
3716 class QtRectPropertyManagerPrivate
3717 {
3718     QtRectPropertyManager *q_ptr;
3719     Q_DECLARE_PUBLIC(QtRectPropertyManager)
3720 public:
3721 
3722     void slotIntChanged(QtProperty *property, int value);
3723     void slotPropertyDestroyed(QtProperty *property);
3724     void setConstraint(QtProperty *property, const QRect &constraint, const QRect &val);
3725 
3726     struct Data
3727     {
3728         QRect val{0, 0, 0, 0};
3729         QRect constraint;
3730     };
3731 
3732     typedef QMap<const QtProperty *, Data> PropertyValueMap;
3733     PropertyValueMap m_values;
3734 
3735     QtIntPropertyManager *m_intPropertyManager;
3736 
3737     QMap<const QtProperty *, QtProperty *> m_propertyToX;
3738     QMap<const QtProperty *, QtProperty *> m_propertyToY;
3739     QMap<const QtProperty *, QtProperty *> m_propertyToW;
3740     QMap<const QtProperty *, QtProperty *> m_propertyToH;
3741 
3742     QMap<const QtProperty *, QtProperty *> m_xToProperty;
3743     QMap<const QtProperty *, QtProperty *> m_yToProperty;
3744     QMap<const QtProperty *, QtProperty *> m_wToProperty;
3745     QMap<const QtProperty *, QtProperty *> m_hToProperty;
3746 };
3747 
3748 void QtRectPropertyManagerPrivate::slotIntChanged(QtProperty *property, int value)
3749 {
3750     if (QtProperty *prop = m_xToProperty.value(property, 0)) {
3751         QRect r = m_values[prop].val;
3752         r.moveLeft(value);
3753         q_ptr->setValue(prop, r);
3754     } else if (QtProperty *prop = m_yToProperty.value(property)) {
3755         QRect r = m_values[prop].val;
3756         r.moveTop(value);
3757         q_ptr->setValue(prop, r);
3758     } else if (QtProperty *prop = m_wToProperty.value(property, 0)) {
3759         Data data = m_values[prop];
3760         QRect r = data.val;
3761         r.setWidth(value);
3762         if (!data.constraint.isNull() && data.constraint.x() + data.constraint.width() < r.x() + r.width()) {
3763             r.moveLeft(data.constraint.left() + data.constraint.width() - r.width());
3764         }
3765         q_ptr->setValue(prop, r);
3766     } else if (QtProperty *prop = m_hToProperty.value(property, 0)) {
3767         Data data = m_values[prop];
3768         QRect r = data.val;
3769         r.setHeight(value);
3770         if (!data.constraint.isNull() && data.constraint.y() + data.constraint.height() < r.y() + r.height()) {
3771             r.moveTop(data.constraint.top() + data.constraint.height() - r.height());
3772         }
3773         q_ptr->setValue(prop, r);
3774     }
3775 }
3776 
3777 void QtRectPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
3778 {
3779     if (QtProperty *pointProp = m_xToProperty.value(property, 0)) {
3780         m_propertyToX[pointProp] = 0;
3781         m_xToProperty.remove(property);
3782     } else if (QtProperty *pointProp = m_yToProperty.value(property, 0)) {
3783         m_propertyToY[pointProp] = 0;
3784         m_yToProperty.remove(property);
3785     } else if (QtProperty *pointProp = m_wToProperty.value(property, 0)) {
3786         m_propertyToW[pointProp] = 0;
3787         m_wToProperty.remove(property);
3788     } else if (QtProperty *pointProp = m_hToProperty.value(property, 0)) {
3789         m_propertyToH[pointProp] = 0;
3790         m_hToProperty.remove(property);
3791     }
3792 }
3793 
3794 void QtRectPropertyManagerPrivate::setConstraint(QtProperty *property,
3795             const QRect &constraint, const QRect &val)
3796 {
3797     const bool isNull = constraint.isNull();
3798     const int left   = isNull ? INT_MIN : constraint.left();
3799     const int right  = isNull ? INT_MAX : constraint.left() + constraint.width();
3800     const int top    = isNull ? INT_MIN : constraint.top();
3801     const int bottom = isNull ? INT_MAX : constraint.top() + constraint.height();
3802     const int width  = isNull ? INT_MAX : constraint.width();
3803     const int height = isNull ? INT_MAX : constraint.height();
3804 
3805     m_intPropertyManager->setRange(m_propertyToX[property], left, right);
3806     m_intPropertyManager->setRange(m_propertyToY[property], top, bottom);
3807     m_intPropertyManager->setRange(m_propertyToW[property], 0, width);
3808     m_intPropertyManager->setRange(m_propertyToH[property], 0, height);
3809 
3810     m_intPropertyManager->setValue(m_propertyToX[property], val.x());
3811     m_intPropertyManager->setValue(m_propertyToY[property], val.y());
3812     m_intPropertyManager->setValue(m_propertyToW[property], val.width());
3813     m_intPropertyManager->setValue(m_propertyToH[property], val.height());
3814 }
3815 
3816 /*!
3817     \class QtRectPropertyManager
3818     \internal
3819     \inmodule QtDesigner
3820     \since 4.4
3821 
3822     \brief The QtRectPropertyManager provides and manages QRect properties.
3823 
3824     A rectangle property has nested \e x, \e y, \e width and \e height
3825     subproperties. The top-level property's value can be retrieved
3826     using the value() function, and set using the setValue() slot.
3827 
3828     The subproperties are created by a QtIntPropertyManager object. This
3829     manager can be retrieved using the subIntPropertyManager() function. In
3830     order to provide editing widgets for the subproperties in a
3831     property browser widget, this manager must be associated with an
3832     editor factory.
3833 
3834     A rectangle property also has a constraint rectangle which can be
3835     retrieved using the constraint() function, and set using the
3836     setConstraint() slot.
3837 
3838     In addition, QtRectPropertyManager provides the valueChanged() signal
3839     which is emitted whenever a property created by this manager
3840     changes, and the constraintChanged() signal which is emitted
3841     whenever such a property changes its constraint rectangle.
3842 
3843     \sa QtAbstractPropertyManager, QtIntPropertyManager, QtRectFPropertyManager
3844 */
3845 
3846 /*!
3847     \fn void QtRectPropertyManager::valueChanged(QtProperty *property, const QRect &value)
3848 
3849     This signal is emitted whenever a property created by this manager
3850     changes its value, passing a pointer to the \a property and the new
3851     \a value as parameters.
3852 
3853     \sa setValue()
3854 */
3855 
3856 /*!
3857     \fn void QtRectPropertyManager::constraintChanged(QtProperty *property, const QRect &constraint)
3858 
3859     This signal is emitted whenever property changes its constraint
3860     rectangle, passing a pointer to the \a property and the new \a
3861     constraint rectangle as parameters.
3862 
3863     \sa setConstraint()
3864 */
3865 
3866 /*!
3867     Creates a manager with the given \a parent.
3868 */
3869 QtRectPropertyManager::QtRectPropertyManager(QObject *parent)
3870     : QtAbstractPropertyManager(parent), d_ptr(new QtRectPropertyManagerPrivate)
3871 {
3872     d_ptr->q_ptr = this;
3873 
3874     d_ptr->m_intPropertyManager = new QtIntPropertyManager(this);
3875     connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty*,int)),
3876                 this, SLOT(slotIntChanged(QtProperty*,int)));
3877     connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
3878                 this, SLOT(slotPropertyDestroyed(QtProperty*)));
3879 }
3880 
3881 /*!
3882     Destroys this manager, and all the properties it has created.
3883 */
3884 QtRectPropertyManager::~QtRectPropertyManager()
3885 {
3886     clear();
3887 }
3888 
3889 /*!
3890     Returns the manager that creates the nested \e x, \e y, \e width
3891     and \e height subproperties.
3892 
3893     In order to provide editing widgets for the mentioned
3894     subproperties in a property browser widget, this manager must be
3895     associated with an editor factory.
3896 
3897     \sa QtAbstractPropertyBrowser::setFactoryForManager()
3898 */
3899 QtIntPropertyManager *QtRectPropertyManager::subIntPropertyManager() const
3900 {
3901     return d_ptr->m_intPropertyManager;
3902 }
3903 
3904 /*!
3905     Returns the given \a property's value.
3906 
3907     If the given \a property is not managed by this manager, this
3908     function returns an invalid rectangle.
3909 
3910     \sa setValue(), constraint()
3911 */
3912 QRect QtRectPropertyManager::value(const QtProperty *property) const
3913 {
3914     return getValue<QRect>(d_ptr->m_values, property);
3915 }
3916 
3917 /*!
3918     Returns the given \a property's constraining rectangle. If returned value is null QRect it means there is no constraint applied.
3919 
3920     \sa value(), setConstraint()
3921 */
3922 QRect QtRectPropertyManager::constraint(const QtProperty *property) const
3923 {
3924     return getData<QRect>(d_ptr->m_values, &QtRectPropertyManagerPrivate::Data::constraint, property, QRect());
3925 }
3926 
3927 /*!
3928     \reimp
3929 */
3930 QString QtRectPropertyManager::valueText(const QtProperty *property) const
3931 {
3932     const QtRectPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
3933     if (it == d_ptr->m_values.constEnd())
3934         return QString();
3935     const QRect v = it.value().val;
3936     return tr("[(%1, %2), %3 x %4]").arg(QString::number(v.x()))
3937                                     .arg(QString::number(v.y()))
3938                                     .arg(QString::number(v.width()))
3939                                     .arg(QString::number(v.height()));
3940 }
3941 
3942 /*!
3943     \fn void QtRectPropertyManager::setValue(QtProperty *property, const QRect &value)
3944 
3945     Sets the value of the given \a property to \a value. Nested
3946     properties are updated automatically.
3947 
3948     If the specified \a value is not inside the given \a property's
3949     constraining rectangle, the value is adjusted accordingly to fit
3950     within the constraint.
3951 
3952     \sa value(), setConstraint(), valueChanged()
3953 */
3954 void QtRectPropertyManager::setValue(QtProperty *property, const QRect &val)
3955 {
3956     const QtRectPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
3957     if (it == d_ptr->m_values.end())
3958         return;
3959 
3960     QtRectPropertyManagerPrivate::Data data = it.value();
3961 
3962     QRect newRect = val.normalized();
3963     if (!data.constraint.isNull() && !data.constraint.contains(newRect)) {
3964         const QRect r1 = data.constraint;
3965         const QRect r2 = newRect;
3966         newRect.setLeft(qMax(r1.left(), r2.left()));
3967         newRect.setRight(qMin(r1.right(), r2.right()));
3968         newRect.setTop(qMax(r1.top(), r2.top()));
3969         newRect.setBottom(qMin(r1.bottom(), r2.bottom()));
3970         if (newRect.width() < 0 || newRect.height() < 0)
3971             return;
3972     }
3973 
3974     if (data.val == newRect)
3975         return;
3976 
3977     data.val = newRect;
3978 
3979     it.value() = data;
3980     d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToX[property], newRect.x());
3981     d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToY[property], newRect.y());
3982     d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToW[property], newRect.width());
3983     d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToH[property], newRect.height());
3984 
3985     Q_EMIT propertyChanged(property);
3986     Q_EMIT valueChanged(property, data.val);
3987 }
3988 
3989 /*!
3990     Sets the given \a property's constraining rectangle to \a
3991     constraint.
3992 
3993     When setting the constraint, the current value is adjusted if
3994     necessary (ensuring that the current rectangle value is inside the
3995     constraint). In order to reset the constraint pass a null QRect value.
3996 
3997     \sa setValue(), constraint(), constraintChanged()
3998 */
3999 void QtRectPropertyManager::setConstraint(QtProperty *property, const QRect &constraint)
4000 {
4001     const QtRectPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
4002     if (it == d_ptr->m_values.end())
4003         return;
4004 
4005     QtRectPropertyManagerPrivate::Data data = it.value();
4006 
4007     QRect newConstraint = constraint.normalized();
4008     if (data.constraint == newConstraint)
4009         return;
4010 
4011     const QRect oldVal = data.val;
4012 
4013     data.constraint = newConstraint;
4014 
4015     if (!data.constraint.isNull() && !data.constraint.contains(oldVal)) {
4016         QRect r1 = data.constraint;
4017         QRect r2 = data.val;
4018 
4019         if (r2.width() > r1.width())
4020             r2.setWidth(r1.width());
4021         if (r2.height() > r1.height())
4022             r2.setHeight(r1.height());
4023         if (r2.left() < r1.left())
4024             r2.moveLeft(r1.left());
4025         else if (r2.right() > r1.right())
4026             r2.moveRight(r1.right());
4027         if (r2.top() < r1.top())
4028             r2.moveTop(r1.top());
4029         else if (r2.bottom() > r1.bottom())
4030             r2.moveBottom(r1.bottom());
4031 
4032         data.val = r2;
4033     }
4034 
4035     it.value() = data;
4036 
4037     Q_EMIT constraintChanged(property, data.constraint);
4038 
4039     d_ptr->setConstraint(property, data.constraint, data.val);
4040 
4041     if (data.val == oldVal)
4042         return;
4043 
4044     Q_EMIT propertyChanged(property);
4045     Q_EMIT valueChanged(property, data.val);
4046 }
4047 
4048 /*!
4049     \reimp
4050 */
4051 void QtRectPropertyManager::initializeProperty(QtProperty *property)
4052 {
4053     d_ptr->m_values[property] = QtRectPropertyManagerPrivate::Data();
4054 
4055     QtProperty *xProp = d_ptr->m_intPropertyManager->addProperty();
4056     xProp->setPropertyName(tr("X"));
4057     d_ptr->m_intPropertyManager->setValue(xProp, 0);
4058     d_ptr->m_propertyToX[property] = xProp;
4059     d_ptr->m_xToProperty[xProp] = property;
4060     property->addSubProperty(xProp);
4061 
4062     QtProperty *yProp = d_ptr->m_intPropertyManager->addProperty();
4063     yProp->setPropertyName(tr("Y"));
4064     d_ptr->m_intPropertyManager->setValue(yProp, 0);
4065     d_ptr->m_propertyToY[property] = yProp;
4066     d_ptr->m_yToProperty[yProp] = property;
4067     property->addSubProperty(yProp);
4068 
4069     QtProperty *wProp = d_ptr->m_intPropertyManager->addProperty();
4070     wProp->setPropertyName(tr("Width"));
4071     d_ptr->m_intPropertyManager->setValue(wProp, 0);
4072     d_ptr->m_intPropertyManager->setMinimum(wProp, 0);
4073     d_ptr->m_propertyToW[property] = wProp;
4074     d_ptr->m_wToProperty[wProp] = property;
4075     property->addSubProperty(wProp);
4076 
4077     QtProperty *hProp = d_ptr->m_intPropertyManager->addProperty();
4078     hProp->setPropertyName(tr("Height"));
4079     d_ptr->m_intPropertyManager->setValue(hProp, 0);
4080     d_ptr->m_intPropertyManager->setMinimum(hProp, 0);
4081     d_ptr->m_propertyToH[property] = hProp;
4082     d_ptr->m_hToProperty[hProp] = property;
4083     property->addSubProperty(hProp);
4084 }
4085 
4086 /*!
4087     \reimp
4088 */
4089 void QtRectPropertyManager::uninitializeProperty(QtProperty *property)
4090 {
4091     QtProperty *xProp = d_ptr->m_propertyToX[property];
4092     if (xProp) {
4093         d_ptr->m_xToProperty.remove(xProp);
4094         delete xProp;
4095     }
4096     d_ptr->m_propertyToX.remove(property);
4097 
4098     QtProperty *yProp = d_ptr->m_propertyToY[property];
4099     if (yProp) {
4100         d_ptr->m_yToProperty.remove(yProp);
4101         delete yProp;
4102     }
4103     d_ptr->m_propertyToY.remove(property);
4104 
4105     QtProperty *wProp = d_ptr->m_propertyToW[property];
4106     if (wProp) {
4107         d_ptr->m_wToProperty.remove(wProp);
4108         delete wProp;
4109     }
4110     d_ptr->m_propertyToW.remove(property);
4111 
4112     QtProperty *hProp = d_ptr->m_propertyToH[property];
4113     if (hProp) {
4114         d_ptr->m_hToProperty.remove(hProp);
4115         delete hProp;
4116     }
4117     d_ptr->m_propertyToH.remove(property);
4118 
4119     d_ptr->m_values.remove(property);
4120 }
4121 
4122 // QtRectFPropertyManager
4123 
4124 class QtRectFPropertyManagerPrivate
4125 {
4126     QtRectFPropertyManager *q_ptr;
4127     Q_DECLARE_PUBLIC(QtRectFPropertyManager)
4128 public:
4129 
4130     void slotDoubleChanged(QtProperty *property, double value);
4131     void slotPropertyDestroyed(QtProperty *property);
4132     void setConstraint(QtProperty *property, const QRectF &constraint, const QRectF &val);
4133 
4134     struct Data
4135     {
4136         QRectF val{0, 0, 0, 0};
4137         QRectF constraint;
4138         int decimals{2};
4139     };
4140 
4141     typedef QMap<const QtProperty *, Data> PropertyValueMap;
4142     PropertyValueMap m_values;
4143 
4144     QtDoublePropertyManager *m_doublePropertyManager;
4145 
4146     QMap<const QtProperty *, QtProperty *> m_propertyToX;
4147     QMap<const QtProperty *, QtProperty *> m_propertyToY;
4148     QMap<const QtProperty *, QtProperty *> m_propertyToW;
4149     QMap<const QtProperty *, QtProperty *> m_propertyToH;
4150 
4151     QMap<const QtProperty *, QtProperty *> m_xToProperty;
4152     QMap<const QtProperty *, QtProperty *> m_yToProperty;
4153     QMap<const QtProperty *, QtProperty *> m_wToProperty;
4154     QMap<const QtProperty *, QtProperty *> m_hToProperty;
4155 };
4156 
4157 void QtRectFPropertyManagerPrivate::slotDoubleChanged(QtProperty *property, double value)
4158 {
4159     if (QtProperty *prop = m_xToProperty.value(property, 0)) {
4160         QRectF r = m_values[prop].val;
4161         r.moveLeft(value);
4162         q_ptr->setValue(prop, r);
4163     } else if (QtProperty *prop = m_yToProperty.value(property, 0)) {
4164         QRectF r = m_values[prop].val;
4165         r.moveTop(value);
4166         q_ptr->setValue(prop, r);
4167     } else if (QtProperty *prop = m_wToProperty.value(property, 0)) {
4168         Data data = m_values[prop];
4169         QRectF r = data.val;
4170         r.setWidth(value);
4171         if (!data.constraint.isNull() && data.constraint.x() + data.constraint.width() < r.x() + r.width()) {
4172             r.moveLeft(data.constraint.left() + data.constraint.width() - r.width());
4173         }
4174         q_ptr->setValue(prop, r);
4175     } else if (QtProperty *prop = m_hToProperty.value(property, 0)) {
4176         Data data = m_values[prop];
4177         QRectF r = data.val;
4178         r.setHeight(value);
4179         if (!data.constraint.isNull() && data.constraint.y() + data.constraint.height() < r.y() + r.height()) {
4180             r.moveTop(data.constraint.top() + data.constraint.height() - r.height());
4181         }
4182         q_ptr->setValue(prop, r);
4183     }
4184 }
4185 
4186 void QtRectFPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
4187 {
4188     if (QtProperty *pointProp = m_xToProperty.value(property, 0)) {
4189         m_propertyToX[pointProp] = 0;
4190         m_xToProperty.remove(property);
4191     } else if (QtProperty *pointProp = m_yToProperty.value(property, 0)) {
4192         m_propertyToY[pointProp] = 0;
4193         m_yToProperty.remove(property);
4194     } else if (QtProperty *pointProp = m_wToProperty.value(property, 0)) {
4195         m_propertyToW[pointProp] = 0;
4196         m_wToProperty.remove(property);
4197     } else if (QtProperty *pointProp = m_hToProperty.value(property, 0)) {
4198         m_propertyToH[pointProp] = 0;
4199         m_hToProperty.remove(property);
4200     }
4201 }
4202 
4203 void QtRectFPropertyManagerPrivate::setConstraint(QtProperty *property,
4204             const QRectF &constraint, const QRectF &val)
4205 {
4206     const bool isNull = constraint.isNull();
4207     const float left   = isNull ? FLT_MIN : constraint.left();
4208     const float right  = isNull ? FLT_MAX : constraint.left() + constraint.width();
4209     const float top    = isNull ? FLT_MIN : constraint.top();
4210     const float bottom = isNull ? FLT_MAX : constraint.top() + constraint.height();
4211     const float width  = isNull ? FLT_MAX : constraint.width();
4212     const float height = isNull ? FLT_MAX : constraint.height();
4213 
4214     m_doublePropertyManager->setRange(m_propertyToX[property], left, right);
4215     m_doublePropertyManager->setRange(m_propertyToY[property], top, bottom);
4216     m_doublePropertyManager->setRange(m_propertyToW[property], 0, width);
4217     m_doublePropertyManager->setRange(m_propertyToH[property], 0, height);
4218 
4219     m_doublePropertyManager->setValue(m_propertyToX[property], val.x());
4220     m_doublePropertyManager->setValue(m_propertyToY[property], val.y());
4221     m_doublePropertyManager->setValue(m_propertyToW[property], val.width());
4222     m_doublePropertyManager->setValue(m_propertyToH[property], val.height());
4223 }
4224 
4225 /*!
4226     \class QtRectFPropertyManager
4227     \internal
4228     \inmodule QtDesigner
4229     \since 4.4
4230 
4231     \brief The QtRectFPropertyManager provides and manages QRectF properties.
4232 
4233     A rectangle property has nested \e x, \e y, \e width and \e height
4234     subproperties. The top-level property's value can be retrieved
4235     using the value() function, and set using the setValue() slot.
4236 
4237     The subproperties are created by a QtDoublePropertyManager object. This
4238     manager can be retrieved using the subDoublePropertyManager() function. In
4239     order to provide editing widgets for the subproperties in a
4240     property browser widget, this manager must be associated with an
4241     editor factory.
4242 
4243     A rectangle property also has a constraint rectangle which can be
4244     retrieved using the constraint() function, and set using the
4245     setConstraint() slot.
4246 
4247     In addition, QtRectFPropertyManager provides the valueChanged() signal
4248     which is emitted whenever a property created by this manager
4249     changes, and the constraintChanged() signal which is emitted
4250     whenever such a property changes its constraint rectangle.
4251 
4252     \sa QtAbstractPropertyManager, QtDoublePropertyManager, QtRectPropertyManager
4253 */
4254 
4255 /*!
4256     \fn void QtRectFPropertyManager::valueChanged(QtProperty *property, const QRectF &value)
4257 
4258     This signal is emitted whenever a property created by this manager
4259     changes its value, passing a pointer to the \a property and the new
4260     \a value as parameters.
4261 
4262     \sa setValue()
4263 */
4264 
4265 /*!
4266     \fn void QtRectFPropertyManager::constraintChanged(QtProperty *property, const QRectF &constraint)
4267 
4268     This signal is emitted whenever property changes its constraint
4269     rectangle, passing a pointer to the \a property and the new \a
4270     constraint rectangle as parameters.
4271 
4272     \sa setConstraint()
4273 */
4274 
4275 /*!
4276     \fn void QtRectFPropertyManager::decimalsChanged(QtProperty *property, int prec)
4277 
4278     This signal is emitted whenever a property created by this manager
4279     changes its precision of value, passing a pointer to the
4280     \a property and the new \a prec value
4281 
4282     \sa setDecimals()
4283 */
4284 
4285 /*!
4286     Creates a manager with the given \a parent.
4287 */
4288 QtRectFPropertyManager::QtRectFPropertyManager(QObject *parent)
4289     : QtAbstractPropertyManager(parent), d_ptr(new QtRectFPropertyManagerPrivate)
4290 {
4291     d_ptr->q_ptr = this;
4292 
4293     d_ptr->m_doublePropertyManager = new QtDoublePropertyManager(this);
4294     connect(d_ptr->m_doublePropertyManager, SIGNAL(valueChanged(QtProperty*,double)),
4295                 this, SLOT(slotDoubleChanged(QtProperty*,double)));
4296     connect(d_ptr->m_doublePropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
4297                 this, SLOT(slotPropertyDestroyed(QtProperty*)));
4298 }
4299 
4300 /*!
4301     Destroys this manager, and all the properties it has created.
4302 */
4303 QtRectFPropertyManager::~QtRectFPropertyManager()
4304 {
4305     clear();
4306 }
4307 
4308 /*!
4309     Returns the manager that creates the nested \e x, \e y, \e width
4310     and \e height subproperties.
4311 
4312     In order to provide editing widgets for the mentioned
4313     subproperties in a property browser widget, this manager must be
4314     associated with an editor factory.
4315 
4316     \sa QtAbstractPropertyBrowser::setFactoryForManager()
4317 */
4318 QtDoublePropertyManager *QtRectFPropertyManager::subDoublePropertyManager() const
4319 {
4320     return d_ptr->m_doublePropertyManager;
4321 }
4322 
4323 /*!
4324     Returns the given \a property's value.
4325 
4326     If the given \a property is not managed by this manager, this
4327     function returns an invalid rectangle.
4328 
4329     \sa setValue(), constraint()
4330 */
4331 QRectF QtRectFPropertyManager::value(const QtProperty *property) const
4332 {
4333     return getValue<QRectF>(d_ptr->m_values, property);
4334 }
4335 
4336 /*!
4337     Returns the given \a property's precision, in decimals.
4338 
4339     \sa setDecimals()
4340 */
4341 int QtRectFPropertyManager::decimals(const QtProperty *property) const
4342 {
4343     return getData<int>(d_ptr->m_values, &QtRectFPropertyManagerPrivate::Data::decimals, property, 0);
4344 }
4345 
4346 /*!
4347     Returns the given \a property's constraining rectangle. If returned value is null QRectF it means there is no constraint applied.
4348 
4349     \sa value(), setConstraint()
4350 */
4351 QRectF QtRectFPropertyManager::constraint(const QtProperty *property) const
4352 {
4353     return getData<QRectF>(d_ptr->m_values, &QtRectFPropertyManagerPrivate::Data::constraint, property, QRect());
4354 }
4355 
4356 /*!
4357     \reimp
4358 */
4359 QString QtRectFPropertyManager::valueText(const QtProperty *property) const
4360 {
4361     const QtRectFPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
4362     if (it == d_ptr->m_values.constEnd())
4363         return QString();
4364     const QRectF v = it.value().val;
4365     const int dec = it.value().decimals;
4366     return QString(tr("[(%1, %2), %3 x %4]").arg(QString::number(v.x(), 'f', dec))
4367                                 .arg(QString::number(v.y(), 'f', dec))
4368                                 .arg(QString::number(v.width(), 'f', dec))
4369                                 .arg(QString::number(v.height(), 'f', dec)));
4370 }
4371 
4372 /*!
4373     \fn void QtRectFPropertyManager::setValue(QtProperty *property, const QRectF &value)
4374 
4375     Sets the value of the given \a property to \a value. Nested
4376     properties are updated automatically.
4377 
4378     If the specified \a value is not inside the given \a property's
4379     constraining rectangle, the value is adjusted accordingly to fit
4380     within the constraint.
4381 
4382     \sa value(), setConstraint(), valueChanged()
4383 */
4384 void QtRectFPropertyManager::setValue(QtProperty *property, const QRectF &val)
4385 {
4386     const QtRectFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
4387     if (it == d_ptr->m_values.end())
4388         return;
4389 
4390     QtRectFPropertyManagerPrivate::Data data = it.value();
4391 
4392     QRectF newRect = val.normalized();
4393     if (!data.constraint.isNull() && !data.constraint.contains(newRect)) {
4394         const QRectF r1 = data.constraint;
4395         const QRectF r2 = newRect;
4396         newRect.setLeft(qMax(r1.left(), r2.left()));
4397         newRect.setRight(qMin(r1.right(), r2.right()));
4398         newRect.setTop(qMax(r1.top(), r2.top()));
4399         newRect.setBottom(qMin(r1.bottom(), r2.bottom()));
4400         if (newRect.width() < 0 || newRect.height() < 0)
4401             return;
4402     }
4403 
4404     if (data.val == newRect)
4405         return;
4406 
4407     data.val = newRect;
4408 
4409     it.value() = data;
4410     d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToX[property], newRect.x());
4411     d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToY[property], newRect.y());
4412     d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToW[property], newRect.width());
4413     d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToH[property], newRect.height());
4414 
4415     Q_EMIT propertyChanged(property);
4416     Q_EMIT valueChanged(property, data.val);
4417 }
4418 
4419 /*!
4420     Sets the given \a property's constraining rectangle to \a
4421     constraint.
4422 
4423     When setting the constraint, the current value is adjusted if
4424     necessary (ensuring that the current rectangle value is inside the
4425     constraint). In order to reset the constraint pass a null QRectF value.
4426 
4427     \sa setValue(), constraint(), constraintChanged()
4428 */
4429 void QtRectFPropertyManager::setConstraint(QtProperty *property, const QRectF &constraint)
4430 {
4431     const QtRectFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
4432     if (it == d_ptr->m_values.end())
4433         return;
4434 
4435     QtRectFPropertyManagerPrivate::Data data = it.value();
4436 
4437     QRectF newConstraint = constraint.normalized();
4438     if (data.constraint == newConstraint)
4439         return;
4440 
4441     const QRectF oldVal = data.val;
4442 
4443     data.constraint = newConstraint;
4444 
4445     if (!data.constraint.isNull() && !data.constraint.contains(oldVal)) {
4446         QRectF r1 = data.constraint;
4447         QRectF r2 = data.val;
4448 
4449         if (r2.width() > r1.width())
4450             r2.setWidth(r1.width());
4451         if (r2.height() > r1.height())
4452             r2.setHeight(r1.height());
4453         if (r2.left() < r1.left())
4454             r2.moveLeft(r1.left());
4455         else if (r2.right() > r1.right())
4456             r2.moveRight(r1.right());
4457         if (r2.top() < r1.top())
4458             r2.moveTop(r1.top());
4459         else if (r2.bottom() > r1.bottom())
4460             r2.moveBottom(r1.bottom());
4461 
4462         data.val = r2;
4463     }
4464 
4465     it.value() = data;
4466 
4467     Q_EMIT constraintChanged(property, data.constraint);
4468 
4469     d_ptr->setConstraint(property, data.constraint, data.val);
4470 
4471     if (data.val == oldVal)
4472         return;
4473 
4474     Q_EMIT propertyChanged(property);
4475     Q_EMIT valueChanged(property, data.val);
4476 }
4477 
4478 /*!
4479     \fn void QtRectFPropertyManager::setDecimals(QtProperty *property, int prec)
4480 
4481     Sets the precision of the given \a property to \a prec.
4482 
4483     The valid decimal range is 0-13. The default is 2.
4484 
4485     \sa decimals()
4486 */
4487 void QtRectFPropertyManager::setDecimals(QtProperty *property, int prec)
4488 {
4489     const QtRectFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
4490     if (it == d_ptr->m_values.end())
4491         return;
4492 
4493     QtRectFPropertyManagerPrivate::Data data = it.value();
4494 
4495     if (prec > 13)
4496         prec = 13;
4497     else if (prec < 0)
4498         prec = 0;
4499 
4500     if (data.decimals == prec)
4501         return;
4502 
4503     data.decimals = prec;
4504     d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToX[property], prec);
4505     d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToY[property], prec);
4506     d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToW[property], prec);
4507     d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToH[property], prec);
4508 
4509     it.value() = data;
4510 
4511     Q_EMIT decimalsChanged(property, data.decimals);
4512 }
4513 
4514 /*!
4515     \reimp
4516 */
4517 void QtRectFPropertyManager::initializeProperty(QtProperty *property)
4518 {
4519     d_ptr->m_values[property] = QtRectFPropertyManagerPrivate::Data();
4520 
4521     QtProperty *xProp = d_ptr->m_doublePropertyManager->addProperty();
4522     xProp->setPropertyName(tr("X"));
4523     d_ptr->m_doublePropertyManager->setDecimals(xProp, decimals(property));
4524     d_ptr->m_doublePropertyManager->setValue(xProp, 0);
4525     d_ptr->m_propertyToX[property] = xProp;
4526     d_ptr->m_xToProperty[xProp] = property;
4527     property->addSubProperty(xProp);
4528 
4529     QtProperty *yProp = d_ptr->m_doublePropertyManager->addProperty();
4530     yProp->setPropertyName(tr("Y"));
4531     d_ptr->m_doublePropertyManager->setDecimals(yProp, decimals(property));
4532     d_ptr->m_doublePropertyManager->setValue(yProp, 0);
4533     d_ptr->m_propertyToY[property] = yProp;
4534     d_ptr->m_yToProperty[yProp] = property;
4535     property->addSubProperty(yProp);
4536 
4537     QtProperty *wProp = d_ptr->m_doublePropertyManager->addProperty();
4538     wProp->setPropertyName(tr("Width"));
4539     d_ptr->m_doublePropertyManager->setDecimals(wProp, decimals(property));
4540     d_ptr->m_doublePropertyManager->setValue(wProp, 0);
4541     d_ptr->m_doublePropertyManager->setMinimum(wProp, 0);
4542     d_ptr->m_propertyToW[property] = wProp;
4543     d_ptr->m_wToProperty[wProp] = property;
4544     property->addSubProperty(wProp);
4545 
4546     QtProperty *hProp = d_ptr->m_doublePropertyManager->addProperty();
4547     hProp->setPropertyName(tr("Height"));
4548     d_ptr->m_doublePropertyManager->setDecimals(hProp, decimals(property));
4549     d_ptr->m_doublePropertyManager->setValue(hProp, 0);
4550     d_ptr->m_doublePropertyManager->setMinimum(hProp, 0);
4551     d_ptr->m_propertyToH[property] = hProp;
4552     d_ptr->m_hToProperty[hProp] = property;
4553     property->addSubProperty(hProp);
4554 }
4555 
4556 /*!
4557     \reimp
4558 */
4559 void QtRectFPropertyManager::uninitializeProperty(QtProperty *property)
4560 {
4561     QtProperty *xProp = d_ptr->m_propertyToX[property];
4562     if (xProp) {
4563         d_ptr->m_xToProperty.remove(xProp);
4564         delete xProp;
4565     }
4566     d_ptr->m_propertyToX.remove(property);
4567 
4568     QtProperty *yProp = d_ptr->m_propertyToY[property];
4569     if (yProp) {
4570         d_ptr->m_yToProperty.remove(yProp);
4571         delete yProp;
4572     }
4573     d_ptr->m_propertyToY.remove(property);
4574 
4575     QtProperty *wProp = d_ptr->m_propertyToW[property];
4576     if (wProp) {
4577         d_ptr->m_wToProperty.remove(wProp);
4578         delete wProp;
4579     }
4580     d_ptr->m_propertyToW.remove(property);
4581 
4582     QtProperty *hProp = d_ptr->m_propertyToH[property];
4583     if (hProp) {
4584         d_ptr->m_hToProperty.remove(hProp);
4585         delete hProp;
4586     }
4587     d_ptr->m_propertyToH.remove(property);
4588 
4589     d_ptr->m_values.remove(property);
4590 }
4591 
4592 // QtEnumPropertyManager
4593 
4594 class QtEnumPropertyManagerPrivate
4595 {
4596     QtEnumPropertyManager *q_ptr;
4597     Q_DECLARE_PUBLIC(QtEnumPropertyManager)
4598 public:
4599 
4600     struct Data
4601     {
4602         int val{-1};
4603         QStringList enumNames;
4604         QMap<int, QIcon> enumIcons;
4605     };
4606 
4607     typedef QMap<const QtProperty *, Data> PropertyValueMap;
4608     PropertyValueMap m_values;
4609 };
4610 
4611 /*!
4612     \class QtEnumPropertyManager
4613     \internal
4614     \inmodule QtDesigner
4615     \since 4.4
4616 
4617     \brief The QtEnumPropertyManager provides and manages enum properties.
4618 
4619     Each enum property has an associated list of enum names which can
4620     be retrieved using the enumNames() function, and set using the
4621     corresponding setEnumNames() function. An enum property's value is
4622     represented by an index in this list, and can be retrieved and set
4623     using the value() and setValue() slots respectively.
4624 
4625     Each enum value can also have an associated icon. The mapping from
4626     values to icons can be set using the setEnumIcons() function and
4627     queried with the enumIcons() function.
4628 
4629     In addition, QtEnumPropertyManager provides the valueChanged() signal
4630     which is emitted whenever a property created by this manager
4631     changes. The enumNamesChanged() or enumIconsChanged() signal is emitted
4632     whenever the list of enum names or icons is altered.
4633 
4634     \sa QtAbstractPropertyManager, QtEnumEditorFactory
4635 */
4636 
4637 /*!
4638     \fn void QtEnumPropertyManager::valueChanged(QtProperty *property, int value)
4639 
4640     This signal is emitted whenever a property created by this manager
4641     changes its value, passing a pointer to the \a property and the new
4642     \a value as parameters.
4643 
4644     \sa setValue()
4645 */
4646 
4647 /*!
4648     \fn void QtEnumPropertyManager::enumNamesChanged(QtProperty *property, const QStringList &names)
4649 
4650     This signal is emitted whenever a property created by this manager
4651     changes its enum names, passing a pointer to the \a property and
4652     the new \a names as parameters.
4653 
4654     \sa setEnumNames()
4655 */
4656 
4657 /*!
4658     \fn void QtEnumPropertyManager::enumIconsChanged(QtProperty *property, const QMap<int, QIcon> &icons)
4659 
4660     This signal is emitted whenever a property created by this manager
4661     changes its enum icons, passing a pointer to the \a property and
4662     the new mapping of values to \a icons as parameters.
4663 
4664     \sa setEnumIcons()
4665 */
4666 
4667 /*!
4668     Creates a manager with the given \a parent.
4669 */
4670 QtEnumPropertyManager::QtEnumPropertyManager(QObject *parent)
4671     : QtAbstractPropertyManager(parent), d_ptr(new QtEnumPropertyManagerPrivate)
4672 {
4673     d_ptr->q_ptr = this;
4674 }
4675 
4676 /*!
4677     Destroys this manager, and all the properties it has created.
4678 */
4679 QtEnumPropertyManager::~QtEnumPropertyManager()
4680 {
4681     clear();
4682 }
4683 
4684 /*!
4685     Returns the given \a property's value which is an index in the
4686     list returned by enumNames()
4687 
4688     If the given property is not managed by this manager, this
4689     function returns -1.
4690 
4691     \sa enumNames(), setValue()
4692 */
4693 int QtEnumPropertyManager::value(const QtProperty *property) const
4694 {
4695     return getValue<int>(d_ptr->m_values, property, -1);
4696 }
4697 
4698 /*!
4699     Returns the given \a property's list of enum names.
4700 
4701     \sa value(), setEnumNames()
4702 */
4703 QStringList QtEnumPropertyManager::enumNames(const QtProperty *property) const
4704 {
4705     return getData<QStringList>(d_ptr->m_values, &QtEnumPropertyManagerPrivate::Data::enumNames, property, QStringList());
4706 }
4707 
4708 /*!
4709     Returns the given \a property's map of enum values to their icons.
4710 
4711     \sa value(), setEnumIcons()
4712 */
4713 QMap<int, QIcon> QtEnumPropertyManager::enumIcons(const QtProperty *property) const
4714 {
4715     return getData<QMap<int, QIcon> >(d_ptr->m_values, &QtEnumPropertyManagerPrivate::Data::enumIcons, property, QMap<int, QIcon>());
4716 }
4717 
4718 /*!
4719     \reimp
4720 */
4721 QString QtEnumPropertyManager::valueText(const QtProperty *property) const
4722 {
4723     const QtEnumPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
4724     if (it == d_ptr->m_values.constEnd())
4725         return QString();
4726 
4727     const QtEnumPropertyManagerPrivate::Data &data = it.value();
4728 
4729     const int v = data.val;
4730     if (v >= 0 && v < data.enumNames.count())
4731         return data.enumNames.at(v);
4732     return QString();
4733 }
4734 
4735 /*!
4736     \reimp
4737 */
4738 QIcon QtEnumPropertyManager::valueIcon(const QtProperty *property) const
4739 {
4740     const QtEnumPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
4741     if (it == d_ptr->m_values.constEnd())
4742         return QIcon();
4743 
4744     const QtEnumPropertyManagerPrivate::Data &data = it.value();
4745 
4746     const int v = data.val;
4747     return data.enumIcons.value(v);
4748 }
4749 
4750 /*!
4751     \fn void QtEnumPropertyManager::setValue(QtProperty *property, int value)
4752 
4753     Sets the value of the given  \a property to \a value.
4754 
4755     The specified \a value must be less than the size of the given \a
4756     property's enumNames() list, and larger than (or equal to) 0.
4757 
4758     \sa value(), valueChanged()
4759 */
4760 void QtEnumPropertyManager::setValue(QtProperty *property, int val)
4761 {
4762     const QtEnumPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
4763     if (it == d_ptr->m_values.end())
4764         return;
4765 
4766     QtEnumPropertyManagerPrivate::Data data = it.value();
4767 
4768     if (val >= data.enumNames.count())
4769         return;
4770 
4771     if (val < 0 && data.enumNames.count() > 0)
4772         return;
4773 
4774     if (val < 0)
4775         val = -1;
4776 
4777     if (data.val == val)
4778         return;
4779 
4780     data.val = val;
4781 
4782     it.value() = data;
4783 
4784     Q_EMIT propertyChanged(property);
4785     Q_EMIT valueChanged(property, data.val);
4786 }
4787 
4788 /*!
4789     Sets the given \a property's list of enum names to \a
4790     enumNames. The \a property's current value is reset to 0
4791     indicating the first item of the list.
4792 
4793     If the specified \a enumNames list is empty, the \a property's
4794     current value is set to -1.
4795 
4796     \sa enumNames(), enumNamesChanged()
4797 */
4798 void QtEnumPropertyManager::setEnumNames(QtProperty *property, const QStringList &enumNames)
4799 {
4800     const QtEnumPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
4801     if (it == d_ptr->m_values.end())
4802         return;
4803 
4804     QtEnumPropertyManagerPrivate::Data data = it.value();
4805 
4806     if (data.enumNames == enumNames)
4807         return;
4808 
4809     data.enumNames = enumNames;
4810 
4811     data.val = -1;
4812 
4813     if (enumNames.count() > 0)
4814         data.val = 0;
4815 
4816     it.value() = data;
4817 
4818     Q_EMIT enumNamesChanged(property, data.enumNames);
4819 
4820     Q_EMIT propertyChanged(property);
4821     Q_EMIT valueChanged(property, data.val);
4822 }
4823 
4824 /*!
4825     Sets the given \a property's map of enum values to their icons to \a
4826     enumIcons.
4827 
4828     Each enum value can have associated icon. This association is represented with passed \a enumIcons map.
4829 
4830     \sa enumNames(), enumNamesChanged()
4831 */
4832 void QtEnumPropertyManager::setEnumIcons(QtProperty *property, const QMap<int, QIcon> &enumIcons)
4833 {
4834     const QtEnumPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
4835     if (it == d_ptr->m_values.end())
4836         return;
4837 
4838     it.value().enumIcons = enumIcons;
4839 
4840     Q_EMIT enumIconsChanged(property, it.value().enumIcons);
4841 
4842     Q_EMIT propertyChanged(property);
4843 }
4844 
4845 /*!
4846     \reimp
4847 */
4848 void QtEnumPropertyManager::initializeProperty(QtProperty *property)
4849 {
4850     d_ptr->m_values[property] = QtEnumPropertyManagerPrivate::Data();
4851 }
4852 
4853 /*!
4854     \reimp
4855 */
4856 void QtEnumPropertyManager::uninitializeProperty(QtProperty *property)
4857 {
4858     d_ptr->m_values.remove(property);
4859 }
4860 
4861 // QtFlagPropertyManager
4862 
4863 class QtFlagPropertyManagerPrivate
4864 {
4865     QtFlagPropertyManager *q_ptr;
4866     Q_DECLARE_PUBLIC(QtFlagPropertyManager)
4867 public:
4868 
4869     void slotBoolChanged(QtProperty *property, bool value);
4870     void slotPropertyDestroyed(QtProperty *property);
4871 
4872     struct Data
4873     {
4874         int val{-1};
4875         QStringList flagNames;
4876     };
4877 
4878     typedef QMap<const QtProperty *, Data> PropertyValueMap;
4879     PropertyValueMap m_values;
4880 
4881     QtBoolPropertyManager *m_boolPropertyManager;
4882 
4883     QMap<const QtProperty *, QList<QtProperty *> > m_propertyToFlags;
4884 
4885     QMap<const QtProperty *, QtProperty *> m_flagToProperty;
4886 };
4887 
4888 void QtFlagPropertyManagerPrivate::slotBoolChanged(QtProperty *property, bool value)
4889 {
4890     QtProperty *prop = m_flagToProperty.value(property, 0);
4891     if (prop == 0)
4892         return;
4893 
4894     const auto pfit = m_propertyToFlags.constFind(prop);
4895     if (pfit == m_propertyToFlags.constEnd())
4896             return;
4897     int level = 0;
4898     for (QtProperty *p : pfit.value()) {
4899         if (p == property) {
4900             int v = m_values[prop].val;
4901             if (value) {
4902                 v |= (1 << level);
4903             } else {
4904                 v &= ~(1 << level);
4905             }
4906             q_ptr->setValue(prop, v);
4907             return;
4908         }
4909         level++;
4910     }
4911 }
4912 
4913 void QtFlagPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
4914 {
4915     QtProperty *flagProperty = m_flagToProperty.value(property, 0);
4916     if (flagProperty == 0)
4917         return;
4918 
4919     m_propertyToFlags[flagProperty].replace(m_propertyToFlags[flagProperty].indexOf(property), 0);
4920     m_flagToProperty.remove(property);
4921 }
4922 
4923 /*!
4924     \class QtFlagPropertyManager
4925     \internal
4926     \inmodule QtDesigner
4927     \since 4.4
4928 
4929     \brief The QtFlagPropertyManager provides and manages flag properties.
4930 
4931     Each flag property has an associated list of flag names which can
4932     be retrieved using the flagNames() function, and set using the
4933     corresponding setFlagNames() function.
4934 
4935     The flag manager provides properties with nested boolean
4936     subproperties representing each flag, i.e. a flag property's value
4937     is the binary combination of the subproperties' values. A
4938     property's value can be retrieved and set using the value() and
4939     setValue() slots respectively. The combination of flags is represented
4940     by single int value - that's why it's possible to store up to
4941     32 independent flags in one flag property.
4942 
4943     The subproperties are created by a QtBoolPropertyManager object. This
4944     manager can be retrieved using the subBoolPropertyManager() function. In
4945     order to provide editing widgets for the subproperties in a
4946     property browser widget, this manager must be associated with an
4947     editor factory.
4948 
4949     In addition, QtFlagPropertyManager provides the valueChanged() signal
4950     which is emitted whenever a property created by this manager
4951     changes, and the flagNamesChanged() signal which is emitted
4952     whenever the list of flag names is altered.
4953 
4954     \sa QtAbstractPropertyManager, QtBoolPropertyManager
4955 */
4956 
4957 /*!
4958     \fn void QtFlagPropertyManager::valueChanged(QtProperty *property, int value)
4959 
4960     This signal is emitted whenever a property created by this manager
4961     changes its value, passing a pointer to the \a  property and the new
4962     \a value as parameters.
4963 
4964     \sa setValue()
4965 */
4966 
4967 /*!
4968     \fn void QtFlagPropertyManager::flagNamesChanged(QtProperty *property, const QStringList &names)
4969 
4970     This signal is emitted whenever a property created by this manager
4971     changes its flag names, passing a pointer to the \a property and the
4972     new \a names as parameters.
4973 
4974     \sa setFlagNames()
4975 */
4976 
4977 /*!
4978     Creates a manager with the given \a parent.
4979 */
4980 QtFlagPropertyManager::QtFlagPropertyManager(QObject *parent)
4981     : QtAbstractPropertyManager(parent), d_ptr(new QtFlagPropertyManagerPrivate)
4982 {
4983     d_ptr->q_ptr = this;
4984 
4985     d_ptr->m_boolPropertyManager = new QtBoolPropertyManager(this);
4986     connect(d_ptr->m_boolPropertyManager, SIGNAL(valueChanged(QtProperty*,bool)),
4987                 this, SLOT(slotBoolChanged(QtProperty*,bool)));
4988     connect(d_ptr->m_boolPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
4989                 this, SLOT(slotPropertyDestroyed(QtProperty*)));
4990 }
4991 
4992 /*!
4993     Destroys this manager, and all the properties it has created.
4994 */
4995 QtFlagPropertyManager::~QtFlagPropertyManager()
4996 {
4997     clear();
4998 }
4999 
5000 /*!
5001     Returns the manager that produces the nested boolean subproperties
5002     representing each flag.
5003 
5004     In order to provide editing widgets for the subproperties in a
5005     property browser widget, this manager must be associated with an
5006     editor factory.
5007 
5008     \sa QtAbstractPropertyBrowser::setFactoryForManager()
5009 */
5010 QtBoolPropertyManager *QtFlagPropertyManager::subBoolPropertyManager() const
5011 {
5012     return d_ptr->m_boolPropertyManager;
5013 }
5014 
5015 /*!
5016     Returns the given \a property's value.
5017 
5018     If the given property is not managed by this manager, this
5019     function returns 0.
5020 
5021     \sa flagNames(), setValue()
5022 */
5023 int QtFlagPropertyManager::value(const QtProperty *property) const
5024 {
5025     return getValue<int>(d_ptr->m_values, property, 0);
5026 }
5027 
5028 /*!
5029     Returns the given \a property's list of flag names.
5030 
5031     \sa value(), setFlagNames()
5032 */
5033 QStringList QtFlagPropertyManager::flagNames(const QtProperty *property) const
5034 {
5035     return getData<QStringList>(d_ptr->m_values, &QtFlagPropertyManagerPrivate::Data::flagNames, property, QStringList());
5036 }
5037 
5038 /*!
5039     \reimp
5040 */
5041 QString QtFlagPropertyManager::valueText(const QtProperty *property) const
5042 {
5043     const QtFlagPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
5044     if (it == d_ptr->m_values.constEnd())
5045         return QString();
5046 
5047     const QtFlagPropertyManagerPrivate::Data &data = it.value();
5048 
5049     QString str;
5050     int level = 0;
5051     const QChar bar = QLatin1Char('|');
5052     const QStringList::const_iterator fncend = data.flagNames.constEnd();
5053     for (QStringList::const_iterator it =  data.flagNames.constBegin(); it != fncend; ++it) {
5054         if (data.val & (1 << level)) {
5055             if (!str.isEmpty())
5056                 str += bar;
5057             str += *it;
5058         }
5059 
5060         level++;
5061     }
5062     return str;
5063 }
5064 
5065 /*!
5066     \fn void QtFlagPropertyManager::setValue(QtProperty *property, int value)
5067 
5068     Sets the value of the given \a property to \a value. Nested
5069     properties are updated automatically.
5070 
5071     The specified \a value must be less than the binary combination of
5072     the property's flagNames() list size (i.e. less than 2\sup n,
5073     where \c n is the size of the list) and larger than (or equal to)
5074     0.
5075 
5076     \sa value(), valueChanged()
5077 */
5078 void QtFlagPropertyManager::setValue(QtProperty *property, int val)
5079 {
5080     const QtFlagPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
5081     if (it == d_ptr->m_values.end())
5082         return;
5083 
5084     QtFlagPropertyManagerPrivate::Data data = it.value();
5085 
5086     if (data.val == val)
5087         return;
5088 
5089     if (val > (1 << data.flagNames.count()) - 1)
5090         return;
5091 
5092     if (val < 0)
5093         return;
5094 
5095     data.val = val;
5096 
5097     it.value() = data;
5098 
5099     const auto pfit = d_ptr->m_propertyToFlags.constFind(property);
5100     int level = 0;
5101     if (pfit != d_ptr->m_propertyToFlags.constEnd()) {
5102         for (QtProperty *prop : pfit.value()) {
5103             if (prop)
5104                 d_ptr->m_boolPropertyManager->setValue(prop, val & (1 << level));
5105             level++;
5106         }
5107     }
5108 
5109     Q_EMIT propertyChanged(property);
5110     Q_EMIT valueChanged(property, data.val);
5111 }
5112 
5113 /*!
5114     Sets the given \a property's list of flag names to \a flagNames. The
5115     property's current value is reset to 0 indicating the first item
5116     of the list.
5117 
5118     \sa flagNames(), flagNamesChanged()
5119 */
5120 void QtFlagPropertyManager::setFlagNames(QtProperty *property, const QStringList &flagNames)
5121 {
5122     const QtFlagPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
5123     if (it == d_ptr->m_values.end())
5124         return;
5125 
5126     QtFlagPropertyManagerPrivate::Data data = it.value();
5127 
5128     if (data.flagNames == flagNames)
5129         return;
5130 
5131     data.flagNames = flagNames;
5132     data.val = 0;
5133 
5134     it.value() = data;
5135 
5136     const auto pfit = d_ptr->m_propertyToFlags.find(property);
5137     if (pfit != d_ptr->m_propertyToFlags.end()) {
5138         for (QtProperty *prop : qAsConst(pfit.value())) {
5139             if (prop) {
5140                 delete prop;
5141                 d_ptr->m_flagToProperty.remove(prop);
5142             }
5143         }
5144         pfit.value().clear();
5145     }
5146 
5147     for (const QString &flagName : flagNames) {
5148         QtProperty *prop = d_ptr->m_boolPropertyManager->addProperty();
5149         prop->setPropertyName(flagName);
5150         property->addSubProperty(prop);
5151         d_ptr->m_propertyToFlags[property].append(prop);
5152         d_ptr->m_flagToProperty[prop] = property;
5153     }
5154 
5155     Q_EMIT flagNamesChanged(property, data.flagNames);
5156 
5157     Q_EMIT propertyChanged(property);
5158     Q_EMIT valueChanged(property, data.val);
5159 }
5160 
5161 /*!
5162     \reimp
5163 */
5164 void QtFlagPropertyManager::initializeProperty(QtProperty *property)
5165 {
5166     d_ptr->m_values[property] = QtFlagPropertyManagerPrivate::Data();
5167 
5168     d_ptr->m_propertyToFlags[property] = QList<QtProperty *>();
5169 }
5170 
5171 /*!
5172     \reimp
5173 */
5174 void QtFlagPropertyManager::uninitializeProperty(QtProperty *property)
5175 {
5176     const auto it = d_ptr->m_propertyToFlags.find(property);
5177     if (it != d_ptr->m_propertyToFlags.end()) {
5178         for (QtProperty *prop : qAsConst(it.value()))  {
5179             if (prop) {
5180                 d_ptr->m_flagToProperty.remove(prop);
5181                 delete prop;
5182             }
5183         }
5184     }
5185     d_ptr->m_propertyToFlags.erase(it);
5186 
5187     d_ptr->m_values.remove(property);
5188 }
5189 
5190 // QtSizePolicyPropertyManager
5191 
5192 class QtSizePolicyPropertyManagerPrivate
5193 {
5194     QtSizePolicyPropertyManager *q_ptr;
5195     Q_DECLARE_PUBLIC(QtSizePolicyPropertyManager)
5196 public:
5197 
5198     QtSizePolicyPropertyManagerPrivate();
5199 
5200     void slotIntChanged(QtProperty *property, int value);
5201     void slotEnumChanged(QtProperty *property, int value);
5202     void slotPropertyDestroyed(QtProperty *property);
5203 
5204     typedef QMap<const QtProperty *, QSizePolicy> PropertyValueMap;
5205     PropertyValueMap m_values;
5206 
5207     QtIntPropertyManager *m_intPropertyManager;
5208     QtEnumPropertyManager *m_enumPropertyManager;
5209 
5210     QMap<const QtProperty *, QtProperty *> m_propertyToHPolicy;
5211     QMap<const QtProperty *, QtProperty *> m_propertyToVPolicy;
5212     QMap<const QtProperty *, QtProperty *> m_propertyToHStretch;
5213     QMap<const QtProperty *, QtProperty *> m_propertyToVStretch;
5214 
5215     QMap<const QtProperty *, QtProperty *> m_hPolicyToProperty;
5216     QMap<const QtProperty *, QtProperty *> m_vPolicyToProperty;
5217     QMap<const QtProperty *, QtProperty *> m_hStretchToProperty;
5218     QMap<const QtProperty *, QtProperty *> m_vStretchToProperty;
5219 };
5220 
5221 QtSizePolicyPropertyManagerPrivate::QtSizePolicyPropertyManagerPrivate()
5222 {
5223 }
5224 
5225 void QtSizePolicyPropertyManagerPrivate::slotIntChanged(QtProperty *property, int value)
5226 {
5227     if (QtProperty *prop = m_hStretchToProperty.value(property, 0)) {
5228         QSizePolicy sp = m_values[prop];
5229         sp.setHorizontalStretch(value);
5230         q_ptr->setValue(prop, sp);
5231     } else if (QtProperty *prop = m_vStretchToProperty.value(property, 0)) {
5232         QSizePolicy sp = m_values[prop];
5233         sp.setVerticalStretch(value);
5234         q_ptr->setValue(prop, sp);
5235     }
5236 }
5237 
5238 void QtSizePolicyPropertyManagerPrivate::slotEnumChanged(QtProperty *property, int value)
5239 {
5240     if (QtProperty *prop = m_hPolicyToProperty.value(property, 0)) {
5241         QSizePolicy sp = m_values[prop];
5242         sp.setHorizontalPolicy(metaEnumProvider()->indexToSizePolicy(value));
5243         q_ptr->setValue(prop, sp);
5244     } else if (QtProperty *prop = m_vPolicyToProperty.value(property, 0)) {
5245         QSizePolicy sp = m_values[prop];
5246         sp.setVerticalPolicy(metaEnumProvider()->indexToSizePolicy(value));
5247         q_ptr->setValue(prop, sp);
5248     }
5249 }
5250 
5251 void QtSizePolicyPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
5252 {
5253     if (QtProperty *pointProp = m_hStretchToProperty.value(property, 0)) {
5254         m_propertyToHStretch[pointProp] = 0;
5255         m_hStretchToProperty.remove(property);
5256     } else if (QtProperty *pointProp = m_vStretchToProperty.value(property, 0)) {
5257         m_propertyToVStretch[pointProp] = 0;
5258         m_vStretchToProperty.remove(property);
5259     } else if (QtProperty *pointProp = m_hPolicyToProperty.value(property, 0)) {
5260         m_propertyToHPolicy[pointProp] = 0;
5261         m_hPolicyToProperty.remove(property);
5262     } else if (QtProperty *pointProp = m_vPolicyToProperty.value(property, 0)) {
5263         m_propertyToVPolicy[pointProp] = 0;
5264         m_vPolicyToProperty.remove(property);
5265     }
5266 }
5267 
5268 /*!
5269     \class QtSizePolicyPropertyManager
5270     \internal
5271     \inmodule QtDesigner
5272     \since 4.4
5273 
5274     \brief The QtSizePolicyPropertyManager provides and manages QSizePolicy properties.
5275 
5276     A size policy property has nested \e horizontalPolicy, \e
5277     verticalPolicy, \e horizontalStretch and \e verticalStretch
5278     subproperties. The top-level property's value can be retrieved
5279     using the value() function, and set using the setValue() slot.
5280 
5281     The subproperties are created by QtIntPropertyManager and QtEnumPropertyManager
5282     objects. These managers can be retrieved using the subIntPropertyManager()
5283     and subEnumPropertyManager() functions respectively. In order to provide
5284     editing widgets for the subproperties in a property browser widget,
5285     these managers must be associated with editor factories.
5286 
5287     In addition, QtSizePolicyPropertyManager provides the valueChanged()
5288     signal which is emitted whenever a property created by this
5289     manager changes.
5290 
5291     \sa QtAbstractPropertyManager, QtIntPropertyManager, QtEnumPropertyManager
5292 */
5293 
5294 /*!
5295     \fn void QtSizePolicyPropertyManager::valueChanged(QtProperty *property, const QSizePolicy &value)
5296 
5297     This signal is emitted whenever a property created by this manager
5298     changes its value, passing a pointer to the \a property and the
5299     new \a value as parameters.
5300 
5301     \sa setValue()
5302 */
5303 
5304 /*!
5305     Creates a manager with the given \a parent.
5306 */
5307 QtSizePolicyPropertyManager::QtSizePolicyPropertyManager(QObject *parent)
5308     : QtAbstractPropertyManager(parent), d_ptr(new QtSizePolicyPropertyManagerPrivate)
5309 {
5310     d_ptr->q_ptr = this;
5311 
5312     d_ptr->m_intPropertyManager = new QtIntPropertyManager(this);
5313     connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty*,int)),
5314                 this, SLOT(slotIntChanged(QtProperty*,int)));
5315     d_ptr->m_enumPropertyManager = new QtEnumPropertyManager(this);
5316     connect(d_ptr->m_enumPropertyManager, SIGNAL(valueChanged(QtProperty*,int)),
5317                 this, SLOT(slotEnumChanged(QtProperty*,int)));
5318 
5319     connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
5320                 this, SLOT(slotPropertyDestroyed(QtProperty*)));
5321     connect(d_ptr->m_enumPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
5322                 this, SLOT(slotPropertyDestroyed(QtProperty*)));
5323 }
5324 
5325 /*!
5326     Destroys this manager, and all the properties it has created.
5327 */
5328 QtSizePolicyPropertyManager::~QtSizePolicyPropertyManager()
5329 {
5330     clear();
5331 }
5332 
5333 /*!
5334     Returns the manager that creates the nested \e horizontalStretch
5335     and \e verticalStretch subproperties.
5336 
5337     In order to provide editing widgets for the mentioned subproperties
5338     in a property browser widget, this manager must be associated with
5339     an editor factory.
5340 
5341     \sa QtAbstractPropertyBrowser::setFactoryForManager()
5342 */
5343 QtIntPropertyManager *QtSizePolicyPropertyManager::subIntPropertyManager() const
5344 {
5345     return d_ptr->m_intPropertyManager;
5346 }
5347 
5348 /*!
5349     Returns the manager that creates the nested \e horizontalPolicy
5350     and \e verticalPolicy subproperties.
5351 
5352     In order to provide editing widgets for the mentioned subproperties
5353     in a property browser widget, this manager must be associated with
5354     an editor factory.
5355 
5356     \sa QtAbstractPropertyBrowser::setFactoryForManager()
5357 */
5358 QtEnumPropertyManager *QtSizePolicyPropertyManager::subEnumPropertyManager() const
5359 {
5360     return d_ptr->m_enumPropertyManager;
5361 }
5362 
5363 /*!
5364     Returns the given \a property's value.
5365 
5366     If the given property is not managed by this manager, this
5367     function returns the default size policy.
5368 
5369     \sa setValue()
5370 */
5371 QSizePolicy QtSizePolicyPropertyManager::value(const QtProperty *property) const
5372 {
5373     return d_ptr->m_values.value(property, QSizePolicy());
5374 }
5375 
5376 /*!
5377     \reimp
5378 */
5379 QString QtSizePolicyPropertyManager::valueText(const QtProperty *property) const
5380 {
5381     const QtSizePolicyPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
5382     if (it == d_ptr->m_values.constEnd())
5383         return QString();
5384 
5385     const QSizePolicy sp = it.value();
5386     const QtMetaEnumProvider *mep = metaEnumProvider();
5387     const int hIndex = mep->sizePolicyToIndex(sp.horizontalPolicy());
5388     const int vIndex = mep->sizePolicyToIndex(sp.verticalPolicy());
5389     //! Unknown size policy on reading invalid uic3 files
5390     const QString hPolicy = hIndex != -1 ? mep->policyEnumNames().at(hIndex) : tr("<Invalid>");
5391     const QString vPolicy = vIndex != -1 ? mep->policyEnumNames().at(vIndex) : tr("<Invalid>");
5392     const QString str = tr("[%1, %2, %3, %4]").arg(hPolicy, vPolicy).arg(sp.horizontalStretch()).arg(sp.verticalStretch());
5393     return str;
5394 }
5395 
5396 /*!
5397     \fn void QtSizePolicyPropertyManager::setValue(QtProperty *property, const QSizePolicy &value)
5398 
5399     Sets the value of the given \a property to \a value. Nested
5400     properties are updated automatically.
5401 
5402     \sa value(), valueChanged()
5403 */
5404 void QtSizePolicyPropertyManager::setValue(QtProperty *property, const QSizePolicy &val)
5405 {
5406     const QtSizePolicyPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
5407     if (it == d_ptr->m_values.end())
5408         return;
5409 
5410     if (it.value() == val)
5411         return;
5412 
5413     it.value() = val;
5414 
5415     d_ptr->m_enumPropertyManager->setValue(d_ptr->m_propertyToHPolicy[property],
5416                 metaEnumProvider()->sizePolicyToIndex(val.horizontalPolicy()));
5417     d_ptr->m_enumPropertyManager->setValue(d_ptr->m_propertyToVPolicy[property],
5418                 metaEnumProvider()->sizePolicyToIndex(val.verticalPolicy()));
5419     d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToHStretch[property],
5420                 val.horizontalStretch());
5421     d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToVStretch[property],
5422                 val.verticalStretch());
5423 
5424     Q_EMIT propertyChanged(property);
5425     Q_EMIT valueChanged(property, val);
5426 }
5427 
5428 /*!
5429     \reimp
5430 */
5431 void QtSizePolicyPropertyManager::initializeProperty(QtProperty *property)
5432 {
5433     QSizePolicy val;
5434     d_ptr->m_values[property] = val;
5435 
5436     QtProperty *hPolicyProp = d_ptr->m_enumPropertyManager->addProperty();
5437     hPolicyProp->setPropertyName(tr("Horizontal Policy"));
5438     d_ptr->m_enumPropertyManager->setEnumNames(hPolicyProp, metaEnumProvider()->policyEnumNames());
5439     d_ptr->m_enumPropertyManager->setValue(hPolicyProp,
5440                 metaEnumProvider()->sizePolicyToIndex(val.horizontalPolicy()));
5441     d_ptr->m_propertyToHPolicy[property] = hPolicyProp;
5442     d_ptr->m_hPolicyToProperty[hPolicyProp] = property;
5443     property->addSubProperty(hPolicyProp);
5444 
5445     QtProperty *vPolicyProp = d_ptr->m_enumPropertyManager->addProperty();
5446     vPolicyProp->setPropertyName(tr("Vertical Policy"));
5447     d_ptr->m_enumPropertyManager->setEnumNames(vPolicyProp, metaEnumProvider()->policyEnumNames());
5448     d_ptr->m_enumPropertyManager->setValue(vPolicyProp,
5449                 metaEnumProvider()->sizePolicyToIndex(val.verticalPolicy()));
5450     d_ptr->m_propertyToVPolicy[property] = vPolicyProp;
5451     d_ptr->m_vPolicyToProperty[vPolicyProp] = property;
5452     property->addSubProperty(vPolicyProp);
5453 
5454     QtProperty *hStretchProp = d_ptr->m_intPropertyManager->addProperty();
5455     hStretchProp->setPropertyName(tr("Horizontal Stretch"));
5456     d_ptr->m_intPropertyManager->setValue(hStretchProp, val.horizontalStretch());
5457     d_ptr->m_intPropertyManager->setRange(hStretchProp, 0, 0xff);
5458     d_ptr->m_propertyToHStretch[property] = hStretchProp;
5459     d_ptr->m_hStretchToProperty[hStretchProp] = property;
5460     property->addSubProperty(hStretchProp);
5461 
5462     QtProperty *vStretchProp = d_ptr->m_intPropertyManager->addProperty();
5463     vStretchProp->setPropertyName(tr("Vertical Stretch"));
5464     d_ptr->m_intPropertyManager->setValue(vStretchProp, val.verticalStretch());
5465     d_ptr->m_intPropertyManager->setRange(vStretchProp, 0, 0xff);
5466     d_ptr->m_propertyToVStretch[property] = vStretchProp;
5467     d_ptr->m_vStretchToProperty[vStretchProp] = property;
5468     property->addSubProperty(vStretchProp);
5469 
5470 }
5471 
5472 /*!
5473     \reimp
5474 */
5475 void QtSizePolicyPropertyManager::uninitializeProperty(QtProperty *property)
5476 {
5477     QtProperty *hPolicyProp = d_ptr->m_propertyToHPolicy[property];
5478     if (hPolicyProp) {
5479         d_ptr->m_hPolicyToProperty.remove(hPolicyProp);
5480         delete hPolicyProp;
5481     }
5482     d_ptr->m_propertyToHPolicy.remove(property);
5483 
5484     QtProperty *vPolicyProp = d_ptr->m_propertyToVPolicy[property];
5485     if (vPolicyProp) {
5486         d_ptr->m_vPolicyToProperty.remove(vPolicyProp);
5487         delete vPolicyProp;
5488     }
5489     d_ptr->m_propertyToVPolicy.remove(property);
5490 
5491     QtProperty *hStretchProp = d_ptr->m_propertyToHStretch[property];
5492     if (hStretchProp) {
5493         d_ptr->m_hStretchToProperty.remove(hStretchProp);
5494         delete hStretchProp;
5495     }
5496     d_ptr->m_propertyToHStretch.remove(property);
5497 
5498     QtProperty *vStretchProp = d_ptr->m_propertyToVStretch[property];
5499     if (vStretchProp) {
5500         d_ptr->m_vStretchToProperty.remove(vStretchProp);
5501         delete vStretchProp;
5502     }
5503     d_ptr->m_propertyToVStretch.remove(property);
5504 
5505     d_ptr->m_values.remove(property);
5506 }
5507 
5508 // QtFontPropertyManager:
5509 // QtFontPropertyManagerPrivate has a mechanism for reacting
5510 // to QApplication::fontDatabaseChanged() [4.5], which is emitted
5511 // when someone loads an application font. The signals are compressed
5512 // using a timer with interval 0, which then causes the family
5513 // enumeration manager to re-set its strings and index values
5514 // for each property.
5515 
5516 Q_GLOBAL_STATIC(QFontDatabase, fontDatabase)
5517 
5518 class QtFontPropertyManagerPrivate
5519 {
5520     QtFontPropertyManager *q_ptr;
5521     Q_DECLARE_PUBLIC(QtFontPropertyManager)
5522 public:
5523 
5524     QtFontPropertyManagerPrivate();
5525 
5526     void slotIntChanged(QtProperty *property, int value);
5527     void slotEnumChanged(QtProperty *property, int value);
5528     void slotBoolChanged(QtProperty *property, bool value);
5529     void slotPropertyDestroyed(QtProperty *property);
5530     void slotFontDatabaseChanged();
5531     void slotFontDatabaseDelayedChange();
5532 
5533     QStringList m_familyNames;
5534 
5535     typedef QMap<const QtProperty *, QFont> PropertyValueMap;
5536     PropertyValueMap m_values;
5537 
5538     QtIntPropertyManager *m_intPropertyManager;
5539     QtEnumPropertyManager *m_enumPropertyManager;
5540     QtBoolPropertyManager *m_boolPropertyManager;
5541 
5542     QMap<const QtProperty *, QtProperty *> m_propertyToFamily;
5543     QMap<const QtProperty *, QtProperty *> m_propertyToPointSize;
5544     QMap<const QtProperty *, QtProperty *> m_propertyToBold;
5545     QMap<const QtProperty *, QtProperty *> m_propertyToItalic;
5546     QMap<const QtProperty *, QtProperty *> m_propertyToUnderline;
5547     QMap<const QtProperty *, QtProperty *> m_propertyToStrikeOut;
5548     QMap<const QtProperty *, QtProperty *> m_propertyToKerning;
5549 
5550     QMap<const QtProperty *, QtProperty *> m_familyToProperty;
5551     QMap<const QtProperty *, QtProperty *> m_pointSizeToProperty;
5552     QMap<const QtProperty *, QtProperty *> m_boldToProperty;
5553     QMap<const QtProperty *, QtProperty *> m_italicToProperty;
5554     QMap<const QtProperty *, QtProperty *> m_underlineToProperty;
5555     QMap<const QtProperty *, QtProperty *> m_strikeOutToProperty;
5556     QMap<const QtProperty *, QtProperty *> m_kerningToProperty;
5557 
5558     bool m_settingValue;
5559     QTimer *m_fontDatabaseChangeTimer;
5560 };
5561 
5562 QtFontPropertyManagerPrivate::QtFontPropertyManagerPrivate() :
5563     m_settingValue(false),
5564     m_fontDatabaseChangeTimer(0)
5565 {
5566 }
5567 
5568 void QtFontPropertyManagerPrivate::slotIntChanged(QtProperty *property, int value)
5569 {
5570     if (m_settingValue)
5571         return;
5572     if (QtProperty *prop = m_pointSizeToProperty.value(property, 0)) {
5573         QFont f = m_values[prop];
5574         f.setPointSize(value);
5575         q_ptr->setValue(prop, f);
5576     }
5577 }
5578 
5579 void QtFontPropertyManagerPrivate::slotEnumChanged(QtProperty *property, int value)
5580 {
5581     if (m_settingValue)
5582         return;
5583     if (QtProperty *prop = m_familyToProperty.value(property, 0)) {
5584         QFont f = m_values[prop];
5585         f.setFamily(m_familyNames.at(value));
5586         q_ptr->setValue(prop, f);
5587     }
5588 }
5589 
5590 void QtFontPropertyManagerPrivate::slotBoolChanged(QtProperty *property, bool value)
5591 {
5592     if (m_settingValue)
5593         return;
5594     if (QtProperty *prop = m_boldToProperty.value(property, 0)) {
5595         QFont f = m_values[prop];
5596         f.setBold(value);
5597         q_ptr->setValue(prop, f);
5598     } else if (QtProperty *prop = m_italicToProperty.value(property, 0)) {
5599         QFont f = m_values[prop];
5600         f.setItalic(value);
5601         q_ptr->setValue(prop, f);
5602     } else if (QtProperty *prop = m_underlineToProperty.value(property, 0)) {
5603         QFont f = m_values[prop];
5604         f.setUnderline(value);
5605         q_ptr->setValue(prop, f);
5606     } else if (QtProperty *prop = m_strikeOutToProperty.value(property, 0)) {
5607         QFont f = m_values[prop];
5608         f.setStrikeOut(value);
5609         q_ptr->setValue(prop, f);
5610     } else if (QtProperty *prop = m_kerningToProperty.value(property, 0)) {
5611         QFont f = m_values[prop];
5612         f.setKerning(value);
5613         q_ptr->setValue(prop, f);
5614     }
5615 }
5616 
5617 void QtFontPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
5618 {
5619     if (QtProperty *pointProp = m_pointSizeToProperty.value(property, 0)) {
5620         m_propertyToPointSize[pointProp] = 0;
5621         m_pointSizeToProperty.remove(property);
5622     } else if (QtProperty *pointProp = m_familyToProperty.value(property, 0)) {
5623         m_propertyToFamily[pointProp] = 0;
5624         m_familyToProperty.remove(property);
5625     } else if (QtProperty *pointProp = m_boldToProperty.value(property, 0)) {
5626         m_propertyToBold[pointProp] = 0;
5627         m_boldToProperty.remove(property);
5628     } else if (QtProperty *pointProp = m_italicToProperty.value(property, 0)) {
5629         m_propertyToItalic[pointProp] = 0;
5630         m_italicToProperty.remove(property);
5631     } else if (QtProperty *pointProp = m_underlineToProperty.value(property, 0)) {
5632         m_propertyToUnderline[pointProp] = 0;
5633         m_underlineToProperty.remove(property);
5634     } else if (QtProperty *pointProp = m_strikeOutToProperty.value(property, 0)) {
5635         m_propertyToStrikeOut[pointProp] = 0;
5636         m_strikeOutToProperty.remove(property);
5637     } else if (QtProperty *pointProp = m_kerningToProperty.value(property, 0)) {
5638         m_propertyToKerning[pointProp] = 0;
5639         m_kerningToProperty.remove(property);
5640     }
5641 }
5642 
5643 void  QtFontPropertyManagerPrivate::slotFontDatabaseChanged()
5644 {
5645     if (!m_fontDatabaseChangeTimer) {
5646         m_fontDatabaseChangeTimer = new QTimer(q_ptr);
5647         m_fontDatabaseChangeTimer->setInterval(0);
5648         m_fontDatabaseChangeTimer->setSingleShot(true);
5649         QObject::connect(m_fontDatabaseChangeTimer, SIGNAL(timeout()), q_ptr, SLOT(slotFontDatabaseDelayedChange()));
5650     }
5651     if (!m_fontDatabaseChangeTimer->isActive())
5652         m_fontDatabaseChangeTimer->start();
5653 }
5654 
5655 void QtFontPropertyManagerPrivate::slotFontDatabaseDelayedChange()
5656 {
5657     typedef QMap<const QtProperty *, QtProperty *> PropertyPropertyMap;
5658     // rescan available font names
5659     const QStringList oldFamilies = m_familyNames;
5660     m_familyNames = fontDatabase()->families();
5661 
5662     // Adapt all existing properties
5663     if (!m_propertyToFamily.empty()) {
5664         PropertyPropertyMap::const_iterator cend = m_propertyToFamily.constEnd();
5665         for (PropertyPropertyMap::const_iterator it = m_propertyToFamily.constBegin(); it != cend; ++it) {
5666             QtProperty *familyProp = it.value();
5667             const int oldIdx = m_enumPropertyManager->value(familyProp);
5668             int newIdx = m_familyNames.indexOf(oldFamilies.at(oldIdx));
5669             if (newIdx < 0)
5670                 newIdx = 0;
5671             m_enumPropertyManager->setEnumNames(familyProp, m_familyNames);
5672             m_enumPropertyManager->setValue(familyProp, newIdx);
5673         }
5674     }
5675 }
5676 
5677 /*!
5678     \class QtFontPropertyManager
5679     \internal
5680     \inmodule QtDesigner
5681     \since 4.4
5682 
5683     \brief The QtFontPropertyManager provides and manages QFont properties.
5684 
5685     A font property has nested \e family, \e pointSize, \e bold, \e
5686     italic, \e underline, \e strikeOut and \e kerning subproperties. The top-level
5687     property's value can be retrieved using the value() function, and
5688     set using the setValue() slot.
5689 
5690     The subproperties are created by QtIntPropertyManager, QtEnumPropertyManager and
5691     QtBoolPropertyManager objects. These managers can be retrieved using the
5692     corresponding subIntPropertyManager(), subEnumPropertyManager() and
5693     subBoolPropertyManager() functions. In order to provide editing widgets
5694     for the subproperties in a property browser widget, these managers
5695     must be associated with editor factories.
5696 
5697     In addition, QtFontPropertyManager provides the valueChanged() signal
5698     which is emitted whenever a property created by this manager
5699     changes.
5700 
5701     \sa QtAbstractPropertyManager, QtEnumPropertyManager, QtIntPropertyManager, QtBoolPropertyManager
5702 */
5703 
5704 /*!
5705     \fn void QtFontPropertyManager::valueChanged(QtProperty *property, const QFont &value)
5706 
5707     This signal is emitted whenever a property created by this manager
5708     changes its value, passing a pointer to the \a property and the
5709     new \a value as parameters.
5710 
5711     \sa setValue()
5712 */
5713 
5714 /*!
5715     Creates a manager with the given \a parent.
5716 */
5717 QtFontPropertyManager::QtFontPropertyManager(QObject *parent)
5718     : QtAbstractPropertyManager(parent), d_ptr(new QtFontPropertyManagerPrivate)
5719 {
5720     d_ptr->q_ptr = this;
5721     QObject::connect(qApp, SIGNAL(fontDatabaseChanged()), this, SLOT(slotFontDatabaseChanged()));
5722 
5723     d_ptr->m_intPropertyManager = new QtIntPropertyManager(this);
5724     connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty*,int)),
5725                 this, SLOT(slotIntChanged(QtProperty*,int)));
5726     d_ptr->m_enumPropertyManager = new QtEnumPropertyManager(this);
5727     connect(d_ptr->m_enumPropertyManager, SIGNAL(valueChanged(QtProperty*,int)),
5728                 this, SLOT(slotEnumChanged(QtProperty*,int)));
5729     d_ptr->m_boolPropertyManager = new QtBoolPropertyManager(this);
5730     connect(d_ptr->m_boolPropertyManager, SIGNAL(valueChanged(QtProperty*,bool)),
5731                 this, SLOT(slotBoolChanged(QtProperty*,bool)));
5732 
5733     connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
5734                 this, SLOT(slotPropertyDestroyed(QtProperty*)));
5735     connect(d_ptr->m_enumPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
5736                 this, SLOT(slotPropertyDestroyed(QtProperty*)));
5737     connect(d_ptr->m_boolPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
5738                 this, SLOT(slotPropertyDestroyed(QtProperty*)));
5739 }
5740 
5741 /*!
5742     Destroys this manager, and all the properties it has created.
5743 */
5744 QtFontPropertyManager::~QtFontPropertyManager()
5745 {
5746     clear();
5747 }
5748 
5749 /*!
5750     Returns the manager that creates the \e pointSize subproperty.
5751 
5752     In order to provide editing widgets for the \e pointSize property
5753     in a property browser widget, this manager must be associated
5754     with an editor factory.
5755 
5756     \sa QtAbstractPropertyBrowser::setFactoryForManager()
5757 */
5758 QtIntPropertyManager *QtFontPropertyManager::subIntPropertyManager() const
5759 {
5760     return d_ptr->m_intPropertyManager;
5761 }
5762 
5763 /*!
5764     Returns the manager that create the \e family subproperty.
5765 
5766     In order to provide editing widgets for the \e family property
5767     in a property browser widget, this manager must be associated
5768     with an editor factory.
5769 
5770     \sa QtAbstractPropertyBrowser::setFactoryForManager()
5771 */
5772 QtEnumPropertyManager *QtFontPropertyManager::subEnumPropertyManager() const
5773 {
5774     return d_ptr->m_enumPropertyManager;
5775 }
5776 
5777 /*!
5778     Returns the manager that creates the  \e bold, \e italic, \e underline,
5779     \e strikeOut and \e kerning subproperties.
5780 
5781     In order to provide editing widgets for the mentioned properties
5782     in a property browser widget, this manager must be associated with
5783     an editor factory.
5784 
5785     \sa QtAbstractPropertyBrowser::setFactoryForManager()
5786 */
5787 QtBoolPropertyManager *QtFontPropertyManager::subBoolPropertyManager() const
5788 {
5789     return d_ptr->m_boolPropertyManager;
5790 }
5791 
5792 /*!
5793     Returns the given \a property's value.
5794 
5795     If the given property is not managed by this manager, this
5796     function returns a font object that uses the application's default
5797     font.
5798 
5799     \sa setValue()
5800 */
5801 QFont QtFontPropertyManager::value(const QtProperty *property) const
5802 {
5803     return d_ptr->m_values.value(property, QFont());
5804 }
5805 
5806 /*!
5807     \reimp
5808 */
5809 QString QtFontPropertyManager::valueText(const QtProperty *property) const
5810 {
5811     const QtFontPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
5812     if (it == d_ptr->m_values.constEnd())
5813         return QString();
5814 
5815     return QtPropertyBrowserUtils::fontValueText(it.value());
5816 }
5817 
5818 /*!
5819     \reimp
5820 */
5821 QIcon QtFontPropertyManager::valueIcon(const QtProperty *property) const
5822 {
5823     const QtFontPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
5824     if (it == d_ptr->m_values.constEnd())
5825         return QIcon();
5826 
5827     return QtPropertyBrowserUtils::fontValueIcon(it.value());
5828 }
5829 
5830 /*!
5831     \fn void QtFontPropertyManager::setValue(QtProperty *property, const QFont &value)
5832 
5833     Sets the value of the given \a property to \a value. Nested
5834     properties are updated automatically.
5835 
5836     \sa value(), valueChanged()
5837 */
5838 void QtFontPropertyManager::setValue(QtProperty *property, const QFont &val)
5839 {
5840     const QtFontPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
5841     if (it == d_ptr->m_values.end())
5842         return;
5843 
5844     const QFont oldVal = it.value();
5845     if (oldVal == val && oldVal.resolve() == val.resolve())
5846         return;
5847 
5848     it.value() = val;
5849 
5850     int idx = d_ptr->m_familyNames.indexOf(val.family());
5851     if (idx == -1)
5852         idx = 0;
5853     bool settingValue = d_ptr->m_settingValue;
5854     d_ptr->m_settingValue = true;
5855     d_ptr->m_enumPropertyManager->setValue(d_ptr->m_propertyToFamily[property], idx);
5856     d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToPointSize[property], val.pointSize());
5857     d_ptr->m_boolPropertyManager->setValue(d_ptr->m_propertyToBold[property], val.bold());
5858     d_ptr->m_boolPropertyManager->setValue(d_ptr->m_propertyToItalic[property], val.italic());
5859     d_ptr->m_boolPropertyManager->setValue(d_ptr->m_propertyToUnderline[property], val.underline());
5860     d_ptr->m_boolPropertyManager->setValue(d_ptr->m_propertyToStrikeOut[property], val.strikeOut());
5861     d_ptr->m_boolPropertyManager->setValue(d_ptr->m_propertyToKerning[property], val.kerning());
5862     d_ptr->m_settingValue = settingValue;
5863 
5864     Q_EMIT propertyChanged(property);
5865     Q_EMIT valueChanged(property, val);
5866 }
5867 
5868 /*!
5869     \reimp
5870 */
5871 void QtFontPropertyManager::initializeProperty(QtProperty *property)
5872 {
5873     QFont val;
5874     d_ptr->m_values[property] = val;
5875 
5876     QtProperty *familyProp = d_ptr->m_enumPropertyManager->addProperty();
5877     familyProp->setPropertyName(tr("Family"));
5878     if (d_ptr->m_familyNames.empty())
5879         d_ptr->m_familyNames = fontDatabase()->families();
5880     d_ptr->m_enumPropertyManager->setEnumNames(familyProp, d_ptr->m_familyNames);
5881     int idx = d_ptr->m_familyNames.indexOf(val.family());
5882     if (idx == -1)
5883         idx = 0;
5884     d_ptr->m_enumPropertyManager->setValue(familyProp, idx);
5885     d_ptr->m_propertyToFamily[property] = familyProp;
5886     d_ptr->m_familyToProperty[familyProp] = property;
5887     property->addSubProperty(familyProp);
5888 
5889     QtProperty *pointSizeProp = d_ptr->m_intPropertyManager->addProperty();
5890     pointSizeProp->setPropertyName(tr("Point Size"));
5891     d_ptr->m_intPropertyManager->setValue(pointSizeProp, val.pointSize());
5892     d_ptr->m_intPropertyManager->setMinimum(pointSizeProp, 1);
5893     d_ptr->m_propertyToPointSize[property] = pointSizeProp;
5894     d_ptr->m_pointSizeToProperty[pointSizeProp] = property;
5895     property->addSubProperty(pointSizeProp);
5896 
5897     QtProperty *boldProp = d_ptr->m_boolPropertyManager->addProperty();
5898     boldProp->setPropertyName(tr("Bold"));
5899     d_ptr->m_boolPropertyManager->setValue(boldProp, val.bold());
5900     d_ptr->m_propertyToBold[property] = boldProp;
5901     d_ptr->m_boldToProperty[boldProp] = property;
5902     property->addSubProperty(boldProp);
5903 
5904     QtProperty *italicProp = d_ptr->m_boolPropertyManager->addProperty();
5905     italicProp->setPropertyName(tr("Italic"));
5906     d_ptr->m_boolPropertyManager->setValue(italicProp, val.italic());
5907     d_ptr->m_propertyToItalic[property] = italicProp;
5908     d_ptr->m_italicToProperty[italicProp] = property;
5909     property->addSubProperty(italicProp);
5910 
5911     QtProperty *underlineProp = d_ptr->m_boolPropertyManager->addProperty();
5912     underlineProp->setPropertyName(tr("Underline"));
5913     d_ptr->m_boolPropertyManager->setValue(underlineProp, val.underline());
5914     d_ptr->m_propertyToUnderline[property] = underlineProp;
5915     d_ptr->m_underlineToProperty[underlineProp] = property;
5916     property->addSubProperty(underlineProp);
5917 
5918     QtProperty *strikeOutProp = d_ptr->m_boolPropertyManager->addProperty();
5919     strikeOutProp->setPropertyName(tr("Strikeout"));
5920     d_ptr->m_boolPropertyManager->setValue(strikeOutProp, val.strikeOut());
5921     d_ptr->m_propertyToStrikeOut[property] = strikeOutProp;
5922     d_ptr->m_strikeOutToProperty[strikeOutProp] = property;
5923     property->addSubProperty(strikeOutProp);
5924 
5925     QtProperty *kerningProp = d_ptr->m_boolPropertyManager->addProperty();
5926     kerningProp->setPropertyName(tr("Kerning"));
5927     d_ptr->m_boolPropertyManager->setValue(kerningProp, val.kerning());
5928     d_ptr->m_propertyToKerning[property] = kerningProp;
5929     d_ptr->m_kerningToProperty[kerningProp] = property;
5930     property->addSubProperty(kerningProp);
5931 }
5932 
5933 /*!
5934     \reimp
5935 */
5936 void QtFontPropertyManager::uninitializeProperty(QtProperty *property)
5937 {
5938     QtProperty *familyProp = d_ptr->m_propertyToFamily[property];
5939     if (familyProp) {
5940         d_ptr->m_familyToProperty.remove(familyProp);
5941         delete familyProp;
5942     }
5943     d_ptr->m_propertyToFamily.remove(property);
5944 
5945     QtProperty *pointSizeProp = d_ptr->m_propertyToPointSize[property];
5946     if (pointSizeProp) {
5947         d_ptr->m_pointSizeToProperty.remove(pointSizeProp);
5948         delete pointSizeProp;
5949     }
5950     d_ptr->m_propertyToPointSize.remove(property);
5951 
5952     QtProperty *boldProp = d_ptr->m_propertyToBold[property];
5953     if (boldProp) {
5954         d_ptr->m_boldToProperty.remove(boldProp);
5955         delete boldProp;
5956     }
5957     d_ptr->m_propertyToBold.remove(property);
5958 
5959     QtProperty *italicProp = d_ptr->m_propertyToItalic[property];
5960     if (italicProp) {
5961         d_ptr->m_italicToProperty.remove(italicProp);
5962         delete italicProp;
5963     }
5964     d_ptr->m_propertyToItalic.remove(property);
5965 
5966     QtProperty *underlineProp = d_ptr->m_propertyToUnderline[property];
5967     if (underlineProp) {
5968         d_ptr->m_underlineToProperty.remove(underlineProp);
5969         delete underlineProp;
5970     }
5971     d_ptr->m_propertyToUnderline.remove(property);
5972 
5973     QtProperty *strikeOutProp = d_ptr->m_propertyToStrikeOut[property];
5974     if (strikeOutProp) {
5975         d_ptr->m_strikeOutToProperty.remove(strikeOutProp);
5976         delete strikeOutProp;
5977     }
5978     d_ptr->m_propertyToStrikeOut.remove(property);
5979 
5980     QtProperty *kerningProp = d_ptr->m_propertyToKerning[property];
5981     if (kerningProp) {
5982         d_ptr->m_kerningToProperty.remove(kerningProp);
5983         delete kerningProp;
5984     }
5985     d_ptr->m_propertyToKerning.remove(property);
5986 
5987     d_ptr->m_values.remove(property);
5988 }
5989 
5990 // QtColorPropertyManager
5991 
5992 class QtColorPropertyManagerPrivate
5993 {
5994     QtColorPropertyManager *q_ptr;
5995     Q_DECLARE_PUBLIC(QtColorPropertyManager)
5996 public:
5997 
5998     void slotIntChanged(QtProperty *property, int value);
5999     void slotPropertyDestroyed(QtProperty *property);
6000 
6001     typedef QMap<const QtProperty *, QColor> PropertyValueMap;
6002     PropertyValueMap m_values;
6003 
6004     QtIntPropertyManager *m_intPropertyManager;
6005 
6006     QMap<const QtProperty *, QtProperty *> m_propertyToR;
6007     QMap<const QtProperty *, QtProperty *> m_propertyToG;
6008     QMap<const QtProperty *, QtProperty *> m_propertyToB;
6009     QMap<const QtProperty *, QtProperty *> m_propertyToA;
6010 
6011     QMap<const QtProperty *, QtProperty *> m_rToProperty;
6012     QMap<const QtProperty *, QtProperty *> m_gToProperty;
6013     QMap<const QtProperty *, QtProperty *> m_bToProperty;
6014     QMap<const QtProperty *, QtProperty *> m_aToProperty;
6015 };
6016 
6017 void QtColorPropertyManagerPrivate::slotIntChanged(QtProperty *property, int value)
6018 {
6019     if (QtProperty *prop = m_rToProperty.value(property, 0)) {
6020         QColor c = m_values[prop];
6021         c.setRed(value);
6022         q_ptr->setValue(prop, c);
6023     } else if (QtProperty *prop = m_gToProperty.value(property, 0)) {
6024         QColor c = m_values[prop];
6025         c.setGreen(value);
6026         q_ptr->setValue(prop, c);
6027     } else if (QtProperty *prop = m_bToProperty.value(property, 0)) {
6028         QColor c = m_values[prop];
6029         c.setBlue(value);
6030         q_ptr->setValue(prop, c);
6031     } else if (QtProperty *prop = m_aToProperty.value(property, 0)) {
6032         QColor c = m_values[prop];
6033         c.setAlpha(value);
6034         q_ptr->setValue(prop, c);
6035     }
6036 }
6037 
6038 void QtColorPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
6039 {
6040     if (QtProperty *pointProp = m_rToProperty.value(property, 0)) {
6041         m_propertyToR[pointProp] = 0;
6042         m_rToProperty.remove(property);
6043     } else if (QtProperty *pointProp = m_gToProperty.value(property, 0)) {
6044         m_propertyToG[pointProp] = 0;
6045         m_gToProperty.remove(property);
6046     } else if (QtProperty *pointProp = m_bToProperty.value(property, 0)) {
6047         m_propertyToB[pointProp] = 0;
6048         m_bToProperty.remove(property);
6049     } else if (QtProperty *pointProp = m_aToProperty.value(property, 0)) {
6050         m_propertyToA[pointProp] = 0;
6051         m_aToProperty.remove(property);
6052     }
6053 }
6054 
6055 /*!
6056     \class QtColorPropertyManager
6057     \internal
6058     \inmodule QtDesigner
6059     \since 4.4
6060 
6061     \brief The QtColorPropertyManager provides and manages QColor properties.
6062 
6063     A color property has nested \e red, \e green and \e blue
6064     subproperties. The top-level property's value can be retrieved
6065     using the value() function, and set using the setValue() slot.
6066 
6067     The subproperties are created by a QtIntPropertyManager object. This
6068     manager can be retrieved using the subIntPropertyManager() function.  In
6069     order to provide editing widgets for the subproperties in a
6070     property browser widget, this manager must be associated with an
6071     editor factory.
6072 
6073     In addition, QtColorPropertyManager provides the valueChanged() signal
6074     which is emitted whenever a property created by this manager
6075     changes.
6076 
6077     \sa QtAbstractPropertyManager, QtAbstractPropertyBrowser, QtIntPropertyManager
6078 */
6079 
6080 /*!
6081     \fn void QtColorPropertyManager::valueChanged(QtProperty *property, const QColor &value)
6082 
6083     This signal is emitted whenever a property created by this manager
6084     changes its value, passing a pointer to the \a property and the new
6085     \a value as parameters.
6086 
6087     \sa setValue()
6088 */
6089 
6090 /*!
6091     Creates a manager with the given \a parent.
6092 */
6093 QtColorPropertyManager::QtColorPropertyManager(QObject *parent)
6094     : QtAbstractPropertyManager(parent), d_ptr(new QtColorPropertyManagerPrivate)
6095 {
6096     d_ptr->q_ptr = this;
6097 
6098     d_ptr->m_intPropertyManager = new QtIntPropertyManager(this);
6099     connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty*,int)),
6100                 this, SLOT(slotIntChanged(QtProperty*,int)));
6101 
6102     connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
6103                 this, SLOT(slotPropertyDestroyed(QtProperty*)));
6104 }
6105 
6106 /*!
6107     Destroys this manager, and all the properties it has created.
6108 */
6109 QtColorPropertyManager::~QtColorPropertyManager()
6110 {
6111     clear();
6112 }
6113 
6114 /*!
6115     Returns the manager that produces the nested \e red, \e green and
6116     \e blue subproperties.
6117 
6118     In order to provide editing widgets for the subproperties in a
6119     property browser widget, this manager must be associated with an
6120     editor factory.
6121 
6122     \sa QtAbstractPropertyBrowser::setFactoryForManager()
6123 */
6124 QtIntPropertyManager *QtColorPropertyManager::subIntPropertyManager() const
6125 {
6126     return d_ptr->m_intPropertyManager;
6127 }
6128 
6129 /*!
6130     Returns the given \a property's value.
6131 
6132     If the given \a property is not managed by \e this manager, this
6133     function returns an invalid color.
6134 
6135     \sa setValue()
6136 */
6137 QColor QtColorPropertyManager::value(const QtProperty *property) const
6138 {
6139     return d_ptr->m_values.value(property, QColor());
6140 }
6141 
6142 /*!
6143     \reimp
6144 */
6145 
6146 QString QtColorPropertyManager::valueText(const QtProperty *property) const
6147 {
6148     const QtColorPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
6149     if (it == d_ptr->m_values.constEnd())
6150         return QString();
6151 
6152     return QtPropertyBrowserUtils::colorValueText(it.value());
6153 }
6154 
6155 /*!
6156     \reimp
6157 */
6158 
6159 QIcon QtColorPropertyManager::valueIcon(const QtProperty *property) const
6160 {
6161     const QtColorPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
6162     if (it == d_ptr->m_values.constEnd())
6163         return QIcon();
6164     return QtPropertyBrowserUtils::brushValueIcon(QBrush(it.value()));
6165 }
6166 
6167 /*!
6168     \fn void QtColorPropertyManager::setValue(QtProperty *property, const QColor &value)
6169 
6170     Sets the value of the given \a property to \a value.  Nested
6171     properties are updated automatically.
6172 
6173     \sa value(), valueChanged()
6174 */
6175 void QtColorPropertyManager::setValue(QtProperty *property, const QColor &val)
6176 {
6177     const QtColorPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
6178     if (it == d_ptr->m_values.end())
6179         return;
6180 
6181     if (it.value() == val)
6182         return;
6183 
6184     it.value() = val;
6185 
6186     d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToR[property], val.red());
6187     d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToG[property], val.green());
6188     d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToB[property], val.blue());
6189     d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToA[property], val.alpha());
6190 
6191     Q_EMIT propertyChanged(property);
6192     Q_EMIT valueChanged(property, val);
6193 }
6194 
6195 /*!
6196     \reimp
6197 */
6198 void QtColorPropertyManager::initializeProperty(QtProperty *property)
6199 {
6200     QColor val;
6201     d_ptr->m_values[property] = val;
6202 
6203     QtProperty *rProp = d_ptr->m_intPropertyManager->addProperty();
6204     rProp->setPropertyName(tr("Red"));
6205     d_ptr->m_intPropertyManager->setValue(rProp, val.red());
6206     d_ptr->m_intPropertyManager->setRange(rProp, 0, 0xFF);
6207     d_ptr->m_propertyToR[property] = rProp;
6208     d_ptr->m_rToProperty[rProp] = property;
6209     property->addSubProperty(rProp);
6210 
6211     QtProperty *gProp = d_ptr->m_intPropertyManager->addProperty();
6212     gProp->setPropertyName(tr("Green"));
6213     d_ptr->m_intPropertyManager->setValue(gProp, val.green());
6214     d_ptr->m_intPropertyManager->setRange(gProp, 0, 0xFF);
6215     d_ptr->m_propertyToG[property] = gProp;
6216     d_ptr->m_gToProperty[gProp] = property;
6217     property->addSubProperty(gProp);
6218 
6219     QtProperty *bProp = d_ptr->m_intPropertyManager->addProperty();
6220     bProp->setPropertyName(tr("Blue"));
6221     d_ptr->m_intPropertyManager->setValue(bProp, val.blue());
6222     d_ptr->m_intPropertyManager->setRange(bProp, 0, 0xFF);
6223     d_ptr->m_propertyToB[property] = bProp;
6224     d_ptr->m_bToProperty[bProp] = property;
6225     property->addSubProperty(bProp);
6226 
6227     QtProperty *aProp = d_ptr->m_intPropertyManager->addProperty();
6228     aProp->setPropertyName(tr("Alpha"));
6229     d_ptr->m_intPropertyManager->setValue(aProp, val.alpha());
6230     d_ptr->m_intPropertyManager->setRange(aProp, 0, 0xFF);
6231     d_ptr->m_propertyToA[property] = aProp;
6232     d_ptr->m_aToProperty[aProp] = property;
6233     property->addSubProperty(aProp);
6234 }
6235 
6236 /*!
6237     \reimp
6238 */
6239 void QtColorPropertyManager::uninitializeProperty(QtProperty *property)
6240 {
6241     QtProperty *rProp = d_ptr->m_propertyToR[property];
6242     if (rProp) {
6243         d_ptr->m_rToProperty.remove(rProp);
6244         delete rProp;
6245     }
6246     d_ptr->m_propertyToR.remove(property);
6247 
6248     QtProperty *gProp = d_ptr->m_propertyToG[property];
6249     if (gProp) {
6250         d_ptr->m_gToProperty.remove(gProp);
6251         delete gProp;
6252     }
6253     d_ptr->m_propertyToG.remove(property);
6254 
6255     QtProperty *bProp = d_ptr->m_propertyToB[property];
6256     if (bProp) {
6257         d_ptr->m_bToProperty.remove(bProp);
6258         delete bProp;
6259     }
6260     d_ptr->m_propertyToB.remove(property);
6261 
6262     QtProperty *aProp = d_ptr->m_propertyToA[property];
6263     if (aProp) {
6264         d_ptr->m_aToProperty.remove(aProp);
6265         delete aProp;
6266     }
6267     d_ptr->m_propertyToA.remove(property);
6268 
6269     d_ptr->m_values.remove(property);
6270 }
6271 
6272 // QtCursorPropertyManager
6273 
6274 // Make sure icons are removed as soon as QApplication is destroyed, otherwise,
6275 // handles are leaked on X11.
6276 static void clearCursorDatabase();
6277 namespace {
6278 struct CursorDatabase : public QtCursorDatabase
6279 {
6280     CursorDatabase()
6281     {
6282         qAddPostRoutine(clearCursorDatabase);
6283     }
6284 };
6285 }
6286 Q_GLOBAL_STATIC(QtCursorDatabase, cursorDatabase)
6287 
6288 static void clearCursorDatabase()
6289 {
6290     cursorDatabase()->clear();
6291 }
6292 
6293 class QtCursorPropertyManagerPrivate
6294 {
6295     QtCursorPropertyManager *q_ptr;
6296     Q_DECLARE_PUBLIC(QtCursorPropertyManager)
6297 public:
6298     typedef QMap<const QtProperty *, QCursor> PropertyValueMap;
6299     PropertyValueMap m_values;
6300 };
6301 
6302 /*!
6303     \class QtCursorPropertyManager
6304     \internal
6305     \inmodule QtDesigner
6306     \since 4.4
6307 
6308     \brief The QtCursorPropertyManager provides and manages QCursor properties.
6309 
6310     A cursor property has a current value which can be
6311     retrieved using the value() function, and set using the setValue()
6312     slot. In addition, QtCursorPropertyManager provides the
6313     valueChanged() signal which is emitted whenever a property created
6314     by this manager changes.
6315 
6316     \sa QtAbstractPropertyManager
6317 */
6318 
6319 /*!
6320     \fn void QtCursorPropertyManager::valueChanged(QtProperty *property, const QCursor &value)
6321 
6322     This signal is emitted whenever a property created by this manager
6323     changes its value, passing a pointer to the \a property and the new
6324     \a value as parameters.
6325 
6326     \sa setValue()
6327 */
6328 
6329 /*!
6330     Creates a manager with the given \a parent.
6331 */
6332 QtCursorPropertyManager::QtCursorPropertyManager(QObject *parent)
6333     : QtAbstractPropertyManager(parent), d_ptr(new QtCursorPropertyManagerPrivate)
6334 {
6335     d_ptr->q_ptr = this;
6336 }
6337 
6338 /*!
6339     Destroys this manager, and all the properties it has created.
6340 */
6341 QtCursorPropertyManager::~QtCursorPropertyManager()
6342 {
6343     clear();
6344 }
6345 
6346 /*!
6347     Returns the given \a property's value.
6348 
6349     If the given \a property is not managed by this manager, this
6350     function returns a default QCursor object.
6351 
6352     \sa setValue()
6353 */
6354 #ifndef QT_NO_CURSOR
6355 QCursor QtCursorPropertyManager::value(const QtProperty *property) const
6356 {
6357     return d_ptr->m_values.value(property, QCursor());
6358 }
6359 #endif
6360 
6361 /*!
6362     \reimp
6363 */
6364 QString QtCursorPropertyManager::valueText(const QtProperty *property) const
6365 {
6366    const QtCursorPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
6367     if (it == d_ptr->m_values.constEnd())
6368         return QString();
6369 
6370     return cursorDatabase()->cursorToShapeName(it.value());
6371 }
6372 
6373 /*!
6374     \reimp
6375 */
6376 QIcon QtCursorPropertyManager::valueIcon(const QtProperty *property) const
6377 {
6378     const QtCursorPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
6379     if (it == d_ptr->m_values.constEnd())
6380         return QIcon();
6381 
6382     return cursorDatabase()->cursorToShapeIcon(it.value());
6383 }
6384 
6385 /*!
6386     \fn void QtCursorPropertyManager::setValue(QtProperty *property, const QCursor &value)
6387 
6388     Sets the value of the given \a property to \a value.
6389 
6390     \sa value(), valueChanged()
6391 */
6392 void QtCursorPropertyManager::setValue(QtProperty *property, const QCursor &value)
6393 {
6394 #ifndef QT_NO_CURSOR
6395     const QtCursorPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
6396     if (it == d_ptr->m_values.end())
6397         return;
6398 
6399     if (it.value().shape() == value.shape() && value.shape() != Qt::BitmapCursor)
6400         return;
6401 
6402     it.value() = value;
6403 
6404     Q_EMIT propertyChanged(property);
6405     Q_EMIT valueChanged(property, value);
6406 #endif
6407 }
6408 
6409 /*!
6410     \reimp
6411 */
6412 void QtCursorPropertyManager::initializeProperty(QtProperty *property)
6413 {
6414 #ifndef QT_NO_CURSOR
6415     d_ptr->m_values[property] = QCursor();
6416 #endif
6417 }
6418 
6419 /*!
6420     \reimp
6421 */
6422 void QtCursorPropertyManager::uninitializeProperty(QtProperty *property)
6423 {
6424     d_ptr->m_values.remove(property);
6425 }
6426 
6427 QT_END_NAMESPACE
6428 
6429 #include "moc_qtpropertymanager.cpp"
6430 #include "qtpropertymanager.moc"