/**************************************************************************** ** ** Copyright (C) 2016 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the tools applications of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms ** and conditions see https://www.qt.io/terms-conditions. For further ** information use the contact form at https://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser ** General Public License version 3 as published by the Free Software ** Foundation and appearing in the file LICENSE.LGPL3 included in the ** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 3 requirements ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. ** ** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 2.0 or (at your option) the GNU General ** Public license version 3 or any later version approved by the KDE Free ** Qt Foundation. The licenses are as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 ** included in the packaging of this file. Please review the following ** information to ensure the GNU General Public License requirements will ** be met: https://www.gnu.org/licenses/gpl-2.0.html and ** https://www.gnu.org/licenses/gpl-3.0.html. ** ** $QT_END_LICENSE$ ** ****************************************************************************/ #include "qtpropertymanager.h" #include "qtpropertybrowserutils_p.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "config.h" #include "entities/EntitiesManager.h" #include "entities/MeshComponent.h" #include "entities/PathComponent.h" #include "entities/ConeWaveComponent.h" #include "entities/DashedLineComponent.h" #if defined(Q_CC_MSVC) # pragma warning(disable: 4786) /* MS VS 6: truncating debug info after 255 characters */ #endif QT_BEGIN_NAMESPACE template static void setSimpleMinimumData(PrivateData* data, const Value& minVal) { data->minVal = minVal; if (data->maxVal < data->minVal) data->maxVal = data->minVal; if (data->val < data->minVal) data->val = data->minVal; } template static void setSimpleMaximumData(PrivateData* data, const Value& maxVal) { data->maxVal = maxVal; if (data->minVal > data->maxVal) data->minVal = data->maxVal; if (data->val > data->maxVal) data->val = data->maxVal; } template static void setSizeMinimumData(PrivateData* data, const Value& newMinVal) { data->minVal = newMinVal; if (data->maxVal.width() < data->minVal.width()) data->maxVal.setWidth(data->minVal.width()); if (data->maxVal.height() < data->minVal.height()) data->maxVal.setHeight(data->minVal.height()); if (data->val.width() < data->minVal.width()) data->val.setWidth(data->minVal.width()); if (data->val.height() < data->minVal.height()) data->val.setHeight(data->minVal.height()); } template static void setSizeMaximumData(PrivateData* data, const Value& newMaxVal) { data->maxVal = newMaxVal; if (data->minVal.width() > data->maxVal.width()) data->minVal.setWidth(data->maxVal.width()); if (data->minVal.height() > data->maxVal.height()) data->minVal.setHeight(data->maxVal.height()); if (data->val.width() > data->maxVal.width()) data->val.setWidth(data->maxVal.width()); if (data->val.height() > data->maxVal.height()) data->val.setHeight(data->maxVal.height()); } template static SizeValue qBoundSize(const SizeValue& minVal, const SizeValue& val, const SizeValue& maxVal) { SizeValue croppedVal = val; if (minVal.width() > val.width()) croppedVal.setWidth(minVal.width()); else if (maxVal.width() < val.width()) croppedVal.setWidth(maxVal.width()); if (minVal.height() > val.height()) croppedVal.setHeight(minVal.height()); else if (maxVal.height() < val.height()) croppedVal.setHeight(maxVal.height()); return croppedVal; } // Match the exact signature of qBound for VS 6. QSize qBound(QSize minVal, QSize val, QSize maxVal) { return qBoundSize(minVal, val, maxVal); } QSizeF qBound(QSizeF minVal, QSizeF val, QSizeF maxVal) { return qBoundSize(minVal, val, maxVal); } namespace { namespace { template void orderBorders(Value& minVal, Value& maxVal) { if (minVal > maxVal) qSwap(minVal, maxVal); } template static void orderSizeBorders(Value& minVal, Value& maxVal) { Value fromSize = minVal; Value toSize = maxVal; if (fromSize.width() > toSize.width()) { fromSize.setWidth(maxVal.width()); toSize.setWidth(minVal.width()); } if (fromSize.height() > toSize.height()) { fromSize.setHeight(maxVal.height()); toSize.setHeight(minVal.height()); } minVal = fromSize; maxVal = toSize; } void orderBorders(QSize& minVal, QSize& maxVal) { orderSizeBorders(minVal, maxVal); } void orderBorders(QSizeF& minVal, QSizeF& maxVal) { orderSizeBorders(minVal, maxVal); } } } //////// template static Value getData(const QMap& propertyMap, Value PrivateData::* data, const QtProperty* property, const Value& defaultValue = Value()) { const auto it = propertyMap.constFind(property); if (it == propertyMap.constEnd()) return defaultValue; return it.value().*data; } template static Value getValue(const QMap& propertyMap, const QtProperty* property, const Value& defaultValue = Value()) { return getData(propertyMap, &PrivateData::val, property, defaultValue); } template static Value getMinimum(const QMap& propertyMap, const QtProperty* property, const Value& defaultValue = Value()) { return getData(propertyMap, &PrivateData::minVal, property, defaultValue); } template static Value getMaximum(const QMap& propertyMap, const QtProperty* property, const Value& defaultValue = Value()) { return getData(propertyMap, &PrivateData::maxVal, property, defaultValue); } template static void setSimpleValue(QMap& propertyMap, PropertyManager* manager, void (PropertyManager::* propertyChangedSignal)(QtProperty*), void (PropertyManager::* valueChangedSignal)(QtProperty*, ValueChangeParameter), QtProperty* property, const Value& val) { const auto it = propertyMap.find(property); if (it == propertyMap.end()) return; if (it.value() == val) return; it.value() = val; emit(manager->*propertyChangedSignal)(property); emit(manager->*valueChangedSignal)(property, val); } template static void setSimpleValue(PropertyManager* manager, PropertyManagerPrivate* managerPrivate, void (PropertyManager::* propertyChangedSignal)(QtProperty*), void (PropertyManager::* valueChangedSignal)(QtProperty*, ValueChangeParameter), QtProperty* property, const Value& val, void (PropertyManagerPrivate::* setSubPropertyValue)(QtProperty*, ValueChangeParameter)) { const auto it = managerPrivate->m_values.find(property); if (it == managerPrivate->m_values.end()) return; auto& data = it.value(); if (data.val == val) return; data.val = val; if (setSubPropertyValue) (managerPrivate->*setSubPropertyValue)(property, data.val); emit(manager->*propertyChangedSignal)(property); emit(manager->*valueChangedSignal)(property, data.val); } template static void setValueInRange(PropertyManager* manager, PropertyManagerPrivate* managerPrivate, void (PropertyManager::* propertyChangedSignal)(QtProperty*), void (PropertyManager::* valueChangedSignal)(QtProperty*, ValueChangeParameter), QtProperty* property, const Value& val, void (PropertyManagerPrivate::* setSubPropertyValue)(QtProperty*, ValueChangeParameter)) { const auto it = managerPrivate->m_values.find(property); if (it == managerPrivate->m_values.end()) return; auto& data = it.value(); if (data.val == val) { qDebug() << "setValueInRange: value unchanged, returning"; return; } const Value oldVal = data.val; data.val = qBound(data.minVal, val, data.maxVal); if (data.val == oldVal) { qDebug() << "setValueInRange: value same after bound, returning"; return; } if (setSubPropertyValue) (managerPrivate->*setSubPropertyValue)(property, data.val); qDebug() << "setValueInRange: emitting signals for property change"; emit(manager->*propertyChangedSignal)(property); emit(manager->*valueChangedSignal)(property, data.val); } template static void setBorderValues(PropertyManager* manager, PropertyManagerPrivate* managerPrivate, void (PropertyManager::* propertyChangedSignal)(QtProperty*), void (PropertyManager::* valueChangedSignal)(QtProperty*, ValueChangeParameter), void (PropertyManager::* rangeChangedSignal)(QtProperty*, ValueChangeParameter, ValueChangeParameter), QtProperty* property, ValueChangeParameter minVal, ValueChangeParameter maxVal, void (PropertyManagerPrivate::* setSubPropertyRange)(QtProperty*, ValueChangeParameter, ValueChangeParameter, ValueChangeParameter)) { const auto it = managerPrivate->m_values.find(property); if (it == managerPrivate->m_values.end()) return; Value fromVal = minVal; Value toVal = maxVal; orderBorders(fromVal, toVal); auto& data = it.value(); if (data.minVal == fromVal && data.maxVal == toVal) return; const Value oldVal = data.val; data.setMinimumValue(fromVal); data.setMaximumValue(toVal); emit(manager->*rangeChangedSignal)(property, data.minVal, data.maxVal); if (setSubPropertyRange) (managerPrivate->*setSubPropertyRange)(property, data.minVal, data.maxVal, data.val); if (data.val == oldVal) return; emit(manager->*propertyChangedSignal)(property); emit(manager->*valueChangedSignal)(property, data.val); } template static void setBorderValue(PropertyManager* manager, PropertyManagerPrivate* managerPrivate, void (PropertyManager::* propertyChangedSignal)(QtProperty*), void (PropertyManager::* valueChangedSignal)(QtProperty*, ValueChangeParameter), void (PropertyManager::* rangeChangedSignal)(QtProperty*, ValueChangeParameter, ValueChangeParameter), QtProperty* property, Value(PrivateData::* getRangeVal)() const, void (PrivateData::* setRangeVal)(ValueChangeParameter), const Value& borderVal, void (PropertyManagerPrivate::* setSubPropertyRange)(QtProperty*, ValueChangeParameter, ValueChangeParameter, ValueChangeParameter)) { const auto it = managerPrivate->m_values.find(property); if (it == managerPrivate->m_values.end()) return; PrivateData& data = it.value(); if ((data.*getRangeVal)() == borderVal) return; const Value oldVal = data.val; (data.*setRangeVal)(borderVal); emit(manager->*rangeChangedSignal)(property, data.minVal, data.maxVal); if (setSubPropertyRange) (managerPrivate->*setSubPropertyRange)(property, data.minVal, data.maxVal, data.val); if (data.val == oldVal) return; emit(manager->*propertyChangedSignal)(property); emit(manager->*valueChangedSignal)(property, data.val); } template static void setMinimumValue(PropertyManager* manager, PropertyManagerPrivate* managerPrivate, void (PropertyManager::* propertyChangedSignal)(QtProperty*), void (PropertyManager::* valueChangedSignal)(QtProperty*, ValueChangeParameter), void (PropertyManager::* rangeChangedSignal)(QtProperty*, ValueChangeParameter, ValueChangeParameter), QtProperty* property, const Value& minVal) { void (PropertyManagerPrivate:: * setSubPropertyRange)(QtProperty*, ValueChangeParameter, ValueChangeParameter, ValueChangeParameter) = 0; setBorderValue(manager, managerPrivate, propertyChangedSignal, valueChangedSignal, rangeChangedSignal, property, &PropertyManagerPrivate::Data::minimumValue, &PropertyManagerPrivate::Data::setMinimumValue, minVal, setSubPropertyRange); } template static void setMaximumValue(PropertyManager* manager, PropertyManagerPrivate* managerPrivate, void (PropertyManager::* propertyChangedSignal)(QtProperty*), void (PropertyManager::* valueChangedSignal)(QtProperty*, ValueChangeParameter), void (PropertyManager::* rangeChangedSignal)(QtProperty*, ValueChangeParameter, ValueChangeParameter), QtProperty* property, const Value& maxVal) { void (PropertyManagerPrivate:: * setSubPropertyRange)(QtProperty*, ValueChangeParameter, ValueChangeParameter, ValueChangeParameter) = 0; setBorderValue(manager, managerPrivate, propertyChangedSignal, valueChangedSignal, rangeChangedSignal, property, &PropertyManagerPrivate::Data::maximumValue, &PropertyManagerPrivate::Data::setMaximumValue, maxVal, setSubPropertyRange); } class QtMetaEnumWrapper : public QObject { Q_OBJECT Q_PROPERTY(QSizePolicy::Policy policy READ policy) public: QSizePolicy::Policy policy() const { return QSizePolicy::Ignored; } private: QtMetaEnumWrapper(QObject* parent) : QObject(parent) {} }; class QtMetaEnumProvider { public: QtMetaEnumProvider(); QStringList policyEnumNames() const { return m_policyEnumNames; } QStringList languageEnumNames() const { return m_languageEnumNames; } QStringList countryEnumNames(QLocale::Language language) const { return m_countryEnumNames.value(language); } QSizePolicy::Policy indexToSizePolicy(int index) const; int sizePolicyToIndex(QSizePolicy::Policy policy) const; void indexToLocale(int languageIndex, int countryIndex, QLocale::Language* language, QLocale::Country* country) const; void localeToIndex(QLocale::Language language, QLocale::Country country, int* languageIndex, int* countryIndex) const; private: void initLocale(); QStringList m_policyEnumNames; QStringList m_languageEnumNames; QMap m_countryEnumNames; QMap m_indexToLanguage; QMap m_languageToIndex; QMap > m_indexToCountry; QMap > m_countryToIndex; QMetaEnum m_policyEnum; }; static QList sortCountries(const QList& countries) { QMultiMap nameToCountry; for (QLocale::Country country : countries) nameToCountry.insert(QLocale::countryToString(country), country); return nameToCountry.values(); } void QtMetaEnumProvider::initLocale() { QMultiMap nameToLanguage; for (int l = QLocale::C, last = QLocale::LastLanguage; l <= last; ++l) { const QLocale::Language language = static_cast(l); QLocale locale(language); if (locale.language() == language) nameToLanguage.insert(QLocale::languageToString(language), language); } const QLocale system = QLocale::system(); if (!nameToLanguage.contains(QLocale::languageToString(system.language()))) nameToLanguage.insert(QLocale::languageToString(system.language()), system.language()); const auto languages = nameToLanguage.values(); for (QLocale::Language language : languages) { QList countries; countries = QLocale::countriesForLanguage(language); if (countries.isEmpty() && language == system.language()) countries << system.country(); if (!countries.isEmpty() && !m_languageToIndex.contains(language)) { countries = sortCountries(countries); int langIdx = m_languageEnumNames.count(); m_indexToLanguage[langIdx] = language; m_languageToIndex[language] = langIdx; QStringList countryNames; int countryIdx = 0; for (QLocale::Country country : qAsConst(countries)) { countryNames << QLocale::countryToString(country); m_indexToCountry[langIdx][countryIdx] = country; m_countryToIndex[language][country] = countryIdx; ++countryIdx; } m_languageEnumNames << QLocale::languageToString(language); m_countryEnumNames[language] = countryNames; } } } QtMetaEnumProvider::QtMetaEnumProvider() { QMetaProperty p; p = QtMetaEnumWrapper::staticMetaObject.property( QtMetaEnumWrapper::staticMetaObject.propertyOffset() + 0); m_policyEnum = p.enumerator(); const int keyCount = m_policyEnum.keyCount(); for (int i = 0; i < keyCount; i++) m_policyEnumNames << QLatin1String(m_policyEnum.key(i)); initLocale(); } QSizePolicy::Policy QtMetaEnumProvider::indexToSizePolicy(int index) const { return static_cast(m_policyEnum.value(index)); } int QtMetaEnumProvider::sizePolicyToIndex(QSizePolicy::Policy policy) const { const int keyCount = m_policyEnum.keyCount(); for (int i = 0; i < keyCount; i++) if (indexToSizePolicy(i) == policy) return i; return -1; } void QtMetaEnumProvider::indexToLocale(int languageIndex, int countryIndex, QLocale::Language* language, QLocale::Country* country) const { QLocale::Language l = QLocale::C; QLocale::Country c = QLocale::AnyCountry; if (m_indexToLanguage.contains(languageIndex)) { l = m_indexToLanguage[languageIndex]; if (m_indexToCountry.contains(languageIndex) && m_indexToCountry[languageIndex].contains(countryIndex)) c = m_indexToCountry[languageIndex][countryIndex]; } if (language) *language = l; if (country) *country = c; } void QtMetaEnumProvider::localeToIndex(QLocale::Language language, QLocale::Country country, int* languageIndex, int* countryIndex) const { int l = -1; int c = -1; if (m_languageToIndex.contains(language)) { l = m_languageToIndex[language]; if (m_countryToIndex.contains(language) && m_countryToIndex[language].contains(country)) c = m_countryToIndex[language][country]; } if (languageIndex) *languageIndex = l; if (countryIndex) *countryIndex = c; } Q_GLOBAL_STATIC(QtMetaEnumProvider, metaEnumProvider) // QtGroupPropertyManager #pragma region QtGroupPropertyManager /*! \class QtGroupPropertyManager \internal \inmodule QtDesigner \since 4.4 \brief The QtGroupPropertyManager provides and manages group properties. This class is intended to provide a grouping element without any value. \sa QtAbstractPropertyManager */ /*! Creates a manager with the given \a parent. */ QtGroupPropertyManager::QtGroupPropertyManager(QObject* parent) : QtAbstractPropertyManager(parent) { } /*! Destroys this manager, and all the properties it has created. */ QtGroupPropertyManager::~QtGroupPropertyManager() { } /*! \reimp */ bool QtGroupPropertyManager::hasValue(const QtProperty* property) const { Q_UNUSED(property); return false; } /*! \reimp */ void QtGroupPropertyManager::initializeProperty(QtProperty* property) { Q_UNUSED(property); } /*! \reimp */ void QtGroupPropertyManager::uninitializeProperty(QtProperty* property) { Q_UNUSED(property); } #pragma endregion // QtIntPropertyManager #pragma region QtIntPropertyManager class QtIntPropertyManagerPrivate { QtIntPropertyManager* q_ptr; Q_DECLARE_PUBLIC(QtIntPropertyManager) public: struct Data { int val{ 0 }; int initVal{ 0 }; int minVal{ -INT_MAX }; int maxVal{ INT_MAX }; int singleStep{ 1 }; bool isInitialed{ false }; int minimumValue() const { return minVal; } int maximumValue() const { return maxVal; } void setMinimumValue(int newMinVal) { setSimpleMinimumData(this, newMinVal); } void setMaximumValue(int newMaxVal) { setSimpleMaximumData(this, newMaxVal); } }; typedef QMap PropertyValueMap; PropertyValueMap m_values; }; /*! \class QtIntPropertyManager \internal \inmodule QtDesigner \since 4.4 \brief The QtIntPropertyManager provides and manages int properties. An int property has a current value, and a range specifying the valid values. The range is defined by a minimum and a maximum value. The property's value and range can be retrieved using the value(), minimum() and maximum() functions, and can be set using the setValue(), setMinimum() and setMaximum() slots. Alternatively, the range can be defined in one go using the setRange() slot. In addition, QtIntPropertyManager provides the valueChanged() signal which is emitted whenever a property created by this manager changes, and the rangeChanged() signal which is emitted whenever such a property changes its range of valid values. \sa QtAbstractPropertyManager, QtSpinBoxFactory, QtSliderFactory, QtScrollBarFactory */ /*! \fn void QtIntPropertyManager::valueChanged(QtProperty *property, int value) This signal is emitted whenever a property created by this manager changes its value, passing a pointer to the \a property and the new \a value as parameters. \sa setValue() */ /*! \fn void QtIntPropertyManager::rangeChanged(QtProperty *property, int minimum, int maximum) This signal is emitted whenever a property created by this manager changes its range of valid values, passing a pointer to the \a property and the new \a minimum and \a maximum values. \sa setRange() */ /*! \fn void QtIntPropertyManager::singleStepChanged(QtProperty *property, int step) This signal is emitted whenever a property created by this manager changes its single step property, passing a pointer to the \a property and the new \a step value \sa setSingleStep() */ /*! Creates a manager with the given \a parent. */ QtIntPropertyManager::QtIntPropertyManager(QObject* parent) : QtAbstractPropertyManager(parent), d_ptr(new QtIntPropertyManagerPrivate) { d_ptr->q_ptr = this; } /*! Destroys this manager, and all the properties it has created. */ QtIntPropertyManager::~QtIntPropertyManager() { clear(); } /*! Returns the given \a property's value. If the given property is not managed by this manager, this function returns 0. \sa setValue() */ int QtIntPropertyManager::value(const QtProperty* property) const { return getValue(d_ptr->m_values, property, 0); } int QtIntPropertyManager::initialValue(const QtProperty* property) const { return getData(d_ptr->m_values, &QtIntPropertyManagerPrivate::Data::initVal, property, 0); } /*! Returns the given \a property's minimum value. \sa setMinimum(), maximum(), setRange() */ int QtIntPropertyManager::minimum(const QtProperty* property) const { return getMinimum(d_ptr->m_values, property, 0); } /*! Returns the given \a property's maximum value. \sa setMaximum(), minimum(), setRange() */ int QtIntPropertyManager::maximum(const QtProperty* property) const { return getMaximum(d_ptr->m_values, property, 0); } /*! Returns the given \a property's step value. The step is typically used to increment or decrement a property value while pressing an arrow key. \sa setSingleStep() */ int QtIntPropertyManager::singleStep(const QtProperty* property) const { return getData(d_ptr->m_values, &QtIntPropertyManagerPrivate::Data::singleStep, property, 0); } /*! \reimp */ QString QtIntPropertyManager::valueText(const QtProperty* property) const { const QtIntPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); if (it == d_ptr->m_values.constEnd()) return QString(); return QString::number(it.value().val); } /*! \fn void QtIntPropertyManager::setValue(QtProperty *property, int value) Sets the value of the given \a property to \a value. If the specified \a value is not valid according to the given \a property's range, the \a value is adjusted to the nearest valid value within the range. \sa value(), setRange(), valueChanged() */ void QtIntPropertyManager::setValue(QtProperty* property, int val) { qDebug() << "QtIntPropertyManager::setValue called with property:" << property << "value:" << val; const QtIntPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) { qDebug() << "Property not found in m_values!"; return; } QtIntPropertyManagerPrivate::Data& data = it.value(); qDebug() << "Current value:" << data.val << "New value:" << val; if (!data.isInitialed) { data.initVal = val; data.isInitialed = true; } void (QtIntPropertyManagerPrivate:: * setSubPropertyValue)(QtProperty*, int) = 0; setValueInRange(this, d_ptr.data(), &QtIntPropertyManager::propertyChanged, &QtIntPropertyManager::valueChanged, property, val, setSubPropertyValue); } void QtIntPropertyManager::setValueOnly(QtProperty* property, int val) { const QtIntPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; QtIntPropertyManagerPrivate::Data& data = it.value(); if (data.initVal != val) { data.initVal = val; } void (QtIntPropertyManagerPrivate:: * setSubPropertyValue)(QtProperty*, int) = 0; setValueInRange(this, d_ptr.data(), &QtIntPropertyManager::propertyChanged, &QtIntPropertyManager::valueChanged, property, val, setSubPropertyValue); } /*! Sets the minimum value for the given \a property to \a minVal. When setting the minimum value, the maximum and current values are adjusted if necessary (ensuring that the range remains valid and that the current value is within the range). \sa minimum(), setRange(), rangeChanged() */ void QtIntPropertyManager::setMinimum(QtProperty* property, int minVal) { setMinimumValue(this, d_ptr.data(), &QtIntPropertyManager::propertyChanged, &QtIntPropertyManager::valueChanged, &QtIntPropertyManager::rangeChanged, property, minVal); } /*! Sets the maximum value for the given \a property to \a maxVal. When setting maximum value, the minimum and current values are adjusted if necessary (ensuring that the range remains valid and that the current value is within the range). \sa maximum(), setRange(), rangeChanged() */ void QtIntPropertyManager::setMaximum(QtProperty* property, int maxVal) { setMaximumValue(this, d_ptr.data(), &QtIntPropertyManager::propertyChanged, &QtIntPropertyManager::valueChanged, &QtIntPropertyManager::rangeChanged, property, maxVal); } /*! \fn void QtIntPropertyManager::setRange(QtProperty *property, int minimum, int maximum) Sets the range of valid values. This is a convenience function defining the range of valid values in one go; setting the \a minimum and \a maximum values for the given \a property with a single function call. When setting a new range, the current value is adjusted if necessary (ensuring that the value remains within range). \sa setMinimum(), setMaximum(), rangeChanged() */ void QtIntPropertyManager::setRange(QtProperty* property, int minVal, int maxVal) { void (QtIntPropertyManagerPrivate:: * setSubPropertyRange)(QtProperty*, int, int, int) = 0; setBorderValues(this, d_ptr.data(), &QtIntPropertyManager::propertyChanged, &QtIntPropertyManager::valueChanged, &QtIntPropertyManager::rangeChanged, property, minVal, maxVal, setSubPropertyRange); } /*! Sets the step value for the given \a property to \a step. The step is typically used to increment or decrement a property value while pressing an arrow key. \sa singleStep() */ void QtIntPropertyManager::setSingleStep(QtProperty* property, int step) { const QtIntPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; QtIntPropertyManagerPrivate::Data data = it.value(); if (step < 0) step = 0; if (data.singleStep == step) return; data.singleStep = step; it.value() = data; emit singleStepChanged(property, data.singleStep); } /*! \reimp */ void QtIntPropertyManager::initializeProperty(QtProperty* property) { d_ptr->m_values[property] = QtIntPropertyManagerPrivate::Data(); } /*! \reimp */ void QtIntPropertyManager::uninitializeProperty(QtProperty* property) { d_ptr->m_values.remove(property); } #pragma endregion // QtDoublePropertyManager #pragma region QtDoublePropertyManager class QtDoublePropertyManagerPrivate { QtDoublePropertyManager* q_ptr; Q_DECLARE_PUBLIC(QtDoublePropertyManager) public: struct Data { double val{ 0 }; double initVal{ 0 }; double minVal{ -DBL_MAX }; double maxVal{ DBL_MAX }; double singleStep{ 1 }; int decimals{ 6 }; bool isInitialed{ false }; double minimumValue() const { return minVal; } double maximumValue() const { return maxVal; } void setMinimumValue(double newMinVal) { setSimpleMinimumData(this, newMinVal); } void setMaximumValue(double newMaxVal) { setSimpleMaximumData(this, newMaxVal); } }; typedef QMap PropertyValueMap; PropertyValueMap m_values; }; /*! \class QtDoublePropertyManager \internal \inmodule QtDesigner \since 4.4 \brief The QtDoublePropertyManager provides and manages double properties. A double property has a current value, and a range specifying the valid values. The range is defined by a minimum and a maximum value. The property's value and range can be retrieved using the value(), minimum() and maximum() functions, and can be set using the setValue(), setMinimum() and setMaximum() slots. Alternatively, the range can be defined in one go using the setRange() slot. In addition, QtDoublePropertyManager provides the valueChanged() signal which is emitted whenever a property created by this manager changes, and the rangeChanged() signal which is emitted whenever such a property changes its range of valid values. \sa QtAbstractPropertyManager, QtDoubleSpinBoxFactory */ /*! \fn void QtDoublePropertyManager::valueChanged(QtProperty *property, double value) This signal is emitted whenever a property created by this manager changes its value, passing a pointer to the \a property and the new \a value as parameters. \sa setValue() */ /*! \fn void QtDoublePropertyManager::rangeChanged(QtProperty *property, double minimum, double maximum) This signal is emitted whenever a property created by this manager changes its range of valid values, passing a pointer to the \a property and the new \a minimum and \a maximum values \sa setRange() */ /*! \fn void QtDoublePropertyManager::decimalsChanged(QtProperty *property, int prec) This signal is emitted whenever a property created by this manager changes its precision of value, passing a pointer to the \a property and the new \a prec value \sa setDecimals() */ /*! \fn void QtDoublePropertyManager::singleStepChanged(QtProperty *property, double step) This signal is emitted whenever a property created by this manager changes its single step property, passing a pointer to the \a property and the new \a step value \sa setSingleStep() */ /*! Creates a manager with the given \a parent. */ QtDoublePropertyManager::QtDoublePropertyManager(QObject* parent) : QtAbstractPropertyManager(parent), d_ptr(new QtDoublePropertyManagerPrivate) { d_ptr->q_ptr = this; } /*! Destroys this manager, and all the properties it has created. */ QtDoublePropertyManager::~QtDoublePropertyManager() { clear(); } /*! Returns the given \a property's value. If the given property is not managed by this manager, this function returns 0. \sa setValue() */ double QtDoublePropertyManager::value(const QtProperty* property) const { return getValue(d_ptr->m_values, property, 0.0); } double QtDoublePropertyManager::initialValue(const QtProperty* property) const { return getData(d_ptr->m_values, &QtDoublePropertyManagerPrivate::Data::initVal, property, 0); } /*! Returns the given \a property's minimum value. \sa maximum(), setRange() */ double QtDoublePropertyManager::minimum(const QtProperty* property) const { return getMinimum(d_ptr->m_values, property, 0.0); } /*! Returns the given \a property's maximum value. \sa minimum(), setRange() */ double QtDoublePropertyManager::maximum(const QtProperty* property) const { return getMaximum(d_ptr->m_values, property, 0.0); } /*! Returns the given \a property's step value. The step is typically used to increment or decrement a property value while pressing an arrow key. \sa setSingleStep() */ double QtDoublePropertyManager::singleStep(const QtProperty* property) const { return getData(d_ptr->m_values, &QtDoublePropertyManagerPrivate::Data::singleStep, property, 0); } /*! Returns the given \a property's precision, in decimals. \sa setDecimals() */ int QtDoublePropertyManager::decimals(const QtProperty* property) const { return getData(d_ptr->m_values, &QtDoublePropertyManagerPrivate::Data::decimals, property, 0); } /*! \reimp */ QString QtDoublePropertyManager::valueText(const QtProperty* property) const { const QtDoublePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); if (it == d_ptr->m_values.constEnd()) return QString(); int decimals = it.value().decimals; if (!IsDecimalValid(it.value().val)) { decimals = 2; } return QString::number(it.value().val, 'f', decimals); } /*! \fn void QtDoublePropertyManager::setValue(QtProperty *property, double value) Sets the value of the given \a property to \a value. If the specified \a value is not valid according to the given \a property's range, the \a value is adjusted to the nearest valid value within the range. \sa value(), setRange(), valueChanged() */ void QtDoublePropertyManager::setValue(QtProperty* property, double val) { const QtDoublePropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; QtDoublePropertyManagerPrivate::Data& data = it.value(); if (!data.isInitialed) { data.initVal = val; data.isInitialed = true; } void (QtDoublePropertyManagerPrivate:: * setSubPropertyValue)(QtProperty*, double) = 0; setValueInRange(this, d_ptr.data(), &QtDoublePropertyManager::propertyChanged, &QtDoublePropertyManager::valueChanged, property, val, setSubPropertyValue); } void QtDoublePropertyManager::setValueOnly(QtProperty* property, double val) { const QtDoublePropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; QtDoublePropertyManagerPrivate::Data& data = it.value(); if (data.initVal != val) { data.initVal = val; } void (QtDoublePropertyManagerPrivate:: * setSubPropertyValue)(QtProperty*, double) = 0; setValueInRange(this, d_ptr.data(), &QtDoublePropertyManager::propertyChanged, &QtDoublePropertyManager::valueChanged, property, val, setSubPropertyValue); } /*! Sets the step value for the given \a property to \a step. The step is typically used to increment or decrement a property value while pressing an arrow key. \sa singleStep() */ void QtDoublePropertyManager::setSingleStep(QtProperty* property, double step) { const QtDoublePropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; QtDoublePropertyManagerPrivate::Data data = it.value(); if (step < 0) step = 0; if (data.singleStep == step) return; data.singleStep = step; it.value() = data; emit singleStepChanged(property, data.singleStep); } /*! \fn void QtDoublePropertyManager::setDecimals(QtProperty *property, int prec) Sets the precision of the given \a property to \a prec. The valid decimal range is 0-13. The default is 2. \sa decimals() */ void QtDoublePropertyManager::setDecimals(QtProperty* property, int prec) { const QtDoublePropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; QtDoublePropertyManagerPrivate::Data data = it.value(); if (prec > 13) prec = 13; else if (prec < 0) prec = 0; if (data.decimals == prec) return; data.decimals = prec; it.value() = data; emit decimalsChanged(property, data.decimals); } /*! Sets the minimum value for the given \a property to \a minVal. When setting the minimum value, the maximum and current values are adjusted if necessary (ensuring that the range remains valid and that the current value is within in the range). \sa minimum(), setRange(), rangeChanged() */ void QtDoublePropertyManager::setMinimum(QtProperty* property, double minVal) { setMinimumValue(this, d_ptr.data(), &QtDoublePropertyManager::propertyChanged, &QtDoublePropertyManager::valueChanged, &QtDoublePropertyManager::rangeChanged, property, minVal); } /*! Sets the maximum value for the given \a property to \a maxVal. When setting the maximum value, the minimum and current values are adjusted if necessary (ensuring that the range remains valid and that the current value is within in the range). \sa maximum(), setRange(), rangeChanged() */ void QtDoublePropertyManager::setMaximum(QtProperty* property, double maxVal) { setMaximumValue(this, d_ptr.data(), &QtDoublePropertyManager::propertyChanged, &QtDoublePropertyManager::valueChanged, &QtDoublePropertyManager::rangeChanged, property, maxVal); } /*! \fn void QtDoublePropertyManager::setRange(QtProperty *property, double minimum, double maximum) Sets the range of valid values. This is a convenience function defining the range of valid values in one go; setting the \a minimum and \a maximum values for the given \a property with a single function call. When setting a new range, the current value is adjusted if necessary (ensuring that the value remains within range). \sa setMinimum(), setMaximum(), rangeChanged() */ void QtDoublePropertyManager::setRange(QtProperty* property, double minVal, double maxVal) { void (QtDoublePropertyManagerPrivate:: * setSubPropertyRange)(QtProperty*, double, double, double) = 0; setBorderValues(this, d_ptr.data(), &QtDoublePropertyManager::propertyChanged, &QtDoublePropertyManager::valueChanged, &QtDoublePropertyManager::rangeChanged, property, minVal, maxVal, setSubPropertyRange); } /*! \reimp */ void QtDoublePropertyManager::initializeProperty(QtProperty* property) { d_ptr->m_values[property] = QtDoublePropertyManagerPrivate::Data(); } /*! \reimp */ void QtDoublePropertyManager::uninitializeProperty(QtProperty* property) { d_ptr->m_values.remove(property); } #pragma endregion // QtStringPropertyManager #pragma region QtStringPropertyManager class QtStringPropertyManagerPrivate { QtStringPropertyManager* q_ptr; Q_DECLARE_PUBLIC(QtStringPropertyManager) public: struct Data { QString val; QString initVal; bool isInitialed; QRegularExpression regExp; }; typedef QMap PropertyValueMap; QMap m_values; }; /*! \class QtStringPropertyManager \internal \inmodule QtDesigner \since 4.4 \brief The QtStringPropertyManager provides and manages QString properties. A string property's value can be retrieved using the value() function, and set using the setValue() slot. The current value can be checked against a regular expression. To set the regular expression use the setRegExp() slot, use the regExp() function to retrieve the currently set expression. In addition, QtStringPropertyManager provides the valueChanged() signal which is emitted whenever a property created by this manager changes, and the regExpChanged() signal which is emitted whenever such a property changes its currently set regular expression. \sa QtAbstractPropertyManager, QtLineEditFactory */ /*! \fn void QtStringPropertyManager::valueChanged(QtProperty *property, const QString &value) This signal is emitted whenever a property created by this manager changes its value, passing a pointer to the \a property and the new \a value as parameters. \sa setValue() */ /*! \fn void QtStringPropertyManager::regExpChanged(QtProperty *property, const QRegularExpression ®Exp) This signal is emitted whenever a property created by this manager changes its currenlty set regular expression, passing a pointer to the \a property and the new \a regExp as parameters. \sa setRegExp() */ /*! Creates a manager with the given \a parent. */ QtStringPropertyManager::QtStringPropertyManager(QObject* parent) : QtAbstractPropertyManager(parent), d_ptr(new QtStringPropertyManagerPrivate) { d_ptr->q_ptr = this; } /*! Destroys this manager, and all the properties it has created. */ QtStringPropertyManager::~QtStringPropertyManager() { clear(); } /*! Returns the given \a property's value. If the given property is not managed by this manager, this function returns an empty string. \sa setValue() */ QString QtStringPropertyManager::value(const QtProperty* property) const { return getValue(d_ptr->m_values, property); } QString QtStringPropertyManager::initialValue(const QtProperty* property) const { return getData(d_ptr->m_values, &QtStringPropertyManagerPrivate::Data::initVal, property, QString()); } /*! Returns the given \a property's currently set regular expression. If the given \a property is not managed by this manager, this function returns an empty expression. \sa setRegExp() */ QRegularExpression QtStringPropertyManager::regExp(const QtProperty* property) const { return getData(d_ptr->m_values, &QtStringPropertyManagerPrivate::Data::regExp, property, QRegularExpression()); } /*! \reimp */ QString QtStringPropertyManager::valueText(const QtProperty* property) const { const QtStringPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); if (it == d_ptr->m_values.constEnd()) return QString(); return it.value().val; } /*! \fn void QtStringPropertyManager::setValue(QtProperty *property, const QString &value) Sets the value of the given \a property to \a value. If the specified \a value doesn't match the given \a property's regular expression, this function does nothing. \sa value(), setRegExp(), valueChanged() */ void QtStringPropertyManager::setValue(QtProperty* property, const QString& val) { const QtStringPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; QtStringPropertyManagerPrivate::Data data = it.value(); if (data.val == val) return; if (data.regExp.isValid() && !data.regExp.pattern().isEmpty() && !data.regExp.match(val).hasMatch()) { return; } if (!data.isInitialed) { data.initVal = val; data.isInitialed = true; } data.val = val; it.value() = data; emit propertyChanged(property); emit valueChanged(property, data.val); } void QtStringPropertyManager::setValueOnly(QtProperty* property, const QString& val) { const QtStringPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; QtStringPropertyManagerPrivate::Data data = it.value(); if (data.val == val) return; if (data.regExp.isValid() && !data.regExp.pattern().isEmpty() && !data.regExp.match(val).hasMatch()) { return; } data.val = val; data.initVal = val; it.value() = data; emit propertyChanged(property); emit valueChanged(property, data.val); } /*! Sets the regular expression of the given \a property to \a regExp. \sa regExp(), setValue(), regExpChanged() */ void QtStringPropertyManager::setRegExp(QtProperty* property, const QRegularExpression& regExp) { const QtStringPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; QtStringPropertyManagerPrivate::Data data = it.value(); if (data.regExp == regExp) return; data.regExp = regExp; it.value() = data; emit regExpChanged(property, data.regExp); } /*! \reimp */ void QtStringPropertyManager::initializeProperty(QtProperty* property) { d_ptr->m_values[property] = QtStringPropertyManagerPrivate::Data(); } /*! \reimp */ void QtStringPropertyManager::uninitializeProperty(QtProperty* property) { d_ptr->m_values.remove(property); } #pragma endregion // QtFilesPropertyManager #pragma region QtFilesPropertyManager class QtFilesPropertyManagerPrivate { QtFilesPropertyManager* q_ptr; Q_DECLARE_PUBLIC(QtFilesPropertyManager) public: struct Data { QString val; QString initVal; bool isInitialed; }; typedef QMap PropertyValueMap; QMap m_values; }; /*! \class QtStringPropertyManager \internal \inmodule QtDesigner \since 4.4 \brief The QtStringPropertyManager provides and manages QString properties. A string property's value can be retrieved using the value() function, and set using the setValue() slot. The current value can be checked against a regular expression. To set the regular expression use the setRegExp() slot, use the regExp() function to retrieve the currently set expression. In addition, QtStringPropertyManager provides the valueChanged() signal which is emitted whenever a property created by this manager changes, and the regExpChanged() signal which is emitted whenever such a property changes its currently set regular expression. \sa QtAbstractPropertyManager, QtLineEditFactory */ /*! \fn void QtStringPropertyManager::valueChanged(QtProperty *property, const QString &value) This signal is emitted whenever a property created by this manager changes its value, passing a pointer to the \a property and the new \a value as parameters. \sa setValue() */ /*! \fn void QtStringPropertyManager::regExpChanged(QtProperty *property, const QRegularExpression ®Exp) This signal is emitted whenever a property created by this manager changes its currenlty set regular expression, passing a pointer to the \a property and the new \a regExp as parameters. \sa setRegExp() */ /*! Creates a manager with the given \a parent. */ QtFilesPropertyManager::QtFilesPropertyManager(QObject* parent) : QtAbstractPropertyManager(parent), d_ptr(new QtFilesPropertyManagerPrivate) { d_ptr->q_ptr = this; } /*! Destroys this manager, and all the properties it has created. */ QtFilesPropertyManager::~QtFilesPropertyManager() { clear(); } /*! Returns the given \a property's value. If the given property is not managed by this manager, this function returns an empty string. \sa setValue() */ QString QtFilesPropertyManager::value(const QtProperty* property) const { return getValue(d_ptr->m_values, property); } QString QtFilesPropertyManager::initialValue(const QtProperty* property) const { return getData(d_ptr->m_values, &QtFilesPropertyManagerPrivate::Data::initVal, property, QString()); } /*! \reimp */ QString QtFilesPropertyManager::valueText(const QtProperty* property) const { const QtFilesPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); if (it == d_ptr->m_values.constEnd()) return QString(); return it.value().val; } /*! \fn void QtStringPropertyManager::setValue(QtProperty *property, const QString &value) Sets the value of the given \a property to \a value. If the specified \a value doesn't match the given \a property's regular expression, this function does nothing. \sa value(), setRegExp(), valueChanged() */ void QtFilesPropertyManager::setValue(QtProperty* property, const QString& val) { const QtFilesPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; QtFilesPropertyManagerPrivate::Data data = it.value(); if (data.val == val) return; if (!data.isInitialed) { data.initVal = val; data.isInitialed = true; } data.val = val; it.value() = data; emit propertyChanged(property); emit valueChanged(property, data.val); } void QtFilesPropertyManager::setValueOnly(QtProperty* property, const QString& val) { const QtFilesPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; QtFilesPropertyManagerPrivate::Data data = it.value(); if (data.val == val) return; data.val = val; data.initVal = val; it.value() = data; emit propertyChanged(property); emit valueChanged(property, data.val); } /*! \reimp */ void QtFilesPropertyManager::initializeProperty(QtProperty* property) { d_ptr->m_values[property] = QtFilesPropertyManagerPrivate::Data(); } /*! \reimp */ void QtFilesPropertyManager::uninitializeProperty(QtProperty* property) { d_ptr->m_values.remove(property); } #pragma endregion // QtModelFilesPropertyManager #pragma region QtModelFilesPropertyManager class QtModelFilesPropertyManagerPrivate { QtModelFilesPropertyManager* q_ptr; Q_DECLARE_PUBLIC(QtModelFilesPropertyManager) public: struct Data { QString val; QString initVal; bool isInitialed; }; typedef QMap PropertyValueMap; QMap m_values; }; /*! \class QtStringPropertyManager \internal \inmodule QtDesigner \since 4.4 \brief The QtStringPropertyManager provides and manages QString properties. A string property's value can be retrieved using the value() function, and set using the setValue() slot. The current value can be checked against a regular expression. To set the regular expression use the setRegExp() slot, use the regExp() function to retrieve the currently set expression. In addition, QtStringPropertyManager provides the valueChanged() signal which is emitted whenever a property created by this manager changes, and the regExpChanged() signal which is emitted whenever such a property changes its currently set regular expression. \sa QtAbstractPropertyManager, QtLineEditFactory */ /*! \fn void QtStringPropertyManager::valueChanged(QtProperty *property, const QString &value) This signal is emitted whenever a property created by this manager changes its value, passing a pointer to the \a property and the new \a value as parameters. \sa setValue() */ /*! \fn void QtStringPropertyManager::regExpChanged(QtProperty *property, const QRegularExpression ®Exp) This signal is emitted whenever a property created by this manager changes its currenlty set regular expression, passing a pointer to the \a property and the new \a regExp as parameters. \sa setRegExp() */ /*! Creates a manager with the given \a parent. */ QtModelFilesPropertyManager::QtModelFilesPropertyManager(QObject* parent) : QtAbstractPropertyManager(parent), d_ptr(new QtModelFilesPropertyManagerPrivate) { d_ptr->q_ptr = this; } /*! Destroys this manager, and all the properties it has created. */ QtModelFilesPropertyManager::~QtModelFilesPropertyManager() { clear(); } /*! Returns the given \a property's value. If the given property is not managed by this manager, this function returns an empty string. \sa setValue() */ QString QtModelFilesPropertyManager::value(const QtProperty* property) const { return getValue(d_ptr->m_values, property); } QString QtModelFilesPropertyManager::initialValue(const QtProperty* property) const { return getData(d_ptr->m_values, &QtModelFilesPropertyManagerPrivate::Data::initVal, property, QString()); } /*! \reimp */ QString QtModelFilesPropertyManager::valueText(const QtProperty* property) const { const QtModelFilesPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); if (it == d_ptr->m_values.constEnd()) return QString(); return it.value().val; } /*! \fn void QtStringPropertyManager::setValue(QtProperty *property, const QString &value) Sets the value of the given \a property to \a value. If the specified \a value doesn't match the given \a property's regular expression, this function does nothing. \sa value(), setRegExp(), valueChanged() */ void QtModelFilesPropertyManager::setValue(QtProperty* property, const QString& val) { const QtModelFilesPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; QtModelFilesPropertyManagerPrivate::Data data = it.value(); if (data.val == val) return; if (!data.isInitialed) { data.initVal = val; data.isInitialed = true; } data.val = val; it.value() = data; emit propertyChanged(property); emit valueChanged(property, data.val); } void QtModelFilesPropertyManager::setValueOnly(QtProperty* property, const QString& val) { const QtModelFilesPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; QtModelFilesPropertyManagerPrivate::Data data = it.value(); if (data.val == val) return; data.val = val; data.initVal = val; it.value() = data; emit propertyChanged(property); emit valueChanged(property, data.val); } /*! \reimp */ void QtModelFilesPropertyManager::initializeProperty(QtProperty* property) { d_ptr->m_values[property] = QtModelFilesPropertyManagerPrivate::Data(); } /*! \reimp */ void QtModelFilesPropertyManager::uninitializeProperty(QtProperty* property) { d_ptr->m_values.remove(property); } #pragma endregion // QtBoolPropertyManager #pragma region QtBoolPropertyManager // Return an icon containing a check box indicator static QIcon drawCheckBox(bool value) { QStyleOptionButton opt; opt.state |= value ? QStyle::State_On : QStyle::State_Off; opt.state |= QStyle::State_Enabled; const QStyle* style = QApplication::style(); // Figure out size of an indicator and make sure it is not scaled down in a list view item // by making the pixmap as big as a list view icon and centering the indicator in it. // (if it is smaller, it can't be helped) const int indicatorWidth = style->pixelMetric(QStyle::PM_IndicatorWidth, &opt); const int indicatorHeight = style->pixelMetric(QStyle::PM_IndicatorHeight, &opt); const int listViewIconSize = indicatorWidth; const int pixmapWidth = indicatorWidth; const int pixmapHeight = qMax(indicatorHeight, listViewIconSize); opt.rect = QRect(0, 0, indicatorWidth, indicatorHeight); QPixmap pixmap = QPixmap(pixmapWidth, pixmapHeight); pixmap.fill(Qt::transparent); { // Center? const int xoff = (pixmapWidth > indicatorWidth) ? (pixmapWidth - indicatorWidth) / 2 : 0; const int yoff = (pixmapHeight > indicatorHeight) ? (pixmapHeight - indicatorHeight) / 2 : 0; QPainter painter(&pixmap); painter.translate(xoff, yoff); style->drawPrimitive(QStyle::PE_IndicatorCheckBox, &opt, &painter); } return QIcon(pixmap); } class QtBoolPropertyManagerPrivate { QtBoolPropertyManager* q_ptr; Q_DECLARE_PUBLIC(QtBoolPropertyManager) public: QtBoolPropertyManagerPrivate(); struct Data { bool val; bool initVal; bool isInitialed; }; typedef QMap PropertyValueMap; QMap m_values; const QIcon m_checkedIcon; const QIcon m_uncheckedIcon; }; QtBoolPropertyManagerPrivate::QtBoolPropertyManagerPrivate() : m_checkedIcon(drawCheckBox(true)), m_uncheckedIcon(drawCheckBox(false)) { } /*! \class QtBoolPropertyManager \internal \inmodule QtDesigner \since 4.4 \brief The QtBoolPropertyManager class provides and manages boolean properties. The property's value can be retrieved using the value() function, and set using the setValue() slot. In addition, QtBoolPropertyManager provides the valueChanged() signal which is emitted whenever a property created by this manager changes. \sa QtAbstractPropertyManager, QtCheckBoxFactory */ /*! \fn void QtBoolPropertyManager::valueChanged(QtProperty *property, bool value) This signal is emitted whenever a property created by this manager changes its value, passing a pointer to the \a property and the new \a value as parameters. */ /*! Creates a manager with the given \a parent. */ QtBoolPropertyManager::QtBoolPropertyManager(QObject* parent) : QtAbstractPropertyManager(parent), d_ptr(new QtBoolPropertyManagerPrivate) { d_ptr->q_ptr = this; } /*! Destroys this manager, and all the properties it has created. */ QtBoolPropertyManager::~QtBoolPropertyManager() { clear(); } /*! Returns the given \a property's value. If the given \a property is not managed by \e this manager, this function returns false. \sa setValue() */ bool QtBoolPropertyManager::value(const QtProperty* property) const { return getData(d_ptr->m_values, &QtBoolPropertyManagerPrivate::Data::val, property, false); } bool QtBoolPropertyManager::initialValue(const QtProperty* property) const { return getData(d_ptr->m_values, &QtBoolPropertyManagerPrivate::Data::initVal, property, false); } /*! \reimp */ QString QtBoolPropertyManager::valueText(const QtProperty* property) const { const QMap::const_iterator it = d_ptr->m_values.constFind(property); if (it == d_ptr->m_values.constEnd()) return QString(); static const QString trueText = tr("True"); static const QString falseText = tr("False"); return it.value().val ? trueText : falseText; } /*! \reimp */ QIcon QtBoolPropertyManager::valueIcon(const QtProperty* property) const { const QMap::const_iterator it = d_ptr->m_values.constFind(property); if (it == d_ptr->m_values.constEnd()) return QIcon(); return it.value().val ? d_ptr->m_checkedIcon : d_ptr->m_uncheckedIcon; } /*! \fn void QtBoolPropertyManager::setValue(QtProperty *property, bool value) Sets the value of the given \a property to \a value. \sa value() */ void QtBoolPropertyManager::setValue(QtProperty* property, bool val) { const QtBoolPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; QtBoolPropertyManagerPrivate::Data& data = it.value(); if (!data.isInitialed) { data.initVal = val; data.isInitialed = true; } void (QtBoolPropertyManagerPrivate:: * setSubPropertyValue)(QtProperty*, bool) = 0; setSimpleValue(this, d_ptr.data(), &QtBoolPropertyManager::propertyChanged, &QtBoolPropertyManager::valueChanged, property, val, setSubPropertyValue); //emit propertyChanged(property); //emit valueChanged(property, data.val); } void QtBoolPropertyManager::setValueOnly(QtProperty* property, bool val) { const QtBoolPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; QtBoolPropertyManagerPrivate::Data& data = it.value(); if (data.initVal != val) { data.initVal = val; } void (QtBoolPropertyManagerPrivate:: * setSubPropertyValue)(QtProperty*, bool) = 0; setSimpleValue(this, d_ptr.data(), &QtBoolPropertyManager::propertyChanged, &QtBoolPropertyManager::valueChanged, property, val, setSubPropertyValue); } /*! \reimp */ void QtBoolPropertyManager::initializeProperty(QtProperty* property) { d_ptr->m_values[property] = QtBoolPropertyManagerPrivate::Data(); } /*! \reimp */ void QtBoolPropertyManager::uninitializeProperty(QtProperty* property) { d_ptr->m_values.remove(property); } #pragma endregion // QtDatePropertyManager #pragma region QtDatePropertyManager class QtDatePropertyManagerPrivate { QtDatePropertyManager* q_ptr; Q_DECLARE_PUBLIC(QtDatePropertyManager) public: explicit QtDatePropertyManagerPrivate(QtDatePropertyManager* q); struct Data { QDate val{ QDate::currentDate() }; QDate minVal{ QDate(1752, 9, 14) }; QDate maxVal{ QDate(9999, 12, 31) }; QDate initVal{ QDate::currentDate() }; bool isInitialed; QDate minimumValue() const { return minVal; } QDate maximumValue() const { return maxVal; } void setMinimumValue(QDate newMinVal) { setSimpleMinimumData(this, newMinVal); } void setMaximumValue(QDate newMaxVal) { setSimpleMaximumData(this, newMaxVal); } }; QString m_format; typedef QMap PropertyValueMap; QMap m_values; }; QtDatePropertyManagerPrivate::QtDatePropertyManagerPrivate(QtDatePropertyManager* q) : q_ptr(q), m_format(QtPropertyBrowserUtils::dateFormat()) { } /*! \class QtDatePropertyManager \internal \inmodule QtDesigner \since 4.4 \brief The QtDatePropertyManager provides and manages QDate properties. A date property has a current value, and a range specifying the valid dates. The range is defined by a minimum and a maximum value. The property's values can be retrieved using the minimum(), maximum() and value() functions, and can be set using the setMinimum(), setMaximum() and setValue() slots. Alternatively, the range can be defined in one go using the setRange() slot. In addition, QtDatePropertyManager provides the valueChanged() signal which is emitted whenever a property created by this manager changes, and the rangeChanged() signal which is emitted whenever such a property changes its range of valid dates. \sa QtAbstractPropertyManager, QtDateEditFactory, QtDateTimePropertyManager */ /*! \fn void QtDatePropertyManager::valueChanged(QtProperty *property, QDate value) This signal is emitted whenever a property created by this manager changes its value, passing a pointer to the \a property and the new \a value as parameters. \sa setValue() */ /*! \fn void QtDatePropertyManager::rangeChanged(QtProperty *property, QDate minimum, QDate maximum) This signal is emitted whenever a property created by this manager changes its range of valid dates, passing a pointer to the \a property and the new \a minimum and \a maximum dates. \sa setRange() */ /*! Creates a manager with the given \a parent. */ QtDatePropertyManager::QtDatePropertyManager(QObject* parent) : QtAbstractPropertyManager(parent), d_ptr(new QtDatePropertyManagerPrivate(this)) { } /*! Destroys this manager, and all the properties it has created. */ QtDatePropertyManager::~QtDatePropertyManager() { clear(); } /*! Returns the given \a property's value. If the given \a property is not managed by \e this manager, this function returns an invalid date. \sa setValue() */ QDate QtDatePropertyManager::value(const QtProperty* property) const { return getValue(d_ptr->m_values, property); } QDate QtDatePropertyManager::initialValue(const QtProperty* property) const { return getData(d_ptr->m_values, &QtDatePropertyManagerPrivate::Data::initVal, property, QDate::currentDate()); } /*! Returns the given \a property's minimum date. \sa maximum(), setRange() */ QDate QtDatePropertyManager::minimum(const QtProperty* property) const { return getMinimum(d_ptr->m_values, property); } /*! Returns the given \a property's maximum date. \sa minimum(), setRange() */ QDate QtDatePropertyManager::maximum(const QtProperty* property) const { return getMaximum(d_ptr->m_values, property); } /*! \reimp */ QString QtDatePropertyManager::valueText(const QtProperty* property) const { const QtDatePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); if (it == d_ptr->m_values.constEnd()) return QString(); return it.value().val.toString(d_ptr->m_format); } /*! \fn void QtDatePropertyManager::setValue(QtProperty *property, QDate value) Sets the value of the given \a property to \a value. If the specified \a value is not a valid date according to the given \a property's range, the value is adjusted to the nearest valid value within the range. \sa value(), setRange(), valueChanged() */ void QtDatePropertyManager::setValue(QtProperty* property, QDate val) { const QtDatePropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; QtDatePropertyManagerPrivate::Data& data = it.value(); if (!data.isInitialed) { data.initVal = val; data.isInitialed = true; } void (QtDatePropertyManagerPrivate:: * setSubPropertyValue)(QtProperty*, QDate) = 0; setValueInRange(this, d_ptr.data(), &QtDatePropertyManager::propertyChanged, &QtDatePropertyManager::valueChanged, property, val, setSubPropertyValue); } void QtDatePropertyManager::setValueOnly(QtProperty* property, QDate val) { const QtDatePropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; QtDatePropertyManagerPrivate::Data& data = it.value(); if (data.initVal != val) { data.initVal = val; } void (QtDatePropertyManagerPrivate:: * setSubPropertyValue)(QtProperty*, QDate) = 0; setValueInRange(this, d_ptr.data(), &QtDatePropertyManager::propertyChanged, &QtDatePropertyManager::valueChanged, property, val, setSubPropertyValue); } /*! Sets the minimum value for the given \a property to \a minVal. When setting the minimum value, the maximum and current values are adjusted if necessary (ensuring that the range remains valid and that the current value is within in the range). \sa minimum(), setRange() */ void QtDatePropertyManager::setMinimum(QtProperty* property, QDate minVal) { setMinimumValue(this, d_ptr.data(), &QtDatePropertyManager::propertyChanged, &QtDatePropertyManager::valueChanged, &QtDatePropertyManager::rangeChanged, property, minVal); } /*! Sets the maximum value for the given \a property to \a maxVal. When setting the maximum value, the minimum and current values are adjusted if necessary (ensuring that the range remains valid and that the current value is within in the range). \sa maximum(), setRange() */ void QtDatePropertyManager::setMaximum(QtProperty* property, QDate maxVal) { setMaximumValue(this, d_ptr.data(), &QtDatePropertyManager::propertyChanged, &QtDatePropertyManager::valueChanged, &QtDatePropertyManager::rangeChanged, property, maxVal); } /*! \fn void QtDatePropertyManager::setRange(QtProperty *property, QDate minimum, QDate maximum) Sets the range of valid dates. This is a convenience function defining the range of valid dates in one go; setting the \a minimum and \a maximum values for the given \a property with a single function call. When setting a new date range, the current value is adjusted if necessary (ensuring that the value remains in date range). \sa setMinimum(), setMaximum(), rangeChanged() */ void QtDatePropertyManager::setRange(QtProperty* property, QDate minVal, QDate maxVal) { void (QtDatePropertyManagerPrivate:: * setSubPropertyRange)(QtProperty*, QDate, QDate, QDate) = 0; setBorderValues(this, d_ptr.data(), &QtDatePropertyManager::propertyChanged, &QtDatePropertyManager::valueChanged, &QtDatePropertyManager::rangeChanged, property, minVal, maxVal, setSubPropertyRange); } /*! \reimp */ void QtDatePropertyManager::initializeProperty(QtProperty* property) { d_ptr->m_values[property] = QtDatePropertyManagerPrivate::Data(); } /*! \reimp */ void QtDatePropertyManager::uninitializeProperty(QtProperty* property) { d_ptr->m_values.remove(property); } #pragma endregion // QtTimePropertyManager #pragma region QtTimePropertyManager class QtTimePropertyManagerPrivate { QtTimePropertyManager* q_ptr; Q_DECLARE_PUBLIC(QtTimePropertyManager) public: explicit QtTimePropertyManagerPrivate(QtTimePropertyManager* q); const QString m_format; struct Data { QTime val{ QTime() }; QTime initVal{ QTime() }; bool isInitialed{ false }; }; typedef QMap PropertyValueMap; PropertyValueMap m_values; }; QtTimePropertyManagerPrivate::QtTimePropertyManagerPrivate(QtTimePropertyManager* q) : q_ptr(q), m_format(QtPropertyBrowserUtils::timeFormat()) { } /*! \class QtTimePropertyManager \internal \inmodule QtDesigner \since 4.4 \brief The QtTimePropertyManager provides and manages QTime properties. A time property's value can be retrieved using the value() function, and set using the setValue() slot. In addition, QtTimePropertyManager provides the valueChanged() signal which is emitted whenever a property created by this manager changes. \sa QtAbstractPropertyManager, QtTimeEditFactory */ /*! \fn void QtTimePropertyManager::valueChanged(QtProperty *property, QTime value) This signal is emitted whenever a property created by this manager changes its value, passing a pointer to the \a property and the new \a value as parameters. \sa setValue() */ /*! Creates a manager with the given \a parent. */ QtTimePropertyManager::QtTimePropertyManager(QObject* parent) : QtAbstractPropertyManager(parent), d_ptr(new QtTimePropertyManagerPrivate(this)) { } /*! Destroys this manager, and all the properties it has created. */ QtTimePropertyManager::~QtTimePropertyManager() { clear(); } /*! Returns the given \a property's value. If the given property is not managed by this manager, this function returns an invalid time object. \sa setValue() */ QTime QtTimePropertyManager::value(const QtProperty* property) const { return getValue(d_ptr->m_values, property, QTime()); } QTime QtTimePropertyManager::initialValue(const QtProperty* property) const { return getData(d_ptr->m_values, &QtTimePropertyManagerPrivate::Data::initVal, property, QTime()); } /*! \reimp */ QString QtTimePropertyManager::valueText(const QtProperty* property) const { const QtTimePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); if (it == d_ptr->m_values.constEnd()) return QString(); return it.value().val.toString(d_ptr->m_format); } /*! \fn void QtTimePropertyManager::setValue(QtProperty *property, QTime value) Sets the value of the given \a property to \a value. \sa value(), valueChanged() */ void QtTimePropertyManager::setValue(QtProperty* property, QTime val) { const QtTimePropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; QtTimePropertyManagerPrivate::Data& data = it.value(); if (!data.isInitialed) { data.initVal = val; data.isInitialed = true; } void (QtTimePropertyManagerPrivate:: * setSubPropertyValue)(QtProperty*, QTime) = 0; setSimpleValue(this, d_ptr.data(), &QtTimePropertyManager::propertyChanged, &QtTimePropertyManager::valueChanged, property, val, setSubPropertyValue); } void QtTimePropertyManager::setValueOnly(QtProperty* property, QTime val) { const QtTimePropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; QtTimePropertyManagerPrivate::Data& data = it.value(); if (data.initVal != val) { data.initVal = val; } void (QtTimePropertyManagerPrivate:: * setSubPropertyValue)(QtProperty*, QTime) = 0; setSimpleValue(this, d_ptr.data(), &QtTimePropertyManager::propertyChanged, &QtTimePropertyManager::valueChanged, property, val, setSubPropertyValue); } /*! \reimp */ void QtTimePropertyManager::initializeProperty(QtProperty* property) { d_ptr->m_values[property] = QtTimePropertyManagerPrivate::Data(); QTime time = QTime::currentTime(); d_ptr->m_values[property].val = time; d_ptr->m_values[property].initVal = time; } /*! \reimp */ void QtTimePropertyManager::uninitializeProperty(QtProperty* property) { d_ptr->m_values.remove(property); } #pragma endregion // QtDateTimePropertyManager #pragma region QtDateTimePropertyManager class QtDateTimePropertyManagerPrivate { QtDateTimePropertyManager* q_ptr; Q_DECLARE_PUBLIC(QtDateTimePropertyManager) public: explicit QtDateTimePropertyManagerPrivate(QtDateTimePropertyManager* q); const QString m_format; struct Data { QDateTime val{ QDateTime() }; QDateTime initVal{ QDateTime() }; bool isInitialed{ false }; }; typedef QMap PropertyValueMap; PropertyValueMap m_values; }; QtDateTimePropertyManagerPrivate::QtDateTimePropertyManagerPrivate(QtDateTimePropertyManager* q) : q_ptr(q), m_format(QtPropertyBrowserUtils::dateTimeFormat()) { } /*! \class QtDateTimePropertyManager \internal \inmodule QtDesigner \since 4.4 \brief The QtDateTimePropertyManager provides and manages QDateTime properties. A date and time property has a current value which can be retrieved using the value() function, and set using the setValue() slot. In addition, QtDateTimePropertyManager provides the valueChanged() signal which is emitted whenever a property created by this manager changes. \sa QtAbstractPropertyManager, QtDateTimeEditFactory, QtDatePropertyManager */ /*! \fn void QtDateTimePropertyManager::valueChanged(QtProperty *property, const QDateTime &value) This signal is emitted whenever a property created by this manager changes its value, passing a pointer to the \a property and the new \a value as parameters. */ /*! Creates a manager with the given \a parent. */ QtDateTimePropertyManager::QtDateTimePropertyManager(QObject* parent) : QtAbstractPropertyManager(parent), d_ptr(new QtDateTimePropertyManagerPrivate(this)) { } /*! Destroys this manager, and all the properties it has created. */ QtDateTimePropertyManager::~QtDateTimePropertyManager() { clear(); } /*! Returns the given \a property's value. If the given \a property is not managed by this manager, this function returns an invalid QDateTime object. \sa setValue() */ QDateTime QtDateTimePropertyManager::value(const QtProperty* property) const { return getValue(d_ptr->m_values, property, QDateTime()); } QDateTime QtDateTimePropertyManager::initialValue(const QtProperty* property) const { return getData(d_ptr->m_values, &QtDateTimePropertyManagerPrivate::Data::initVal, property, QDateTime()); } /*! \reimp */ QString QtDateTimePropertyManager::valueText(const QtProperty* property) const { const QtDateTimePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); if (it == d_ptr->m_values.constEnd()) return QString(); return it.value().val.toString(d_ptr->m_format); } /*! \fn void QtDateTimePropertyManager::setValue(QtProperty *property, const QDateTime &value) Sets the value of the given \a property to \a value. \sa value(), valueChanged() */ void QtDateTimePropertyManager::setValue(QtProperty* property, const QDateTime& val) { const QtDateTimePropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; QtDateTimePropertyManagerPrivate::Data& data = it.value(); if (!data.isInitialed) { data.initVal = val; data.isInitialed = true; } void (QtDateTimePropertyManagerPrivate:: * setSubPropertyValue)(QtProperty*, const QDateTime&) = 0; setSimpleValue(this, d_ptr.data(), &QtDateTimePropertyManager::propertyChanged, &QtDateTimePropertyManager::valueChanged, property, val, setSubPropertyValue); } void QtDateTimePropertyManager::setValueOnly(QtProperty* property, const QDateTime& val) { const QtDateTimePropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; QtDateTimePropertyManagerPrivate::Data& data = it.value(); if (data.initVal != val) { data.initVal = val; } void (QtDateTimePropertyManagerPrivate:: * setSubPropertyValue)(QtProperty*, const QDateTime&) = 0; setSimpleValue(this, d_ptr.data(), &QtDateTimePropertyManager::propertyChanged, &QtDateTimePropertyManager::valueChanged, property, val, setSubPropertyValue); } /*! \reimp */ void QtDateTimePropertyManager::initializeProperty(QtProperty* property) { d_ptr->m_values[property] = QtDateTimePropertyManagerPrivate::Data(); QDateTime dt = QDateTime::currentDateTime(); d_ptr->m_values[property].val = dt; d_ptr->m_values[property].initVal = dt; } /*! \reimp */ void QtDateTimePropertyManager::uninitializeProperty(QtProperty* property) { d_ptr->m_values.remove(property); } #pragma endregion // QtKeySequencePropertyManager #pragma region QtKeySequencePropertyManager class QtKeySequencePropertyManagerPrivate { QtKeySequencePropertyManager* q_ptr; Q_DECLARE_PUBLIC(QtKeySequencePropertyManager) public: QString m_format; typedef QMap PropertyValueMap; PropertyValueMap m_values; }; /*! \class QtKeySequencePropertyManager \internal \inmodule QtDesigner \since 4.4 \brief The QtKeySequencePropertyManager provides and manages QKeySequence properties. A key sequence's value can be retrieved using the value() function, and set using the setValue() slot. In addition, QtKeySequencePropertyManager provides the valueChanged() signal which is emitted whenever a property created by this manager changes. \sa QtAbstractPropertyManager */ /*! \fn void QtKeySequencePropertyManager::valueChanged(QtProperty *property, const QKeySequence &value) This signal is emitted whenever a property created by this manager changes its value, passing a pointer to the \a property and the new \a value as parameters. */ /*! Creates a manager with the given \a parent. */ QtKeySequencePropertyManager::QtKeySequencePropertyManager(QObject* parent) : QtAbstractPropertyManager(parent), d_ptr(new QtKeySequencePropertyManagerPrivate) { d_ptr->q_ptr = this; } /*! Destroys this manager, and all the properties it has created. */ QtKeySequencePropertyManager::~QtKeySequencePropertyManager() { clear(); } /*! Returns the given \a property's value. If the given \a property is not managed by this manager, this function returns an empty QKeySequence object. \sa setValue() */ QKeySequence QtKeySequencePropertyManager::value(const QtProperty* property) const { return d_ptr->m_values.value(property, QKeySequence()); } /*! \reimp */ QString QtKeySequencePropertyManager::valueText(const QtProperty* property) const { const QtKeySequencePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); if (it == d_ptr->m_values.constEnd()) return QString(); return it.value().toString(QKeySequence::NativeText); } /*! \fn void QtKeySequencePropertyManager::setValue(QtProperty *property, const QKeySequence &value) Sets the value of the given \a property to \a value. \sa value(), valueChanged() */ void QtKeySequencePropertyManager::setValue(QtProperty* property, const QKeySequence& val) { setSimpleValue(d_ptr->m_values, this, &QtKeySequencePropertyManager::propertyChanged, &QtKeySequencePropertyManager::valueChanged, property, val); } /*! \reimp */ void QtKeySequencePropertyManager::initializeProperty(QtProperty* property) { d_ptr->m_values[property] = QKeySequence(); } /*! \reimp */ void QtKeySequencePropertyManager::uninitializeProperty(QtProperty* property) { d_ptr->m_values.remove(property); } #pragma endregion // QtCharPropertyManager #pragma region QtCharPropertyManager class QtCharPropertyManagerPrivate { QtCharPropertyManager* q_ptr; Q_DECLARE_PUBLIC(QtCharPropertyManager) public: typedef QMap PropertyValueMap; PropertyValueMap m_values; }; /*! \class QtCharPropertyManager \internal \inmodule QtDesigner \since 4.4 \brief The QtCharPropertyManager provides and manages QChar properties. A char's value can be retrieved using the value() function, and set using the setValue() slot. In addition, QtCharPropertyManager provides the valueChanged() signal which is emitted whenever a property created by this manager changes. \sa QtAbstractPropertyManager */ /*! \fn void QtCharPropertyManager::valueChanged(QtProperty *property, const QChar &value) This signal is emitted whenever a property created by this manager changes its value, passing a pointer to the \a property and the new \a value as parameters. */ /*! Creates a manager with the given \a parent. */ QtCharPropertyManager::QtCharPropertyManager(QObject* parent) : QtAbstractPropertyManager(parent), d_ptr(new QtCharPropertyManagerPrivate) { d_ptr->q_ptr = this; } /*! Destroys this manager, and all the properties it has created. */ QtCharPropertyManager::~QtCharPropertyManager() { clear(); } /*! Returns the given \a property's value. If the given \a property is not managed by this manager, this function returns an null QChar object. \sa setValue() */ QChar QtCharPropertyManager::value(const QtProperty* property) const { return d_ptr->m_values.value(property, QChar()); } /*! \reimp */ QString QtCharPropertyManager::valueText(const QtProperty* property) const { const QtCharPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); if (it == d_ptr->m_values.constEnd()) return QString(); const QChar c = it.value(); return c.isNull() ? QString() : QString(c); } /*! \fn void QtCharPropertyManager::setValue(QtProperty *property, const QChar &value) Sets the value of the given \a property to \a value. \sa value(), valueChanged() */ void QtCharPropertyManager::setValue(QtProperty* property, const QChar& val) { setSimpleValue(d_ptr->m_values, this, &QtCharPropertyManager::propertyChanged, &QtCharPropertyManager::valueChanged, property, val); } /*! \reimp */ void QtCharPropertyManager::initializeProperty(QtProperty* property) { d_ptr->m_values[property] = QChar(); } /*! \reimp */ void QtCharPropertyManager::uninitializeProperty(QtProperty* property) { d_ptr->m_values.remove(property); } #pragma endregion // QtLocalePropertyManager #pragma region QtLocalePropertyManager class QtLocalePropertyManagerPrivate { QtLocalePropertyManager* q_ptr; Q_DECLARE_PUBLIC(QtLocalePropertyManager) public: QtLocalePropertyManagerPrivate(); void slotEnumChanged(QtProperty* property, int value); void slotPropertyDestroyed(QtProperty* property); typedef QMap PropertyValueMap; PropertyValueMap m_values; QtEnumPropertyManager* m_enumPropertyManager; QMap m_propertyToLanguage; QMap m_propertyToCountry; QMap m_languageToProperty; QMap m_countryToProperty; }; QtLocalePropertyManagerPrivate::QtLocalePropertyManagerPrivate() { } void QtLocalePropertyManagerPrivate::slotEnumChanged(QtProperty* property, int value) { if (QtProperty* prop = m_languageToProperty.value(property, 0)) { const QLocale loc = m_values[prop]; QLocale::Language newLanguage = loc.language(); QLocale::Country newCountry = loc.country(); metaEnumProvider()->indexToLocale(value, 0, &newLanguage, 0); QLocale newLoc(newLanguage, newCountry); q_ptr->setValue(prop, newLoc); } else if (QtProperty* prop = m_countryToProperty.value(property, 0)) { const QLocale loc = m_values[prop]; QLocale::Language newLanguage = loc.language(); QLocale::Country newCountry = loc.country(); metaEnumProvider()->indexToLocale(m_enumPropertyManager->value(m_propertyToLanguage.value(prop)), value, &newLanguage, &newCountry); QLocale newLoc(newLanguage, newCountry); q_ptr->setValue(prop, newLoc); } } void QtLocalePropertyManagerPrivate::slotPropertyDestroyed(QtProperty* property) { if (QtProperty* subProp = m_languageToProperty.value(property, 0)) { m_propertyToLanguage[subProp] = 0; m_languageToProperty.remove(property); } else if (QtProperty* subProp = m_countryToProperty.value(property, 0)) { m_propertyToCountry[subProp] = 0; m_countryToProperty.remove(property); } } /*! \class QtLocalePropertyManager \internal \inmodule QtDesigner \since 4.4 \brief The QtLocalePropertyManager provides and manages QLocale properties. A locale property has nested \e language and \e country subproperties. The top-level property's value can be retrieved using the value() function, and set using the setValue() slot. The subproperties are created by QtEnumPropertyManager object. These submanager can be retrieved using the subEnumPropertyManager() function. In order to provide editing widgets for the subproperties in a property browser widget, this manager must be associated with editor factory. In addition, QtLocalePropertyManager provides the valueChanged() signal which is emitted whenever a property created by this manager changes. \sa QtAbstractPropertyManager, QtEnumPropertyManager */ /*! \fn void QtLocalePropertyManager::valueChanged(QtProperty *property, const QLocale &value) This signal is emitted whenever a property created by this manager changes its value, passing a pointer to the \a property and the new \a value as parameters. \sa setValue() */ /*! Creates a manager with the given \a parent. */ QtLocalePropertyManager::QtLocalePropertyManager(QObject* parent) : QtAbstractPropertyManager(parent), d_ptr(new QtLocalePropertyManagerPrivate) { d_ptr->q_ptr = this; d_ptr->m_enumPropertyManager = new QtEnumPropertyManager(this); connect(d_ptr->m_enumPropertyManager, SIGNAL(valueChanged(QtProperty*, int)), this, SLOT(slotEnumChanged(QtProperty*, int))); connect(d_ptr->m_enumPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)), this, SLOT(slotPropertyDestroyed(QtProperty*))); } /*! Destroys this manager, and all the properties it has created. */ QtLocalePropertyManager::~QtLocalePropertyManager() { clear(); } /*! Returns the manager that creates the nested \e language and \e country subproperties. In order to provide editing widgets for the mentioned subproperties in a property browser widget, this manager must be associated with an editor factory. \sa QtAbstractPropertyBrowser::setFactoryForManager() */ QtEnumPropertyManager* QtLocalePropertyManager::subEnumPropertyManager() const { return d_ptr->m_enumPropertyManager; } /*! Returns the given \a property's value. If the given property is not managed by this manager, this function returns the default locale. \sa setValue() */ QLocale QtLocalePropertyManager::value(const QtProperty* property) const { return d_ptr->m_values.value(property, QLocale()); } /*! \reimp */ QString QtLocalePropertyManager::valueText(const QtProperty* property) const { const QtLocalePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); if (it == d_ptr->m_values.constEnd()) return QString(); const QLocale loc = it.value(); int langIdx = 0; int countryIdx = 0; const QtMetaEnumProvider* me = metaEnumProvider(); me->localeToIndex(loc.language(), loc.country(), &langIdx, &countryIdx); if (langIdx < 0) { qWarning("QtLocalePropertyManager::valueText: Unknown language %d", loc.language()); return tr(""); } const QString languageName = me->languageEnumNames().at(langIdx); if (countryIdx < 0) { qWarning("QtLocalePropertyManager::valueText: Unknown country %d for %s", loc.country(), qPrintable(languageName)); return languageName; } const QString countryName = me->countryEnumNames(loc.language()).at(countryIdx); return tr("%1, %2").arg(languageName, countryName); } /*! \fn void QtLocalePropertyManager::setValue(QtProperty *property, const QLocale &value) Sets the value of the given \a property to \a value. Nested properties are updated automatically. \sa value(), valueChanged() */ void QtLocalePropertyManager::setValue(QtProperty* property, const QLocale& val) { const QtLocalePropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; const QLocale loc = it.value(); if (loc == val) return; it.value() = val; int langIdx = 0; int countryIdx = 0; metaEnumProvider()->localeToIndex(val.language(), val.country(), &langIdx, &countryIdx); if (loc.language() != val.language()) { d_ptr->m_enumPropertyManager->setValue(d_ptr->m_propertyToLanguage.value(property), langIdx); d_ptr->m_enumPropertyManager->setEnumNames(d_ptr->m_propertyToCountry.value(property), metaEnumProvider()->countryEnumNames(val.language())); } d_ptr->m_enumPropertyManager->setValue(d_ptr->m_propertyToCountry.value(property), countryIdx); emit propertyChanged(property); emit valueChanged(property, val); } /*! \reimp */ void QtLocalePropertyManager::initializeProperty(QtProperty* property) { QLocale val; d_ptr->m_values[property] = val; int langIdx = 0; int countryIdx = 0; metaEnumProvider()->localeToIndex(val.language(), val.country(), &langIdx, &countryIdx); QtProperty* languageProp = d_ptr->m_enumPropertyManager->addProperty(); languageProp->setPropertyName(tr("Language")); d_ptr->m_enumPropertyManager->setEnumNames(languageProp, metaEnumProvider()->languageEnumNames()); d_ptr->m_enumPropertyManager->setValue(languageProp, langIdx); d_ptr->m_propertyToLanguage[property] = languageProp; d_ptr->m_languageToProperty[languageProp] = property; property->addSubProperty(languageProp); QtProperty* countryProp = d_ptr->m_enumPropertyManager->addProperty(); countryProp->setPropertyName(tr("Country")); d_ptr->m_enumPropertyManager->setEnumNames(countryProp, metaEnumProvider()->countryEnumNames(val.language())); d_ptr->m_enumPropertyManager->setValue(countryProp, countryIdx); d_ptr->m_propertyToCountry[property] = countryProp; d_ptr->m_countryToProperty[countryProp] = property; property->addSubProperty(countryProp); } /*! \reimp */ void QtLocalePropertyManager::uninitializeProperty(QtProperty* property) { QtProperty* languageProp = d_ptr->m_propertyToLanguage[property]; if (languageProp) { d_ptr->m_languageToProperty.remove(languageProp); delete languageProp; } d_ptr->m_propertyToLanguage.remove(property); QtProperty* countryProp = d_ptr->m_propertyToCountry[property]; if (countryProp) { d_ptr->m_countryToProperty.remove(countryProp); delete countryProp; } d_ptr->m_propertyToCountry.remove(property); d_ptr->m_values.remove(property); } #pragma endregion // QtPointPropertyManager #pragma region QtPointPropertyManager class QtPointPropertyManagerPrivate { QtPointPropertyManager* q_ptr; Q_DECLARE_PUBLIC(QtPointPropertyManager) public: void slotIntChanged(QtProperty* property, int value); void slotPropertyDestroyed(QtProperty* property); typedef QMap PropertyValueMap; PropertyValueMap m_values; QtIntPropertyManager* m_intPropertyManager; QMap m_propertyToX; QMap m_propertyToY; QMap m_xToProperty; QMap m_yToProperty; }; void QtPointPropertyManagerPrivate::slotIntChanged(QtProperty* property, int value) { if (QtProperty* xprop = m_xToProperty.value(property, 0)) { QPoint p = m_values[xprop]; p.setX(value); q_ptr->setValue(xprop, p); } else if (QtProperty* yprop = m_yToProperty.value(property, 0)) { QPoint p = m_values[yprop]; p.setY(value); q_ptr->setValue(yprop, p); } } void QtPointPropertyManagerPrivate::slotPropertyDestroyed(QtProperty* property) { if (QtProperty* pointProp = m_xToProperty.value(property, 0)) { m_propertyToX[pointProp] = 0; m_xToProperty.remove(property); } else if (QtProperty* pointProp = m_yToProperty.value(property, 0)) { m_propertyToY[pointProp] = 0; m_yToProperty.remove(property); } } /*! \class QtPointPropertyManager \internal \inmodule QtDesigner \since 4.4 \brief The QtPointPropertyManager provides and manages QPoint properties. A point property has nested \e x and \e y subproperties. The top-level property's value can be retrieved using the value() function, and set using the setValue() slot. The subproperties are created by a QtIntPropertyManager object. This manager can be retrieved using the subIntPropertyManager() function. In order to provide editing widgets for the subproperties in a property browser widget, this manager must be associated with an editor factory. In addition, QtPointPropertyManager provides the valueChanged() signal which is emitted whenever a property created by this manager changes. \sa QtAbstractPropertyManager, QtIntPropertyManager, QtPointFPropertyManager */ /*! \fn void QtPointPropertyManager::valueChanged(QtProperty *property, const QPoint &value) This signal is emitted whenever a property created by this manager changes its value, passing a pointer to the \a property and the new \a value as parameters. \sa setValue() */ /*! Creates a manager with the given \a parent. */ QtPointPropertyManager::QtPointPropertyManager(QObject* parent) : QtAbstractPropertyManager(parent), d_ptr(new QtPointPropertyManagerPrivate) { d_ptr->q_ptr = this; d_ptr->m_intPropertyManager = new QtIntPropertyManager(this); connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty*, int)), this, SLOT(slotIntChanged(QtProperty*, int))); connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)), this, SLOT(slotPropertyDestroyed(QtProperty*))); } /*! Destroys this manager, and all the properties it has created. */ QtPointPropertyManager::~QtPointPropertyManager() { clear(); } /*! Returns the manager that creates the nested \e x and \e y subproperties. In order to provide editing widgets for the subproperties in a property browser widget, this manager must be associated with an editor factory. \sa QtAbstractPropertyBrowser::setFactoryForManager() */ QtIntPropertyManager* QtPointPropertyManager::subIntPropertyManager() const { return d_ptr->m_intPropertyManager; } /*! Returns the given \a property's value. If the given \a property is not managed by this manager, this function returns a point with coordinates (0, 0). \sa setValue() */ QPoint QtPointPropertyManager::value(const QtProperty* property) const { return d_ptr->m_values.value(property, QPoint()); } /*! \reimp */ QString QtPointPropertyManager::valueText(const QtProperty* property) const { const QtPointPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); if (it == d_ptr->m_values.constEnd()) return QString(); const QPoint v = it.value(); return tr("(%1, %2)").arg(QString::number(v.x())) .arg(QString::number(v.y())); } /*! \fn void QtPointPropertyManager::setValue(QtProperty *property, const QPoint &value) Sets the value of the given \a property to \a value. Nested properties are updated automatically. \sa value(), valueChanged() */ void QtPointPropertyManager::setValue(QtProperty* property, const QPoint& val) { const QtPointPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; if (it.value() == val) return; it.value() = val; d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToX[property], val.x()); d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToY[property], val.y()); emit propertyChanged(property); emit valueChanged(property, val); } /*! \reimp */ void QtPointPropertyManager::initializeProperty(QtProperty* property) { d_ptr->m_values[property] = QPoint(0, 0); QtProperty* xProp = d_ptr->m_intPropertyManager->addProperty(); xProp->setPropertyName(tr("X")); d_ptr->m_intPropertyManager->setValueOnly(xProp, 0); d_ptr->m_propertyToX[property] = xProp; d_ptr->m_xToProperty[xProp] = property; property->addSubProperty(xProp); QtProperty* yProp = d_ptr->m_intPropertyManager->addProperty(); yProp->setPropertyName(tr("Y")); d_ptr->m_intPropertyManager->setValueOnly(yProp, 0); d_ptr->m_propertyToY[property] = yProp; d_ptr->m_yToProperty[yProp] = property; property->addSubProperty(yProp); } /*! \reimp */ void QtPointPropertyManager::uninitializeProperty(QtProperty* property) { QtProperty* xProp = d_ptr->m_propertyToX[property]; if (xProp) { d_ptr->m_xToProperty.remove(xProp); delete xProp; } d_ptr->m_propertyToX.remove(property); QtProperty* yProp = d_ptr->m_propertyToY[property]; if (yProp) { d_ptr->m_yToProperty.remove(yProp); delete yProp; } d_ptr->m_propertyToY.remove(property); d_ptr->m_values.remove(property); } #pragma endregion // QtPointFPropertyManager #pragma region QtPointFPropertyManager class QtPointFPropertyManagerPrivate { QtPointFPropertyManager* q_ptr; Q_DECLARE_PUBLIC(QtPointFPropertyManager) public: struct Data { QPointF val; int decimals{ 2 }; }; void slotDoubleChanged(QtProperty* property, double value); void slotPropertyDestroyed(QtProperty* property); typedef QMap PropertyValueMap; PropertyValueMap m_values; QtDoublePropertyManager* m_doublePropertyManager; QMap m_propertyToX; QMap m_propertyToY; QMap m_xToProperty; QMap m_yToProperty; }; void QtPointFPropertyManagerPrivate::slotDoubleChanged(QtProperty* property, double value) { if (QtProperty* prop = m_xToProperty.value(property, 0)) { QPointF p = m_values[prop].val; p.setX(value); q_ptr->setValue(prop, p); } else if (QtProperty* prop = m_yToProperty.value(property, 0)) { QPointF p = m_values[prop].val; p.setY(value); q_ptr->setValue(prop, p); } } void QtPointFPropertyManagerPrivate::slotPropertyDestroyed(QtProperty* property) { if (QtProperty* pointProp = m_xToProperty.value(property, 0)) { m_propertyToX[pointProp] = 0; m_xToProperty.remove(property); } else if (QtProperty* pointProp = m_yToProperty.value(property, 0)) { m_propertyToY[pointProp] = 0; m_yToProperty.remove(property); } } /*! \class QtPointFPropertyManager \internal \inmodule QtDesigner \since 4.4 \brief The QtPointFPropertyManager provides and manages QPointF properties. A point property has nested \e x and \e y subproperties. The top-level property's value can be retrieved using the value() function, and set using the setValue() slot. The subproperties are created by a QtDoublePropertyManager object. This manager can be retrieved using the subDoublePropertyManager() function. In order to provide editing widgets for the subproperties in a property browser widget, this manager must be associated with an editor factory. In addition, QtPointFPropertyManager provides the valueChanged() signal which is emitted whenever a property created by this manager changes. \sa QtAbstractPropertyManager, QtDoublePropertyManager, QtPointPropertyManager */ /*! \fn void QtPointFPropertyManager::valueChanged(QtProperty *property, const QPointF &value) This signal is emitted whenever a property created by this manager changes its value, passing a pointer to the \a property and the new \a value as parameters. \sa setValue() */ /*! \fn void QtPointFPropertyManager::decimalsChanged(QtProperty *property, int prec) This signal is emitted whenever a property created by this manager changes its precision of value, passing a pointer to the \a property and the new \a prec value \sa setDecimals() */ /*! Creates a manager with the given \a parent. */ QtPointFPropertyManager::QtPointFPropertyManager(QObject* parent) : QtAbstractPropertyManager(parent), d_ptr(new QtPointFPropertyManagerPrivate) { d_ptr->q_ptr = this; d_ptr->m_doublePropertyManager = new QtDoublePropertyManager(this); connect(d_ptr->m_doublePropertyManager, SIGNAL(valueChanged(QtProperty*, double)), this, SLOT(slotDoubleChanged(QtProperty*, double))); connect(d_ptr->m_doublePropertyManager, SIGNAL(propertyDestroyed(QtProperty*)), this, SLOT(slotPropertyDestroyed(QtProperty*))); } /*! Destroys this manager, and all the properties it has created. */ QtPointFPropertyManager::~QtPointFPropertyManager() { clear(); } /*! Returns the manager that creates the nested \e x and \e y subproperties. In order to provide editing widgets for the subproperties in a property browser widget, this manager must be associated with an editor factory. \sa QtAbstractPropertyBrowser::setFactoryForManager() */ QtDoublePropertyManager* QtPointFPropertyManager::subDoublePropertyManager() const { return d_ptr->m_doublePropertyManager; } /*! Returns the given \a property's value. If the given \a property is not managed by this manager, this function returns a point with coordinates (0, 0). \sa setValue() */ QPointF QtPointFPropertyManager::value(const QtProperty* property) const { return getValue(d_ptr->m_values, property); } /*! Returns the given \a property's precision, in decimals. \sa setDecimals() */ int QtPointFPropertyManager::decimals(const QtProperty* property) const { return getData(d_ptr->m_values, &QtPointFPropertyManagerPrivate::Data::decimals, property, 0); } /*! \reimp */ QString QtPointFPropertyManager::valueText(const QtProperty* property) const { const QtPointFPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); if (it == d_ptr->m_values.constEnd()) return QString(); const QPointF v = it.value().val; const int dec = it.value().decimals; return tr("(%1, %2)").arg(QString::number(v.x(), 'f', dec)) .arg(QString::number(v.y(), 'f', dec)); } /*! \fn void QtPointFPropertyManager::setValue(QtProperty *property, const QPointF &value) Sets the value of the given \a property to \a value. Nested properties are updated automatically. \sa value(), valueChanged() */ void QtPointFPropertyManager::setValue(QtProperty* property, const QPointF& val) { const QtPointFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; if (it.value().val == val) return; it.value().val = val; d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToX[property], val.x()); d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToY[property], val.y()); emit propertyChanged(property); emit valueChanged(property, val); } /*! \fn void QtPointFPropertyManager::setDecimals(QtProperty *property, int prec) Sets the precision of the given \a property to \a prec. The valid decimal range is 0-13. The default is 2. \sa decimals() */ void QtPointFPropertyManager::setDecimals(QtProperty* property, int prec) { const QtPointFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; QtPointFPropertyManagerPrivate::Data data = it.value(); if (prec > 13) prec = 13; else if (prec < 0) prec = 0; if (data.decimals == prec) return; data.decimals = prec; d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToX[property], prec); d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToY[property], prec); it.value() = data; emit decimalsChanged(property, data.decimals); } /*! \reimp */ void QtPointFPropertyManager::initializeProperty(QtProperty* property) { d_ptr->m_values[property] = QtPointFPropertyManagerPrivate::Data(); QtProperty* xProp = d_ptr->m_doublePropertyManager->addProperty(); xProp->setPropertyName(tr("X")); d_ptr->m_doublePropertyManager->setDecimals(xProp, decimals(property)); d_ptr->m_doublePropertyManager->setValueOnly(xProp, 0); d_ptr->m_propertyToX[property] = xProp; d_ptr->m_xToProperty[xProp] = property; property->addSubProperty(xProp); QtProperty* yProp = d_ptr->m_doublePropertyManager->addProperty(); yProp->setPropertyName(tr("Y")); d_ptr->m_doublePropertyManager->setDecimals(yProp, decimals(property)); d_ptr->m_doublePropertyManager->setValueOnly(yProp, 0); d_ptr->m_propertyToY[property] = yProp; d_ptr->m_yToProperty[yProp] = property; property->addSubProperty(yProp); } /*! \reimp */ void QtPointFPropertyManager::uninitializeProperty(QtProperty* property) { QtProperty* xProp = d_ptr->m_propertyToX[property]; if (xProp) { d_ptr->m_xToProperty.remove(xProp); delete xProp; } d_ptr->m_propertyToX.remove(property); QtProperty* yProp = d_ptr->m_propertyToY[property]; if (yProp) { d_ptr->m_yToProperty.remove(yProp); delete yProp; } d_ptr->m_propertyToY.remove(property); d_ptr->m_values.remove(property); } #pragma endregion // QtSizePropertyManager #pragma region QtSizePropertyManager class QtSizePropertyManagerPrivate { QtSizePropertyManager* q_ptr; Q_DECLARE_PUBLIC(QtSizePropertyManager) public: void slotIntChanged(QtProperty* property, int value); void slotPropertyDestroyed(QtProperty* property); void setValue(QtProperty* property, const QSize& val); void setRange(QtProperty* property, const QSize& minVal, const QSize& maxVal, const QSize& val); struct Data { QSize val{ 0, 0 }; QSize minVal{ 0, 0 }; QSize maxVal{ INT_MAX, INT_MAX }; QSize minimumValue() const { return minVal; } QSize maximumValue() const { return maxVal; } void setMinimumValue(const QSize& newMinVal) { setSizeMinimumData(this, newMinVal); } void setMaximumValue(const QSize& newMaxVal) { setSizeMaximumData(this, newMaxVal); } }; typedef QMap PropertyValueMap; PropertyValueMap m_values; QtIntPropertyManager* m_intPropertyManager; QMap m_propertyToW; QMap m_propertyToH; QMap m_wToProperty; QMap m_hToProperty; }; void QtSizePropertyManagerPrivate::slotIntChanged(QtProperty* property, int value) { if (QtProperty* prop = m_wToProperty.value(property, 0)) { QSize s = m_values[prop].val; s.setWidth(value); q_ptr->setValue(prop, s); } else if (QtProperty* prop = m_hToProperty.value(property, 0)) { QSize s = m_values[prop].val; s.setHeight(value); q_ptr->setValue(prop, s); } } void QtSizePropertyManagerPrivate::slotPropertyDestroyed(QtProperty* property) { if (QtProperty* pointProp = m_wToProperty.value(property, 0)) { m_propertyToW[pointProp] = 0; m_wToProperty.remove(property); } else if (QtProperty* pointProp = m_hToProperty.value(property, 0)) { m_propertyToH[pointProp] = 0; m_hToProperty.remove(property); } } void QtSizePropertyManagerPrivate::setValue(QtProperty* property, const QSize& val) { m_intPropertyManager->setValue(m_propertyToW.value(property), val.width()); m_intPropertyManager->setValue(m_propertyToH.value(property), val.height()); } void QtSizePropertyManagerPrivate::setRange(QtProperty* property, const QSize& minVal, const QSize& maxVal, const QSize& val) { QtProperty* wProperty = m_propertyToW.value(property); QtProperty* hProperty = m_propertyToH.value(property); m_intPropertyManager->setRange(wProperty, minVal.width(), maxVal.width()); m_intPropertyManager->setValue(wProperty, val.width()); m_intPropertyManager->setRange(hProperty, minVal.height(), maxVal.height()); m_intPropertyManager->setValue(hProperty, val.height()); } /*! \class QtSizePropertyManager \internal \inmodule QtDesigner \since 4.4 \brief The QtSizePropertyManager provides and manages QSize properties. A size property has nested \e width and \e height subproperties. The top-level property's value can be retrieved using the value() function, and set using the setValue() slot. The subproperties are created by a QtIntPropertyManager object. This manager can be retrieved using the subIntPropertyManager() function. In order to provide editing widgets for the subproperties in a property browser widget, this manager must be associated with an editor factory. A size property also has a range of valid values defined by a minimum size and a maximum size. These sizes can be retrieved using the minimum() and the maximum() functions, and set using the setMinimum() and setMaximum() slots. Alternatively, the range can be defined in one go using the setRange() slot. In addition, QtSizePropertyManager provides the valueChanged() signal which is emitted whenever a property created by this manager changes, and the rangeChanged() signal which is emitted whenever such a property changes its range of valid sizes. \sa QtAbstractPropertyManager, QtIntPropertyManager, QtSizeFPropertyManager */ /*! \fn void QtSizePropertyManager::valueChanged(QtProperty *property, const QSize &value) This signal is emitted whenever a property created by this manager changes its value, passing a pointer to the \a property and the new \a value as parameters. \sa setValue() */ /*! \fn void QtSizePropertyManager::rangeChanged(QtProperty *property, const QSize &minimum, const QSize &maximum) This signal is emitted whenever a property created by this manager changes its range of valid sizes, passing a pointer to the \a property and the new \a minimum and \a maximum sizes. \sa setRange() */ /*! Creates a manager with the given \a parent. */ QtSizePropertyManager::QtSizePropertyManager(QObject* parent) : QtAbstractPropertyManager(parent), d_ptr(new QtSizePropertyManagerPrivate) { d_ptr->q_ptr = this; d_ptr->m_intPropertyManager = new QtIntPropertyManager(this); connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty*, int)), this, SLOT(slotIntChanged(QtProperty*, int))); connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)), this, SLOT(slotPropertyDestroyed(QtProperty*))); } /*! Destroys this manager, and all the properties it has created. */ QtSizePropertyManager::~QtSizePropertyManager() { clear(); } /*! Returns the manager that creates the nested \e width and \e height subproperties. In order to provide editing widgets for the \e width and \e height properties in a property browser widget, this manager must be associated with an editor factory. \sa QtAbstractPropertyBrowser::setFactoryForManager() */ QtIntPropertyManager* QtSizePropertyManager::subIntPropertyManager() const { return d_ptr->m_intPropertyManager; } /*! Returns the given \a property's value. If the given \a property is not managed by this manager, this function returns an invalid size \sa setValue() */ QSize QtSizePropertyManager::value(const QtProperty* property) const { return getValue(d_ptr->m_values, property); } /*! Returns the given \a property's minimum size value. \sa setMinimum(), maximum(), setRange() */ QSize QtSizePropertyManager::minimum(const QtProperty* property) const { return getMinimum(d_ptr->m_values, property); } /*! Returns the given \a property's maximum size value. \sa setMaximum(), minimum(), setRange() */ QSize QtSizePropertyManager::maximum(const QtProperty* property) const { return getMaximum(d_ptr->m_values, property); } /*! \reimp */ QString QtSizePropertyManager::valueText(const QtProperty* property) const { const QtSizePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); if (it == d_ptr->m_values.constEnd()) return QString(); const QSize v = it.value().val; return tr("%1 x %2").arg(QString::number(v.width())) .arg(QString::number(v.height())); } /*! \fn void QtSizePropertyManager::setValue(QtProperty *property, const QSize &value) Sets the value of the given \a property to \a value. If the specified \a value is not valid according to the given \a property's size range, the \a value is adjusted to the nearest valid value within the size range. \sa value(), setRange(), valueChanged() */ void QtSizePropertyManager::setValue(QtProperty* property, const QSize& val) { setValueInRange(this, d_ptr.data(), &QtSizePropertyManager::propertyChanged, &QtSizePropertyManager::valueChanged, property, val, &QtSizePropertyManagerPrivate::setValue); } /*! Sets the minimum size value for the given \a property to \a minVal. When setting the minimum size value, the maximum and current values are adjusted if necessary (ensuring that the size range remains valid and that the current value is within the range). \sa minimum(), setRange(), rangeChanged() */ void QtSizePropertyManager::setMinimum(QtProperty* property, const QSize& minVal) { setBorderValue(this, d_ptr.data(), &QtSizePropertyManager::propertyChanged, &QtSizePropertyManager::valueChanged, &QtSizePropertyManager::rangeChanged, property, &QtSizePropertyManagerPrivate::Data::minimumValue, &QtSizePropertyManagerPrivate::Data::setMinimumValue, minVal, &QtSizePropertyManagerPrivate::setRange); } /*! Sets the maximum size value for the given \a property to \a maxVal. When setting the maximum size value, the minimum and current values are adjusted if necessary (ensuring that the size range remains valid and that the current value is within the range). \sa maximum(), setRange(), rangeChanged() */ void QtSizePropertyManager::setMaximum(QtProperty* property, const QSize& maxVal) { setBorderValue(this, d_ptr.data(), &QtSizePropertyManager::propertyChanged, &QtSizePropertyManager::valueChanged, &QtSizePropertyManager::rangeChanged, property, &QtSizePropertyManagerPrivate::Data::maximumValue, &QtSizePropertyManagerPrivate::Data::setMaximumValue, maxVal, &QtSizePropertyManagerPrivate::setRange); } /*! \fn void QtSizePropertyManager::setRange(QtProperty *property, const QSize &minimum, const QSize &maximum) Sets the range of valid values. This is a convenience function defining the range of valid values in one go; setting the \a minimum and \a maximum values for the given \a property with a single function call. When setting a new range, the current value is adjusted if necessary (ensuring that the value remains within the range). \sa setMinimum(), setMaximum(), rangeChanged() */ void QtSizePropertyManager::setRange(QtProperty* property, const QSize& minVal, const QSize& maxVal) { setBorderValues(this, d_ptr.data(), &QtSizePropertyManager::propertyChanged, &QtSizePropertyManager::valueChanged, &QtSizePropertyManager::rangeChanged, property, minVal, maxVal, &QtSizePropertyManagerPrivate::setRange); } /*! \reimp */ void QtSizePropertyManager::initializeProperty(QtProperty* property) { d_ptr->m_values[property] = QtSizePropertyManagerPrivate::Data(); QtProperty* wProp = d_ptr->m_intPropertyManager->addProperty(); wProp->setPropertyName(tr("Width")); d_ptr->m_intPropertyManager->setValueOnly(wProp, 0); d_ptr->m_intPropertyManager->setMinimum(wProp, 0); d_ptr->m_propertyToW[property] = wProp; d_ptr->m_wToProperty[wProp] = property; property->addSubProperty(wProp); QtProperty* hProp = d_ptr->m_intPropertyManager->addProperty(); hProp->setPropertyName(tr("Height")); d_ptr->m_intPropertyManager->setValueOnly(hProp, 0); d_ptr->m_intPropertyManager->setMinimum(hProp, 0); d_ptr->m_propertyToH[property] = hProp; d_ptr->m_hToProperty[hProp] = property; property->addSubProperty(hProp); } /*! \reimp */ void QtSizePropertyManager::uninitializeProperty(QtProperty* property) { QtProperty* wProp = d_ptr->m_propertyToW[property]; if (wProp) { d_ptr->m_wToProperty.remove(wProp); delete wProp; } d_ptr->m_propertyToW.remove(property); QtProperty* hProp = d_ptr->m_propertyToH[property]; if (hProp) { d_ptr->m_hToProperty.remove(hProp); delete hProp; } d_ptr->m_propertyToH.remove(property); d_ptr->m_values.remove(property); } #pragma endregion // QtSizeFPropertyManager #pragma region QtSizeFPropertyManager class QtSizeFPropertyManagerPrivate { QtSizeFPropertyManager* q_ptr; Q_DECLARE_PUBLIC(QtSizeFPropertyManager) public: void slotDoubleChanged(QtProperty* property, double value); void slotPropertyDestroyed(QtProperty* property); void setValue(QtProperty* property, const QSizeF& val); void setRange(QtProperty* property, const QSizeF& minVal, const QSizeF& maxVal, const QSizeF& val); struct Data { QSizeF val{ 0, 0 }; QSizeF minVal{ 0, 0 }; QSizeF maxVal{ std::numeric_limits::max(), std::numeric_limits::max() }; int decimals{ 2 }; QSizeF minimumValue() const { return minVal; } QSizeF maximumValue() const { return maxVal; } void setMinimumValue(const QSizeF& newMinVal) { setSizeMinimumData(this, newMinVal); } void setMaximumValue(const QSizeF& newMaxVal) { setSizeMaximumData(this, newMaxVal); } }; typedef QMap PropertyValueMap; PropertyValueMap m_values; QtDoublePropertyManager* m_doublePropertyManager; QMap m_propertyToW; QMap m_propertyToH; QMap m_wToProperty; QMap m_hToProperty; }; void QtSizeFPropertyManagerPrivate::slotDoubleChanged(QtProperty* property, double value) { if (QtProperty* prop = m_wToProperty.value(property, 0)) { QSizeF s = m_values[prop].val; s.setWidth(value); q_ptr->setValue(prop, s); } else if (QtProperty* prop = m_hToProperty.value(property, 0)) { QSizeF s = m_values[prop].val; s.setHeight(value); q_ptr->setValue(prop, s); } } void QtSizeFPropertyManagerPrivate::slotPropertyDestroyed(QtProperty* property) { if (QtProperty* pointProp = m_wToProperty.value(property, 0)) { m_propertyToW[pointProp] = 0; m_wToProperty.remove(property); } else if (QtProperty* pointProp = m_hToProperty.value(property, 0)) { m_propertyToH[pointProp] = 0; m_hToProperty.remove(property); } } void QtSizeFPropertyManagerPrivate::setValue(QtProperty* property, const QSizeF& val) { m_doublePropertyManager->setValue(m_propertyToW.value(property), val.width()); m_doublePropertyManager->setValue(m_propertyToH.value(property), val.height()); } void QtSizeFPropertyManagerPrivate::setRange(QtProperty* property, const QSizeF& minVal, const QSizeF& maxVal, const QSizeF& val) { m_doublePropertyManager->setRange(m_propertyToW[property], minVal.width(), maxVal.width()); m_doublePropertyManager->setValue(m_propertyToW[property], val.width()); m_doublePropertyManager->setRange(m_propertyToH[property], minVal.height(), maxVal.height()); m_doublePropertyManager->setValue(m_propertyToH[property], val.height()); } /*! \class QtSizeFPropertyManager \internal \inmodule QtDesigner \since 4.4 \brief The QtSizeFPropertyManager provides and manages QSizeF properties. A size property has nested \e width and \e height subproperties. The top-level property's value can be retrieved using the value() function, and set using the setValue() slot. The subproperties are created by a QtDoublePropertyManager object. This manager can be retrieved using the subDoublePropertyManager() function. In order to provide editing widgets for the subproperties in a property browser widget, this manager must be associated with an editor factory. A size property also has a range of valid values defined by a minimum size and a maximum size. These sizes can be retrieved using the minimum() and the maximum() functions, and set using the setMinimum() and setMaximum() slots. Alternatively, the range can be defined in one go using the setRange() slot. In addition, QtSizeFPropertyManager provides the valueChanged() signal which is emitted whenever a property created by this manager changes, and the rangeChanged() signal which is emitted whenever such a property changes its range of valid sizes. \sa QtAbstractPropertyManager, QtDoublePropertyManager, QtSizePropertyManager */ /*! \fn void QtSizeFPropertyManager::valueChanged(QtProperty *property, const QSizeF &value) This signal is emitted whenever a property created by this manager changes its value, passing a pointer to the \a property and the new \a value as parameters. \sa setValue() */ /*! \fn void QtSizeFPropertyManager::rangeChanged(QtProperty *property, const QSizeF &minimum, const QSizeF &maximum) This signal is emitted whenever a property created by this manager changes its range of valid sizes, passing a pointer to the \a property and the new \a minimum and \a maximum sizes. \sa setRange() */ /*! \fn void QtSizeFPropertyManager::decimalsChanged(QtProperty *property, int prec) This signal is emitted whenever a property created by this manager changes its precision of value, passing a pointer to the \a property and the new \a prec value \sa setDecimals() */ /*! Creates a manager with the given \a parent. */ QtSizeFPropertyManager::QtSizeFPropertyManager(QObject* parent) : QtAbstractPropertyManager(parent), d_ptr(new QtSizeFPropertyManagerPrivate) { d_ptr->q_ptr = this; d_ptr->m_doublePropertyManager = new QtDoublePropertyManager(this); connect(d_ptr->m_doublePropertyManager, SIGNAL(valueChanged(QtProperty*, double)), this, SLOT(slotDoubleChanged(QtProperty*, double))); connect(d_ptr->m_doublePropertyManager, SIGNAL(propertyDestroyed(QtProperty*)), this, SLOT(slotPropertyDestroyed(QtProperty*))); } /*! Destroys this manager, and all the properties it has created. */ QtSizeFPropertyManager::~QtSizeFPropertyManager() { clear(); } /*! Returns the manager that creates the nested \e width and \e height subproperties. In order to provide editing widgets for the \e width and \e height properties in a property browser widget, this manager must be associated with an editor factory. \sa QtAbstractPropertyBrowser::setFactoryForManager() */ QtDoublePropertyManager* QtSizeFPropertyManager::subDoublePropertyManager() const { return d_ptr->m_doublePropertyManager; } /*! Returns the given \a property's value. If the given \a property is not managed by this manager, this function returns an invalid size \sa setValue() */ QSizeF QtSizeFPropertyManager::value(const QtProperty* property) const { return getValue(d_ptr->m_values, property); } /*! Returns the given \a property's precision, in decimals. \sa setDecimals() */ int QtSizeFPropertyManager::decimals(const QtProperty* property) const { return getData(d_ptr->m_values, &QtSizeFPropertyManagerPrivate::Data::decimals, property, 0); } /*! Returns the given \a property's minimum size value. \sa setMinimum(), maximum(), setRange() */ QSizeF QtSizeFPropertyManager::minimum(const QtProperty* property) const { return getMinimum(d_ptr->m_values, property); } /*! Returns the given \a property's maximum size value. \sa setMaximum(), minimum(), setRange() */ QSizeF QtSizeFPropertyManager::maximum(const QtProperty* property) const { return getMaximum(d_ptr->m_values, property); } /*! \reimp */ QString QtSizeFPropertyManager::valueText(const QtProperty* property) const { const QtSizeFPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); if (it == d_ptr->m_values.constEnd()) return QString(); const QSizeF v = it.value().val; const int dec = it.value().decimals; return tr("%1 x %2").arg(QString::number(v.width(), 'f', dec)) .arg(QString::number(v.height(), 'f', dec)); } /*! \fn void QtSizeFPropertyManager::setValue(QtProperty *property, const QSizeF &value) Sets the value of the given \a property to \a value. If the specified \a value is not valid according to the given \a property's size range, the \a value is adjusted to the nearest valid value within the size range. \sa value(), setRange(), valueChanged() */ void QtSizeFPropertyManager::setValue(QtProperty* property, const QSizeF& val) { setValueInRange(this, d_ptr.data(), &QtSizeFPropertyManager::propertyChanged, &QtSizeFPropertyManager::valueChanged, property, val, &QtSizeFPropertyManagerPrivate::setValue); } /*! \fn void QtSizeFPropertyManager::setDecimals(QtProperty *property, int prec) Sets the precision of the given \a property to \a prec. The valid decimal range is 0-13. The default is 2. \sa decimals() */ void QtSizeFPropertyManager::setDecimals(QtProperty* property, int prec) { const QtSizeFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; QtSizeFPropertyManagerPrivate::Data data = it.value(); if (prec > 13) prec = 13; else if (prec < 0) prec = 0; if (data.decimals == prec) return; data.decimals = prec; d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToW[property], prec); d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToH[property], prec); it.value() = data; emit decimalsChanged(property, data.decimals); } /*! Sets the minimum size value for the given \a property to \a minVal. When setting the minimum size value, the maximum and current values are adjusted if necessary (ensuring that the size range remains valid and that the current value is within the range). \sa minimum(), setRange(), rangeChanged() */ void QtSizeFPropertyManager::setMinimum(QtProperty* property, const QSizeF& minVal) { setBorderValue(this, d_ptr.data(), &QtSizeFPropertyManager::propertyChanged, &QtSizeFPropertyManager::valueChanged, &QtSizeFPropertyManager::rangeChanged, property, &QtSizeFPropertyManagerPrivate::Data::minimumValue, &QtSizeFPropertyManagerPrivate::Data::setMinimumValue, minVal, &QtSizeFPropertyManagerPrivate::setRange); } /*! Sets the maximum size value for the given \a property to \a maxVal. When setting the maximum size value, the minimum and current values are adjusted if necessary (ensuring that the size range remains valid and that the current value is within the range). \sa maximum(), setRange(), rangeChanged() */ void QtSizeFPropertyManager::setMaximum(QtProperty* property, const QSizeF& maxVal) { setBorderValue(this, d_ptr.data(), &QtSizeFPropertyManager::propertyChanged, &QtSizeFPropertyManager::valueChanged, &QtSizeFPropertyManager::rangeChanged, property, &QtSizeFPropertyManagerPrivate::Data::maximumValue, &QtSizeFPropertyManagerPrivate::Data::setMaximumValue, maxVal, &QtSizeFPropertyManagerPrivate::setRange); } /*! \fn void QtSizeFPropertyManager::setRange(QtProperty *property, const QSizeF &minimum, const QSizeF &maximum) Sets the range of valid values. This is a convenience function defining the range of valid values in one go; setting the \a minimum and \a maximum values for the given \a property with a single function call. When setting a new range, the current value is adjusted if necessary (ensuring that the value remains within the range). \sa setMinimum(), setMaximum(), rangeChanged() */ void QtSizeFPropertyManager::setRange(QtProperty* property, const QSizeF& minVal, const QSizeF& maxVal) { setBorderValues(this, d_ptr.data(), &QtSizeFPropertyManager::propertyChanged, &QtSizeFPropertyManager::valueChanged, &QtSizeFPropertyManager::rangeChanged, property, minVal, maxVal, &QtSizeFPropertyManagerPrivate::setRange); } /*! \reimp */ void QtSizeFPropertyManager::initializeProperty(QtProperty* property) { d_ptr->m_values[property] = QtSizeFPropertyManagerPrivate::Data(); QtProperty* wProp = d_ptr->m_doublePropertyManager->addProperty(); wProp->setPropertyName(tr("Width")); d_ptr->m_doublePropertyManager->setDecimals(wProp, decimals(property)); d_ptr->m_doublePropertyManager->setValueOnly(wProp, 0); d_ptr->m_doublePropertyManager->setMinimum(wProp, 0); d_ptr->m_propertyToW[property] = wProp; d_ptr->m_wToProperty[wProp] = property; property->addSubProperty(wProp); QtProperty* hProp = d_ptr->m_doublePropertyManager->addProperty(); hProp->setPropertyName(tr("Height")); d_ptr->m_doublePropertyManager->setDecimals(hProp, decimals(property)); d_ptr->m_doublePropertyManager->setValueOnly(hProp, 0); d_ptr->m_doublePropertyManager->setMinimum(hProp, 0); d_ptr->m_propertyToH[property] = hProp; d_ptr->m_hToProperty[hProp] = property; property->addSubProperty(hProp); } /*! \reimp */ void QtSizeFPropertyManager::uninitializeProperty(QtProperty* property) { QtProperty* wProp = d_ptr->m_propertyToW[property]; if (wProp) { d_ptr->m_wToProperty.remove(wProp); delete wProp; } d_ptr->m_propertyToW.remove(property); QtProperty* hProp = d_ptr->m_propertyToH[property]; if (hProp) { d_ptr->m_hToProperty.remove(hProp); delete hProp; } d_ptr->m_propertyToH.remove(property); d_ptr->m_values.remove(property); } #pragma endregion // QtRectPropertyManager #pragma region QtRectPropertyManager class QtRectPropertyManagerPrivate { QtRectPropertyManager* q_ptr; Q_DECLARE_PUBLIC(QtRectPropertyManager) public: void slotIntChanged(QtProperty* property, int value); void slotPropertyDestroyed(QtProperty* property); void setConstraint(QtProperty* property, const QRect& constraint, const QRect& val); struct Data { QRect val{ 0, 0, 0, 0 }; QRect constraint; }; typedef QMap PropertyValueMap; PropertyValueMap m_values; QtIntPropertyManager* m_intPropertyManager; QMap m_propertyToX; QMap m_propertyToY; QMap m_propertyToW; QMap m_propertyToH; QMap m_xToProperty; QMap m_yToProperty; QMap m_wToProperty; QMap m_hToProperty; }; void QtRectPropertyManagerPrivate::slotIntChanged(QtProperty* property, int value) { if (QtProperty* prop = m_xToProperty.value(property, 0)) { QRect r = m_values[prop].val; r.moveLeft(value); q_ptr->setValue(prop, r); } else if (QtProperty* prop = m_yToProperty.value(property)) { QRect r = m_values[prop].val; r.moveTop(value); q_ptr->setValue(prop, r); } else if (QtProperty* prop = m_wToProperty.value(property, 0)) { Data data = m_values[prop]; QRect r = data.val; r.setWidth(value); if (!data.constraint.isNull() && data.constraint.x() + data.constraint.width() < r.x() + r.width()) { r.moveLeft(data.constraint.left() + data.constraint.width() - r.width()); } q_ptr->setValue(prop, r); } else if (QtProperty* prop = m_hToProperty.value(property, 0)) { Data data = m_values[prop]; QRect r = data.val; r.setHeight(value); if (!data.constraint.isNull() && data.constraint.y() + data.constraint.height() < r.y() + r.height()) { r.moveTop(data.constraint.top() + data.constraint.height() - r.height()); } q_ptr->setValue(prop, r); } } void QtRectPropertyManagerPrivate::slotPropertyDestroyed(QtProperty* property) { if (QtProperty* pointProp = m_xToProperty.value(property, 0)) { m_propertyToX[pointProp] = 0; m_xToProperty.remove(property); } else if (QtProperty* pointProp = m_yToProperty.value(property, 0)) { m_propertyToY[pointProp] = 0; m_yToProperty.remove(property); } else if (QtProperty* pointProp = m_wToProperty.value(property, 0)) { m_propertyToW[pointProp] = 0; m_wToProperty.remove(property); } else if (QtProperty* pointProp = m_hToProperty.value(property, 0)) { m_propertyToH[pointProp] = 0; m_hToProperty.remove(property); } } void QtRectPropertyManagerPrivate::setConstraint(QtProperty* property, const QRect& constraint, const QRect& val) { const bool isNull = constraint.isNull(); const int left = isNull ? INT_MIN : constraint.left(); const int right = isNull ? INT_MAX : constraint.left() + constraint.width(); const int top = isNull ? INT_MIN : constraint.top(); const int bottom = isNull ? INT_MAX : constraint.top() + constraint.height(); const int width = isNull ? INT_MAX : constraint.width(); const int height = isNull ? INT_MAX : constraint.height(); m_intPropertyManager->setRange(m_propertyToX[property], left, right); m_intPropertyManager->setRange(m_propertyToY[property], top, bottom); m_intPropertyManager->setRange(m_propertyToW[property], 0, width); m_intPropertyManager->setRange(m_propertyToH[property], 0, height); m_intPropertyManager->setValue(m_propertyToX[property], val.x()); m_intPropertyManager->setValue(m_propertyToY[property], val.y()); m_intPropertyManager->setValue(m_propertyToW[property], val.width()); m_intPropertyManager->setValue(m_propertyToH[property], val.height()); } /*! \class QtRectPropertyManager \internal \inmodule QtDesigner \since 4.4 \brief The QtRectPropertyManager provides and manages QRect properties. A rectangle property has nested \e x, \e y, \e width and \e height subproperties. The top-level property's value can be retrieved using the value() function, and set using the setValue() slot. The subproperties are created by a QtIntPropertyManager object. This manager can be retrieved using the subIntPropertyManager() function. In order to provide editing widgets for the subproperties in a property browser widget, this manager must be associated with an editor factory. A rectangle property also has a constraint rectangle which can be retrieved using the constraint() function, and set using the setConstraint() slot. In addition, QtRectPropertyManager provides the valueChanged() signal which is emitted whenever a property created by this manager changes, and the constraintChanged() signal which is emitted whenever such a property changes its constraint rectangle. \sa QtAbstractPropertyManager, QtIntPropertyManager, QtRectFPropertyManager */ /*! \fn void QtRectPropertyManager::valueChanged(QtProperty *property, const QRect &value) This signal is emitted whenever a property created by this manager changes its value, passing a pointer to the \a property and the new \a value as parameters. \sa setValue() */ /*! \fn void QtRectPropertyManager::constraintChanged(QtProperty *property, const QRect &constraint) This signal is emitted whenever property changes its constraint rectangle, passing a pointer to the \a property and the new \a constraint rectangle as parameters. \sa setConstraint() */ /*! Creates a manager with the given \a parent. */ QtRectPropertyManager::QtRectPropertyManager(QObject* parent) : QtAbstractPropertyManager(parent), d_ptr(new QtRectPropertyManagerPrivate) { d_ptr->q_ptr = this; d_ptr->m_intPropertyManager = new QtIntPropertyManager(this); connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty*, int)), this, SLOT(slotIntChanged(QtProperty*, int))); connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)), this, SLOT(slotPropertyDestroyed(QtProperty*))); } /*! Destroys this manager, and all the properties it has created. */ QtRectPropertyManager::~QtRectPropertyManager() { clear(); } /*! Returns the manager that creates the nested \e x, \e y, \e width and \e height subproperties. In order to provide editing widgets for the mentioned subproperties in a property browser widget, this manager must be associated with an editor factory. \sa QtAbstractPropertyBrowser::setFactoryForManager() */ QtIntPropertyManager* QtRectPropertyManager::subIntPropertyManager() const { return d_ptr->m_intPropertyManager; } /*! Returns the given \a property's value. If the given \a property is not managed by this manager, this function returns an invalid rectangle. \sa setValue(), constraint() */ QRect QtRectPropertyManager::value(const QtProperty* property) const { return getValue(d_ptr->m_values, property); } /*! Returns the given \a property's constraining rectangle. If returned value is null QRect it means there is no constraint applied. \sa value(), setConstraint() */ QRect QtRectPropertyManager::constraint(const QtProperty* property) const { return getData(d_ptr->m_values, &QtRectPropertyManagerPrivate::Data::constraint, property, QRect()); } /*! \reimp */ QString QtRectPropertyManager::valueText(const QtProperty* property) const { const QtRectPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); if (it == d_ptr->m_values.constEnd()) return QString(); const QRect v = it.value().val; return tr("[(%1, %2), %3 x %4]").arg(QString::number(v.x())) .arg(QString::number(v.y())) .arg(QString::number(v.width())) .arg(QString::number(v.height())); } /*! \fn void QtRectPropertyManager::setValue(QtProperty *property, const QRect &value) Sets the value of the given \a property to \a value. Nested properties are updated automatically. If the specified \a value is not inside the given \a property's constraining rectangle, the value is adjusted accordingly to fit within the constraint. \sa value(), setConstraint(), valueChanged() */ void QtRectPropertyManager::setValue(QtProperty* property, const QRect& val) { const QtRectPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; QtRectPropertyManagerPrivate::Data data = it.value(); QRect newRect = val.normalized(); if (!data.constraint.isNull() && !data.constraint.contains(newRect)) { const QRect r1 = data.constraint; const QRect r2 = newRect; newRect.setLeft(qMax(r1.left(), r2.left())); newRect.setRight(qMin(r1.right(), r2.right())); newRect.setTop(qMax(r1.top(), r2.top())); newRect.setBottom(qMin(r1.bottom(), r2.bottom())); if (newRect.width() < 0 || newRect.height() < 0) return; } if (data.val == newRect) return; data.val = newRect; it.value() = data; d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToX[property], newRect.x()); d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToY[property], newRect.y()); d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToW[property], newRect.width()); d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToH[property], newRect.height()); emit propertyChanged(property); emit valueChanged(property, data.val); } /*! Sets the given \a property's constraining rectangle to \a constraint. When setting the constraint, the current value is adjusted if necessary (ensuring that the current rectangle value is inside the constraint). In order to reset the constraint pass a null QRect value. \sa setValue(), constraint(), constraintChanged() */ void QtRectPropertyManager::setConstraint(QtProperty* property, const QRect& constraint) { const QtRectPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; QtRectPropertyManagerPrivate::Data data = it.value(); QRect newConstraint = constraint.normalized(); if (data.constraint == newConstraint) return; const QRect oldVal = data.val; data.constraint = newConstraint; if (!data.constraint.isNull() && !data.constraint.contains(oldVal)) { QRect r1 = data.constraint; QRect r2 = data.val; if (r2.width() > r1.width()) r2.setWidth(r1.width()); if (r2.height() > r1.height()) r2.setHeight(r1.height()); if (r2.left() < r1.left()) r2.moveLeft(r1.left()); else if (r2.right() > r1.right()) r2.moveRight(r1.right()); if (r2.top() < r1.top()) r2.moveTop(r1.top()); else if (r2.bottom() > r1.bottom()) r2.moveBottom(r1.bottom()); data.val = r2; } it.value() = data; emit constraintChanged(property, data.constraint); d_ptr->setConstraint(property, data.constraint, data.val); if (data.val == oldVal) return; emit propertyChanged(property); emit valueChanged(property, data.val); } /*! \reimp */ void QtRectPropertyManager::initializeProperty(QtProperty* property) { d_ptr->m_values[property] = QtRectPropertyManagerPrivate::Data(); QtProperty* xProp = d_ptr->m_intPropertyManager->addProperty(); xProp->setPropertyName(tr("X")); d_ptr->m_intPropertyManager->setValueOnly(xProp, 0); d_ptr->m_propertyToX[property] = xProp; d_ptr->m_xToProperty[xProp] = property; property->addSubProperty(xProp); QtProperty* yProp = d_ptr->m_intPropertyManager->addProperty(); yProp->setPropertyName(tr("Y")); d_ptr->m_intPropertyManager->setValueOnly(yProp, 0); d_ptr->m_propertyToY[property] = yProp; d_ptr->m_yToProperty[yProp] = property; property->addSubProperty(yProp); QtProperty* wProp = d_ptr->m_intPropertyManager->addProperty(); wProp->setPropertyName(tr("Width")); d_ptr->m_intPropertyManager->setValueOnly(wProp, 0); d_ptr->m_intPropertyManager->setMinimum(wProp, 0); d_ptr->m_propertyToW[property] = wProp; d_ptr->m_wToProperty[wProp] = property; property->addSubProperty(wProp); QtProperty* hProp = d_ptr->m_intPropertyManager->addProperty(); hProp->setPropertyName(tr("Height")); d_ptr->m_intPropertyManager->setValueOnly(hProp, 0); d_ptr->m_intPropertyManager->setMinimum(hProp, 0); d_ptr->m_propertyToH[property] = hProp; d_ptr->m_hToProperty[hProp] = property; property->addSubProperty(hProp); } /*! \reimp */ void QtRectPropertyManager::uninitializeProperty(QtProperty* property) { QtProperty* xProp = d_ptr->m_propertyToX[property]; if (xProp) { d_ptr->m_xToProperty.remove(xProp); delete xProp; } d_ptr->m_propertyToX.remove(property); QtProperty* yProp = d_ptr->m_propertyToY[property]; if (yProp) { d_ptr->m_yToProperty.remove(yProp); delete yProp; } d_ptr->m_propertyToY.remove(property); QtProperty* wProp = d_ptr->m_propertyToW[property]; if (wProp) { d_ptr->m_wToProperty.remove(wProp); delete wProp; } d_ptr->m_propertyToW.remove(property); QtProperty* hProp = d_ptr->m_propertyToH[property]; if (hProp) { d_ptr->m_hToProperty.remove(hProp); delete hProp; } d_ptr->m_propertyToH.remove(property); d_ptr->m_values.remove(property); } #pragma endregion // QtRectFPropertyManager #pragma region QtRectFPropertyManager class QtRectFPropertyManagerPrivate { QtRectFPropertyManager* q_ptr; Q_DECLARE_PUBLIC(QtRectFPropertyManager) public: void slotDoubleChanged(QtProperty* property, double value); void slotPropertyDestroyed(QtProperty* property); void setConstraint(QtProperty* property, const QRectF& constraint, const QRectF& val); struct Data { QRectF val{ 0, 0, 0, 0 }; QRectF constraint; int decimals{ 2 }; }; typedef QMap PropertyValueMap; PropertyValueMap m_values; QtDoublePropertyManager* m_doublePropertyManager; QMap m_propertyToX; QMap m_propertyToY; QMap m_propertyToW; QMap m_propertyToH; QMap m_xToProperty; QMap m_yToProperty; QMap m_wToProperty; QMap m_hToProperty; }; void QtRectFPropertyManagerPrivate::slotDoubleChanged(QtProperty* property, double value) { if (QtProperty* prop = m_xToProperty.value(property, 0)) { QRectF r = m_values[prop].val; r.moveLeft(value); q_ptr->setValue(prop, r); } else if (QtProperty* prop = m_yToProperty.value(property, 0)) { QRectF r = m_values[prop].val; r.moveTop(value); q_ptr->setValue(prop, r); } else if (QtProperty* prop = m_wToProperty.value(property, 0)) { Data data = m_values[prop]; QRectF r = data.val; r.setWidth(value); if (!data.constraint.isNull() && data.constraint.x() + data.constraint.width() < r.x() + r.width()) { r.moveLeft(data.constraint.left() + data.constraint.width() - r.width()); } q_ptr->setValue(prop, r); } else if (QtProperty* prop = m_hToProperty.value(property, 0)) { Data data = m_values[prop]; QRectF r = data.val; r.setHeight(value); if (!data.constraint.isNull() && data.constraint.y() + data.constraint.height() < r.y() + r.height()) { r.moveTop(data.constraint.top() + data.constraint.height() - r.height()); } q_ptr->setValue(prop, r); } } void QtRectFPropertyManagerPrivate::slotPropertyDestroyed(QtProperty* property) { if (QtProperty* pointProp = m_xToProperty.value(property, 0)) { m_propertyToX[pointProp] = 0; m_xToProperty.remove(property); } else if (QtProperty* pointProp = m_yToProperty.value(property, 0)) { m_propertyToY[pointProp] = 0; m_yToProperty.remove(property); } else if (QtProperty* pointProp = m_wToProperty.value(property, 0)) { m_propertyToW[pointProp] = 0; m_wToProperty.remove(property); } else if (QtProperty* pointProp = m_hToProperty.value(property, 0)) { m_propertyToH[pointProp] = 0; m_hToProperty.remove(property); } } void QtRectFPropertyManagerPrivate::setConstraint(QtProperty* property, const QRectF& constraint, const QRectF& val) { const bool isNull = constraint.isNull(); const float left = isNull ? FLT_MIN : constraint.left(); const float right = isNull ? FLT_MAX : constraint.left() + constraint.width(); const float top = isNull ? FLT_MIN : constraint.top(); const float bottom = isNull ? FLT_MAX : constraint.top() + constraint.height(); const float width = isNull ? FLT_MAX : constraint.width(); const float height = isNull ? FLT_MAX : constraint.height(); m_doublePropertyManager->setRange(m_propertyToX[property], left, right); m_doublePropertyManager->setRange(m_propertyToY[property], top, bottom); m_doublePropertyManager->setRange(m_propertyToW[property], 0, width); m_doublePropertyManager->setRange(m_propertyToH[property], 0, height); m_doublePropertyManager->setValue(m_propertyToX[property], val.x()); m_doublePropertyManager->setValue(m_propertyToY[property], val.y()); m_doublePropertyManager->setValue(m_propertyToW[property], val.width()); m_doublePropertyManager->setValue(m_propertyToH[property], val.height()); } /*! \class QtRectFPropertyManager \internal \inmodule QtDesigner \since 4.4 \brief The QtRectFPropertyManager provides and manages QRectF properties. A rectangle property has nested \e x, \e y, \e width and \e height subproperties. The top-level property's value can be retrieved using the value() function, and set using the setValue() slot. The subproperties are created by a QtDoublePropertyManager object. This manager can be retrieved using the subDoublePropertyManager() function. In order to provide editing widgets for the subproperties in a property browser widget, this manager must be associated with an editor factory. A rectangle property also has a constraint rectangle which can be retrieved using the constraint() function, and set using the setConstraint() slot. In addition, QtRectFPropertyManager provides the valueChanged() signal which is emitted whenever a property created by this manager changes, and the constraintChanged() signal which is emitted whenever such a property changes its constraint rectangle. \sa QtAbstractPropertyManager, QtDoublePropertyManager, QtRectPropertyManager */ /*! \fn void QtRectFPropertyManager::valueChanged(QtProperty *property, const QRectF &value) This signal is emitted whenever a property created by this manager changes its value, passing a pointer to the \a property and the new \a value as parameters. \sa setValue() */ /*! \fn void QtRectFPropertyManager::constraintChanged(QtProperty *property, const QRectF &constraint) This signal is emitted whenever property changes its constraint rectangle, passing a pointer to the \a property and the new \a constraint rectangle as parameters. \sa setConstraint() */ /*! \fn void QtRectFPropertyManager::decimalsChanged(QtProperty *property, int prec) This signal is emitted whenever a property created by this manager changes its precision of value, passing a pointer to the \a property and the new \a prec value \sa setDecimals() */ /*! Creates a manager with the given \a parent. */ QtRectFPropertyManager::QtRectFPropertyManager(QObject* parent) : QtAbstractPropertyManager(parent), d_ptr(new QtRectFPropertyManagerPrivate) { d_ptr->q_ptr = this; d_ptr->m_doublePropertyManager = new QtDoublePropertyManager(this); connect(d_ptr->m_doublePropertyManager, SIGNAL(valueChanged(QtProperty*, double)), this, SLOT(slotDoubleChanged(QtProperty*, double))); connect(d_ptr->m_doublePropertyManager, SIGNAL(propertyDestroyed(QtProperty*)), this, SLOT(slotPropertyDestroyed(QtProperty*))); } /*! Destroys this manager, and all the properties it has created. */ QtRectFPropertyManager::~QtRectFPropertyManager() { clear(); } /*! Returns the manager that creates the nested \e x, \e y, \e width and \e height subproperties. In order to provide editing widgets for the mentioned subproperties in a property browser widget, this manager must be associated with an editor factory. \sa QtAbstractPropertyBrowser::setFactoryForManager() */ QtDoublePropertyManager* QtRectFPropertyManager::subDoublePropertyManager() const { return d_ptr->m_doublePropertyManager; } /*! Returns the given \a property's value. If the given \a property is not managed by this manager, this function returns an invalid rectangle. \sa setValue(), constraint() */ QRectF QtRectFPropertyManager::value(const QtProperty* property) const { return getValue(d_ptr->m_values, property); } /*! Returns the given \a property's precision, in decimals. \sa setDecimals() */ int QtRectFPropertyManager::decimals(const QtProperty* property) const { return getData(d_ptr->m_values, &QtRectFPropertyManagerPrivate::Data::decimals, property, 0); } /*! Returns the given \a property's constraining rectangle. If returned value is null QRectF it means there is no constraint applied. \sa value(), setConstraint() */ QRectF QtRectFPropertyManager::constraint(const QtProperty* property) const { return getData(d_ptr->m_values, &QtRectFPropertyManagerPrivate::Data::constraint, property, QRect()); } /*! \reimp */ QString QtRectFPropertyManager::valueText(const QtProperty* property) const { const QtRectFPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); if (it == d_ptr->m_values.constEnd()) return QString(); const QRectF v = it.value().val; const int dec = it.value().decimals; return QString(tr("[(%1, %2), %3 x %4]").arg(QString::number(v.x(), 'f', dec)) .arg(QString::number(v.y(), 'f', dec)) .arg(QString::number(v.width(), 'f', dec)) .arg(QString::number(v.height(), 'f', dec))); } /*! \fn void QtRectFPropertyManager::setValue(QtProperty *property, const QRectF &value) Sets the value of the given \a property to \a value. Nested properties are updated automatically. If the specified \a value is not inside the given \a property's constraining rectangle, the value is adjusted accordingly to fit within the constraint. \sa value(), setConstraint(), valueChanged() */ void QtRectFPropertyManager::setValue(QtProperty* property, const QRectF& val) { const QtRectFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; QtRectFPropertyManagerPrivate::Data data = it.value(); QRectF newRect = val.normalized(); if (!data.constraint.isNull() && !data.constraint.contains(newRect)) { const QRectF r1 = data.constraint; const QRectF r2 = newRect; newRect.setLeft(qMax(r1.left(), r2.left())); newRect.setRight(qMin(r1.right(), r2.right())); newRect.setTop(qMax(r1.top(), r2.top())); newRect.setBottom(qMin(r1.bottom(), r2.bottom())); if (newRect.width() < 0 || newRect.height() < 0) return; } if (data.val == newRect) return; data.val = newRect; it.value() = data; d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToX[property], newRect.x()); d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToY[property], newRect.y()); d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToW[property], newRect.width()); d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToH[property], newRect.height()); emit propertyChanged(property); emit valueChanged(property, data.val); } /*! Sets the given \a property's constraining rectangle to \a constraint. When setting the constraint, the current value is adjusted if necessary (ensuring that the current rectangle value is inside the constraint). In order to reset the constraint pass a null QRectF value. \sa setValue(), constraint(), constraintChanged() */ void QtRectFPropertyManager::setConstraint(QtProperty* property, const QRectF& constraint) { const QtRectFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; QtRectFPropertyManagerPrivate::Data data = it.value(); QRectF newConstraint = constraint.normalized(); if (data.constraint == newConstraint) return; const QRectF oldVal = data.val; data.constraint = newConstraint; if (!data.constraint.isNull() && !data.constraint.contains(oldVal)) { QRectF r1 = data.constraint; QRectF r2 = data.val; if (r2.width() > r1.width()) r2.setWidth(r1.width()); if (r2.height() > r1.height()) r2.setHeight(r1.height()); if (r2.left() < r1.left()) r2.moveLeft(r1.left()); else if (r2.right() > r1.right()) r2.moveRight(r1.right()); if (r2.top() < r1.top()) r2.moveTop(r1.top()); else if (r2.bottom() > r1.bottom()) r2.moveBottom(r1.bottom()); data.val = r2; } it.value() = data; emit constraintChanged(property, data.constraint); d_ptr->setConstraint(property, data.constraint, data.val); if (data.val == oldVal) return; emit propertyChanged(property); emit valueChanged(property, data.val); } /*! \fn void QtRectFPropertyManager::setDecimals(QtProperty *property, int prec) Sets the precision of the given \a property to \a prec. The valid decimal range is 0-13. The default is 2. \sa decimals() */ void QtRectFPropertyManager::setDecimals(QtProperty* property, int prec) { const QtRectFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; QtRectFPropertyManagerPrivate::Data data = it.value(); if (prec > 13) prec = 13; else if (prec < 0) prec = 0; if (data.decimals == prec) return; data.decimals = prec; d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToX[property], prec); d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToY[property], prec); d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToW[property], prec); d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToH[property], prec); it.value() = data; emit decimalsChanged(property, data.decimals); } /*! \reimp */ void QtRectFPropertyManager::initializeProperty(QtProperty* property) { d_ptr->m_values[property] = QtRectFPropertyManagerPrivate::Data(); QtProperty* xProp = d_ptr->m_doublePropertyManager->addProperty(); xProp->setPropertyName(tr("X")); d_ptr->m_doublePropertyManager->setDecimals(xProp, decimals(property)); d_ptr->m_doublePropertyManager->setValueOnly(xProp, 0); d_ptr->m_propertyToX[property] = xProp; d_ptr->m_xToProperty[xProp] = property; property->addSubProperty(xProp); QtProperty* yProp = d_ptr->m_doublePropertyManager->addProperty(); yProp->setPropertyName(tr("Y")); d_ptr->m_doublePropertyManager->setDecimals(yProp, decimals(property)); d_ptr->m_doublePropertyManager->setValueOnly(yProp, 0); d_ptr->m_propertyToY[property] = yProp; d_ptr->m_yToProperty[yProp] = property; property->addSubProperty(yProp); QtProperty* wProp = d_ptr->m_doublePropertyManager->addProperty(); wProp->setPropertyName(tr("Width")); d_ptr->m_doublePropertyManager->setDecimals(wProp, decimals(property)); d_ptr->m_doublePropertyManager->setValueOnly(wProp, 0); d_ptr->m_doublePropertyManager->setMinimum(wProp, 0); d_ptr->m_propertyToW[property] = wProp; d_ptr->m_wToProperty[wProp] = property; property->addSubProperty(wProp); QtProperty* hProp = d_ptr->m_doublePropertyManager->addProperty(); hProp->setPropertyName(tr("Height")); d_ptr->m_doublePropertyManager->setDecimals(hProp, decimals(property)); d_ptr->m_doublePropertyManager->setValueOnly(hProp, 0); d_ptr->m_doublePropertyManager->setMinimum(hProp, 0); d_ptr->m_propertyToH[property] = hProp; d_ptr->m_hToProperty[hProp] = property; property->addSubProperty(hProp); } /*! \reimp */ void QtRectFPropertyManager::uninitializeProperty(QtProperty* property) { QtProperty* xProp = d_ptr->m_propertyToX[property]; if (xProp) { d_ptr->m_xToProperty.remove(xProp); delete xProp; } d_ptr->m_propertyToX.remove(property); QtProperty* yProp = d_ptr->m_propertyToY[property]; if (yProp) { d_ptr->m_yToProperty.remove(yProp); delete yProp; } d_ptr->m_propertyToY.remove(property); QtProperty* wProp = d_ptr->m_propertyToW[property]; if (wProp) { d_ptr->m_wToProperty.remove(wProp); delete wProp; } d_ptr->m_propertyToW.remove(property); QtProperty* hProp = d_ptr->m_propertyToH[property]; if (hProp) { d_ptr->m_hToProperty.remove(hProp); delete hProp; } d_ptr->m_propertyToH.remove(property); d_ptr->m_values.remove(property); } #pragma endregion // QtEnumPropertyManager #pragma region QtEnumPropertyManager class QtEnumPropertyManagerPrivate { QtEnumPropertyManager* q_ptr; Q_DECLARE_PUBLIC(QtEnumPropertyManager) public: struct Data { int val{ -1 }; QStringList enumNames; QMap enumIcons; }; typedef QMap PropertyValueMap; PropertyValueMap m_values; }; /*! \class QtEnumPropertyManager \internal \inmodule QtDesigner \since 4.4 \brief The QtEnumPropertyManager provides and manages enum properties. Each enum property has an associated list of enum names which can be retrieved using the enumNames() function, and set using the corresponding setEnumNames() function. An enum property's value is represented by an index in this list, and can be retrieved and set using the value() and setValue() slots respectively. Each enum value can also have an associated icon. The mapping from values to icons can be set using the setEnumIcons() function and queried with the enumIcons() function. In addition, QtEnumPropertyManager provides the valueChanged() signal which is emitted whenever a property created by this manager changes. The enumNamesChanged() or enumIconsChanged() signal is emitted whenever the list of enum names or icons is altered. \sa QtAbstractPropertyManager, QtEnumEditorFactory */ /*! \fn void QtEnumPropertyManager::valueChanged(QtProperty *property, int value) This signal is emitted whenever a property created by this manager changes its value, passing a pointer to the \a property and the new \a value as parameters. \sa setValue() */ /*! \fn void QtEnumPropertyManager::enumNamesChanged(QtProperty *property, const QStringList &names) This signal is emitted whenever a property created by this manager changes its enum names, passing a pointer to the \a property and the new \a names as parameters. \sa setEnumNames() */ /*! \fn void QtEnumPropertyManager::enumIconsChanged(QtProperty *property, const QMap &icons) This signal is emitted whenever a property created by this manager changes its enum icons, passing a pointer to the \a property and the new mapping of values to \a icons as parameters. \sa setEnumIcons() */ /*! Creates a manager with the given \a parent. */ QtEnumPropertyManager::QtEnumPropertyManager(QObject* parent) : QtAbstractPropertyManager(parent), d_ptr(new QtEnumPropertyManagerPrivate) { d_ptr->q_ptr = this; } /*! Destroys this manager, and all the properties it has created. */ QtEnumPropertyManager::~QtEnumPropertyManager() { clear(); } /*! Returns the given \a property's value which is an index in the list returned by enumNames() If the given property is not managed by this manager, this function returns -1. \sa enumNames(), setValue() */ int QtEnumPropertyManager::value(const QtProperty* property) const { return getValue(d_ptr->m_values, property, -1); } /*! Returns the given \a property's list of enum names. \sa value(), setEnumNames() */ QStringList QtEnumPropertyManager::enumNames(const QtProperty* property) const { return getData(d_ptr->m_values, &QtEnumPropertyManagerPrivate::Data::enumNames, property, QStringList()); } /*! Returns the given \a property's map of enum values to their icons. \sa value(), setEnumIcons() */ QMap QtEnumPropertyManager::enumIcons(const QtProperty* property) const { return getData >(d_ptr->m_values, &QtEnumPropertyManagerPrivate::Data::enumIcons, property, QMap()); } /*! \reimp */ QString QtEnumPropertyManager::valueText(const QtProperty* property) const { const QtEnumPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); if (it == d_ptr->m_values.constEnd()) return QString(); const QtEnumPropertyManagerPrivate::Data& data = it.value(); const int v = data.val; if (v >= 0 && v < data.enumNames.count()) return data.enumNames.at(v); return QString(); } /*! \reimp */ QIcon QtEnumPropertyManager::valueIcon(const QtProperty* property) const { const QtEnumPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); if (it == d_ptr->m_values.constEnd()) return QIcon(); const QtEnumPropertyManagerPrivate::Data& data = it.value(); const int v = data.val; return data.enumIcons.value(v); } /*! \fn void QtEnumPropertyManager::setValue(QtProperty *property, int value) Sets the value of the given \a property to \a value. The specified \a value must be less than the size of the given \a property's enumNames() list, and larger than (or equal to) 0. \sa value(), valueChanged() */ void QtEnumPropertyManager::setValue(QtProperty* property, int val) { const QtEnumPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; QtEnumPropertyManagerPrivate::Data data = it.value(); if (val >= data.enumNames.count()) return; if (val < 0 && data.enumNames.count() > 0) return; if (val < 0) val = -1; if (data.val == val) return; data.val = val; it.value() = data; emit propertyChanged(property); emit valueChanged(property, data.val); } /*! Sets the given \a property's list of enum names to \a enumNames. The \a property's current value is reset to 0 indicating the first item of the list. If the specified \a enumNames list is empty, the \a property's current value is set to -1. \sa enumNames(), enumNamesChanged() */ void QtEnumPropertyManager::setEnumNames(QtProperty* property, const QStringList& enumNames) { const QtEnumPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; QtEnumPropertyManagerPrivate::Data data = it.value(); if (data.enumNames == enumNames) return; data.enumNames = enumNames; data.val = -1; if (enumNames.count() > 0) data.val = 0; it.value() = data; emit enumNamesChanged(property, data.enumNames); emit propertyChanged(property); emit valueChanged(property, data.val); } /*! Sets the given \a property's map of enum values to their icons to \a enumIcons. Each enum value can have associated icon. This association is represented with passed \a enumIcons map. \sa enumNames(), enumNamesChanged() */ void QtEnumPropertyManager::setEnumIcons(QtProperty* property, const QMap& enumIcons) { const QtEnumPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; it.value().enumIcons = enumIcons; emit enumIconsChanged(property, it.value().enumIcons); emit propertyChanged(property); } /*! \reimp */ void QtEnumPropertyManager::initializeProperty(QtProperty* property) { d_ptr->m_values[property] = QtEnumPropertyManagerPrivate::Data(); } /*! \reimp */ void QtEnumPropertyManager::uninitializeProperty(QtProperty* property) { d_ptr->m_values.remove(property); } #pragma endregion // QtFlagPropertyManager #pragma region QtFlagPropertyManager class QtFlagPropertyManagerPrivate { QtFlagPropertyManager* q_ptr; Q_DECLARE_PUBLIC(QtFlagPropertyManager) public: void slotBoolChanged(QtProperty* property, bool value); void slotPropertyDestroyed(QtProperty* property); struct Data { int val{ -1 }; QStringList flagNames; }; typedef QMap PropertyValueMap; PropertyValueMap m_values; QtBoolPropertyManager* m_boolPropertyManager; QMap > m_propertyToFlags; QMap m_flagToProperty; }; void QtFlagPropertyManagerPrivate::slotBoolChanged(QtProperty* property, bool value) { QtProperty* prop = m_flagToProperty.value(property, 0); if (prop == 0) return; const auto pfit = m_propertyToFlags.constFind(prop); if (pfit == m_propertyToFlags.constEnd()) return; int level = 0; for (QtProperty* p : pfit.value()) { if (p == property) { int v = m_values[prop].val; if (value) { v |= (1 << level); } else { v &= ~(1 << level); } q_ptr->setValue(prop, v); return; } level++; } } void QtFlagPropertyManagerPrivate::slotPropertyDestroyed(QtProperty* property) { QtProperty* flagProperty = m_flagToProperty.value(property, 0); if (flagProperty == 0) return; m_propertyToFlags[flagProperty].replace(m_propertyToFlags[flagProperty].indexOf(property), 0); m_flagToProperty.remove(property); } /*! \class QtFlagPropertyManager \internal \inmodule QtDesigner \since 4.4 \brief The QtFlagPropertyManager provides and manages flag properties. Each flag property has an associated list of flag names which can be retrieved using the flagNames() function, and set using the corresponding setFlagNames() function. The flag manager provides properties with nested boolean subproperties representing each flag, i.e. a flag property's value is the binary combination of the subproperties' values. A property's value can be retrieved and set using the value() and setValue() slots respectively. The combination of flags is represented by single int value - that's why it's possible to store up to 32 independent flags in one flag property. The subproperties are created by a QtBoolPropertyManager object. This manager can be retrieved using the subBoolPropertyManager() function. In order to provide editing widgets for the subproperties in a property browser widget, this manager must be associated with an editor factory. In addition, QtFlagPropertyManager provides the valueChanged() signal which is emitted whenever a property created by this manager changes, and the flagNamesChanged() signal which is emitted whenever the list of flag names is altered. \sa QtAbstractPropertyManager, QtBoolPropertyManager */ /*! \fn void QtFlagPropertyManager::valueChanged(QtProperty *property, int value) This signal is emitted whenever a property created by this manager changes its value, passing a pointer to the \a property and the new \a value as parameters. \sa setValue() */ /*! \fn void QtFlagPropertyManager::flagNamesChanged(QtProperty *property, const QStringList &names) This signal is emitted whenever a property created by this manager changes its flag names, passing a pointer to the \a property and the new \a names as parameters. \sa setFlagNames() */ /*! Creates a manager with the given \a parent. */ QtFlagPropertyManager::QtFlagPropertyManager(QObject* parent) : QtAbstractPropertyManager(parent), d_ptr(new QtFlagPropertyManagerPrivate) { d_ptr->q_ptr = this; d_ptr->m_boolPropertyManager = new QtBoolPropertyManager(this); connect(d_ptr->m_boolPropertyManager, SIGNAL(valueChanged(QtProperty*, bool)), this, SLOT(slotBoolChanged(QtProperty*, bool))); connect(d_ptr->m_boolPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)), this, SLOT(slotPropertyDestroyed(QtProperty*))); } /*! Destroys this manager, and all the properties it has created. */ QtFlagPropertyManager::~QtFlagPropertyManager() { clear(); } /*! Returns the manager that produces the nested boolean subproperties representing each flag. In order to provide editing widgets for the subproperties in a property browser widget, this manager must be associated with an editor factory. \sa QtAbstractPropertyBrowser::setFactoryForManager() */ QtBoolPropertyManager* QtFlagPropertyManager::subBoolPropertyManager() const { return d_ptr->m_boolPropertyManager; } /*! Returns the given \a property's value. If the given property is not managed by this manager, this function returns 0. \sa flagNames(), setValue() */ int QtFlagPropertyManager::value(const QtProperty* property) const { return getValue(d_ptr->m_values, property, 0); } /*! Returns the given \a property's list of flag names. \sa value(), setFlagNames() */ QStringList QtFlagPropertyManager::flagNames(const QtProperty* property) const { return getData(d_ptr->m_values, &QtFlagPropertyManagerPrivate::Data::flagNames, property, QStringList()); } /*! \reimp */ QString QtFlagPropertyManager::valueText(const QtProperty* property) const { const QtFlagPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); if (it == d_ptr->m_values.constEnd()) return QString(); const QtFlagPropertyManagerPrivate::Data& data = it.value(); QString str; int level = 0; const QChar bar = QLatin1Char('|'); const QStringList::const_iterator fncend = data.flagNames.constEnd(); for (QStringList::const_iterator it = data.flagNames.constBegin(); it != fncend; ++it) { if (data.val & (1 << level)) { if (!str.isEmpty()) str += bar; str += *it; } level++; } return str; } /*! \fn void QtFlagPropertyManager::setValue(QtProperty *property, int value) Sets the value of the given \a property to \a value. Nested properties are updated automatically. The specified \a value must be less than the binary combination of the property's flagNames() list size (i.e. less than 2\sup n, where \c n is the size of the list) and larger than (or equal to) 0. \sa value(), valueChanged() */ void QtFlagPropertyManager::setValue(QtProperty* property, int val) { const QtFlagPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; QtFlagPropertyManagerPrivate::Data data = it.value(); if (data.val == val) return; if (val > (1 << data.flagNames.count()) - 1) return; if (val < 0) return; data.val = val; it.value() = data; const auto pfit = d_ptr->m_propertyToFlags.constFind(property); int level = 0; if (pfit != d_ptr->m_propertyToFlags.constEnd()) { for (QtProperty* prop : pfit.value()) { if (prop) d_ptr->m_boolPropertyManager->setValue(prop, val & (1 << level)); level++; } } emit propertyChanged(property); emit valueChanged(property, data.val); } /*! Sets the given \a property's list of flag names to \a flagNames. The property's current value is reset to 0 indicating the first item of the list. \sa flagNames(), flagNamesChanged() */ void QtFlagPropertyManager::setFlagNames(QtProperty* property, const QStringList& flagNames) { const QtFlagPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; QtFlagPropertyManagerPrivate::Data data = it.value(); if (data.flagNames == flagNames) return; data.flagNames = flagNames; data.val = 0; it.value() = data; const auto pfit = d_ptr->m_propertyToFlags.find(property); if (pfit != d_ptr->m_propertyToFlags.end()) { for (QtProperty* prop : qAsConst(pfit.value())) { if (prop) { delete prop; d_ptr->m_flagToProperty.remove(prop); } } pfit.value().clear(); } for (const QString& flagName : flagNames) { QtProperty* prop = d_ptr->m_boolPropertyManager->addProperty(); prop->setPropertyName(flagName); property->addSubProperty(prop); d_ptr->m_propertyToFlags[property].append(prop); d_ptr->m_flagToProperty[prop] = property; } emit flagNamesChanged(property, data.flagNames); emit propertyChanged(property); emit valueChanged(property, data.val); } /*! \reimp */ void QtFlagPropertyManager::initializeProperty(QtProperty* property) { d_ptr->m_values[property] = QtFlagPropertyManagerPrivate::Data(); d_ptr->m_propertyToFlags[property] = QList(); } /*! \reimp */ void QtFlagPropertyManager::uninitializeProperty(QtProperty* property) { const auto it = d_ptr->m_propertyToFlags.find(property); if (it != d_ptr->m_propertyToFlags.end()) { for (QtProperty* prop : qAsConst(it.value())) { if (prop) { d_ptr->m_flagToProperty.remove(prop); delete prop; } } } d_ptr->m_propertyToFlags.erase(it); d_ptr->m_values.remove(property); } #pragma endregion // QtSizePolicyPropertyManager #pragma region QtSizePolicyPropertyManager class QtSizePolicyPropertyManagerPrivate { QtSizePolicyPropertyManager* q_ptr; Q_DECLARE_PUBLIC(QtSizePolicyPropertyManager) public: QtSizePolicyPropertyManagerPrivate(); void slotIntChanged(QtProperty* property, int value); void slotEnumChanged(QtProperty* property, int value); void slotPropertyDestroyed(QtProperty* property); typedef QMap PropertyValueMap; PropertyValueMap m_values; QtIntPropertyManager* m_intPropertyManager; QtEnumPropertyManager* m_enumPropertyManager; QMap m_propertyToHPolicy; QMap m_propertyToVPolicy; QMap m_propertyToHStretch; QMap m_propertyToVStretch; QMap m_hPolicyToProperty; QMap m_vPolicyToProperty; QMap m_hStretchToProperty; QMap m_vStretchToProperty; }; QtSizePolicyPropertyManagerPrivate::QtSizePolicyPropertyManagerPrivate() { } void QtSizePolicyPropertyManagerPrivate::slotIntChanged(QtProperty* property, int value) { if (QtProperty* prop = m_hStretchToProperty.value(property, 0)) { QSizePolicy sp = m_values[prop]; sp.setHorizontalStretch(value); q_ptr->setValue(prop, sp); } else if (QtProperty* prop = m_vStretchToProperty.value(property, 0)) { QSizePolicy sp = m_values[prop]; sp.setVerticalStretch(value); q_ptr->setValue(prop, sp); } } void QtSizePolicyPropertyManagerPrivate::slotEnumChanged(QtProperty* property, int value) { if (QtProperty* prop = m_hPolicyToProperty.value(property, 0)) { QSizePolicy sp = m_values[prop]; sp.setHorizontalPolicy(metaEnumProvider()->indexToSizePolicy(value)); q_ptr->setValue(prop, sp); } else if (QtProperty* prop = m_vPolicyToProperty.value(property, 0)) { QSizePolicy sp = m_values[prop]; sp.setVerticalPolicy(metaEnumProvider()->indexToSizePolicy(value)); q_ptr->setValue(prop, sp); } } void QtSizePolicyPropertyManagerPrivate::slotPropertyDestroyed(QtProperty* property) { if (QtProperty* pointProp = m_hStretchToProperty.value(property, 0)) { m_propertyToHStretch[pointProp] = 0; m_hStretchToProperty.remove(property); } else if (QtProperty* pointProp = m_vStretchToProperty.value(property, 0)) { m_propertyToVStretch[pointProp] = 0; m_vStretchToProperty.remove(property); } else if (QtProperty* pointProp = m_hPolicyToProperty.value(property, 0)) { m_propertyToHPolicy[pointProp] = 0; m_hPolicyToProperty.remove(property); } else if (QtProperty* pointProp = m_vPolicyToProperty.value(property, 0)) { m_propertyToVPolicy[pointProp] = 0; m_vPolicyToProperty.remove(property); } } /*! \class QtSizePolicyPropertyManager \internal \inmodule QtDesigner \since 4.4 \brief The QtSizePolicyPropertyManager provides and manages QSizePolicy properties. A size policy property has nested \e horizontalPolicy, \e verticalPolicy, \e horizontalStretch and \e verticalStretch subproperties. The top-level property's value can be retrieved using the value() function, and set using the setValue() slot. The subproperties are created by QtIntPropertyManager and QtEnumPropertyManager objects. These managers can be retrieved using the subIntPropertyManager() and subEnumPropertyManager() functions respectively. In order to provide editing widgets for the subproperties in a property browser widget, these managers must be associated with editor factories. In addition, QtSizePolicyPropertyManager provides the valueChanged() signal which is emitted whenever a property created by this manager changes. \sa QtAbstractPropertyManager, QtIntPropertyManager, QtEnumPropertyManager */ /*! \fn void QtSizePolicyPropertyManager::valueChanged(QtProperty *property, const QSizePolicy &value) This signal is emitted whenever a property created by this manager changes its value, passing a pointer to the \a property and the new \a value as parameters. \sa setValue() */ /*! Creates a manager with the given \a parent. */ QtSizePolicyPropertyManager::QtSizePolicyPropertyManager(QObject* parent) : QtAbstractPropertyManager(parent), d_ptr(new QtSizePolicyPropertyManagerPrivate) { d_ptr->q_ptr = this; d_ptr->m_intPropertyManager = new QtIntPropertyManager(this); connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty*, int)), this, SLOT(slotIntChanged(QtProperty*, int))); d_ptr->m_enumPropertyManager = new QtEnumPropertyManager(this); connect(d_ptr->m_enumPropertyManager, SIGNAL(valueChanged(QtProperty*, int)), this, SLOT(slotEnumChanged(QtProperty*, int))); connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)), this, SLOT(slotPropertyDestroyed(QtProperty*))); connect(d_ptr->m_enumPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)), this, SLOT(slotPropertyDestroyed(QtProperty*))); } /*! Destroys this manager, and all the properties it has created. */ QtSizePolicyPropertyManager::~QtSizePolicyPropertyManager() { clear(); } /*! Returns the manager that creates the nested \e horizontalStretch and \e verticalStretch subproperties. In order to provide editing widgets for the mentioned subproperties in a property browser widget, this manager must be associated with an editor factory. \sa QtAbstractPropertyBrowser::setFactoryForManager() */ QtIntPropertyManager* QtSizePolicyPropertyManager::subIntPropertyManager() const { return d_ptr->m_intPropertyManager; } /*! Returns the manager that creates the nested \e horizontalPolicy and \e verticalPolicy subproperties. In order to provide editing widgets for the mentioned subproperties in a property browser widget, this manager must be associated with an editor factory. \sa QtAbstractPropertyBrowser::setFactoryForManager() */ QtEnumPropertyManager* QtSizePolicyPropertyManager::subEnumPropertyManager() const { return d_ptr->m_enumPropertyManager; } /*! Returns the given \a property's value. If the given property is not managed by this manager, this function returns the default size policy. \sa setValue() */ QSizePolicy QtSizePolicyPropertyManager::value(const QtProperty* property) const { return d_ptr->m_values.value(property, QSizePolicy()); } /*! \reimp */ QString QtSizePolicyPropertyManager::valueText(const QtProperty* property) const { const QtSizePolicyPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); if (it == d_ptr->m_values.constEnd()) return QString(); const QSizePolicy sp = it.value(); const QtMetaEnumProvider* mep = metaEnumProvider(); const int hIndex = mep->sizePolicyToIndex(sp.horizontalPolicy()); const int vIndex = mep->sizePolicyToIndex(sp.verticalPolicy()); //! Unknown size policy on reading invalid uic3 files const QString hPolicy = hIndex != -1 ? mep->policyEnumNames().at(hIndex) : tr(""); const QString vPolicy = vIndex != -1 ? mep->policyEnumNames().at(vIndex) : tr(""); const QString str = tr("[%1, %2, %3, %4]").arg(hPolicy, vPolicy).arg(sp.horizontalStretch()).arg(sp.verticalStretch()); return str; } /*! \fn void QtSizePolicyPropertyManager::setValue(QtProperty *property, const QSizePolicy &value) Sets the value of the given \a property to \a value. Nested properties are updated automatically. \sa value(), valueChanged() */ void QtSizePolicyPropertyManager::setValue(QtProperty* property, const QSizePolicy& val) { const QtSizePolicyPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; if (it.value() == val) return; it.value() = val; d_ptr->m_enumPropertyManager->setValue(d_ptr->m_propertyToHPolicy[property], metaEnumProvider()->sizePolicyToIndex(val.horizontalPolicy())); d_ptr->m_enumPropertyManager->setValue(d_ptr->m_propertyToVPolicy[property], metaEnumProvider()->sizePolicyToIndex(val.verticalPolicy())); d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToHStretch[property], val.horizontalStretch()); d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToVStretch[property], val.verticalStretch()); emit propertyChanged(property); emit valueChanged(property, val); } /*! \reimp */ void QtSizePolicyPropertyManager::initializeProperty(QtProperty* property) { QSizePolicy val; d_ptr->m_values[property] = val; QtProperty* hPolicyProp = d_ptr->m_enumPropertyManager->addProperty(); hPolicyProp->setPropertyName(tr("Horizontal Policy")); d_ptr->m_enumPropertyManager->setEnumNames(hPolicyProp, metaEnumProvider()->policyEnumNames()); d_ptr->m_enumPropertyManager->setValue(hPolicyProp, metaEnumProvider()->sizePolicyToIndex(val.horizontalPolicy())); d_ptr->m_propertyToHPolicy[property] = hPolicyProp; d_ptr->m_hPolicyToProperty[hPolicyProp] = property; property->addSubProperty(hPolicyProp); QtProperty* vPolicyProp = d_ptr->m_enumPropertyManager->addProperty(); vPolicyProp->setPropertyName(tr("Vertical Policy")); d_ptr->m_enumPropertyManager->setEnumNames(vPolicyProp, metaEnumProvider()->policyEnumNames()); d_ptr->m_enumPropertyManager->setValue(vPolicyProp, metaEnumProvider()->sizePolicyToIndex(val.verticalPolicy())); d_ptr->m_propertyToVPolicy[property] = vPolicyProp; d_ptr->m_vPolicyToProperty[vPolicyProp] = property; property->addSubProperty(vPolicyProp); QtProperty* hStretchProp = d_ptr->m_intPropertyManager->addProperty(); hStretchProp->setPropertyName(tr("Horizontal Stretch")); d_ptr->m_intPropertyManager->setValueOnly(hStretchProp, val.horizontalStretch()); d_ptr->m_intPropertyManager->setRange(hStretchProp, 0, 0xff); d_ptr->m_propertyToHStretch[property] = hStretchProp; d_ptr->m_hStretchToProperty[hStretchProp] = property; property->addSubProperty(hStretchProp); QtProperty* vStretchProp = d_ptr->m_intPropertyManager->addProperty(); vStretchProp->setPropertyName(tr("Vertical Stretch")); d_ptr->m_intPropertyManager->setValueOnly(vStretchProp, val.verticalStretch()); d_ptr->m_intPropertyManager->setRange(vStretchProp, 0, 0xff); d_ptr->m_propertyToVStretch[property] = vStretchProp; d_ptr->m_vStretchToProperty[vStretchProp] = property; property->addSubProperty(vStretchProp); } /*! \reimp */ void QtSizePolicyPropertyManager::uninitializeProperty(QtProperty* property) { QtProperty* hPolicyProp = d_ptr->m_propertyToHPolicy[property]; if (hPolicyProp) { d_ptr->m_hPolicyToProperty.remove(hPolicyProp); delete hPolicyProp; } d_ptr->m_propertyToHPolicy.remove(property); QtProperty* vPolicyProp = d_ptr->m_propertyToVPolicy[property]; if (vPolicyProp) { d_ptr->m_vPolicyToProperty.remove(vPolicyProp); delete vPolicyProp; } d_ptr->m_propertyToVPolicy.remove(property); QtProperty* hStretchProp = d_ptr->m_propertyToHStretch[property]; if (hStretchProp) { d_ptr->m_hStretchToProperty.remove(hStretchProp); delete hStretchProp; } d_ptr->m_propertyToHStretch.remove(property); QtProperty* vStretchProp = d_ptr->m_propertyToVStretch[property]; if (vStretchProp) { d_ptr->m_vStretchToProperty.remove(vStretchProp); delete vStretchProp; } d_ptr->m_propertyToVStretch.remove(property); d_ptr->m_values.remove(property); } #pragma endregion // QtFontPropertyManager: // QtFontPropertyManagerPrivate has a mechanism for reacting // to QApplication::fontDatabaseChanged() [4.5], which is emitted // when someone loads an application font. The signals are compressed // using a timer with interval 0, which then causes the family // enumeration manager to re-set its strings and index values // for each property. #pragma region QtFontPropertyManager Q_GLOBAL_STATIC(QFontDatabase, fontDatabase) class QtFontPropertyManagerPrivate { QtFontPropertyManager* q_ptr; Q_DECLARE_PUBLIC(QtFontPropertyManager) public: QtFontPropertyManagerPrivate(); void slotIntChanged(QtProperty* property, int value); void slotEnumChanged(QtProperty* property, int value); void slotBoolChanged(QtProperty* property, bool value); void slotPropertyDestroyed(QtProperty* property); void slotFontDatabaseChanged(); void slotFontDatabaseDelayedChange(); QStringList m_familyNames; typedef QMap PropertyValueMap; PropertyValueMap m_values; QtIntPropertyManager* m_intPropertyManager; QtEnumPropertyManager* m_enumPropertyManager; QtBoolPropertyManager* m_boolPropertyManager; QMap m_propertyToFamily; QMap m_propertyToPointSize; QMap m_propertyToBold; QMap m_propertyToItalic; QMap m_propertyToUnderline; QMap m_propertyToStrikeOut; QMap m_propertyToKerning; QMap m_familyToProperty; QMap m_pointSizeToProperty; QMap m_boldToProperty; QMap m_italicToProperty; QMap m_underlineToProperty; QMap m_strikeOutToProperty; QMap m_kerningToProperty; bool m_settingValue; QTimer* m_fontDatabaseChangeTimer; }; QtFontPropertyManagerPrivate::QtFontPropertyManagerPrivate() : m_settingValue(false), m_fontDatabaseChangeTimer(0) { } void QtFontPropertyManagerPrivate::slotIntChanged(QtProperty* property, int value) { if (m_settingValue) return; if (QtProperty* prop = m_pointSizeToProperty.value(property, 0)) { QFont f = m_values[prop]; f.setPointSize(value); q_ptr->setValue(prop, f); } } void QtFontPropertyManagerPrivate::slotEnumChanged(QtProperty* property, int value) { if (m_settingValue) return; if (QtProperty* prop = m_familyToProperty.value(property, 0)) { QFont f = m_values[prop]; f.setFamily(m_familyNames.at(value)); q_ptr->setValue(prop, f); } } void QtFontPropertyManagerPrivate::slotBoolChanged(QtProperty* property, bool value) { if (m_settingValue) return; if (QtProperty* prop = m_boldToProperty.value(property, 0)) { QFont f = m_values[prop]; f.setBold(value); q_ptr->setValue(prop, f); } else if (QtProperty* prop = m_italicToProperty.value(property, 0)) { QFont f = m_values[prop]; f.setItalic(value); q_ptr->setValue(prop, f); } else if (QtProperty* prop = m_underlineToProperty.value(property, 0)) { QFont f = m_values[prop]; f.setUnderline(value); q_ptr->setValue(prop, f); } else if (QtProperty* prop = m_strikeOutToProperty.value(property, 0)) { QFont f = m_values[prop]; f.setStrikeOut(value); q_ptr->setValue(prop, f); } else if (QtProperty* prop = m_kerningToProperty.value(property, 0)) { QFont f = m_values[prop]; f.setKerning(value); q_ptr->setValue(prop, f); } } void QtFontPropertyManagerPrivate::slotPropertyDestroyed(QtProperty* property) { if (QtProperty* pointProp = m_pointSizeToProperty.value(property, 0)) { m_propertyToPointSize[pointProp] = 0; m_pointSizeToProperty.remove(property); } else if (QtProperty* pointProp = m_familyToProperty.value(property, 0)) { m_propertyToFamily[pointProp] = 0; m_familyToProperty.remove(property); } else if (QtProperty* pointProp = m_boldToProperty.value(property, 0)) { m_propertyToBold[pointProp] = 0; m_boldToProperty.remove(property); } else if (QtProperty* pointProp = m_italicToProperty.value(property, 0)) { m_propertyToItalic[pointProp] = 0; m_italicToProperty.remove(property); } else if (QtProperty* pointProp = m_underlineToProperty.value(property, 0)) { m_propertyToUnderline[pointProp] = 0; m_underlineToProperty.remove(property); } else if (QtProperty* pointProp = m_strikeOutToProperty.value(property, 0)) { m_propertyToStrikeOut[pointProp] = 0; m_strikeOutToProperty.remove(property); } else if (QtProperty* pointProp = m_kerningToProperty.value(property, 0)) { m_propertyToKerning[pointProp] = 0; m_kerningToProperty.remove(property); } } void QtFontPropertyManagerPrivate::slotFontDatabaseChanged() { if (!m_fontDatabaseChangeTimer) { m_fontDatabaseChangeTimer = new QTimer(q_ptr); m_fontDatabaseChangeTimer->setInterval(0); m_fontDatabaseChangeTimer->setSingleShot(true); QObject::connect(m_fontDatabaseChangeTimer, SIGNAL(timeout()), q_ptr, SLOT(slotFontDatabaseDelayedChange())); } if (!m_fontDatabaseChangeTimer->isActive()) m_fontDatabaseChangeTimer->start(); } void QtFontPropertyManagerPrivate::slotFontDatabaseDelayedChange() { typedef QMap PropertyPropertyMap; // rescan available font names const QStringList oldFamilies = m_familyNames; #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) m_familyNames = QFontDatabase::families(); #else m_familyNames = fontDatabase()->families(); #endif // Adapt all existing properties if (!m_propertyToFamily.isEmpty()) { PropertyPropertyMap::const_iterator cend = m_propertyToFamily.constEnd(); for (PropertyPropertyMap::const_iterator it = m_propertyToFamily.constBegin(); it != cend; ++it) { QtProperty* familyProp = it.value(); const int oldIdx = m_enumPropertyManager->value(familyProp); int newIdx = m_familyNames.indexOf(oldFamilies.at(oldIdx)); if (newIdx < 0) newIdx = 0; m_enumPropertyManager->setEnumNames(familyProp, m_familyNames); m_enumPropertyManager->setValue(familyProp, newIdx); } } } /*! \class QtFontPropertyManager \internal \inmodule QtDesigner \since 4.4 \brief The QtFontPropertyManager provides and manages QFont properties. A font property has nested \e family, \e pointSize, \e bold, \e italic, \e underline, \e strikeOut and \e kerning subproperties. The top-level property's value can be retrieved using the value() function, and set using the setValue() slot. The subproperties are created by QtIntPropertyManager, QtEnumPropertyManager and QtBoolPropertyManager objects. These managers can be retrieved using the corresponding subIntPropertyManager(), subEnumPropertyManager() and subBoolPropertyManager() functions. In order to provide editing widgets for the subproperties in a property browser widget, these managers must be associated with editor factories. In addition, QtFontPropertyManager provides the valueChanged() signal which is emitted whenever a property created by this manager changes. \sa QtAbstractPropertyManager, QtEnumPropertyManager, QtIntPropertyManager, QtBoolPropertyManager */ /*! \fn void QtFontPropertyManager::valueChanged(QtProperty *property, const QFont &value) This signal is emitted whenever a property created by this manager changes its value, passing a pointer to the \a property and the new \a value as parameters. \sa setValue() */ /*! Creates a manager with the given \a parent. */ QtFontPropertyManager::QtFontPropertyManager(QObject* parent) : QtAbstractPropertyManager(parent), d_ptr(new QtFontPropertyManagerPrivate) { d_ptr->q_ptr = this; QObject::connect(qApp, SIGNAL(fontDatabaseChanged()), this, SLOT(slotFontDatabaseChanged())); d_ptr->m_intPropertyManager = new QtIntPropertyManager(this); connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty*, int)), this, SLOT(slotIntChanged(QtProperty*, int))); d_ptr->m_enumPropertyManager = new QtEnumPropertyManager(this); connect(d_ptr->m_enumPropertyManager, SIGNAL(valueChanged(QtProperty*, int)), this, SLOT(slotEnumChanged(QtProperty*, int))); d_ptr->m_boolPropertyManager = new QtBoolPropertyManager(this); connect(d_ptr->m_boolPropertyManager, SIGNAL(valueChanged(QtProperty*, bool)), this, SLOT(slotBoolChanged(QtProperty*, bool))); connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)), this, SLOT(slotPropertyDestroyed(QtProperty*))); connect(d_ptr->m_enumPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)), this, SLOT(slotPropertyDestroyed(QtProperty*))); connect(d_ptr->m_boolPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)), this, SLOT(slotPropertyDestroyed(QtProperty*))); } /*! Destroys this manager, and all the properties it has created. */ QtFontPropertyManager::~QtFontPropertyManager() { clear(); } /*! Returns the manager that creates the \e pointSize subproperty. In order to provide editing widgets for the \e pointSize property in a property browser widget, this manager must be associated with an editor factory. \sa QtAbstractPropertyBrowser::setFactoryForManager() */ QtIntPropertyManager* QtFontPropertyManager::subIntPropertyManager() const { return d_ptr->m_intPropertyManager; } /*! Returns the manager that create the \e family subproperty. In order to provide editing widgets for the \e family property in a property browser widget, this manager must be associated with an editor factory. \sa QtAbstractPropertyBrowser::setFactoryForManager() */ QtEnumPropertyManager* QtFontPropertyManager::subEnumPropertyManager() const { return d_ptr->m_enumPropertyManager; } /*! Returns the manager that creates the \e bold, \e italic, \e underline, \e strikeOut and \e kerning subproperties. In order to provide editing widgets for the mentioned properties in a property browser widget, this manager must be associated with an editor factory. \sa QtAbstractPropertyBrowser::setFactoryForManager() */ QtBoolPropertyManager* QtFontPropertyManager::subBoolPropertyManager() const { return d_ptr->m_boolPropertyManager; } /*! Returns the given \a property's value. If the given property is not managed by this manager, this function returns a font object that uses the application's default font. \sa setValue() */ QFont QtFontPropertyManager::value(const QtProperty* property) const { return d_ptr->m_values.value(property, QFont()); } /*! \reimp */ QString QtFontPropertyManager::valueText(const QtProperty* property) const { const QtFontPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); if (it == d_ptr->m_values.constEnd()) return QString(); return QtPropertyBrowserUtils::fontValueText(it.value()); } /*! \reimp */ QIcon QtFontPropertyManager::valueIcon(const QtProperty* property) const { const QtFontPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); if (it == d_ptr->m_values.constEnd()) return QIcon(); return QtPropertyBrowserUtils::fontValueIcon(it.value()); } /*! \fn void QtFontPropertyManager::setValue(QtProperty *property, const QFont &value) Sets the value of the given \a property to \a value. Nested properties are updated automatically. \sa value(), valueChanged() */ void QtFontPropertyManager::setValue(QtProperty* property, const QFont& val) { const QtFontPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; const QFont oldVal = it.value(); #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) if (oldVal == val && oldVal.resolveMask() == val.resolveMask()) #else if (oldVal == val && oldVal.resolve() == val.resolve()) #endif return; it.value() = val; int idx = d_ptr->m_familyNames.indexOf(val.family()); if (idx == -1) idx = 0; bool settingValue = d_ptr->m_settingValue; d_ptr->m_settingValue = true; d_ptr->m_enumPropertyManager->setValue(d_ptr->m_propertyToFamily[property], idx); d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToPointSize[property], val.pointSize()); d_ptr->m_boolPropertyManager->setValue(d_ptr->m_propertyToBold[property], val.bold()); d_ptr->m_boolPropertyManager->setValue(d_ptr->m_propertyToItalic[property], val.italic()); d_ptr->m_boolPropertyManager->setValue(d_ptr->m_propertyToUnderline[property], val.underline()); d_ptr->m_boolPropertyManager->setValue(d_ptr->m_propertyToStrikeOut[property], val.strikeOut()); d_ptr->m_boolPropertyManager->setValue(d_ptr->m_propertyToKerning[property], val.kerning()); d_ptr->m_settingValue = settingValue; emit propertyChanged(property); emit valueChanged(property, val); } /*! \reimp */ void QtFontPropertyManager::initializeProperty(QtProperty* property) { QFont val; d_ptr->m_values[property] = val; QtProperty* familyProp = d_ptr->m_enumPropertyManager->addProperty(); familyProp->setPropertyName(tr("Family")); if (d_ptr->m_familyNames.isEmpty()) #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) d_ptr->m_familyNames = QFontDatabase::families(); #else d_ptr->m_familyNames = fontDatabase()->families(); #endif d_ptr->m_enumPropertyManager->setEnumNames(familyProp, d_ptr->m_familyNames); int idx = d_ptr->m_familyNames.indexOf(val.family()); if (idx == -1) idx = 0; d_ptr->m_enumPropertyManager->setValue(familyProp, idx); d_ptr->m_propertyToFamily[property] = familyProp; d_ptr->m_familyToProperty[familyProp] = property; property->addSubProperty(familyProp); QtProperty* pointSizeProp = d_ptr->m_intPropertyManager->addProperty(); pointSizeProp->setPropertyName(tr("Point Size")); d_ptr->m_intPropertyManager->setValueOnly(pointSizeProp, val.pointSize()); d_ptr->m_intPropertyManager->setMinimum(pointSizeProp, 1); d_ptr->m_propertyToPointSize[property] = pointSizeProp; d_ptr->m_pointSizeToProperty[pointSizeProp] = property; property->addSubProperty(pointSizeProp); QtProperty* boldProp = d_ptr->m_boolPropertyManager->addProperty(); boldProp->setPropertyName(tr("Bold")); d_ptr->m_boolPropertyManager->setValueOnly(boldProp, val.bold()); d_ptr->m_propertyToBold[property] = boldProp; d_ptr->m_boldToProperty[boldProp] = property; property->addSubProperty(boldProp); QtProperty* italicProp = d_ptr->m_boolPropertyManager->addProperty(); italicProp->setPropertyName(tr("Italic")); d_ptr->m_boolPropertyManager->setValueOnly(italicProp, val.italic()); d_ptr->m_propertyToItalic[property] = italicProp; d_ptr->m_italicToProperty[italicProp] = property; property->addSubProperty(italicProp); QtProperty* underlineProp = d_ptr->m_boolPropertyManager->addProperty(); underlineProp->setPropertyName(tr("Underline")); d_ptr->m_boolPropertyManager->setValueOnly(underlineProp, val.underline()); d_ptr->m_propertyToUnderline[property] = underlineProp; d_ptr->m_underlineToProperty[underlineProp] = property; property->addSubProperty(underlineProp); QtProperty* strikeOutProp = d_ptr->m_boolPropertyManager->addProperty(); strikeOutProp->setPropertyName(tr("Strikeout")); d_ptr->m_boolPropertyManager->setValueOnly(strikeOutProp, val.strikeOut()); d_ptr->m_propertyToStrikeOut[property] = strikeOutProp; d_ptr->m_strikeOutToProperty[strikeOutProp] = property; property->addSubProperty(strikeOutProp); QtProperty* kerningProp = d_ptr->m_boolPropertyManager->addProperty(); kerningProp->setPropertyName(tr("Kerning")); d_ptr->m_boolPropertyManager->setValueOnly(kerningProp, val.kerning()); d_ptr->m_propertyToKerning[property] = kerningProp; d_ptr->m_kerningToProperty[kerningProp] = property; property->addSubProperty(kerningProp); } /*! \reimp */ void QtFontPropertyManager::uninitializeProperty(QtProperty* property) { QtProperty* familyProp = d_ptr->m_propertyToFamily[property]; if (familyProp) { d_ptr->m_familyToProperty.remove(familyProp); delete familyProp; } d_ptr->m_propertyToFamily.remove(property); QtProperty* pointSizeProp = d_ptr->m_propertyToPointSize[property]; if (pointSizeProp) { d_ptr->m_pointSizeToProperty.remove(pointSizeProp); delete pointSizeProp; } d_ptr->m_propertyToPointSize.remove(property); QtProperty* boldProp = d_ptr->m_propertyToBold[property]; if (boldProp) { d_ptr->m_boldToProperty.remove(boldProp); delete boldProp; } d_ptr->m_propertyToBold.remove(property); QtProperty* italicProp = d_ptr->m_propertyToItalic[property]; if (italicProp) { d_ptr->m_italicToProperty.remove(italicProp); delete italicProp; } d_ptr->m_propertyToItalic.remove(property); QtProperty* underlineProp = d_ptr->m_propertyToUnderline[property]; if (underlineProp) { d_ptr->m_underlineToProperty.remove(underlineProp); delete underlineProp; } d_ptr->m_propertyToUnderline.remove(property); QtProperty* strikeOutProp = d_ptr->m_propertyToStrikeOut[property]; if (strikeOutProp) { d_ptr->m_strikeOutToProperty.remove(strikeOutProp); delete strikeOutProp; } d_ptr->m_propertyToStrikeOut.remove(property); QtProperty* kerningProp = d_ptr->m_propertyToKerning[property]; if (kerningProp) { d_ptr->m_kerningToProperty.remove(kerningProp); delete kerningProp; } d_ptr->m_propertyToKerning.remove(property); d_ptr->m_values.remove(property); } #pragma endregion // QtColorPropertyManager #pragma region QtColorPropertyManager class QtColorPropertyManagerPrivate { QtColorPropertyManager* q_ptr; Q_DECLARE_PUBLIC(QtColorPropertyManager) public: void slotIntChanged(QtProperty* property, int value); void slotPropertyDestroyed(QtProperty* property); typedef QMap PropertyValueMap; PropertyValueMap m_values; QtIntPropertyManager* m_intPropertyManager; QMap m_propertyToR; QMap m_propertyToG; QMap m_propertyToB; QMap m_propertyToA; QMap m_rToProperty; QMap m_gToProperty; QMap m_bToProperty; QMap m_aToProperty; }; void QtColorPropertyManagerPrivate::slotIntChanged(QtProperty* property, int value) { if (QtProperty* prop = m_rToProperty.value(property, 0)) { QColor c = m_values[prop]; c.setRed(value); q_ptr->setValue(prop, c); } else if (QtProperty* prop = m_gToProperty.value(property, 0)) { QColor c = m_values[prop]; c.setGreen(value); q_ptr->setValue(prop, c); } else if (QtProperty* prop = m_bToProperty.value(property, 0)) { QColor c = m_values[prop]; c.setBlue(value); q_ptr->setValue(prop, c); } else if (QtProperty* prop = m_aToProperty.value(property, 0)) { QColor c = m_values[prop]; c.setAlpha(value); q_ptr->setValue(prop, c); } } void QtColorPropertyManagerPrivate::slotPropertyDestroyed(QtProperty* property) { if (QtProperty* pointProp = m_rToProperty.value(property, 0)) { m_propertyToR[pointProp] = 0; m_rToProperty.remove(property); } else if (QtProperty* pointProp = m_gToProperty.value(property, 0)) { m_propertyToG[pointProp] = 0; m_gToProperty.remove(property); } else if (QtProperty* pointProp = m_bToProperty.value(property, 0)) { m_propertyToB[pointProp] = 0; m_bToProperty.remove(property); } else if (QtProperty* pointProp = m_aToProperty.value(property, 0)) { m_propertyToA[pointProp] = 0; m_aToProperty.remove(property); } } /*! \class QtColorPropertyManager \internal \inmodule QtDesigner \since 4.4 \brief The QtColorPropertyManager provides and manages QColor properties. A color property has nested \e red, \e green and \e blue subproperties. The top-level property's value can be retrieved using the value() function, and set using the setValue() slot. The subproperties are created by a QtIntPropertyManager object. This manager can be retrieved using the subIntPropertyManager() function. In order to provide editing widgets for the subproperties in a property browser widget, this manager must be associated with an editor factory. In addition, QtColorPropertyManager provides the valueChanged() signal which is emitted whenever a property created by this manager changes. \sa QtAbstractPropertyManager, QtAbstractPropertyBrowser, QtIntPropertyManager */ /*! \fn void QtColorPropertyManager::valueChanged(QtProperty *property, const QColor &value) This signal is emitted whenever a property created by this manager changes its value, passing a pointer to the \a property and the new \a value as parameters. \sa setValue() */ /*! Creates a manager with the given \a parent. */ QtColorPropertyManager::QtColorPropertyManager(QObject* parent) : QtAbstractPropertyManager(parent), d_ptr(new QtColorPropertyManagerPrivate) { d_ptr->q_ptr = this; d_ptr->m_intPropertyManager = new QtIntPropertyManager(this); connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty*, int)), this, SLOT(slotIntChanged(QtProperty*, int))); connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)), this, SLOT(slotPropertyDestroyed(QtProperty*))); } /*! Destroys this manager, and all the properties it has created. */ QtColorPropertyManager::~QtColorPropertyManager() { clear(); } /*! Returns the manager that produces the nested \e red, \e green and \e blue subproperties. In order to provide editing widgets for the subproperties in a property browser widget, this manager must be associated with an editor factory. \sa QtAbstractPropertyBrowser::setFactoryForManager() */ QtIntPropertyManager* QtColorPropertyManager::subIntPropertyManager() const { return d_ptr->m_intPropertyManager; } /*! Returns the given \a property's value. If the given \a property is not managed by \e this manager, this function returns an invalid color. \sa setValue() */ QColor QtColorPropertyManager::value(const QtProperty* property) const { return d_ptr->m_values.value(property, QColor()); } /*! \reimp */ QString QtColorPropertyManager::valueText(const QtProperty* property) const { const QtColorPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); if (it == d_ptr->m_values.constEnd()) return QString(); return QtPropertyBrowserUtils::colorValueText(it.value()); } /*! \reimp */ QIcon QtColorPropertyManager::valueIcon(const QtProperty* property) const { const QtColorPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); if (it == d_ptr->m_values.constEnd()) return QIcon(); return QtPropertyBrowserUtils::brushValueIcon(QBrush(it.value())); } /*! \fn void QtColorPropertyManager::setValue(QtProperty *property, const QColor &value) Sets the value of the given \a property to \a value. Nested properties are updated automatically. \sa value(), valueChanged() */ void QtColorPropertyManager::setValue(QtProperty* property, const QColor& val) { const QtColorPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; if (it.value() == val) return; it.value() = val; d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToR[property], val.red()); d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToG[property], val.green()); d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToB[property], val.blue()); d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToA[property], val.alpha()); emit propertyChanged(property); emit valueChanged(property, val); } /*! \reimp */ void QtColorPropertyManager::initializeProperty(QtProperty* property) { QColor val; d_ptr->m_values[property] = val; QtProperty* rProp = d_ptr->m_intPropertyManager->addProperty(); rProp->setPropertyName(tr("Red")); d_ptr->m_intPropertyManager->setValueOnly(rProp, val.red()); d_ptr->m_intPropertyManager->setRange(rProp, 0, 0xFF); d_ptr->m_propertyToR[property] = rProp; d_ptr->m_rToProperty[rProp] = property; property->addSubProperty(rProp); QtProperty* gProp = d_ptr->m_intPropertyManager->addProperty(); gProp->setPropertyName(tr("Green")); d_ptr->m_intPropertyManager->setValueOnly(gProp, val.green()); d_ptr->m_intPropertyManager->setRange(gProp, 0, 0xFF); d_ptr->m_propertyToG[property] = gProp; d_ptr->m_gToProperty[gProp] = property; property->addSubProperty(gProp); QtProperty* bProp = d_ptr->m_intPropertyManager->addProperty(); bProp->setPropertyName(tr("Blue")); d_ptr->m_intPropertyManager->setValueOnly(bProp, val.blue()); d_ptr->m_intPropertyManager->setRange(bProp, 0, 0xFF); d_ptr->m_propertyToB[property] = bProp; d_ptr->m_bToProperty[bProp] = property; property->addSubProperty(bProp); QtProperty* aProp = d_ptr->m_intPropertyManager->addProperty(); aProp->setPropertyName(tr("Alpha")); d_ptr->m_intPropertyManager->setValueOnly(aProp, val.alpha()); d_ptr->m_intPropertyManager->setRange(aProp, 0, 0xFF); d_ptr->m_propertyToA[property] = aProp; d_ptr->m_aToProperty[aProp] = property; property->addSubProperty(aProp); } /*! \reimp */ void QtColorPropertyManager::uninitializeProperty(QtProperty* property) { QtProperty* rProp = d_ptr->m_propertyToR[property]; if (rProp) { d_ptr->m_rToProperty.remove(rProp); delete rProp; } d_ptr->m_propertyToR.remove(property); QtProperty* gProp = d_ptr->m_propertyToG[property]; if (gProp) { d_ptr->m_gToProperty.remove(gProp); delete gProp; } d_ptr->m_propertyToG.remove(property); QtProperty* bProp = d_ptr->m_propertyToB[property]; if (bProp) { d_ptr->m_bToProperty.remove(bProp); delete bProp; } d_ptr->m_propertyToB.remove(property); QtProperty* aProp = d_ptr->m_propertyToA[property]; if (aProp) { d_ptr->m_aToProperty.remove(aProp); delete aProp; } d_ptr->m_propertyToA.remove(property); d_ptr->m_values.remove(property); } #pragma endregion // QtCursorPropertyManager #pragma region QtCursorPropertyManager // Make sure icons are removed as soon as QApplication is destroyed, otherwise, // handles are leaked on X11. static void clearCursorDatabase(); namespace { struct CursorDatabase : public QtCursorDatabase { CursorDatabase() { qAddPostRoutine(clearCursorDatabase); } }; } Q_GLOBAL_STATIC(QtCursorDatabase, cursorDatabase) static void clearCursorDatabase() { cursorDatabase()->clear(); } class QtCursorPropertyManagerPrivate { QtCursorPropertyManager* q_ptr; Q_DECLARE_PUBLIC(QtCursorPropertyManager) public: typedef QMap PropertyValueMap; PropertyValueMap m_values; }; /*! \class QtCursorPropertyManager \internal \inmodule QtDesigner \since 4.4 \brief The QtCursorPropertyManager provides and manages QCursor properties. A cursor property has a current value which can be retrieved using the value() function, and set using the setValue() slot. In addition, QtCursorPropertyManager provides the valueChanged() signal which is emitted whenever a property created by this manager changes. \sa QtAbstractPropertyManager */ /*! \fn void QtCursorPropertyManager::valueChanged(QtProperty *property, const QCursor &value) This signal is emitted whenever a property created by this manager changes its value, passing a pointer to the \a property and the new \a value as parameters. \sa setValue() */ /*! Creates a manager with the given \a parent. */ QtCursorPropertyManager::QtCursorPropertyManager(QObject* parent) : QtAbstractPropertyManager(parent), d_ptr(new QtCursorPropertyManagerPrivate) { d_ptr->q_ptr = this; } /*! Destroys this manager, and all the properties it has created. */ QtCursorPropertyManager::~QtCursorPropertyManager() { clear(); } /*! Returns the given \a property's value. If the given \a property is not managed by this manager, this function returns a default QCursor object. \sa setValue() */ #ifndef QT_NO_CURSOR QCursor QtCursorPropertyManager::value(const QtProperty* property) const { return d_ptr->m_values.value(property, QCursor()); } #endif /*! \reimp */ QString QtCursorPropertyManager::valueText(const QtProperty* property) const { const QtCursorPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); if (it == d_ptr->m_values.constEnd()) return QString(); return cursorDatabase()->cursorToShapeName(it.value()); } /*! \reimp */ QIcon QtCursorPropertyManager::valueIcon(const QtProperty* property) const { const QtCursorPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); if (it == d_ptr->m_values.constEnd()) return QIcon(); return cursorDatabase()->cursorToShapeIcon(it.value()); } /*! \fn void QtCursorPropertyManager::setValue(QtProperty *property, const QCursor &value) Sets the value of the given \a property to \a value. \sa value(), valueChanged() */ void QtCursorPropertyManager::setValue(QtProperty* property, const QCursor& value) { #ifndef QT_NO_CURSOR const QtCursorPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; if (it.value().shape() == value.shape() && value.shape() != Qt::BitmapCursor) return; it.value() = value; emit propertyChanged(property); emit valueChanged(property, value); #endif } /*! \reimp */ void QtCursorPropertyManager::initializeProperty(QtProperty* property) { #ifndef QT_NO_CURSOR d_ptr->m_values[property] = QCursor(); #endif } /*! \reimp */ void QtCursorPropertyManager::uninitializeProperty(QtProperty* property) { d_ptr->m_values.remove(property); } #pragma endregion // QtVec3PropertyManager #pragma region QtVec3PropertyManager class QtVec3PropertyManagerPrivate { QtVec3PropertyManager* q_ptr; Q_DECLARE_PUBLIC(QtVec3PropertyManager) public: typedef QMap PropertyValueMap; PropertyValueMap m_values; void slotDoubleChanged(QtProperty* property, double value); void slotPropertyDestroyed(QtProperty* property); QtDoublePropertyManager* m_doublePropertyManager; QMap m_propertyToTx; QMap m_propertyToTy; QMap m_propertyToTz; QMap m_txToProperty; QMap m_tyToProperty; QMap m_tzToProperty; }; void QtVec3PropertyManagerPrivate::slotDoubleChanged(QtProperty* property, double value) { if (QtProperty* prop = m_txToProperty.value(property, 0)) { osg::Vec3 c = m_values[prop]; c._v[0] = value; q_ptr->setValue(prop, c); } else if (QtProperty* prop = m_tyToProperty.value(property, 0)) { osg::Vec3 c = m_values[prop]; c._v[1] = value; q_ptr->setValue(prop, c); } else if (QtProperty* prop = m_tzToProperty.value(property, 0)) { osg::Vec3 c = m_values[prop]; c._v[2] = value; q_ptr->setValue(prop, c); } } void QtVec3PropertyManagerPrivate::slotPropertyDestroyed(QtProperty* property) { if (QtProperty* pointProp = m_txToProperty.value(property, 0)) { m_propertyToTx[pointProp] = 0; m_txToProperty.remove(property); } else if (QtProperty* pointProp = m_tyToProperty.value(property, 0)) { m_propertyToTy[pointProp] = 0; m_tyToProperty.remove(property); } else if (QtProperty* pointProp = m_tzToProperty.value(property, 0)) { m_propertyToTz[pointProp] = 0; m_tzToProperty.remove(property); } } QtVec3PropertyManager::QtVec3PropertyManager(QObject* parent) : QtAbstractPropertyManager(parent), d_ptr(new QtVec3PropertyManagerPrivate) { d_ptr->q_ptr = this; d_ptr->m_doublePropertyManager = new QtDoublePropertyManager(this); connect(d_ptr->m_doublePropertyManager, SIGNAL(valueChanged(QtProperty*, double)), this, SLOT(slotDoubleChanged(QtProperty*, double))); connect(d_ptr->m_doublePropertyManager, SIGNAL(propertyDestroyed(QtProperty*)), this, SLOT(slotPropertyDestroyed(QtProperty*))); } /*! Destroys this manager, and all the properties it has created. */ QtVec3PropertyManager::~QtVec3PropertyManager() { clear(); } osg::Vec3 QtVec3PropertyManager::value(const QtProperty* property) const { return d_ptr->m_values.value(property, osg::Vec3()); } QtDoublePropertyManager* QtVec3PropertyManager::subDoublePropertyManager() const { return d_ptr->m_doublePropertyManager; } void QtVec3PropertyManager::setValue(QtProperty* property, osg::Vec3 val) { const QtVec3PropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; if (it.value() == val) return; it.value() = val; d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToTx[property], val.x()); d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToTy[property], val.y()); d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToTz[property], val.z()); emit propertyChanged(property); emit valueChanged(property, val); } void QtVec3PropertyManager::setValueOnly(QtProperty* property, osg::Vec3 val) { const QtVec3PropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; if (it.value() == val) return; it.value() = val; d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToTx[property], val.x()); d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToTy[property], val.y()); d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToTz[property], val.z()); } QString QtVec3PropertyManager::valueText(const QtProperty* property) const { const QtVec3PropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); if (it == d_ptr->m_values.constEnd()) return QString(); osg::Vec3 c = it.value(); return QCoreApplication::translate("QtPropertyBrowserUtils", "[%1, %2, %3]") .arg(c.x()).arg(c.y()).arg(c.z()); } void QtVec3PropertyManager::initializeProperty(QtProperty* property) { osg::Vec3 val; d_ptr->m_values[property] = val; QtProperty* rProp = d_ptr->m_doublePropertyManager->addProperty(); rProp->setPropertyName(tr("X")); d_ptr->m_doublePropertyManager->setValueOnly(rProp, val.x()); d_ptr->m_propertyToTx[property] = rProp; d_ptr->m_txToProperty[rProp] = property; property->addSubProperty(rProp); QtProperty* gProp = d_ptr->m_doublePropertyManager->addProperty(); gProp->setPropertyName(tr("Y")); d_ptr->m_doublePropertyManager->setValueOnly(gProp, val.y()); d_ptr->m_propertyToTy[property] = gProp; d_ptr->m_tyToProperty[gProp] = property; property->addSubProperty(gProp); QtProperty* bProp = d_ptr->m_doublePropertyManager->addProperty(); bProp->setPropertyName(tr("Z")); d_ptr->m_doublePropertyManager->setValueOnly(bProp, val.z()); d_ptr->m_propertyToTz[property] = bProp; d_ptr->m_tzToProperty[bProp] = property; property->addSubProperty(bProp); } void QtVec3PropertyManager::uninitializeProperty(QtProperty* property) { QtProperty* rProp = d_ptr->m_propertyToTx[property]; if (rProp) { d_ptr->m_txToProperty.remove(rProp); delete rProp; } d_ptr->m_propertyToTx.remove(property); QtProperty* gProp = d_ptr->m_propertyToTy[property]; if (gProp) { d_ptr->m_tyToProperty.remove(gProp); delete gProp; } d_ptr->m_propertyToTy.remove(property); QtProperty* bProp = d_ptr->m_propertyToTz[property]; if (bProp) { d_ptr->m_tzToProperty.remove(bProp); delete bProp; } d_ptr->m_propertyToTz.remove(property); d_ptr->m_values.remove(property); } #pragma endregion // QtTransfromPropertyManager #pragma region QtTransfromPropertyManager class QtTransfromPropertyManagerPrivate { QtTransfromPropertyManager* q_ptr; Q_DECLARE_PUBLIC(QtTransfromPropertyManager) public: typedef QMap PropertyValueMap; PropertyValueMap m_values; void slotVec3Changed(QtProperty* property, osg::Vec3 value); void slotPropertyDestroyed(QtProperty* property); QtVec3PropertyManager* m_vec3TPropertyManager; QtVec3PropertyManager* m_vec3RPropertyManager; QtVec3PropertyManager* m_vec3SPropertyManager; QMap m_propertyTot; QMap m_propertyTor; QMap m_propertyTos; QMap m_tToProperty; QMap m_rToProperty; QMap m_sToProperty; }; void QtTransfromPropertyManagerPrivate::slotVec3Changed(QtProperty* property, osg::Vec3 value) { if (QtProperty* prop = m_tToProperty.value(property, 0)) { QTransformAttribute c = m_values[prop]; /*osg::Vec3 l = c.GetLocation(); l._v[0] = value;*/ c.SetLocation(value); q_ptr->setValue(prop, c); } else if (QtProperty* prop = m_rToProperty.value(property, 0)) { QTransformAttribute c = m_values[prop]; /*osg::Vec3 l = c.GetLocation(); l._v[1] = value;*/ c.SetRotation(value); q_ptr->setValue(prop, c); } else if (QtProperty* prop = m_sToProperty.value(property, 0)) { QTransformAttribute c = m_values[prop]; /*osg::Vec3 l = c.GetLocation(); l._v[2] = value;*/ c.SetScale(value); q_ptr->setValue(prop, c); } } void QtTransfromPropertyManagerPrivate::slotPropertyDestroyed(QtProperty* property) { if (QtProperty* pointProp = m_tToProperty.value(property, 0)) { m_propertyTot[pointProp] = 0; m_tToProperty.remove(property); } else if (QtProperty* pointProp = m_rToProperty.value(property, 0)) { m_propertyTor[pointProp] = 0; m_rToProperty.remove(property); } else if (QtProperty* pointProp = m_sToProperty.value(property, 0)) { m_propertyTos[pointProp] = 0; m_sToProperty.remove(property); } } QtTransfromPropertyManager::QtTransfromPropertyManager(QObject* parent) : QtAbstractPropertyManager(parent), d_ptr(new QtTransfromPropertyManagerPrivate) { d_ptr->q_ptr = this; d_ptr->m_vec3TPropertyManager = new QtVec3PropertyManager(this); connect(d_ptr->m_vec3TPropertyManager, SIGNAL(valueChanged(QtProperty*, osg::Vec3)), this, SLOT(slotVec3Changed(QtProperty*, osg::Vec3))); connect(d_ptr->m_vec3TPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)), this, SLOT(slotPropertyDestroyed(QtProperty*))); d_ptr->m_vec3RPropertyManager = new QtVec3PropertyManager(this); connect(d_ptr->m_vec3RPropertyManager, SIGNAL(valueChanged(QtProperty*, osg::Vec3)), this, SLOT(slotVec3Changed(QtProperty*, osg::Vec3))); connect(d_ptr->m_vec3RPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)), this, SLOT(slotPropertyDestroyed(QtProperty*))); d_ptr->m_vec3SPropertyManager = new QtVec3PropertyManager(this); connect(d_ptr->m_vec3SPropertyManager, SIGNAL(valueChanged(QtProperty*, osg::Vec3)), this, SLOT(slotVec3Changed(QtProperty*, osg::Vec3))); connect(d_ptr->m_vec3SPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)), this, SLOT(slotPropertyDestroyed(QtProperty*))); } /*! Destroys this manager, and all the properties it has created. */ QtTransfromPropertyManager::~QtTransfromPropertyManager() { clear(); } /*! Returns the given \a property's value. If the given property is not managed by this manager, this function returns 0. \sa setValue() */ QTransformAttribute QtTransfromPropertyManager::value(const QtProperty* property) const { return d_ptr->m_values.value(property, QTransformAttribute()); } QtVec3PropertyManager* QtTransfromPropertyManager::subVec3TPropertyManager() const { return d_ptr->m_vec3TPropertyManager; } QtVec3PropertyManager* QtTransfromPropertyManager::subVec3RPropertyManager() const { return d_ptr->m_vec3RPropertyManager; } QtVec3PropertyManager* QtTransfromPropertyManager::subVec3SPropertyManager() const { return d_ptr->m_vec3SPropertyManager; } void QtTransfromPropertyManager::setValue(QtProperty* property, QTransformAttribute val) { const QtTransfromPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; if (it.value() == val) return; it.value() = val; d_ptr->m_vec3TPropertyManager->setValue(d_ptr->m_propertyTot[property], val.GetLocation()); d_ptr->m_vec3RPropertyManager->setValue(d_ptr->m_propertyTor[property], val.GetRotation()); d_ptr->m_vec3SPropertyManager->setValue(d_ptr->m_propertyTos[property], val.GetScale()); emit propertyChanged(property); emit valueChanged(property, val); } void QtTransfromPropertyManager::setValueOnly(QtProperty* property, QTransformAttribute val) { const QtTransfromPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; if (it.value() == val) return; it.value() = val; d_ptr->m_vec3TPropertyManager->setValue(d_ptr->m_propertyTot[property], val.GetLocation()); d_ptr->m_vec3RPropertyManager->setValue(d_ptr->m_propertyTor[property], val.GetRotation()); d_ptr->m_vec3SPropertyManager->setValue(d_ptr->m_propertyTos[property], val.GetScale()); } QString QtTransfromPropertyManager::valueText(const QtProperty* property) const { const QtTransfromPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); if (it == d_ptr->m_values.constEnd()) return QString(); QTransformAttribute c = it.value(); osg::Vec3 t = c.GetLocation(); osg::Vec3 r = c.GetLocation(); osg::Vec3 s = c.GetLocation(); return QCoreApplication::translate("QtPropertyBrowserUtils", "[%1, %2, %3] [%4, %5, %6] [%7, %8, %9]") .arg(t.x()).arg(t.y()).arg(t.z()) .arg(r.x()).arg(r.y()).arg(r.z()) .arg(s.x()).arg(s.y()).arg(s.z()); } void QtTransfromPropertyManager::initializeProperty(QtProperty* property) { QTransformAttribute val; d_ptr->m_values[property] = val; QtProperty* rProp = d_ptr->m_vec3TPropertyManager->addProperty(); rProp->setPropertyName(tr("Location")); d_ptr->m_vec3TPropertyManager->setValueOnly(rProp, val.GetLocation()); d_ptr->m_propertyTot[property] = rProp; d_ptr->m_tToProperty[rProp] = property; property->addSubProperty(rProp); QtProperty* gProp = d_ptr->m_vec3RPropertyManager->addProperty(); gProp->setPropertyName(tr("Rotation")); d_ptr->m_vec3RPropertyManager->setValueOnly(gProp, val.GetRotation()); d_ptr->m_propertyTor[property] = gProp; d_ptr->m_rToProperty[gProp] = property; property->addSubProperty(gProp); QtProperty* bProp = d_ptr->m_vec3SPropertyManager->addProperty(); bProp->setPropertyName(tr("Scale")); d_ptr->m_vec3SPropertyManager->setValueOnly(bProp, val.GetScale()); d_ptr->m_propertyTos[property] = bProp; d_ptr->m_sToProperty[bProp] = property; property->addSubProperty(bProp); } void QtTransfromPropertyManager::uninitializeProperty(QtProperty* property) { QtProperty* rProp = d_ptr->m_propertyTot[property]; if (rProp) { d_ptr->m_tToProperty.remove(rProp); delete rProp; } d_ptr->m_propertyTot.remove(property); QtProperty* gProp = d_ptr->m_propertyTor[property]; if (gProp) { d_ptr->m_rToProperty.remove(gProp); delete gProp; } d_ptr->m_propertyTor.remove(property); QtProperty* bProp = d_ptr->m_propertyTos[property]; if (bProp) { d_ptr->m_sToProperty.remove(bProp); delete bProp; } d_ptr->m_propertyTos.remove(property); d_ptr->m_values.remove(property); } #pragma endregion // QtModelBasePropertyManager #pragma region QtModelBasePropertyManager class QtModelBasePropertyManagerPrivate { QtModelBasePropertyManager* q_ptr; Q_DECLARE_PUBLIC(QtModelBasePropertyManager) public: void slotStringChanged(QtProperty* property, QString value); void slotBoolChanged(QtProperty* property, bool value); void slotDoubleChanged(QtProperty* property, double value); void slotPropertyDestroyed(QtProperty* property); typedef QMap PropertyValueMap; PropertyValueMap m_values; QtStringPropertyManager* m_stringProperyManager; QtBoolPropertyManager* m_boolPropertyManager; QtDoublePropertyManager* m_deoubleProperyManager; QMap m_properyToName; QMap m_properyToDescription; QMap m_properyToInflow; QMap m_properyToInnerBottomElevation; QMap m_properyToVisible; QMap m_nameToPropery; QMap m_descriptionToPropery; QMap m_inflowToPropery; QMap m_InnerBottomElevationToPropery; QMap m_visibleToPropery; }; void QtModelBasePropertyManagerPrivate::slotStringChanged(QtProperty* property, QString value) { if (QtProperty* prop = m_properyToName.value(property, 0)) { QModelAttbute c = m_values[prop]; c.SetName(value); q_ptr->setValue(prop, c); } } void QtModelBasePropertyManagerPrivate::slotBoolChanged(QtProperty* property, bool value) { if (QtProperty* prop = m_properyToVisible.value(property, 0)) { QModelAttbute c = m_values[prop]; c.EnableInflow(value); q_ptr->setValue(prop, c); } } void QtModelBasePropertyManagerPrivate::slotDoubleChanged(QtProperty* property, double value) { if (QtProperty* prop = m_properyToInnerBottomElevation.value(property, 0)) { QModelAttbute c = m_values[prop]; c.SetInnerBottomElevation(value); q_ptr->setValue(prop, c); } } void QtModelBasePropertyManagerPrivate::slotPropertyDestroyed(QtProperty* property) { if (QtProperty* subProp = m_nameToPropery.value(property, nullptr)) { m_nameToPropery[subProp] = 0; m_nameToPropery.remove(property); } } QtModelBasePropertyManager::QtModelBasePropertyManager(QObject* parent) : QtAbstractPropertyManager(parent), d_ptr(new QtModelBasePropertyManagerPrivate) { d_ptr->q_ptr = this; d_ptr->m_stringProperyManager = new QtStringPropertyManager(this); connect(d_ptr->m_stringProperyManager, SIGNAL(valueChanged(QtProperty*, QString)), this, SLOT(slotStringChanged(QtProperty*, QString))); d_ptr->m_boolPropertyManager = new QtBoolPropertyManager(this); connect(d_ptr->m_boolPropertyManager, SIGNAL(valueChanged(QtProperty*, bool)), this, SLOT(slotBoolChanged(QtProperty*, bool))); d_ptr->m_deoubleProperyManager = new QtDoublePropertyManager(this); connect(d_ptr->m_deoubleProperyManager, SIGNAL(valueChanged(QtProperty*, double)), this, SLOT(slotStringChanged(QtProperty*, double))); } /*! Destroys this manager, and all the properties it has created. */ QtModelBasePropertyManager::~QtModelBasePropertyManager() { clear(); } /*! Returns the given \a property's value. If the given \a property is not managed by this manager, this function returns a default QCursor object. \sa setValue() */ QModelAttbute QtModelBasePropertyManager::value(const QtProperty* property) const { return d_ptr->m_values.value(property, QModelAttbute()); } QtStringPropertyManager* QtModelBasePropertyManager::subStringProperyManager() const { return d_ptr->m_stringProperyManager; } QtBoolPropertyManager* QtModelBasePropertyManager::subBoolProperyManager() const { return d_ptr->m_boolPropertyManager; } QtDoublePropertyManager* QtModelBasePropertyManager::subDoubleManager() const { return d_ptr->m_deoubleProperyManager; } /*! \reimp */ QString QtModelBasePropertyManager::valueText(const QtProperty* property) const { const QtModelBasePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); if (it == d_ptr->m_values.constEnd()) return QString(); return QString("model base");//cursorDatabase()->cursorToShapeName(it.value()); } /*! \reimp */ QIcon QtModelBasePropertyManager::valueIcon(const QtProperty* property) const { const QtModelBasePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); if (it == d_ptr->m_values.constEnd()) return QIcon(); return QIcon(); //cursorDatabase()->cursorToShapeIcon(it.value()); } /*! \fn void QtCursorPropertyManager::setValue(QtProperty *property, const QCursor &value) Sets the value of the given \a property to \a value. \sa value(), valueChanged() */ void QtModelBasePropertyManager::setValue(QtProperty* property, const QModelAttbute& value) { const QtModelBasePropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; if (it.value() == value) return; it.value() = value; d_ptr->m_stringProperyManager->setValue(d_ptr->m_properyToName[property], value.GetName()); d_ptr->m_stringProperyManager->setValue(d_ptr->m_properyToDescription[property], value.GetDescription()); d_ptr->m_boolPropertyManager->setValue(d_ptr->m_properyToInflow[property], value.IsEnableInfow()); d_ptr->m_deoubleProperyManager->setValue(d_ptr->m_properyToInnerBottomElevation[property], value.GetInnerBottomElevation()); d_ptr->m_boolPropertyManager->setValue(d_ptr->m_properyToVisible[property], value.IsVisible()); emit propertyChanged(property); emit valueChanged(property, value); } /*! \reimp */ void QtModelBasePropertyManager::initializeProperty(QtProperty* property) { QModelAttbute val; d_ptr->m_values[property] = val; QtProperty* prop = d_ptr->m_stringProperyManager->addProperty(); prop->setPropertyName(tr("Name")); d_ptr->m_stringProperyManager->setValueOnly(prop, val.GetName()); d_ptr->m_properyToName[property] = prop; d_ptr->m_nameToPropery[prop] = property; property->addSubProperty(prop); prop = d_ptr->m_stringProperyManager->addProperty(); prop->setPropertyName(tr("Description")); d_ptr->m_stringProperyManager->setValueOnly(prop, val.GetDescription()); d_ptr->m_properyToDescription[property] = prop; d_ptr->m_descriptionToPropery[prop] = property; property->addSubProperty(prop); prop = d_ptr->m_boolPropertyManager->addProperty(); prop->setPropertyName(tr("Inflow")); d_ptr->m_boolPropertyManager->setValueOnly(prop, val.IsEnableInfow()); d_ptr->m_properyToInflow[property] = prop; d_ptr->m_inflowToPropery[prop] = property; property->addSubProperty(prop); prop = d_ptr->m_deoubleProperyManager->addProperty(); prop->setPropertyName(tr("InnerBottomElevation")); d_ptr->m_deoubleProperyManager->setValueOnly(prop, val.GetInnerBottomElevation()); d_ptr->m_properyToInnerBottomElevation[property] = prop; d_ptr->m_InnerBottomElevationToPropery[prop] = property; property->addSubProperty(prop); prop = d_ptr->m_boolPropertyManager->addProperty(); prop->setPropertyName(tr("Visible")); d_ptr->m_boolPropertyManager->setValueOnly(prop, val.IsVisible()); d_ptr->m_properyToVisible[property] = prop; d_ptr->m_visibleToPropery[prop] = property; property->addSubProperty(prop); } /*! \reimp */ void QtModelBasePropertyManager::uninitializeProperty(QtProperty* property) { QtProperty* prop = d_ptr->m_nameToPropery[property]; if (prop) { d_ptr->m_nameToPropery.remove(prop); delete prop; } d_ptr->m_properyToName.remove(property); prop = d_ptr->m_descriptionToPropery[property]; if (prop) { d_ptr->m_descriptionToPropery.remove(prop); delete prop; } d_ptr->m_properyToDescription.remove(property); prop = d_ptr->m_inflowToPropery[property]; if (prop) { d_ptr->m_inflowToPropery.remove(prop); delete prop; } d_ptr->m_properyToInflow.remove(property); prop = d_ptr->m_InnerBottomElevationToPropery[property]; if (prop) { d_ptr->m_InnerBottomElevationToPropery.remove(prop); delete prop; } d_ptr->m_properyToInnerBottomElevation.remove(property); prop = d_ptr->m_visibleToPropery[property]; if (prop) { d_ptr->m_visibleToPropery.remove(prop); delete prop; } d_ptr->m_properyToVisible.remove(property); } #pragma endregion // QtWorkspacePropertyManager #pragma region QtWorkspacePropertyManager class QtWorkspacePropertyManagerPrivate { QtWorkspacePropertyManager* q_ptr; Q_DECLARE_PUBLIC(QtWorkspacePropertyManager) public: void slotStringChanged(QtProperty* property, QString value); void slotIntChanged(QtProperty* property, int value); void slotPropertyDestroyed(QtProperty* property); typedef QMap PropertyValueMap; PropertyValueMap m_values; QtStringPropertyManager* m_stringProperyManager; QtFilesPropertyManager* m_filesProperyManager; QtIntPropertyManager* m_intProperyManager{ nullptr }; QtGroupPropertyManager* m_groupProperyManager{ nullptr }; QMap m_properyToName; QMap m_properyToDescription; QMap m_properyToTimestep; QMap m_properyToSimMatlab; QMap m_properyToMatlabParam; QMap m_properyToWavePath; QMap m_properyToReportPath; QMap m_properyToRDPath; QMap m_properyToCommondPath; QMap m_nameToPropery; QMap m_descriptionToPropery; QMap m_timestepToPropery; QMap m_simMatlabToPropery; QMap m_matlabParamToPropery; QMap m_wavePathToPropery; QMap m_reportPathToPropery; QMap m_rdPathToPropery; QMap m_commondPathToPropery; // Grouped file entries: Curve QMap m_properyToCurveGroup; QMap m_curveGroupToPropery; QMap m_properyToCurveCount; QMap m_curveCountToPropery; QMap> m_properyToCurvePaths; QMap m_curvePathToPropery; QMap m_curvePathIndex; // Surface QMap m_properyToSurfaceGroup; QMap m_surfaceGroupToPropery; QMap m_properyToSurfaceCount; QMap m_surfaceCountToPropery; QMap> m_properyToSurfacePaths; QMap m_surfacePathToPropery; QMap m_surfacePathIndex; // Table QMap m_properyToTableGroup; QMap m_tableGroupToPropery; QMap m_properyToTableCount; QMap m_tableCountToPropery; QMap> m_properyToTablePaths; QMap m_tablePathToPropery; QMap m_tablePathIndex; // Light QMap m_properyToLightGroup; QMap m_lightGroupToPropery; QMap m_properyToLightCount; QMap m_lightCountToPropery; QMap> m_properyToLightPaths; QMap m_lightPathToPropery; QMap m_lightPathIndex; // Polar QMap m_properyToPolarGroup; QMap m_polarGroupToPropery; QMap m_properyToPolarCount; QMap m_polarCountToPropery; QMap> m_properyToPolarPaths; QMap m_polarPathToPropery; QMap m_polarPathIndex; // Image QMap m_properyToImageGroup; QMap m_imageGroupToPropery; QMap m_properyToImageCount; QMap m_imageCountToPropery; QMap> m_properyToImagePaths; QMap m_imagePathToPropery; QMap m_imagePathIndex; }; void QtWorkspacePropertyManagerPrivate::slotStringChanged(QtProperty* property, QString value) { if (QtProperty* prop = m_nameToPropery.value(property, 0)) { QWorkspaceAttribute c = m_values[prop]; c.SetName(value); q_ptr->setValue(prop, c); } else if (QtProperty* prop = m_descriptionToPropery.value(property, 0)) { QWorkspaceAttribute c = m_values[prop]; c.SetDescription(value); q_ptr->setValue(prop, c); } else if (QtProperty* prop = m_timestepToPropery.value(property, 0)) { QWorkspaceAttribute c = m_values[prop]; c.SetTimeStep(value); q_ptr->setValue(prop, c); } else if (QtProperty* prop = m_commondPathToPropery.value(property, 0)) { QWorkspaceAttribute c = m_values[prop]; c.SetCommondFilePath(value); q_ptr->setValue(prop, c); } else if (QtProperty* prop = m_commondPathToPropery.value(property, 0)) { QWorkspaceAttribute c = m_values[prop]; c.SetCommondFilePath(value); q_ptr->setValue(prop, c); } else if (QtProperty* prop = m_curvePathToPropery.value(property, 0)) { QWorkspaceAttribute c = m_values[prop]; int idx = m_curvePathIndex.value(property, 0); c.SetFileEntryPath(FileEntryType::Curve, idx, value); q_ptr->setValue(prop, c); } else if (QtProperty* prop = m_surfacePathToPropery.value(property, 0)) { QWorkspaceAttribute c = m_values[prop]; int idx = m_surfacePathIndex.value(property, 0); c.SetFileEntryPath(FileEntryType::Surface, idx, value); q_ptr->setValue(prop, c); } else if (QtProperty* prop = m_tablePathToPropery.value(property, 0)) { QWorkspaceAttribute c = m_values[prop]; int idx = m_tablePathIndex.value(property, 0); c.SetFileEntryPath(FileEntryType::Table, idx, value); q_ptr->setValue(prop, c); } else if (QtProperty* prop = m_lightPathToPropery.value(property, 0)) { QWorkspaceAttribute c = m_values[prop]; int idx = m_lightPathIndex.value(property, 0); c.SetFileEntryPath(FileEntryType::Light, idx, value); q_ptr->setValue(prop, c); } else if (QtProperty* prop = m_polarPathToPropery.value(property, 0)) { QWorkspaceAttribute c = m_values[prop]; int idx = m_polarPathIndex.value(property, 0); c.SetFileEntryPath(FileEntryType::Polar, idx, value); q_ptr->setValue(prop, c); } else if (QtProperty* prop = m_imagePathToPropery.value(property, 0)) { QWorkspaceAttribute c = m_values[prop]; int idx = m_imagePathIndex.value(property, 0); c.SetFileEntryPath(FileEntryType::Image, idx, value); q_ptr->setValue(prop, c); } } void QtWorkspacePropertyManagerPrivate::slotIntChanged(QtProperty* property, int value) { // Determine which type this count property belongs to auto handleType = [&](FileEntryType type, QMap& countToProp, QMap>& propToPaths, QMap& pathToProp, QMap& pathIndex, QMap& propToGroup) { if (QtProperty* root = countToProp.value(property, nullptr)) { // Adjust UI path properties to match new count QVector& paths = propToPaths[root]; int current = paths.size(); // Add new path properties if (value > current) { QtProperty* group = propToGroup.value(root, nullptr); for (int i = current; i < value; ++i) { QtProperty* p = m_filesProperyManager->addProperty(); QString title; switch (type) { case FileEntryType::Curve: title = QObject::tr("Curve[%1]").arg(i + 1); break; case FileEntryType::Surface: title = QObject::tr("Surface[%1]").arg(i + 1); break; case FileEntryType::Table: title = QObject::tr("Table[%1]").arg(i + 1); break; case FileEntryType::Light: title = QObject::tr("Light[%1]").arg(i + 1); break; case FileEntryType::Polar: title = QObject::tr("Polar[%1]").arg(i + 1); break; case FileEntryType::Image: title = QObject::tr("Image[%1]").arg(i + 1); break; } p->setPropertyName(title); group->addSubProperty(p); paths.append(p); pathToProp[p] = root; pathIndex[p] = i; } } else if (value < current) { // Remove excess path properties for (int i = current - 1; i >= value; --i) { QtProperty* p = paths.at(i); pathIndex.remove(p); pathToProp.remove(p); paths.remove(i); delete p; } } // Update underlying model count QWorkspaceAttribute c = m_values[root]; c.SetFileEntryCount(type, value); q_ptr->setValue(root, c); } }; handleType(FileEntryType::Curve, m_curveCountToPropery, m_properyToCurvePaths, m_curvePathToPropery, m_curvePathIndex, m_properyToCurveGroup); handleType(FileEntryType::Surface, m_surfaceCountToPropery, m_properyToSurfacePaths, m_surfacePathToPropery, m_surfacePathIndex, m_properyToSurfaceGroup); handleType(FileEntryType::Table, m_tableCountToPropery, m_properyToTablePaths, m_tablePathToPropery, m_tablePathIndex, m_properyToTableGroup); handleType(FileEntryType::Light, m_lightCountToPropery, m_properyToLightPaths, m_lightPathToPropery, m_lightPathIndex, m_properyToLightGroup); handleType(FileEntryType::Polar, m_polarCountToPropery, m_properyToPolarPaths, m_polarPathToPropery, m_polarPathIndex, m_properyToPolarGroup); handleType(FileEntryType::Image, m_imageCountToPropery, m_properyToImagePaths, m_imagePathToPropery, m_imagePathIndex, m_properyToImageGroup); } void QtWorkspacePropertyManagerPrivate::slotPropertyDestroyed(QtProperty* property) { if (QtProperty* subProp = m_nameToPropery.value(property, nullptr)) { m_nameToPropery[subProp] = 0; m_nameToPropery.remove(property); } if (QtProperty* subProp = m_descriptionToPropery.value(property, nullptr)) { m_descriptionToPropery[subProp] = 0; m_descriptionToPropery.remove(property); } if (QtProperty* subProp = m_timestepToPropery.value(property, nullptr)) { m_timestepToPropery[subProp] = 0; m_timestepToPropery.remove(property); } if (QtProperty* subProp = m_simMatlabToPropery.value(property, nullptr)) { m_simMatlabToPropery[subProp] = 0; m_simMatlabToPropery.remove(property); } if (QtProperty* subProp = m_matlabParamToPropery.value(property, nullptr)) { m_matlabParamToPropery[subProp] = 0; m_matlabParamToPropery.remove(property); } if (QtProperty* subProp = m_wavePathToPropery.value(property, nullptr)) { m_wavePathToPropery[subProp] = 0; m_wavePathToPropery.remove(property); } if (QtProperty* subProp = m_reportPathToPropery.value(property, nullptr)) { m_reportPathToPropery[subProp] = 0; m_reportPathToPropery.remove(property); } if (QtProperty* subProp = m_rdPathToPropery.value(property, nullptr)) { m_rdPathToPropery[subProp] = 0; m_rdPathToPropery.remove(property); } } QtWorkspacePropertyManager::QtWorkspacePropertyManager(QObject* parent) : QtAbstractPropertyManager(parent), d_ptr(new QtWorkspacePropertyManagerPrivate) { d_ptr->q_ptr = this; d_ptr->m_stringProperyManager = new QtStringPropertyManager(this); connect(d_ptr->m_stringProperyManager, SIGNAL(valueChanged(QtProperty*, QString)), this, SLOT(slotStringChanged(QtProperty*, QString))); d_ptr->m_filesProperyManager = new QtFilesPropertyManager(this); connect(d_ptr->m_filesProperyManager, SIGNAL(valueChanged(QtProperty*, QString)), this, SLOT(slotStringChanged(QtProperty*, QString))); d_ptr->m_intProperyManager = new QtIntPropertyManager(this); connect(d_ptr->m_intProperyManager, SIGNAL(valueChanged(QtProperty*, int)), this, SLOT(slotIntChanged(QtProperty*, int))); d_ptr->m_groupProperyManager = new QtGroupPropertyManager(this); } /*! Destroys this manager, and all the properties it has created. */ QtWorkspacePropertyManager::~QtWorkspacePropertyManager() { clear(); } /*! Returns the given \a property's value. If the given \a property is not managed by this manager, this function returns a default QCursor object. \sa setValue() */ QWorkspaceAttribute QtWorkspacePropertyManager::value(const QtProperty* property) const { return d_ptr->m_values.value(property, QWorkspaceAttribute()); } QtStringPropertyManager* QtWorkspacePropertyManager::subStringProperyManager() const { return d_ptr->m_stringProperyManager; } QtFilesPropertyManager* QtWorkspacePropertyManager::subFilesProperyManager() const { return d_ptr->m_filesProperyManager; } QtIntPropertyManager* QtWorkspacePropertyManager::subIntProperyManager() const { return d_ptr->m_intProperyManager; } QtGroupPropertyManager* QtWorkspacePropertyManager::subGroupProperyManager() const { return d_ptr->m_groupProperyManager; } /*! \reimp */ QString QtWorkspacePropertyManager::valueText(const QtProperty* property) const { const QtWorkspacePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); if (it == d_ptr->m_values.constEnd()) return QString(); return QString("workspace");//cursorDatabase()->cursorToShapeName(it.value()); } /*! \reimp */ QIcon QtWorkspacePropertyManager::valueIcon(const QtProperty* property) const { const QtWorkspacePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); if (it == d_ptr->m_values.constEnd()) return QIcon(); return QIcon(); //cursorDatabase()->cursorToShapeIcon(it.value()); } /*! \fn void QtCursorPropertyManager::setValue(QtProperty *property, const QCursor &value) Sets the value of the given \a property to \a value. \sa value(), valueChanged() */ void QtWorkspacePropertyManager::setValue(QtProperty* property, const QWorkspaceAttribute& value) { const QtWorkspacePropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; if (it.value() == value) return; it.value() = value; d_ptr->m_stringProperyManager->setValue(d_ptr->m_properyToName[property], value.GetName()); d_ptr->m_stringProperyManager->setValue(d_ptr->m_properyToDescription[property], value.GetDescription()); d_ptr->m_filesProperyManager->setValue(d_ptr->m_properyToTimestep[property], value.GetTimeStep()); d_ptr->m_filesProperyManager->setValue(d_ptr->m_properyToCommondPath[property], value.GetCommondFilePath()); auto syncGroup = [&](FileEntryType type, QMap& propToGroup, QMap& propToCount, QMap>& propToPaths, QMap& pathToProp, QMap& pathIndex) { QtProperty* group = propToGroup.value(property, nullptr); if (!group) return; auto entries = value.GetFileEntries(type); int count = static_cast(entries.size()); // update count without triggering slot QtProperty* countProp = propToCount.value(property, nullptr); if (countProp) d_ptr->m_intProperyManager->setValueOnly(countProp, count); QVector& paths = propToPaths[property]; int current = paths.size(); // expand if (count > current) { for (int i = current; i < count; ++i) { QtProperty* p = d_ptr->m_filesProperyManager->addProperty(); QString title; switch (type) { case FileEntryType::Curve: title = QObject::tr("Curve[%1]").arg(i + 1); break; case FileEntryType::Surface: title = QObject::tr("Surface[%1]").arg(i + 1); break; case FileEntryType::Table: title = QObject::tr("Table[%1]").arg(i + 1); break; case FileEntryType::Light: title = QObject::tr("Light[%1]").arg(i + 1); break; case FileEntryType::Image: title = QObject::tr("Image[%1]").arg(i + 1); break; } p->setPropertyName(title); group->addSubProperty(p); paths.append(p); pathToProp[p] = property; pathIndex[p] = i; } } else if (count < current) { for (int i = current - 1; i >= count; --i) { QtProperty* p = paths.at(i); pathIndex.remove(p); pathToProp.remove(p); paths.remove(i); delete p; } } // set values for (int i = 0; i < count; ++i) { const QString absPath = value.GetFileEntryAbsPath(type, i); d_ptr->m_filesProperyManager->setValueOnly(paths.at(i), absPath); } }; syncGroup(FileEntryType::Curve, d_ptr->m_properyToCurveGroup, d_ptr->m_properyToCurveCount, d_ptr->m_properyToCurvePaths, d_ptr->m_curvePathToPropery, d_ptr->m_curvePathIndex); syncGroup(FileEntryType::Surface, d_ptr->m_properyToSurfaceGroup, d_ptr->m_properyToSurfaceCount, d_ptr->m_properyToSurfacePaths, d_ptr->m_surfacePathToPropery, d_ptr->m_surfacePathIndex); syncGroup(FileEntryType::Table, d_ptr->m_properyToTableGroup, d_ptr->m_properyToTableCount, d_ptr->m_properyToTablePaths, d_ptr->m_tablePathToPropery, d_ptr->m_tablePathIndex); syncGroup(FileEntryType::Light, d_ptr->m_properyToLightGroup, d_ptr->m_properyToLightCount, d_ptr->m_properyToLightPaths, d_ptr->m_lightPathToPropery, d_ptr->m_lightPathIndex); syncGroup(FileEntryType::Polar, d_ptr->m_properyToPolarGroup, d_ptr->m_properyToPolarCount, d_ptr->m_properyToPolarPaths, d_ptr->m_polarPathToPropery, d_ptr->m_polarPathIndex); syncGroup(FileEntryType::Image, d_ptr->m_properyToImageGroup, d_ptr->m_properyToImageCount, d_ptr->m_properyToImagePaths, d_ptr->m_imagePathToPropery, d_ptr->m_imagePathIndex); emit propertyChanged(property); emit valueChanged(property, value); } /*! \reimp */ void QtWorkspacePropertyManager::initializeProperty(QtProperty* property) { QWorkspaceAttribute val; d_ptr->m_values[property] = val; QtProperty* prop = d_ptr->m_stringProperyManager->addProperty(); prop->setPropertyName(tr("Name")); d_ptr->m_stringProperyManager->setValueOnly(prop, val.GetName()); d_ptr->m_properyToName[property] = prop; d_ptr->m_nameToPropery[prop] = property; property->addSubProperty(prop); prop = d_ptr->m_stringProperyManager->addProperty(); prop->setPropertyName(tr("Description")); d_ptr->m_stringProperyManager->setValueOnly(prop, val.GetDescription()); d_ptr->m_properyToDescription[property] = prop; d_ptr->m_descriptionToPropery[prop] = property; property->addSubProperty(prop); prop = d_ptr->m_filesProperyManager->addProperty(); prop->setPropertyName(tr("Timestep")); d_ptr->m_filesProperyManager->setValueOnly(prop, val.GetTimeStep()); d_ptr->m_properyToTimestep[property] = prop; d_ptr->m_timestepToPropery[prop] = property; property->addSubProperty(prop); // Deprecated properties (SimMatlab/MatlabParam/WavePath/ReportPath/RDPath) removed from UI // Command XML path prop = d_ptr->m_filesProperyManager->addProperty(); prop->setPropertyName(tr("CommondPath")); d_ptr->m_filesProperyManager->setValueOnly(prop, val.GetCommondFilePath()); d_ptr->m_properyToCommondPath[property] = prop; d_ptr->m_commondPathToPropery[prop] = property; property->addSubProperty(prop); // Add grouped file sections auto addGroup = [&](FileEntryType type, const QString& groupName, QMap& propToGroup, QMap& groupToProp, QMap& propToCount, QMap& countToProp, QMap>& propToPaths, QMap& pathToProp, QMap& pathIndex) { QtProperty* group = d_ptr->m_groupProperyManager->addProperty(); group->setPropertyName(groupName); property->addSubProperty(group); propToGroup[property] = group; groupToProp[group] = property; // Count property QtProperty* countProp = d_ptr->m_intProperyManager->addProperty(); countProp->setPropertyName(tr("Count")); d_ptr->m_intProperyManager->setRange(countProp, 0, 1024); // initial count from workspace int initialCount = static_cast(val.GetFileEntries(type).size()); d_ptr->m_intProperyManager->setValueOnly(countProp, initialCount); propToCount[property] = countProp; countToProp[countProp] = property; group->addSubProperty(countProp); // initial paths auto entries = val.GetFileEntries(type); QVector& paths = propToPaths[property]; for (int i = 0; i < static_cast(entries.size()); ++i) { QtProperty* p = d_ptr->m_filesProperyManager->addProperty(); QString title; switch (type) { case FileEntryType::Curve: title = tr("Curve[%1]").arg(i + 1); break; case FileEntryType::Surface: title = tr("Surface[%1]").arg(i + 1); break; case FileEntryType::Table: title = tr("Table[%1]").arg(i + 1); break; case FileEntryType::Light: title = tr("Light[%1]").arg(i + 1); break; case FileEntryType::Image: title = tr("Image[%1]").arg(i + 1); break; } p->setPropertyName(title); d_ptr->m_filesProperyManager->setValueOnly(p, val.GetFileEntryAbsPath(type, i)); group->addSubProperty(p); paths.append(p); pathToProp[p] = property; pathIndex[p] = i; } }; addGroup(FileEntryType::Curve, tr("Curves"), d_ptr->m_properyToCurveGroup, d_ptr->m_curveGroupToPropery, d_ptr->m_properyToCurveCount, d_ptr->m_curveCountToPropery, d_ptr->m_properyToCurvePaths, d_ptr->m_curvePathToPropery, d_ptr->m_curvePathIndex); addGroup(FileEntryType::Surface, tr("Surfaces"), d_ptr->m_properyToSurfaceGroup, d_ptr->m_surfaceGroupToPropery, d_ptr->m_properyToSurfaceCount, d_ptr->m_surfaceCountToPropery, d_ptr->m_properyToSurfacePaths, d_ptr->m_surfacePathToPropery, d_ptr->m_surfacePathIndex); addGroup(FileEntryType::Table, tr("Tables"), d_ptr->m_properyToTableGroup, d_ptr->m_tableGroupToPropery, d_ptr->m_properyToTableCount, d_ptr->m_tableCountToPropery, d_ptr->m_properyToTablePaths, d_ptr->m_tablePathToPropery, d_ptr->m_tablePathIndex); addGroup(FileEntryType::Light, tr("Lights"), d_ptr->m_properyToLightGroup, d_ptr->m_lightGroupToPropery, d_ptr->m_properyToLightCount, d_ptr->m_lightCountToPropery, d_ptr->m_properyToLightPaths, d_ptr->m_lightPathToPropery, d_ptr->m_lightPathIndex); addGroup(FileEntryType::Polar, tr("Polars"), d_ptr->m_properyToPolarGroup, d_ptr->m_polarGroupToPropery, d_ptr->m_properyToPolarCount, d_ptr->m_polarCountToPropery, d_ptr->m_properyToPolarPaths, d_ptr->m_polarPathToPropery, d_ptr->m_polarPathIndex); addGroup(FileEntryType::Image, tr("Images"), d_ptr->m_properyToImageGroup, d_ptr->m_imageGroupToPropery, d_ptr->m_properyToImageCount, d_ptr->m_imageCountToPropery, d_ptr->m_properyToImagePaths, d_ptr->m_imagePathToPropery, d_ptr->m_imagePathIndex); } /*! \reimp */ void QtWorkspacePropertyManager::uninitializeProperty(QtProperty* property) { QtProperty* prop = d_ptr->m_nameToPropery[property]; if (prop) { d_ptr->m_nameToPropery.remove(prop); delete prop; } d_ptr->m_properyToName.remove(property); prop = d_ptr->m_descriptionToPropery[property]; if (prop) { d_ptr->m_descriptionToPropery.remove(prop); delete prop; } d_ptr->m_properyToDescription.remove(property); prop = d_ptr->m_timestepToPropery[property]; if (prop) { d_ptr->m_timestepToPropery.remove(prop); delete prop; } d_ptr->m_properyToTimestep.remove(property); prop = d_ptr->m_simMatlabToPropery[property]; if (prop) { d_ptr->m_simMatlabToPropery.remove(prop); delete prop; } d_ptr->m_properyToSimMatlab.remove(property); prop = d_ptr->m_matlabParamToPropery[property]; if (prop) { d_ptr->m_matlabParamToPropery.remove(prop); delete prop; } d_ptr->m_properyToMatlabParam.remove(property); prop = d_ptr->m_wavePathToPropery[property]; if (prop) { d_ptr->m_wavePathToPropery.remove(prop); delete prop; } d_ptr->m_properyToWavePath.remove(property); prop = d_ptr->m_reportPathToPropery[property]; if (prop) { d_ptr->m_reportPathToPropery.remove(prop); delete prop; } d_ptr->m_properyToReportPath.remove(property); prop = d_ptr->m_rdPathToPropery[property]; if (prop) { d_ptr->m_rdPathToPropery.remove(prop); delete prop; } d_ptr->m_properyToRDPath.remove(property); prop = d_ptr->m_commondPathToPropery[property]; if (prop) { d_ptr->m_commondPathToPropery.remove(prop); delete prop; } d_ptr->m_properyToCommondPath.remove(property); // Cleanup grouped file properties auto cleanupGroup = [&](QMap& propToGroup, QMap& groupToProp, QMap& propToCount, QMap& countToProp, QMap>& propToPaths, QMap& pathToProp, QMap& pathIndex) { QtProperty* group = propToGroup.value(property, nullptr); if (group) { propToGroup.remove(property); groupToProp.remove(group); } QtProperty* countProp = propToCount.value(property, nullptr); if (countProp) { countToProp.remove(countProp); propToCount.remove(property); delete countProp; } QVector& paths = propToPaths[property]; for (QtProperty* p : paths) { pathIndex.remove(p); pathToProp.remove(p); delete p; } paths.clear(); propToPaths.remove(property); if (group) delete group; }; cleanupGroup(d_ptr->m_properyToCurveGroup, d_ptr->m_curveGroupToPropery, d_ptr->m_properyToCurveCount, d_ptr->m_curveCountToPropery, d_ptr->m_properyToCurvePaths, d_ptr->m_curvePathToPropery, d_ptr->m_curvePathIndex); cleanupGroup(d_ptr->m_properyToSurfaceGroup, d_ptr->m_surfaceGroupToPropery, d_ptr->m_properyToSurfaceCount, d_ptr->m_surfaceCountToPropery, d_ptr->m_properyToSurfacePaths, d_ptr->m_surfacePathToPropery, d_ptr->m_surfacePathIndex); cleanupGroup(d_ptr->m_properyToTableGroup, d_ptr->m_tableGroupToPropery, d_ptr->m_properyToTableCount, d_ptr->m_tableCountToPropery, d_ptr->m_properyToTablePaths, d_ptr->m_tablePathToPropery, d_ptr->m_tablePathIndex); cleanupGroup(d_ptr->m_properyToLightGroup, d_ptr->m_lightGroupToPropery, d_ptr->m_properyToLightCount, d_ptr->m_lightCountToPropery, d_ptr->m_properyToLightPaths, d_ptr->m_lightPathToPropery, d_ptr->m_lightPathIndex); cleanupGroup(d_ptr->m_properyToPolarGroup, d_ptr->m_polarGroupToPropery, d_ptr->m_properyToPolarCount, d_ptr->m_polarCountToPropery, d_ptr->m_properyToPolarPaths, d_ptr->m_polarPathToPropery, d_ptr->m_polarPathIndex); cleanupGroup(d_ptr->m_properyToImageGroup, d_ptr->m_imageGroupToPropery, d_ptr->m_properyToImageCount, d_ptr->m_imageCountToPropery, d_ptr->m_properyToImagePaths, d_ptr->m_imagePathToPropery, d_ptr->m_imagePathIndex); } #pragma endregion // QtCurveEntryPropertyManager #pragma region QtCurveEntryPropertyManager class QtCurveEntryPropertyManagerPrivate { QtCurveEntryPropertyManager* q_ptr; Q_DECLARE_PUBLIC(QtCurveEntryPropertyManager) public: void slotStringChanged(QtProperty* property, QString value); void slotEnumChanged(QtProperty* property, int value); void slotIntChanged(QtProperty* property, int value); void slotDoubleChanged(QtProperty* property, double value); void slotColorChanged(QtProperty* property, const QColor& value); void slotPropertyDestroyed(QtProperty* property); typedef QMap PropertyValueMap; PropertyValueMap m_values; QtStringPropertyManager* m_stringProperyManager{ nullptr }; QtEnumPropertyManager* m_enumProperyManager{ nullptr }; QtIntPropertyManager* m_intProperyManager{ nullptr }; QtDoublePropertyManager* m_doubleProperyManager{ nullptr }; QtColorPropertyManager* m_colorProperyManager{ nullptr }; QtGroupPropertyManager* m_groupProperyManager{ nullptr }; // Top-level mappings QMap m_properyToName; QMap m_nameToPropery; QMap m_properyToChartType; QMap m_chartTypeToPropery; QMap m_properyToCurvesGroup; QMap m_curvesGroupToPropery; QMap m_properyToCurveCount; QMap m_curveCountToPropery; // Per-curve sub-properties struct CurveSubProps { QVector names; QVector colors; QVector waveStarts; QVector waveStops; QVector reportXs; QVector reportYs; }; QMap m_curveProps; // Reverse lookup for per-curve properties QMap m_curveNameToRoot; QMap m_curveNameIndex; QMap m_curveColorToRoot; QMap m_curveColorIndex; QMap m_waveStartToRoot; QMap m_waveStartIndex; QMap m_waveStopToRoot; QMap m_waveStopIndex; QMap m_reportXToRoot; QMap m_reportXIndex; QMap m_reportYToRoot; QMap m_reportYIndex; }; void QtCurveEntryPropertyManagerPrivate::slotStringChanged(QtProperty* property, QString value) { if (QtProperty* root = m_nameToPropery.value(property, nullptr)) { QCurveEntryAttribute c = m_values[root]; c.SetName(value); q_ptr->setValue(root, c); } else if (QtProperty* root2 = m_curveNameToRoot.value(property, nullptr)) { QCurveEntryAttribute c = m_values[root2]; int idx = m_curveNameIndex.value(property, 0); c.SetCurveName(idx, value); q_ptr->setValue(root2, c); } } void QtCurveEntryPropertyManagerPrivate::slotEnumChanged(QtProperty* property, int value) { if (QtProperty* root = m_chartTypeToPropery.value(property, nullptr)) { QCurveEntryAttribute c = m_values[root]; ChartType t = ChartType::Wave; if (value == 1) t = ChartType::Report; c.SetChartType(t); q_ptr->setValue(root, c); } } void QtCurveEntryPropertyManagerPrivate::slotIntChanged(QtProperty* property, int value) { if (QtProperty* root = m_curveCountToPropery.value(property, nullptr)) { // Adjust per-curve subproperties to match new count CurveSubProps& subs = m_curveProps[root]; int current = subs.names.size(); QtProperty* group = m_properyToCurvesGroup.value(root, nullptr); if (value > current) { for (int i = current; i < value; ++i) { // Create a subgroup label // Name QtProperty* nameProp = m_stringProperyManager->addProperty(); nameProp->setPropertyName(QObject::tr("Curve[%1] Name").arg(i + 1)); group->addSubProperty(nameProp); subs.names.append(nameProp); m_curveNameToRoot[nameProp] = root; m_curveNameIndex[nameProp] = i; // Color QtProperty* colorProp = m_colorProperyManager->addProperty(); colorProp->setPropertyName(QObject::tr("Curve[%1] Color").arg(i + 1)); group->addSubProperty(colorProp); subs.colors.append(colorProp); m_curveColorToRoot[colorProp] = root; m_curveColorIndex[colorProp] = i; // WaveStart QtProperty* wsProp = m_intProperyManager->addProperty(); wsProp->setPropertyName(QObject::tr("Curve[%1] WaveStart").arg(i + 1)); group->addSubProperty(wsProp); subs.waveStarts.append(wsProp); m_waveStartToRoot[wsProp] = root; m_waveStartIndex[wsProp] = i; // WaveStop QtProperty* weProp = m_intProperyManager->addProperty(); weProp->setPropertyName(QObject::tr("Curve[%1] WaveStop").arg(i + 1)); group->addSubProperty(weProp); subs.waveStops.append(weProp); m_waveStopToRoot[weProp] = root; m_waveStopIndex[weProp] = i; // ReportX QtProperty* rxProp = m_doubleProperyManager->addProperty(); rxProp->setPropertyName(QObject::tr("Curve[%1] ReportX").arg(i + 1)); group->addSubProperty(rxProp); subs.reportXs.append(rxProp); m_reportXToRoot[rxProp] = root; m_reportXIndex[rxProp] = i; // ReportY QtProperty* ryProp = m_doubleProperyManager->addProperty(); ryProp->setPropertyName(QObject::tr("Curve[%1] ReportY").arg(i + 1)); group->addSubProperty(ryProp); subs.reportYs.append(ryProp); m_reportYToRoot[ryProp] = root; m_reportYIndex[ryProp] = i; } } else if (value < current) { for (int i = current - 1; i >= value; --i) { auto eraseProp = [&](QtProperty* p, QMap& toRoot, QMap& toIndex) { toIndex.remove(p); toRoot.remove(p); delete p; }; eraseProp(subs.names.at(i), m_curveNameToRoot, m_curveNameIndex); eraseProp(subs.colors.at(i), m_curveColorToRoot, m_curveColorIndex); eraseProp(subs.waveStarts.at(i), m_waveStartToRoot, m_waveStartIndex); eraseProp(subs.waveStops.at(i), m_waveStopToRoot, m_waveStopIndex); eraseProp(subs.reportXs.at(i), m_reportXToRoot, m_reportXIndex); eraseProp(subs.reportYs.at(i), m_reportYToRoot, m_reportYIndex); subs.names.remove(i); subs.colors.remove(i); subs.waveStarts.remove(i); subs.waveStops.remove(i); subs.reportXs.remove(i); subs.reportYs.remove(i); } } // Update underlying model QCurveEntryAttribute c = m_values[root]; c.SetCurveCount(value); q_ptr->setValue(root, c); } else if (QtProperty* root2 = m_waveStartToRoot.value(property, nullptr)) { QCurveEntryAttribute c = m_values[root2]; int idx = m_waveStartIndex.value(property, 0); c.SetWaveStart(idx, value); q_ptr->setValue(root2, c); } else if (QtProperty* root3 = m_waveStopToRoot.value(property, nullptr)) { QCurveEntryAttribute c = m_values[root3]; int idx = m_waveStopIndex.value(property, 0); c.SetWaveStop(idx, value); q_ptr->setValue(root3, c); } } void QtCurveEntryPropertyManagerPrivate::slotDoubleChanged(QtProperty* property, double value) { if (QtProperty* root = m_reportXToRoot.value(property, nullptr)) { QCurveEntryAttribute c = m_values[root]; int idx = m_reportXIndex.value(property, 0); c.SetReportX(idx, value); q_ptr->setValue(root, c); } else if (QtProperty* root2 = m_reportYToRoot.value(property, nullptr)) { QCurveEntryAttribute c = m_values[root2]; int idx = m_reportYIndex.value(property, 0); c.SetReportY(idx, value); q_ptr->setValue(root2, c); } } void QtCurveEntryPropertyManagerPrivate::slotColorChanged(QtProperty* property, const QColor& value) { if (QtProperty* root = m_curveColorToRoot.value(property, nullptr)) { QCurveEntryAttribute c = m_values[root]; int idx = m_curveColorIndex.value(property, 0); c.SetCurveColor(idx, value); q_ptr->setValue(root, c); } } void QtCurveEntryPropertyManagerPrivate::slotPropertyDestroyed(QtProperty* property) { if (QtProperty* subProp = m_nameToPropery.value(property, nullptr)) { m_nameToPropery[subProp] = 0; m_nameToPropery.remove(property); } else if (QtProperty* subProp = m_chartTypeToPropery.value(property, nullptr)) { m_chartTypeToPropery[subProp] = 0; m_chartTypeToPropery.remove(property); } } QtCurveEntryPropertyManager::QtCurveEntryPropertyManager(QObject* parent) : QtAbstractPropertyManager(parent), d_ptr(new QtCurveEntryPropertyManagerPrivate) { d_ptr->q_ptr = this; d_ptr->m_stringProperyManager = new QtStringPropertyManager(this); connect(d_ptr->m_stringProperyManager, SIGNAL(valueChanged(QtProperty*, QString)), this, SLOT(slotStringChanged(QtProperty*, QString))); d_ptr->m_enumProperyManager = new QtEnumPropertyManager(this); connect(d_ptr->m_enumProperyManager, SIGNAL(valueChanged(QtProperty*, int)), this, SLOT(slotEnumChanged(QtProperty*, int))); d_ptr->m_intProperyManager = new QtIntPropertyManager(this); connect(d_ptr->m_intProperyManager, SIGNAL(valueChanged(QtProperty*, int)), this, SLOT(slotIntChanged(QtProperty*, int))); d_ptr->m_doubleProperyManager = new QtDoublePropertyManager(this); connect(d_ptr->m_doubleProperyManager, SIGNAL(valueChanged(QtProperty*, double)), this, SLOT(slotDoubleChanged(QtProperty*, double))); d_ptr->m_colorProperyManager = new QtColorPropertyManager(this); connect(d_ptr->m_colorProperyManager, SIGNAL(valueChanged(QtProperty*, const QColor&)), this, SLOT(slotColorChanged(QtProperty*, const QColor&))); d_ptr->m_groupProperyManager = new QtGroupPropertyManager(this); } QtCurveEntryPropertyManager::~QtCurveEntryPropertyManager() { clear(); } QCurveEntryAttribute QtCurveEntryPropertyManager::value(const QtProperty* property) const { return d_ptr->m_values.value(property, QCurveEntryAttribute()); } QtStringPropertyManager* QtCurveEntryPropertyManager::subStringProperyManager() const { return d_ptr->m_stringProperyManager; } QtEnumPropertyManager* QtCurveEntryPropertyManager::subEnumProperyManager() const { return d_ptr->m_enumProperyManager; } QtIntPropertyManager* QtCurveEntryPropertyManager::subIntProperyManager() const { return d_ptr->m_intProperyManager; } QtDoublePropertyManager* QtCurveEntryPropertyManager::subDoubleProperyManager() const { return d_ptr->m_doubleProperyManager; } QtColorPropertyManager* QtCurveEntryPropertyManager::subColorProperyManager() const { return d_ptr->m_colorProperyManager; } QtGroupPropertyManager* QtCurveEntryPropertyManager::subGroupProperyManager() const { return d_ptr->m_groupProperyManager; } QString QtCurveEntryPropertyManager::valueText(const QtProperty* property) const { const QtCurveEntryPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); if (it == d_ptr->m_values.constEnd()) return QString(); return QString("curve entry"); } QIcon QtCurveEntryPropertyManager::valueIcon(const QtProperty* /*property*/) const { return QIcon(); } void QtCurveEntryPropertyManager::setValue(QtProperty* property, const QCurveEntryAttribute& val) { const QtCurveEntryPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; if (it.value() == val) return; it.value() = val; // Update top-level subproperties d_ptr->m_stringProperyManager->setValue(d_ptr->m_properyToName[property], val.GetName()); // ChartType enum: 0 Wave, 1 Report int enumVal = (val.GetChartType() == ChartType::Report) ? 1 : 0; d_ptr->m_enumProperyManager->setValue(d_ptr->m_properyToChartType[property], enumVal); // Sync curves group QtProperty* group = d_ptr->m_properyToCurvesGroup.value(property, nullptr); if (group) { int count = val.GetCurveCount(); QtProperty* countProp = d_ptr->m_properyToCurveCount.value(property, nullptr); if (countProp) d_ptr->m_intProperyManager->setValueOnly(countProp, count); // Resize child arrays QtCurveEntryPropertyManagerPrivate::CurveSubProps& subs = d_ptr->m_curveProps[property]; int current = subs.names.size(); if (count > current) { for (int i = current; i < count; ++i) { // Name QtProperty* nameProp = d_ptr->m_stringProperyManager->addProperty(); nameProp->setPropertyName(tr("Curve[%1] Name").arg(i + 1)); group->addSubProperty(nameProp); subs.names.append(nameProp); d_ptr->m_curveNameToRoot[nameProp] = property; d_ptr->m_curveNameIndex[nameProp] = i; // Color QtProperty* colorProp = d_ptr->m_colorProperyManager->addProperty(); colorProp->setPropertyName(tr("Curve[%1] Color").arg(i + 1)); group->addSubProperty(colorProp); subs.colors.append(colorProp); d_ptr->m_curveColorToRoot[colorProp] = property; d_ptr->m_curveColorIndex[colorProp] = i; // WaveStart QtProperty* wsProp = d_ptr->m_intProperyManager->addProperty(); wsProp->setPropertyName(tr("Curve[%1] WaveStart").arg(i + 1)); group->addSubProperty(wsProp); subs.waveStarts.append(wsProp); d_ptr->m_waveStartToRoot[wsProp] = property; d_ptr->m_waveStartIndex[wsProp] = i; // WaveStop QtProperty* weProp = d_ptr->m_intProperyManager->addProperty(); weProp->setPropertyName(tr("Curve[%1] WaveStop").arg(i + 1)); group->addSubProperty(weProp); subs.waveStops.append(weProp); d_ptr->m_waveStopToRoot[weProp] = property; d_ptr->m_waveStopIndex[weProp] = i; // ReportX QtProperty* rxProp = d_ptr->m_doubleProperyManager->addProperty(); rxProp->setPropertyName(tr("Curve[%1] ReportX").arg(i + 1)); group->addSubProperty(rxProp); subs.reportXs.append(rxProp); d_ptr->m_reportXToRoot[rxProp] = property; d_ptr->m_reportXIndex[rxProp] = i; // ReportY QtProperty* ryProp = d_ptr->m_doubleProperyManager->addProperty(); ryProp->setPropertyName(tr("Curve[%1] ReportY").arg(i + 1)); group->addSubProperty(ryProp); subs.reportYs.append(ryProp); d_ptr->m_reportYToRoot[ryProp] = property; d_ptr->m_reportYIndex[ryProp] = i; } } else if (count < current) { for (int i = current - 1; i >= count; --i) { auto eraseProp = [&](QtProperty* p, QMap& toRoot, QMap& toIndex) { toIndex.remove(p); toRoot.remove(p); delete p; }; eraseProp(subs.names.at(i), d_ptr->m_curveNameToRoot, d_ptr->m_curveNameIndex); eraseProp(subs.colors.at(i), d_ptr->m_curveColorToRoot, d_ptr->m_curveColorIndex); eraseProp(subs.waveStarts.at(i), d_ptr->m_waveStartToRoot, d_ptr->m_waveStartIndex); eraseProp(subs.waveStops.at(i), d_ptr->m_waveStopToRoot, d_ptr->m_waveStopIndex); eraseProp(subs.reportXs.at(i), d_ptr->m_reportXToRoot, d_ptr->m_reportXIndex); eraseProp(subs.reportYs.at(i), d_ptr->m_reportYToRoot, d_ptr->m_reportYIndex); subs.names.remove(i); subs.colors.remove(i); subs.waveStarts.remove(i); subs.waveStops.remove(i); subs.reportXs.remove(i); subs.reportYs.remove(i); } } // Set values from attribute for (int i = 0; i < count; ++i) { d_ptr->m_stringProperyManager->setValueOnly(subs.names.at(i), val.GetCurveName(i)); d_ptr->m_colorProperyManager->setValue(subs.colors.at(i), val.GetCurveColor(i)); d_ptr->m_intProperyManager->setValueOnly(subs.waveStarts.at(i), val.GetWaveStart(i)); d_ptr->m_intProperyManager->setValueOnly(subs.waveStops.at(i), val.GetWaveStop(i)); d_ptr->m_doubleProperyManager->setValueOnly(subs.reportXs.at(i), val.GetReportX(i)); d_ptr->m_doubleProperyManager->setValueOnly(subs.reportYs.at(i), val.GetReportY(i)); } } emit propertyChanged(property); emit valueChanged(property, val); } void QtCurveEntryPropertyManager::initializeProperty(QtProperty* property) { QCurveEntryAttribute val; d_ptr->m_values[property] = val; // Name QtProperty* prop = d_ptr->m_stringProperyManager->addProperty(); prop->setPropertyName(tr("Name")); d_ptr->m_stringProperyManager->setValueOnly(prop, val.GetName()); d_ptr->m_properyToName[property] = prop; d_ptr->m_nameToPropery[prop] = property; property->addSubProperty(prop); // ChartType enum prop = d_ptr->m_enumProperyManager->addProperty(); prop->setPropertyName(tr("ChartType")); d_ptr->m_enumProperyManager->setEnumNames(prop, QStringList() << tr("Wave") << tr("Report")); d_ptr->m_enumProperyManager->setValue(prop, 0); d_ptr->m_properyToChartType[property] = prop; d_ptr->m_chartTypeToPropery[prop] = property; property->addSubProperty(prop); // Curves group QtProperty* group = d_ptr->m_groupProperyManager->addProperty(); group->setPropertyName(tr("Curves")); property->addSubProperty(group); d_ptr->m_properyToCurvesGroup[property] = group; d_ptr->m_curvesGroupToPropery[group] = property; // Count QtProperty* countProp = d_ptr->m_intProperyManager->addProperty(); countProp->setPropertyName(tr("Count")); d_ptr->m_intProperyManager->setRange(countProp, 0, 1024); d_ptr->m_intProperyManager->setValueOnly(countProp, val.GetCurveCount()); d_ptr->m_properyToCurveCount[property] = countProp; d_ptr->m_curveCountToPropery[countProp] = property; group->addSubProperty(countProp); // Initialize existing curves if any QtCurveEntryPropertyManagerPrivate::CurveSubProps& subs = d_ptr->m_curveProps[property]; int count = val.GetCurveCount(); for (int i = 0; i < count; ++i) { QtProperty* nameProp = d_ptr->m_stringProperyManager->addProperty(); nameProp->setPropertyName(tr("Curve[%1] Name").arg(i + 1)); d_ptr->m_stringProperyManager->setValueOnly(nameProp, val.GetCurveName(i)); group->addSubProperty(nameProp); subs.names.append(nameProp); d_ptr->m_curveNameToRoot[nameProp] = property; d_ptr->m_curveNameIndex[nameProp] = i; QtProperty* colorProp = d_ptr->m_colorProperyManager->addProperty(); colorProp->setPropertyName(tr("Curve[%1] Color").arg(i + 1)); d_ptr->m_colorProperyManager->setValue(colorProp, val.GetCurveColor(i)); group->addSubProperty(colorProp); subs.colors.append(colorProp); d_ptr->m_curveColorToRoot[colorProp] = property; d_ptr->m_curveColorIndex[colorProp] = i; QtProperty* wsProp = d_ptr->m_intProperyManager->addProperty(); wsProp->setPropertyName(tr("Curve[%1] WaveStart").arg(i + 1)); d_ptr->m_intProperyManager->setValueOnly(wsProp, val.GetWaveStart(i)); group->addSubProperty(wsProp); subs.waveStarts.append(wsProp); d_ptr->m_waveStartToRoot[wsProp] = property; d_ptr->m_waveStartIndex[wsProp] = i; QtProperty* weProp = d_ptr->m_intProperyManager->addProperty(); weProp->setPropertyName(tr("Curve[%1] WaveStop").arg(i + 1)); d_ptr->m_intProperyManager->setValueOnly(weProp, val.GetWaveStop(i)); group->addSubProperty(weProp); subs.waveStops.append(weProp); d_ptr->m_waveStopToRoot[weProp] = property; d_ptr->m_waveStopIndex[weProp] = i; QtProperty* rxProp = d_ptr->m_doubleProperyManager->addProperty(); rxProp->setPropertyName(tr("Curve[%1] ReportX").arg(i + 1)); d_ptr->m_doubleProperyManager->setValueOnly(rxProp, val.GetReportX(i)); group->addSubProperty(rxProp); subs.reportXs.append(rxProp); d_ptr->m_reportXToRoot[rxProp] = property; d_ptr->m_reportXIndex[rxProp] = i; QtProperty* ryProp = d_ptr->m_doubleProperyManager->addProperty(); ryProp->setPropertyName(tr("Curve[%1] ReportY").arg(i + 1)); d_ptr->m_doubleProperyManager->setValueOnly(ryProp, val.GetReportY(i)); group->addSubProperty(ryProp); subs.reportYs.append(ryProp); d_ptr->m_reportYToRoot[ryProp] = property; d_ptr->m_reportYIndex[ryProp] = i; } } void QtCurveEntryPropertyManager::uninitializeProperty(QtProperty* property) { // Cleanup top-level QtProperty* prop = d_ptr->m_nameToPropery[property]; if (prop) { d_ptr->m_nameToPropery.remove(prop); delete prop; } d_ptr->m_properyToName.remove(property); prop = d_ptr->m_chartTypeToPropery[property]; if (prop) { d_ptr->m_chartTypeToPropery.remove(prop); delete prop; } d_ptr->m_properyToChartType.remove(property); // Curves QtProperty* group = d_ptr->m_properyToCurvesGroup.value(property, nullptr); QtCurveEntryPropertyManagerPrivate::CurveSubProps& subs = d_ptr->m_curveProps[property]; auto eraseProp = [&](QtProperty* p, QMap& toRoot, QMap& toIndex) { toIndex.remove(p); toRoot.remove(p); delete p; }; for (QtProperty* p : subs.names) eraseProp(p, d_ptr->m_curveNameToRoot, d_ptr->m_curveNameIndex); for (QtProperty* p : subs.colors) eraseProp(p, d_ptr->m_curveColorToRoot, d_ptr->m_curveColorIndex); for (QtProperty* p : subs.waveStarts) eraseProp(p, d_ptr->m_waveStartToRoot, d_ptr->m_waveStartIndex); for (QtProperty* p : subs.waveStops) eraseProp(p, d_ptr->m_waveStopToRoot, d_ptr->m_waveStopIndex); for (QtProperty* p : subs.reportXs) eraseProp(p, d_ptr->m_reportXToRoot, d_ptr->m_reportXIndex); for (QtProperty* p : subs.reportYs) eraseProp(p, d_ptr->m_reportYToRoot, d_ptr->m_reportYIndex); subs.names.clear(); subs.colors.clear(); subs.waveStarts.clear(); subs.waveStops.clear(); subs.reportXs.clear(); subs.reportYs.clear(); d_ptr->m_curveProps.remove(property); QtProperty* countProp = d_ptr->m_properyToCurveCount.value(property, nullptr); if (countProp) { d_ptr->m_curveCountToPropery.remove(countProp); d_ptr->m_properyToCurveCount.remove(property); delete countProp; } if (group) { d_ptr->m_curvesGroupToPropery.remove(group); d_ptr->m_properyToCurvesGroup.remove(property); delete group; } } #pragma endregion // QtEntityPropertyManager #pragma region QtEntityPropertyManager class QtEntityPropertyManagerPrivate { QtEntityPropertyManager* q_ptr; Q_DECLARE_PUBLIC(QtEntityPropertyManager) public: void slotStringChanged(QtProperty* property, QString value); void slotTransfromChanged(QtProperty* property, QTransformAttribute value); void slotBoolChanged(QtProperty* property, bool value); void slotPropertyDestroyed(QtProperty* property); typedef QMap PropertyValueMap; PropertyValueMap m_values; QtStringPropertyManager* m_stringProperyManager{ nullptr }; QtBoolPropertyManager* m_boolProperyManager{ nullptr }; QtTransfromPropertyManager* m_transfromPropertyManager{ nullptr }; QMap m_properyToName; QMap m_properyTotrans; QMap m_properyToVisible; QMap m_nameToPropery; QMap m_transToPropery; QMap m_visibleToPropery; }; void QtEntityPropertyManagerPrivate::slotStringChanged(QtProperty* property, QString value) { if (QtProperty* prop = m_nameToPropery.value(property, 0)) { QEntityAttribute c = m_values[prop]; c.SetName(value); q_ptr->setValue(prop, c); } } void QtEntityPropertyManagerPrivate::slotTransfromChanged(QtProperty* property, QTransformAttribute value) { if (QtProperty* prop = m_transToPropery.value(property, 0)) { QEntityAttribute c = m_values[prop]; //c.SetMesh(value); q_ptr->setValue(prop, c); } } void QtEntityPropertyManagerPrivate::slotBoolChanged(QtProperty* property, bool value) { if (QtProperty* prop = m_visibleToPropery.value(property, 0)) { QEntityAttribute c = m_values[prop]; c.SetVisible(value); q_ptr->setValue(prop, c); } } void QtEntityPropertyManagerPrivate::slotPropertyDestroyed(QtProperty* property) { if (QtProperty* subProp = m_nameToPropery.value(property, nullptr)) { m_nameToPropery[subProp] = 0; m_nameToPropery.remove(property); } else if (QtProperty* subProp = m_transToPropery.value(property, nullptr)) { m_transToPropery[subProp] = 0; m_transToPropery.remove(property); } else if (QtProperty* subProp = m_visibleToPropery.value(property, nullptr)) { m_visibleToPropery[subProp] = 0; m_visibleToPropery.remove(property); } } QtEntityPropertyManager::QtEntityPropertyManager(QObject* parent) : QtAbstractPropertyManager(parent), d_ptr(new QtEntityPropertyManagerPrivate) { d_ptr->q_ptr = this; d_ptr->m_stringProperyManager = new QtStringPropertyManager(this); connect(d_ptr->m_stringProperyManager, SIGNAL(valueChanged(QtProperty*, QString)), this, SLOT(slotStringChanged(QtProperty*, QString))); d_ptr->m_boolProperyManager = new QtBoolPropertyManager(this); connect(d_ptr->m_boolProperyManager, SIGNAL(valueChanged(QtProperty*, bool)), this, SLOT(slotBoolChanged(QtProperty*, bool))); d_ptr->m_transfromPropertyManager = new QtTransfromPropertyManager(this); connect(d_ptr->m_transfromPropertyManager, SIGNAL(valueChanged(QtProperty*, QTransformAttribute)), this, SLOT(slotTransfromChanged(QtProperty*, QTransformAttribute))); } /*! Destroys this manager, and all the properties it has created. */ QtEntityPropertyManager::~QtEntityPropertyManager() { clear(); } /*! Returns the given \a property's value. If the given \a property is not managed by this manager, this function returns a default QCursor object. \sa setValue() */ QEntityAttribute QtEntityPropertyManager::value(const QtProperty* property) const { return d_ptr->m_values.value(property, QEntityAttribute()); } QtStringPropertyManager* QtEntityPropertyManager::subStringProperyManager() const { return d_ptr->m_stringProperyManager; } QtBoolPropertyManager* QtEntityPropertyManager::subBoolProperyManager() const { return d_ptr->m_boolProperyManager; } QtTransfromPropertyManager* QtEntityPropertyManager::subTransfromProperyManager() const { return d_ptr->m_transfromPropertyManager; } /*! \reimp */ QString QtEntityPropertyManager::valueText(const QtProperty* property) const { const QtEntityPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); if (it == d_ptr->m_values.constEnd()) return QString(); return QString("entity");//cursorDatabase()->cursorToShapeName(it.value()); } /*! \reimp */ QIcon QtEntityPropertyManager::valueIcon(const QtProperty* property) const { const QtEntityPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); if (it == d_ptr->m_values.constEnd()) return QIcon(); return QIcon(); //cursorDatabase()->cursorToShapeIcon(it.value()); } /*! \fn void QtCursorPropertyManager::setValue(QtProperty *property, const QCursor &value) Sets the value of the given \a property to \a value. \sa value(), valueChanged() */ void QtEntityPropertyManager::setValue(QtProperty* property, const QEntityAttribute& value) { const QtEntityPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; if (it.value() == value) return; it.value() = value; d_ptr->m_stringProperyManager->setValue(d_ptr->m_properyToName[property], value.GetName()); d_ptr->m_transfromPropertyManager->setValue(d_ptr->m_properyTotrans[property], value.GetTransform()); d_ptr->m_boolProperyManager->setValue(d_ptr->m_properyToVisible[property], value.IsVisible()); emit propertyChanged(property); emit valueChanged(property, value); } /*! \reimp */ void QtEntityPropertyManager::initializeProperty(QtProperty* property) { QEntityAttribute val; d_ptr->m_values[property] = val; QtProperty* prop = d_ptr->m_stringProperyManager->addProperty(); prop->setPropertyName(tr("Name")); d_ptr->m_stringProperyManager->setValueOnly(prop, val.GetName()); d_ptr->m_properyToName[property] = prop; d_ptr->m_nameToPropery[prop] = property; property->addSubProperty(prop); prop = d_ptr->m_boolProperyManager->addProperty(); prop->setPropertyName(tr("Visible")); d_ptr->m_boolProperyManager->setValueOnly(prop, val.IsVisible()); d_ptr->m_properyToVisible[property] = prop; d_ptr->m_visibleToPropery[prop] = property; property->addSubProperty(prop); prop = d_ptr->m_transfromPropertyManager->addProperty(); prop->setPropertyName(tr("Transform")); d_ptr->m_transfromPropertyManager->setValueOnly(prop, val.GetTransform()); d_ptr->m_properyTotrans[property] = prop; d_ptr->m_transToPropery[prop] = property; property->addSubProperty(prop); } /*! \reimp */ void QtEntityPropertyManager::uninitializeProperty(QtProperty* property) { QtProperty* prop = d_ptr->m_properyToName.value(property, nullptr); if (prop) { d_ptr->m_nameToPropery.remove(prop); delete prop; } d_ptr->m_properyToName.remove(property); prop = d_ptr->m_properyToVisible.value(property, nullptr); if (prop) { d_ptr->m_visibleToPropery.remove(prop); delete prop; } d_ptr->m_properyToVisible.remove(property); prop = d_ptr->m_properyTotrans.value(property, nullptr); if (prop) { d_ptr->m_transToPropery.remove(prop); delete prop; } d_ptr->m_properyTotrans.remove(property); } #pragma endregion QtComponentPropertyManager::QtComponentPropertyManager(QObject* parent /*= 0*/) : QtAbstractPropertyManager(parent) { } QtComponentPropertyManager::~QtComponentPropertyManager() { clear(); } QtProperty* QtComponentPropertyManager::AddProperty() { return nullptr; } void QtComponentPropertyManager::SetPropertyValue(QtProperty* property, SceneComponent* sceneComponent) { } QString QtComponentPropertyManager::GetPropertyId() const { return tr(""); } // QtMeshComponetManager #pragma region QtMeshComponetManager class QtMeshComponetManagerPrivate { QtMeshComponetManager* q_ptr; Q_DECLARE_PUBLIC(QtMeshComponetManager) public: void slotStringChanged(QtProperty* property, QString value); void slotPropertyDestroyed(QtProperty* property); typedef QMap PropertyValueMap; PropertyValueMap m_values; QtModelFilesPropertyManager* m_modelFileProperyManager; QMap m_properyToMesh; QMap m_meshToPropery; }; void QtMeshComponetManagerPrivate::slotStringChanged(QtProperty* property, QString value) { if (QtProperty* prop = m_meshToPropery.value(property, 0)) { QMeshComponentAttribute c = m_values[prop]; c.SetMesh(value); q_ptr->setValue(prop, c); } } void QtMeshComponetManagerPrivate::slotPropertyDestroyed(QtProperty* property) { if (QtProperty* subProp = m_meshToPropery.value(property, nullptr)) { m_meshToPropery[subProp] = 0; m_meshToPropery.remove(property); } } QtMeshComponetManager::QtMeshComponetManager(QObject* parent) : QtComponentPropertyManager(parent), d_ptr(new QtMeshComponetManagerPrivate) { d_ptr->q_ptr = this; d_ptr->m_modelFileProperyManager = new QtModelFilesPropertyManager(this); connect(d_ptr->m_modelFileProperyManager, SIGNAL(valueChanged(QtProperty*, QString)), this, SLOT(slotStringChanged(QtProperty*, QString))); } /*! Destroys this manager, and all the properties it has created. */ QtMeshComponetManager::~QtMeshComponetManager() { clear(); } QtProperty* QtMeshComponetManager::AddProperty() { return addProperty(tr("MeshComponent")); } void QtMeshComponetManager::SetPropertyValue(QtProperty* property, SceneComponent* sceneComponent) { QMeshComponentAttribute meshComponentAttribute(reinterpret_cast(sceneComponent)); setValue(property, meshComponentAttribute); } QString QtMeshComponetManager::GetPropertyId() const { return tr("MeshComponent"); } /*! Returns the given \a property's value. If the given \a property is not managed by this manager, this function returns a default QCursor object. \sa setValue() */ QMeshComponentAttribute QtMeshComponetManager::value(const QtProperty* property) const { return d_ptr->m_values.value(property, QMeshComponentAttribute()); } QtModelFilesPropertyManager* QtMeshComponetManager::subModelFileProperyManager() const { return d_ptr->m_modelFileProperyManager; } /*! \reimp */ QString QtMeshComponetManager::valueText(const QtProperty* property) const { const QtMeshComponetManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); if (it == d_ptr->m_values.constEnd()) return QString(); return QString("MeshComponet");//cursorDatabase()->cursorToShapeName(it.value()); } /*! \reimp */ QIcon QtMeshComponetManager::valueIcon(const QtProperty* property) const { const QtMeshComponetManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); if (it == d_ptr->m_values.constEnd()) return QIcon(); return QIcon(); //cursorDatabase()->cursorToShapeIcon(it.value()); } /*! \fn void QtCursorPropertyManager::setValue(QtProperty *property, const QCursor &value) Sets the value of the given \a property to \a value. \sa value(), valueChanged() */ void QtMeshComponetManager::setValue(QtProperty* property, const QMeshComponentAttribute& value) { const QtMeshComponetManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; if (it.value() == value) return; it.value() = value; d_ptr->m_modelFileProperyManager->setValue(d_ptr->m_properyToMesh[property], value.GetMesh()); emit propertyChanged(property); emit valueChanged(property, value); } /*! \reimp */ void QtMeshComponetManager::initializeProperty(QtProperty* property) { QMeshComponentAttribute val; d_ptr->m_values[property] = val; QtProperty* prop = d_ptr->m_modelFileProperyManager->addProperty(); prop->setPropertyName(tr("Mesh")); d_ptr->m_modelFileProperyManager->setValueOnly(prop, val.GetMesh()); d_ptr->m_properyToMesh[property] = prop; d_ptr->m_meshToPropery[prop] = property; property->addSubProperty(prop); } /*! \reimp */ void QtMeshComponetManager::uninitializeProperty(QtProperty* property) { QtProperty* prop = d_ptr->m_meshToPropery[property]; if (prop) { d_ptr->m_meshToPropery.remove(prop); delete prop; } d_ptr->m_properyToMesh.remove(property); } #pragma endregion // QtPathComponentManager #pragma region QtPathComponentManager class QtPathComponentManagerPrivate { QtPathComponentManager* q_ptr; Q_DECLARE_PUBLIC(QtPathComponentManager) public: void slotStringChanged(QtProperty* property, QString value); void slotPropertyDestroyed(QtProperty* property); typedef QMap PropertyValueMap; PropertyValueMap m_values; QtFilesPropertyManager* m_filesProperyManager; QMap m_properyToPath; QMap m_pathToPropery; }; void QtPathComponentManagerPrivate::slotStringChanged(QtProperty* property, QString value) { if (QtProperty* prop = m_pathToPropery.value(property, 0)) { QPathComponentAttribute c = m_values[prop]; c.SetPath(value); q_ptr->setValue(prop, c); } } void QtPathComponentManagerPrivate::slotPropertyDestroyed(QtProperty* property) { if (QtProperty* subProp = m_pathToPropery.value(property, nullptr)) { m_pathToPropery[subProp] = 0; m_pathToPropery.remove(property); } } QtPathComponentManager::QtPathComponentManager(QObject* parent) : QtComponentPropertyManager(parent), d_ptr(new QtPathComponentManagerPrivate) { d_ptr->q_ptr = this; d_ptr->m_filesProperyManager = new QtFilesPropertyManager(this); connect(d_ptr->m_filesProperyManager, SIGNAL(valueChanged(QtProperty*, QString)), this, SLOT(slotStringChanged(QtProperty*, QString))); } /*! Destroys this manager, and all the properties it has created. */ QtPathComponentManager::~QtPathComponentManager() { clear(); } QtProperty* QtPathComponentManager::AddProperty() { return addProperty(tr("PathComponent")); } void QtPathComponentManager::SetPropertyValue(QtProperty* property, SceneComponent* sceneComponent) { QPathComponentAttribute componentAttribute(reinterpret_cast(sceneComponent)); setValue(property, componentAttribute); } QString QtPathComponentManager::GetPropertyId() const { return tr("PathComponent"); } /*! Returns the given \a property's value. If the given \a property is not managed by this manager, this function returns a default QCursor object. \sa setValue() */ QPathComponentAttribute QtPathComponentManager::value(const QtProperty* property) const { return d_ptr->m_values.value(property, QPathComponentAttribute()); } QtFilesPropertyManager* QtPathComponentManager::subFilesProperyManager() const { return d_ptr->m_filesProperyManager; } /*! \reimp */ QString QtPathComponentManager::valueText(const QtProperty* property) const { const QtPathComponentManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); if (it == d_ptr->m_values.constEnd()) return QString(); return QString("PathComponet");//cursorDatabase()->cursorToShapeName(it.value()); } /*! \reimp */ QIcon QtPathComponentManager::valueIcon(const QtProperty* property) const { const QtPathComponentManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); if (it == d_ptr->m_values.constEnd()) return QIcon(); return QIcon(); //cursorDatabase()->cursorToShapeIcon(it.value()); } /*! \fn void QtCursorPropertyManager::setValue(QtProperty *property, const QCursor &value) Sets the value of the given \a property to \a value. \sa value(), valueChanged() */ void QtPathComponentManager::setValue(QtProperty* property, const QPathComponentAttribute& value) { const QtPathComponentManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; if (it.value() == value) return; it.value() = value; d_ptr->m_filesProperyManager->setValue(d_ptr->m_properyToPath[property], value.GetPath()); emit propertyChanged(property); emit valueChanged(property, value); } /*! \reimp */ void QtPathComponentManager::initializeProperty(QtProperty* property) { QPathComponentAttribute val; d_ptr->m_values[property] = val; QtProperty* prop = d_ptr->m_filesProperyManager->addProperty(); prop->setPropertyName(tr("Path")); d_ptr->m_filesProperyManager->setValueOnly(prop, val.GetPath()); d_ptr->m_properyToPath[property] = prop; d_ptr->m_pathToPropery[prop] = property; property->addSubProperty(prop); } /*! \reimp */ void QtPathComponentManager::uninitializeProperty(QtProperty* property) { QtProperty* prop = d_ptr->m_pathToPropery[property]; if (prop) { d_ptr->m_pathToPropery.remove(prop); delete prop; } d_ptr->m_properyToPath.remove(property); } #pragma endregion // QtConeWaveComponentManager #pragma region QtConeWaveComponentManager class QtConeWaveComponentManagerPrivate { QtConeWaveComponentManager* q_ptr; Q_DECLARE_PUBLIC(QtConeWaveComponentManager) public: void slotDoubleChanged(QtProperty* property, double value); void slotIntChanged(QtProperty* property, int value); void slotColorChanged(QtProperty* property, const QColor& value); void slotPropertyDestroyed(QtProperty* property); typedef QMap PropertyValueMap; PropertyValueMap m_values; QtDoublePropertyManager* m_doubleProperyManager; QtIntPropertyManager* m_intProperyManager; QtColorPropertyManager* m_colorProperyManager; QMap m_properyToRadius; QMap m_properyToHeight; QMap m_properyToWaveCount; QMap m_properyToWaveSpeed; QMap m_properyToBaseColor; QMap m_properyToWaveColor; QMap m_properyToRingBrightAlpha; QMap m_properyToRingDarkAlpha; QMap m_radiusToPropery; QMap m_heightToPropery; QMap m_waveCountToPropery; QMap m_waveSpeedToPropery; QMap m_baseColorToPropery; QMap m_waveColorToPropery; QMap m_ringBrightAlphaToPropery; QMap m_ringDarkAlphaToPropery; }; void QtConeWaveComponentManagerPrivate::slotDoubleChanged(QtProperty* property, double value) { if (QtProperty* prop = m_radiusToPropery.value(property, 0)) { QConeWaveComponentAttribute c = m_values[prop]; c.SetRadius(value); q_ptr->setValue(prop, c); } else if (QtProperty* prop = m_heightToPropery.value(property, 0)) { QConeWaveComponentAttribute c = m_values[prop]; c.SetHeight(value); q_ptr->setValue(prop, c); } else if (QtProperty* prop = m_waveSpeedToPropery.value(property, 0)) { QConeWaveComponentAttribute c = m_values[prop]; c.SetWaveSpeed(value); q_ptr->setValue(prop, c); } else if (QtProperty* prop = m_ringBrightAlphaToPropery.value(property, 0)) { QConeWaveComponentAttribute c = m_values[prop]; c.SetRingBrightAlpha(value); q_ptr->setValue(prop, c); } else if (QtProperty* prop = m_ringDarkAlphaToPropery.value(property, 0)) { QConeWaveComponentAttribute c = m_values[prop]; c.SetRingDarkAlpha(value); q_ptr->setValue(prop, c); } } #include void QtConeWaveComponentManagerPrivate::slotIntChanged(QtProperty* property, int value) { qDebug() << "slotIntChanged called with value:" << value; qDebug() << "Property address:" << property; qDebug() << "m_waveCountToPropery size:" << m_waveCountToPropery.size(); if (QtProperty* prop = m_waveCountToPropery.value(property, 0)) { qDebug() << "Found waveCount property mapping, updating value to:" << value; QConeWaveComponentAttribute c = m_values[prop]; c.SetWaveCount(value); q_ptr->setValue(prop, c); } else { qDebug() << "Property not found in m_waveCountToPropery mapping"; } } void QtConeWaveComponentManagerPrivate::slotColorChanged(QtProperty* property, const QColor& value) { if (QtProperty* prop = m_baseColorToPropery.value(property, 0)) { QConeWaveComponentAttribute c = m_values[prop]; c.SetBaseColor(value); q_ptr->setValue(prop, c); } else if (QtProperty* prop = m_waveColorToPropery.value(property, 0)) { QConeWaveComponentAttribute c = m_values[prop]; c.SetWaveColor(value); q_ptr->setValue(prop, c); } } void QtConeWaveComponentManagerPrivate::slotPropertyDestroyed(QtProperty* property) { if (QtProperty* subProp = m_radiusToPropery.value(property, nullptr)) { m_radiusToPropery[subProp] = 0; m_radiusToPropery.remove(property); } if (QtProperty* subProp = m_heightToPropery.value(property, nullptr)) { m_heightToPropery[subProp] = 0; m_heightToPropery.remove(property); } if (QtProperty* subProp = m_waveCountToPropery.value(property, nullptr)) { m_waveCountToPropery[subProp] = 0; m_waveCountToPropery.remove(property); } if (QtProperty* subProp = m_waveSpeedToPropery.value(property, nullptr)) { m_waveSpeedToPropery[subProp] = 0; m_waveSpeedToPropery.remove(property); } if (QtProperty* subProp = m_baseColorToPropery.value(property, nullptr)) { m_baseColorToPropery[subProp] = 0; m_baseColorToPropery.remove(property); } if (QtProperty* subProp = m_waveColorToPropery.value(property, nullptr)) { m_waveColorToPropery[subProp] = 0; m_waveColorToPropery.remove(property); } if (QtProperty* subProp = m_ringBrightAlphaToPropery.value(property, nullptr)) { m_ringBrightAlphaToPropery[subProp] = 0; m_ringBrightAlphaToPropery.remove(property); } if (QtProperty* subProp = m_ringDarkAlphaToPropery.value(property, nullptr)) { m_ringDarkAlphaToPropery[subProp] = 0; m_ringDarkAlphaToPropery.remove(property); } } QtConeWaveComponentManager::QtConeWaveComponentManager(QObject* parent) : QtComponentPropertyManager(parent), d_ptr(new QtConeWaveComponentManagerPrivate) { d_ptr->q_ptr = this; d_ptr->m_doubleProperyManager = new QtDoublePropertyManager(this); connect(d_ptr->m_doubleProperyManager, SIGNAL(valueChanged(QtProperty*, double)), this, SLOT(slotDoubleChanged(QtProperty*, double))); connect(d_ptr->m_doubleProperyManager, SIGNAL(propertyDestroyed(QtProperty*)), this, SLOT(slotPropertyDestroyed(QtProperty*))); d_ptr->m_intProperyManager = new QtIntPropertyManager(this); connect(d_ptr->m_intProperyManager, SIGNAL(valueChanged(QtProperty*, int)), this, SLOT(slotIntChanged(QtProperty*, int))); connect(d_ptr->m_intProperyManager, SIGNAL(propertyDestroyed(QtProperty*)), this, SLOT(slotPropertyDestroyed(QtProperty*))); d_ptr->m_colorProperyManager = new QtColorPropertyManager(this); connect(d_ptr->m_colorProperyManager, SIGNAL(valueChanged(QtProperty*, const QColor&)), this, SLOT(slotColorChanged(QtProperty*, const QColor&))); connect(d_ptr->m_colorProperyManager, SIGNAL(propertyDestroyed(QtProperty*)), this, SLOT(slotPropertyDestroyed(QtProperty*))); } /*! Destroys this manager, and all the properties it has created. */ QtConeWaveComponentManager::~QtConeWaveComponentManager() { clear(); } QtProperty* QtConeWaveComponentManager::AddProperty() { return addProperty(tr("ConeWaveComponent")); } void QtConeWaveComponentManager::SetPropertyValue(QtProperty* property, SceneComponent* sceneComponent) { QConeWaveComponentAttribute componentAttribute(reinterpret_cast(sceneComponent)); setValue(property, componentAttribute); } QString QtConeWaveComponentManager::GetPropertyId() const { return tr("ConeWaveComponent"); } /*! Returns the given \a property's value. If the given \a property is not managed by this manager, this function returns a default QCursor object. \sa setValue() */ QConeWaveComponentAttribute QtConeWaveComponentManager::value(const QtProperty* property) const { return d_ptr->m_values.value(property, QConeWaveComponentAttribute()); } QtDoublePropertyManager* QtConeWaveComponentManager::subDoubleProperyManager() const { return d_ptr->m_doubleProperyManager; } QtIntPropertyManager* QtConeWaveComponentManager::subIntProperyManager() const { return d_ptr->m_intProperyManager; } QtColorPropertyManager* QtConeWaveComponentManager::subColorProperyManager() const { return d_ptr->m_colorProperyManager; } /*! \reimp */ QString QtConeWaveComponentManager::valueText(const QtProperty* property) const { const QtConeWaveComponentManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); if (it == d_ptr->m_values.constEnd()) return QString(); return QString("ConeWaveComponent");//cursorDatabase()->cursorToShapeName(it.value()); } /*! \reimp */ QIcon QtConeWaveComponentManager::valueIcon(const QtProperty* property) const { const QtConeWaveComponentManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); if (it == d_ptr->m_values.constEnd()) return QIcon(); return QIcon(); //cursorDatabase()->cursorToShapeIcon(it.value()); } /*! \fn void QtCursorPropertyManager::setValue(QtProperty *property, const QCursor &value) Sets the value of the given \a property to \a value. \sa value(), valueChanged() */ void QtConeWaveComponentManager::setValue(QtProperty* property, const QConeWaveComponentAttribute& value) { const QtConeWaveComponentManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; if (it.value() == value) return; it.value() = value; d_ptr->m_doubleProperyManager->setValue(d_ptr->m_properyToRadius[property], value.GetRadius()); d_ptr->m_doubleProperyManager->setValue(d_ptr->m_properyToHeight[property], value.GetHeight()); d_ptr->m_doubleProperyManager->setValue(d_ptr->m_properyToWaveSpeed[property], value.GetWaveSpeed()); d_ptr->m_intProperyManager->setValue(d_ptr->m_properyToWaveCount[property], value.GetWaveCount()); d_ptr->m_colorProperyManager->setValue(d_ptr->m_properyToBaseColor[property], value.GetBaseColor()); d_ptr->m_colorProperyManager->setValue(d_ptr->m_properyToWaveColor[property], value.GetWaveColor()); d_ptr->m_doubleProperyManager->setValue(d_ptr->m_properyToRingBrightAlpha[property], value.GetRingBrightAlpha()); d_ptr->m_doubleProperyManager->setValue(d_ptr->m_properyToRingDarkAlpha[property], value.GetRingDarkAlpha()); emit propertyChanged(property); emit valueChanged(property, value); } /*! \reimp */ void QtConeWaveComponentManager::initializeProperty(QtProperty* property) { QConeWaveComponentAttribute val; d_ptr->m_values[property] = val; QtProperty* prop = d_ptr->m_doubleProperyManager->addProperty(); prop->setPropertyName(tr("Height")); d_ptr->m_doubleProperyManager->setValueOnly(prop, val.GetHeight()); d_ptr->m_properyToHeight[property] = prop; d_ptr->m_heightToPropery[prop] = property; property->addSubProperty(prop); prop = d_ptr->m_doubleProperyManager->addProperty(); prop->setPropertyName(tr("Radius")); d_ptr->m_doubleProperyManager->setValueOnly(prop, val.GetHeight()); d_ptr->m_properyToRadius[property] = prop; d_ptr->m_radiusToPropery[prop] = property; property->addSubProperty(prop); prop = d_ptr->m_intProperyManager->addProperty(); prop->setPropertyName(tr("waveCount")); d_ptr->m_intProperyManager->setValueOnly(prop, val.GetWaveCount()); d_ptr->m_intProperyManager->setRange(prop, 1, 100); d_ptr->m_properyToWaveCount[property] = prop; d_ptr->m_waveCountToPropery[prop] = property; property->addSubProperty(prop); qDebug() << "Created waveCount property. Prop address:" << prop << "Parent address:" << property; qDebug() << "m_waveCountToPropery now has" << d_ptr->m_waveCountToPropery.size() << "entries"; prop = d_ptr->m_doubleProperyManager->addProperty(); prop->setPropertyName(tr("waveSpeed")); d_ptr->m_doubleProperyManager->setValueOnly(prop, val.GetWaveSpeed()); d_ptr->m_properyToWaveSpeed[property] = prop; d_ptr->m_waveSpeedToPropery[prop] = property; property->addSubProperty(prop); prop = d_ptr->m_colorProperyManager->addProperty(); prop->setPropertyName(tr("baseColor")); d_ptr->m_colorProperyManager->setValue(prop, val.GetBaseColor()); d_ptr->m_properyToBaseColor[property] = prop; d_ptr->m_baseColorToPropery[prop] = property; property->addSubProperty(prop); prop = d_ptr->m_colorProperyManager->addProperty(); prop->setPropertyName(tr("waveColor")); d_ptr->m_colorProperyManager->setValue(prop, val.GetWaveColor()); d_ptr->m_properyToWaveColor[property] = prop; d_ptr->m_waveColorToPropery[prop] = property; property->addSubProperty(prop); prop = d_ptr->m_doubleProperyManager->addProperty(); prop->setPropertyName(tr("ringBrightAlpha")); d_ptr->m_doubleProperyManager->setValue(prop, val.GetRingBrightAlpha()); d_ptr->m_properyToRingBrightAlpha[property] = prop; d_ptr->m_ringBrightAlphaToPropery[prop] = property; property->addSubProperty(prop); prop = d_ptr->m_doubleProperyManager->addProperty(); prop->setPropertyName(tr("ringDarkAlpha")); d_ptr->m_doubleProperyManager->setValue(prop, val.GetRingDarkAlpha()); d_ptr->m_properyToRingDarkAlpha[property] = prop; d_ptr->m_ringDarkAlphaToPropery[prop] = property; property->addSubProperty(prop); } /*! \reimp */ void QtConeWaveComponentManager::uninitializeProperty(QtProperty* property) { QtProperty* prop = d_ptr->m_radiusToPropery[property]; if (prop) { d_ptr->m_radiusToPropery.remove(prop); delete prop; } d_ptr->m_properyToRadius.remove(property); prop = d_ptr->m_heightToPropery[property]; if (prop) { d_ptr->m_heightToPropery.remove(prop); delete prop; } d_ptr->m_properyToHeight.remove(property); prop = d_ptr->m_waveCountToPropery[property]; if (prop) { d_ptr->m_waveCountToPropery.remove(prop); delete prop; } d_ptr->m_properyToWaveCount.remove(property); prop = d_ptr->m_waveSpeedToPropery[property]; if (prop) { d_ptr->m_waveSpeedToPropery.remove(prop); delete prop; } d_ptr->m_properyToWaveSpeed.remove(property); prop = d_ptr->m_baseColorToPropery[property]; if (prop) { d_ptr->m_baseColorToPropery.remove(prop); delete prop; } d_ptr->m_properyToBaseColor.remove(property); prop = d_ptr->m_waveColorToPropery[property]; if (prop) { d_ptr->m_waveColorToPropery.remove(prop); delete prop; } d_ptr->m_properyToWaveColor.remove(property); prop = d_ptr->m_ringBrightAlphaToPropery[property]; if (prop) { d_ptr->m_ringBrightAlphaToPropery.remove(prop); delete prop; } d_ptr->m_properyToRingBrightAlpha.remove(property); prop = d_ptr->m_ringDarkAlphaToPropery[property]; if (prop) { d_ptr->m_ringDarkAlphaToPropery.remove(prop); delete prop; } d_ptr->m_properyToRingDarkAlpha.remove(property); } #pragma endregion // QtDashedLineComponentManager #pragma region QtDashedLineComponentManager class QtDashedLineComponentManagerPrivate { QtDashedLineComponentManager* q_ptr; Q_DECLARE_PUBLIC(QtDashedLineComponentManager) public: void slotEntityChanged(QtProperty* property, const QEntityAttribute& value); void slotDoubleChanged(QtProperty* property, double value); void slotColorChanged(QtProperty* property, const QColor& value); void slotPropertyDestroyed(QtProperty* property); typedef QMap PropertyValueMap; PropertyValueMap m_values; QtEntityPropertyManager* m_entityProperyManager; QtDoublePropertyManager* m_doubleProperyManager; QtColorPropertyManager* m_colorProperyManager; QMap m_properyToStart; QMap m_properyToEnd; QMap m_properyToRadius; QMap m_properyToColor; QMap m_startToPropery; QMap m_endToPropery; QMap m_radiusToPropery; QMap m_colorToPropery; }; void QtDashedLineComponentManagerPrivate::slotEntityChanged(QtProperty* property, const QEntityAttribute& value) { if (QtProperty* prop = m_startToPropery.value(property, 0)) { QDashedLineComponentAttribute c = m_values[prop]; c.SetStart(value); //c.SetStart(value); /*std::string name = value.toStdString(); Entity* entity = EntitiesManager::Get().GetEntity(value); if (nullptr != entity) { q_ptr->setValue(prop, c); } else { q_ptr->setValue(prop, c); }*/ } if (QtProperty* prop = m_endToPropery.value(property, 0)) { QDashedLineComponentAttribute c = m_values[prop]; c.SetEnd(value); /*c.SetEnd(value); Entity* entity = EntitiesManager::Get().GetEntity(value); if (nullptr != entity) { q_ptr->setValue(prop, c); } else { q_ptr->setValue(prop, c); }*/ } } void QtDashedLineComponentManagerPrivate::slotDoubleChanged(QtProperty* property, double value) { if (QtProperty* prop = m_radiusToPropery.value(property, 0)) { QDashedLineComponentAttribute c = m_values[prop]; c.SetRadius(value); q_ptr->setValue(prop, c); } } void QtDashedLineComponentManagerPrivate::slotColorChanged(QtProperty* property, const QColor& value) { if (QtProperty* prop = m_radiusToPropery.value(property, 0)) { QDashedLineComponentAttribute c = m_values[prop]; c.SetColor(value); q_ptr->setValue(prop, c); } } void QtDashedLineComponentManagerPrivate::slotPropertyDestroyed(QtProperty* property) { if (QtProperty* subProp = m_startToPropery.value(property, nullptr)) { m_startToPropery[subProp] = 0; m_startToPropery.remove(property); } if (QtProperty* subProp = m_endToPropery.value(property, nullptr)) { m_endToPropery[subProp] = 0; m_endToPropery.remove(property); } if (QtProperty* subProp = m_radiusToPropery.value(property, nullptr)) { m_radiusToPropery[subProp] = 0; m_radiusToPropery.remove(property); } } QtDashedLineComponentManager::QtDashedLineComponentManager(QObject* parent) : QtComponentPropertyManager(parent), d_ptr(new QtDashedLineComponentManagerPrivate) { d_ptr->q_ptr = this; d_ptr->m_entityProperyManager = new QtEntityPropertyManager(this); connect(d_ptr->m_entityProperyManager, SIGNAL(valueChanged(QtProperty*, QEntityAttribute)), this, SLOT(slotStringChanged(QtProperty*, QString))); connect(d_ptr->m_entityProperyManager, SIGNAL(propertyDestroyed(QtProperty*)), this, SLOT(slotPropertyDestroyed(QtProperty*))); d_ptr->m_doubleProperyManager = new QtDoublePropertyManager(this); connect(d_ptr->m_doubleProperyManager, SIGNAL(valueChanged(QtProperty*, double)), this, SLOT(slotDoubleChanged(QtProperty*, double))); connect(d_ptr->m_doubleProperyManager, SIGNAL(propertyDestroyed(QtProperty*)), this, SLOT(slotPropertyDestroyed(QtProperty*))); d_ptr->m_colorProperyManager = new QtColorPropertyManager(this); connect(d_ptr->m_colorProperyManager, SIGNAL(valueChanged(QtProperty*, const QColor&)), this, SLOT(slotColorChanged(QtProperty*, const QColor&))); connect(d_ptr->m_colorProperyManager, SIGNAL(propertyDestroyed(QtProperty*)), this, SLOT(slotPropertyDestroyed(QtProperty*))); } /*! Destroys this manager, and all the properties it has created. */ QtDashedLineComponentManager::~QtDashedLineComponentManager() { clear(); } QtProperty* QtDashedLineComponentManager::AddProperty() { return addProperty(tr("DashedLineComponent")); } void QtDashedLineComponentManager::SetPropertyValue(QtProperty* property, SceneComponent* sceneComponent) { QDashedLineComponentAttribute componentAttribute(reinterpret_cast(sceneComponent)); setValue(property, componentAttribute); } QString QtDashedLineComponentManager::GetPropertyId() const { return tr("DashedLineComponent"); } QDashedLineComponentAttribute QtDashedLineComponentManager::value(const QtProperty* property) const { return d_ptr->m_values.value(property, QDashedLineComponentAttribute()); } QtEntityPropertyManager* QtDashedLineComponentManager::subEntityProperyManager() const { return d_ptr->m_entityProperyManager; } QtDoublePropertyManager* QtDashedLineComponentManager::subDoubleProperyManager() const { return d_ptr->m_doubleProperyManager; } QtColorPropertyManager* QtDashedLineComponentManager::subColorProperyManager() const { return d_ptr->m_colorProperyManager; } /*! \reimp */ QString QtDashedLineComponentManager::valueText(const QtProperty* property) const { const QtDashedLineComponentManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); if (it == d_ptr->m_values.constEnd()) return QString(); return QString("ConeWaveComponent");//cursorDatabase()->cursorToShapeName(it.value()); } /*! \reimp */ QIcon QtDashedLineComponentManager::valueIcon(const QtProperty* property) const { const QtDashedLineComponentManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property); if (it == d_ptr->m_values.constEnd()) return QIcon(); return QIcon(); //cursorDatabase()->cursorToShapeIcon(it.value()); } void QtDashedLineComponentManager::setValue(QtProperty* property, const QDashedLineComponentAttribute& value) { const QtDashedLineComponentManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property); if (it == d_ptr->m_values.end()) return; if (it.value() == value) return; it.value() = value; d_ptr->m_entityProperyManager->setValue(d_ptr->m_properyToStart[property], value.GetStart()); d_ptr->m_entityProperyManager->setValue(d_ptr->m_properyToEnd[property], value.GetEnd()); d_ptr->m_doubleProperyManager->setValue(d_ptr->m_properyToRadius[property], value.GetRadius()); d_ptr->m_colorProperyManager->setValue(d_ptr->m_properyToColor[property], value.GetColor()); emit propertyChanged(property); emit valueChanged(property, value); } /*! \reimp */ void QtDashedLineComponentManager::initializeProperty(QtProperty* property) { QDashedLineComponentAttribute val; d_ptr->m_values[property] = val; QtProperty* prop = d_ptr->m_entityProperyManager->addProperty(); prop->setPropertyName(tr("Start")); //d_ptr->m_entityProperyManager->setValueOnly(prop, val.GetStart()); d_ptr->m_properyToStart[property] = prop; d_ptr->m_startToPropery[prop] = property; property->addSubProperty(prop); prop = d_ptr->m_entityProperyManager->addProperty(); prop->setPropertyName(tr("End")); //d_ptr->m_entityProperyManager->setValueOnly(prop, val.GetEnd()); d_ptr->m_properyToEnd[property] = prop; d_ptr->m_endToPropery[prop] = property; property->addSubProperty(prop); prop = d_ptr->m_doubleProperyManager->addProperty(); prop->setPropertyName(tr("Radius")); d_ptr->m_doubleProperyManager->setValueOnly(prop, val.GetRadius()); d_ptr->m_properyToRadius[property] = prop; d_ptr->m_radiusToPropery[prop] = property; property->addSubProperty(prop); prop = d_ptr->m_colorProperyManager->addProperty(); prop->setPropertyName(tr("Color")); d_ptr->m_colorProperyManager->setValue(prop, val.GetColor()); d_ptr->m_properyToColor[property] = prop; d_ptr->m_colorToPropery[prop] = property; property->addSubProperty(prop); } /*! \reimp */ void QtDashedLineComponentManager::uninitializeProperty(QtProperty* property) { QtProperty* prop = d_ptr->m_startToPropery[property]; if (prop) { d_ptr->m_startToPropery.remove(prop); delete prop; } d_ptr->m_properyToStart.remove(property); prop = d_ptr->m_endToPropery[property]; if (prop) { d_ptr->m_endToPropery.remove(prop); delete prop; } d_ptr->m_properyToEnd.remove(property); prop = d_ptr->m_radiusToPropery[property]; if (prop) { d_ptr->m_radiusToPropery.remove(prop); delete prop; } d_ptr->m_properyToRadius.remove(property); prop = d_ptr->m_colorToPropery[property]; if (prop) { d_ptr->m_colorToPropery.remove(prop); delete prop; } d_ptr->m_properyToColor.remove(property); } #pragma endregion QT_END_NAMESPACE #include "moc_qtpropertymanager.cpp" #include "qtpropertymanager.moc"