| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #include "qtpropertymanager_p.h" |
| 5 | #include "qtpropertybrowserutils_p.h" |
| 6 | |
| 7 | #include <QtCore/QDateTime> |
| 8 | #include <QtCore/QHash> |
| 9 | #include <QtCore/QLocale> |
| 10 | #include <QtCore/QMap> |
| 11 | #include <QtCore/QMetaEnum> |
| 12 | #include <QtCore/QRegularExpression> |
| 13 | #include <QtCore/QTimer> |
| 14 | #include <QtGui/QFontDatabase> |
| 15 | #include <QtGui/QIcon> |
| 16 | #include <QtGui/QPainter> |
| 17 | #include <QtWidgets/QApplication> |
| 18 | #include <QtWidgets/QLabel> |
| 19 | #include <QtWidgets/QStyle> |
| 20 | #include <QtWidgets/QStyleOption> |
| 21 | |
| 22 | #include <limits> |
| 23 | #include <limits.h> |
| 24 | #include <float.h> |
| 25 | |
| 26 | #include <algorithm> |
| 27 | #include <utility> |
| 28 | |
| 29 | #if defined(Q_CC_MSVC) |
| 30 | # pragma warning(disable: 4786) /* MS VS 6: truncating debug info after 255 characters */ |
| 31 | #endif |
| 32 | |
| 33 | QT_BEGIN_NAMESPACE |
| 34 | |
| 35 | using DisambiguatedTranslation = std::pair<const char *, const char *>; |
| 36 | |
| 37 | static const QFont::Weight weightValues[] = { |
| 38 | QFont::Thin, QFont::ExtraLight, QFont::Light, QFont::Normal, QFont::Medium, QFont::DemiBold, |
| 39 | QFont::Bold, QFont::ExtraBold, QFont::Black |
| 40 | }; |
| 41 | |
| 42 | static int indexOfFontWeight(QFont::Weight w) |
| 43 | { |
| 44 | auto it = std::find(first: std::begin(arr: weightValues), last: std::end(arr: weightValues), val: w); |
| 45 | return int(it - std::begin(arr: weightValues)); |
| 46 | } |
| 47 | |
| 48 | static inline QFont::Weight weightFromIndex(int i) |
| 49 | { |
| 50 | return weightValues[i]; |
| 51 | } |
| 52 | |
| 53 | template <class PrivateData, class Value> |
| 54 | static void setSimpleMinimumData(PrivateData *data, const Value &minVal) |
| 55 | { |
| 56 | data->minVal = minVal; |
| 57 | if (data->maxVal < data->minVal) |
| 58 | data->maxVal = data->minVal; |
| 59 | |
| 60 | if (data->val < data->minVal) |
| 61 | data->val = data->minVal; |
| 62 | } |
| 63 | |
| 64 | template <class PrivateData, class Value> |
| 65 | static void setSimpleMaximumData(PrivateData *data, const Value &maxVal) |
| 66 | { |
| 67 | data->maxVal = maxVal; |
| 68 | if (data->minVal > data->maxVal) |
| 69 | data->minVal = data->maxVal; |
| 70 | |
| 71 | if (data->val > data->maxVal) |
| 72 | data->val = data->maxVal; |
| 73 | } |
| 74 | |
| 75 | template <class PrivateData, class Value> |
| 76 | static void setSizeMinimumData(PrivateData *data, const Value &newMinVal) |
| 77 | { |
| 78 | data->minVal = newMinVal; |
| 79 | if (data->maxVal.width() < data->minVal.width()) |
| 80 | data->maxVal.setWidth(data->minVal.width()); |
| 81 | if (data->maxVal.height() < data->minVal.height()) |
| 82 | data->maxVal.setHeight(data->minVal.height()); |
| 83 | |
| 84 | if (data->val.width() < data->minVal.width()) |
| 85 | data->val.setWidth(data->minVal.width()); |
| 86 | if (data->val.height() < data->minVal.height()) |
| 87 | data->val.setHeight(data->minVal.height()); |
| 88 | } |
| 89 | |
| 90 | template <class PrivateData, class Value> |
| 91 | static void setSizeMaximumData(PrivateData *data, const Value &newMaxVal) |
| 92 | { |
| 93 | data->maxVal = newMaxVal; |
| 94 | if (data->minVal.width() > data->maxVal.width()) |
| 95 | data->minVal.setWidth(data->maxVal.width()); |
| 96 | if (data->minVal.height() > data->maxVal.height()) |
| 97 | data->minVal.setHeight(data->maxVal.height()); |
| 98 | |
| 99 | if (data->val.width() > data->maxVal.width()) |
| 100 | data->val.setWidth(data->maxVal.width()); |
| 101 | if (data->val.height() > data->maxVal.height()) |
| 102 | data->val.setHeight(data->maxVal.height()); |
| 103 | } |
| 104 | |
| 105 | template <class SizeValue> |
| 106 | static SizeValue qBoundSize(const SizeValue &minVal, const SizeValue &val, const SizeValue &maxVal) |
| 107 | { |
| 108 | SizeValue croppedVal = val; |
| 109 | if (minVal.width() > val.width()) |
| 110 | croppedVal.setWidth(minVal.width()); |
| 111 | else if (maxVal.width() < val.width()) |
| 112 | croppedVal.setWidth(maxVal.width()); |
| 113 | |
| 114 | if (minVal.height() > val.height()) |
| 115 | croppedVal.setHeight(minVal.height()); |
| 116 | else if (maxVal.height() < val.height()) |
| 117 | croppedVal.setHeight(maxVal.height()); |
| 118 | |
| 119 | return croppedVal; |
| 120 | } |
| 121 | |
| 122 | // Match the exact signature of qBound for VS 6. |
| 123 | QSize qBound(QSize minVal, QSize val, QSize maxVal) |
| 124 | { |
| 125 | return qBoundSize(minVal, val, maxVal); |
| 126 | } |
| 127 | |
| 128 | QSizeF qBound(QSizeF minVal, QSizeF val, QSizeF maxVal) |
| 129 | { |
| 130 | return qBoundSize(minVal, val, maxVal); |
| 131 | } |
| 132 | |
| 133 | namespace { |
| 134 | |
| 135 | namespace { |
| 136 | template <class Value> |
| 137 | void orderBorders(Value &minVal, Value &maxVal) |
| 138 | { |
| 139 | if (minVal > maxVal) |
| 140 | qSwap(minVal, maxVal); |
| 141 | } |
| 142 | |
| 143 | template <class Value> |
| 144 | static void orderSizeBorders(Value &minVal, Value &maxVal) |
| 145 | { |
| 146 | Value fromSize = minVal; |
| 147 | Value toSize = maxVal; |
| 148 | if (fromSize.width() > toSize.width()) { |
| 149 | fromSize.setWidth(maxVal.width()); |
| 150 | toSize.setWidth(minVal.width()); |
| 151 | } |
| 152 | if (fromSize.height() > toSize.height()) { |
| 153 | fromSize.setHeight(maxVal.height()); |
| 154 | toSize.setHeight(minVal.height()); |
| 155 | } |
| 156 | minVal = fromSize; |
| 157 | maxVal = toSize; |
| 158 | } |
| 159 | |
| 160 | void orderBorders(QSize &minVal, QSize &maxVal) |
| 161 | { |
| 162 | orderSizeBorders(minVal, maxVal); |
| 163 | } |
| 164 | |
| 165 | void orderBorders(QSizeF &minVal, QSizeF &maxVal) |
| 166 | { |
| 167 | orderSizeBorders(minVal, maxVal); |
| 168 | } |
| 169 | |
| 170 | } |
| 171 | } |
| 172 | //////// |
| 173 | |
| 174 | template <class Value, class PrivateData> |
| 175 | static Value getData(const QHash<const QtProperty *, PrivateData> &propertyMap, |
| 176 | Value PrivateData::*data, |
| 177 | const QtProperty *property, const Value &defaultValue = Value()) |
| 178 | { |
| 179 | const auto it = propertyMap.constFind(property); |
| 180 | if (it == propertyMap.constEnd()) |
| 181 | return defaultValue; |
| 182 | return it.value().*data; |
| 183 | } |
| 184 | |
| 185 | template <class Value, class PrivateData> |
| 186 | static Value getValue(const QHash<const QtProperty *, PrivateData> &propertyMap, |
| 187 | const QtProperty *property, const Value &defaultValue = Value()) |
| 188 | { |
| 189 | return getData<Value>(propertyMap, &PrivateData::val, property, defaultValue); |
| 190 | } |
| 191 | |
| 192 | template <class Value, class PrivateData> |
| 193 | static Value getMinimum(const QHash<const QtProperty *, PrivateData> &propertyMap, |
| 194 | const QtProperty *property, const Value &defaultValue = Value()) |
| 195 | { |
| 196 | return getData<Value>(propertyMap, &PrivateData::minVal, property, defaultValue); |
| 197 | } |
| 198 | |
| 199 | template <class Value, class PrivateData> |
| 200 | static Value getMaximum(const QHash<const QtProperty *, PrivateData> &propertyMap, |
| 201 | const QtProperty *property, const Value &defaultValue = Value()) |
| 202 | { |
| 203 | return getData<Value>(propertyMap, &PrivateData::maxVal, property, defaultValue); |
| 204 | } |
| 205 | |
| 206 | template <class ValueChangeParameter, class Value, class PropertyManager> |
| 207 | static void setSimpleValue(QHash<const QtProperty *, Value> &propertyMap, |
| 208 | PropertyManager *manager, |
| 209 | void (PropertyManager::*propertyChangedSignal)(QtProperty *), |
| 210 | void (PropertyManager::*valueChangedSignal)(QtProperty *, ValueChangeParameter), |
| 211 | QtProperty *property, const Value &val) |
| 212 | { |
| 213 | const auto it = propertyMap.find(property); |
| 214 | if (it == propertyMap.end()) |
| 215 | return; |
| 216 | |
| 217 | if (it.value() == val) |
| 218 | return; |
| 219 | |
| 220 | it.value() = val; |
| 221 | |
| 222 | emit (manager->*propertyChangedSignal)(property); |
| 223 | emit (manager->*valueChangedSignal)(property, val); |
| 224 | } |
| 225 | |
| 226 | template <class ValueChangeParameter, class PropertyManagerPrivate, class PropertyManager, class Value> |
| 227 | static void setValueInRange(PropertyManager *manager, PropertyManagerPrivate *managerPrivate, |
| 228 | void (PropertyManager::*propertyChangedSignal)(QtProperty *), |
| 229 | void (PropertyManager::*valueChangedSignal)(QtProperty *, ValueChangeParameter), |
| 230 | QtProperty *property, const Value &val, |
| 231 | void (PropertyManagerPrivate::*setSubPropertyValue)(QtProperty *, ValueChangeParameter)) |
| 232 | { |
| 233 | const auto it = managerPrivate->m_values.find(property); |
| 234 | if (it == managerPrivate->m_values.end()) |
| 235 | return; |
| 236 | |
| 237 | auto &data = it.value(); |
| 238 | |
| 239 | if (data.val == val) |
| 240 | return; |
| 241 | |
| 242 | const Value oldVal = data.val; |
| 243 | |
| 244 | data.val = qBound(data.minVal, val, data.maxVal); |
| 245 | |
| 246 | if (data.val == oldVal) |
| 247 | return; |
| 248 | |
| 249 | if (setSubPropertyValue) |
| 250 | (managerPrivate->*setSubPropertyValue)(property, data.val); |
| 251 | |
| 252 | emit (manager->*propertyChangedSignal)(property); |
| 253 | emit (manager->*valueChangedSignal)(property, data.val); |
| 254 | } |
| 255 | |
| 256 | template <class ValueChangeParameter, class PropertyManagerPrivate, class PropertyManager, class Value> |
| 257 | static void setBorderValues(PropertyManager *manager, PropertyManagerPrivate *managerPrivate, |
| 258 | void (PropertyManager::*propertyChangedSignal)(QtProperty *), |
| 259 | void (PropertyManager::*valueChangedSignal)(QtProperty *, ValueChangeParameter), |
| 260 | void (PropertyManager::*rangeChangedSignal)(QtProperty *, ValueChangeParameter, ValueChangeParameter), |
| 261 | QtProperty *property, ValueChangeParameter minVal, ValueChangeParameter maxVal, |
| 262 | void (PropertyManagerPrivate::*setSubPropertyRange)(QtProperty *, |
| 263 | ValueChangeParameter, ValueChangeParameter, ValueChangeParameter)) |
| 264 | { |
| 265 | const auto it = managerPrivate->m_values.find(property); |
| 266 | if (it == managerPrivate->m_values.end()) |
| 267 | return; |
| 268 | |
| 269 | Value fromVal = minVal; |
| 270 | Value toVal = maxVal; |
| 271 | orderBorders(fromVal, toVal); |
| 272 | |
| 273 | auto &data = it.value(); |
| 274 | |
| 275 | if (data.minVal == fromVal && data.maxVal == toVal) |
| 276 | return; |
| 277 | |
| 278 | const Value oldVal = data.val; |
| 279 | |
| 280 | data.setMinimumValue(fromVal); |
| 281 | data.setMaximumValue(toVal); |
| 282 | |
| 283 | emit (manager->*rangeChangedSignal)(property, data.minVal, data.maxVal); |
| 284 | |
| 285 | if (setSubPropertyRange) |
| 286 | (managerPrivate->*setSubPropertyRange)(property, data.minVal, data.maxVal, data.val); |
| 287 | |
| 288 | if (data.val == oldVal) |
| 289 | return; |
| 290 | |
| 291 | emit (manager->*propertyChangedSignal)(property); |
| 292 | emit (manager->*valueChangedSignal)(property, data.val); |
| 293 | } |
| 294 | |
| 295 | template <class ValueChangeParameter, class PropertyManagerPrivate, class PropertyManager, class Value, class PrivateData> |
| 296 | static void setBorderValue(PropertyManager *manager, PropertyManagerPrivate *managerPrivate, |
| 297 | void (PropertyManager::*propertyChangedSignal)(QtProperty *), |
| 298 | void (PropertyManager::*valueChangedSignal)(QtProperty *, ValueChangeParameter), |
| 299 | void (PropertyManager::*rangeChangedSignal)(QtProperty *, ValueChangeParameter, ValueChangeParameter), |
| 300 | QtProperty *property, |
| 301 | Value (PrivateData::*getRangeVal)() const, |
| 302 | void (PrivateData::*setRangeVal)(ValueChangeParameter), const Value &borderVal, |
| 303 | void (PropertyManagerPrivate::*setSubPropertyRange)(QtProperty *, |
| 304 | ValueChangeParameter, ValueChangeParameter, ValueChangeParameter)) |
| 305 | { |
| 306 | const auto it = managerPrivate->m_values.find(property); |
| 307 | if (it == managerPrivate->m_values.end()) |
| 308 | return; |
| 309 | |
| 310 | PrivateData &data = it.value(); |
| 311 | |
| 312 | if ((data.*getRangeVal)() == borderVal) |
| 313 | return; |
| 314 | |
| 315 | const Value oldVal = data.val; |
| 316 | |
| 317 | (data.*setRangeVal)(borderVal); |
| 318 | |
| 319 | emit (manager->*rangeChangedSignal)(property, data.minVal, data.maxVal); |
| 320 | |
| 321 | if (setSubPropertyRange) |
| 322 | (managerPrivate->*setSubPropertyRange)(property, data.minVal, data.maxVal, data.val); |
| 323 | |
| 324 | if (data.val == oldVal) |
| 325 | return; |
| 326 | |
| 327 | emit (manager->*propertyChangedSignal)(property); |
| 328 | emit (manager->*valueChangedSignal)(property, data.val); |
| 329 | } |
| 330 | |
| 331 | template <class ValueChangeParameter, class PropertyManagerPrivate, class PropertyManager, class Value, class PrivateData> |
| 332 | static void setMinimumValue(PropertyManager *manager, PropertyManagerPrivate *managerPrivate, |
| 333 | void (PropertyManager::*propertyChangedSignal)(QtProperty *), |
| 334 | void (PropertyManager::*valueChangedSignal)(QtProperty *, ValueChangeParameter), |
| 335 | void (PropertyManager::*rangeChangedSignal)(QtProperty *, ValueChangeParameter, ValueChangeParameter), |
| 336 | QtProperty *property, const Value &minVal) |
| 337 | { |
| 338 | void (PropertyManagerPrivate::*setSubPropertyRange)(QtProperty *, |
| 339 | ValueChangeParameter, ValueChangeParameter, ValueChangeParameter) = nullptr; |
| 340 | setBorderValue<ValueChangeParameter, PropertyManagerPrivate, PropertyManager, Value, PrivateData>(manager, managerPrivate, |
| 341 | propertyChangedSignal, valueChangedSignal, rangeChangedSignal, |
| 342 | property, &PropertyManagerPrivate::Data::minimumValue, &PropertyManagerPrivate::Data::setMinimumValue, minVal, setSubPropertyRange); |
| 343 | } |
| 344 | |
| 345 | template <class ValueChangeParameter, class PropertyManagerPrivate, class PropertyManager, class Value, class PrivateData> |
| 346 | static void setMaximumValue(PropertyManager *manager, PropertyManagerPrivate *managerPrivate, |
| 347 | void (PropertyManager::*propertyChangedSignal)(QtProperty *), |
| 348 | void (PropertyManager::*valueChangedSignal)(QtProperty *, ValueChangeParameter), |
| 349 | void (PropertyManager::*rangeChangedSignal)(QtProperty *, ValueChangeParameter, ValueChangeParameter), |
| 350 | QtProperty *property, const Value &maxVal) |
| 351 | { |
| 352 | void (PropertyManagerPrivate::*setSubPropertyRange)(QtProperty *, |
| 353 | ValueChangeParameter, ValueChangeParameter, ValueChangeParameter) = nullptr; |
| 354 | setBorderValue<ValueChangeParameter, PropertyManagerPrivate, PropertyManager, Value, PrivateData>(manager, managerPrivate, |
| 355 | propertyChangedSignal, valueChangedSignal, rangeChangedSignal, |
| 356 | property, &PropertyManagerPrivate::Data::maximumValue, &PropertyManagerPrivate::Data::setMaximumValue, maxVal, setSubPropertyRange); |
| 357 | } |
| 358 | |
| 359 | class QtMetaEnumWrapper : public QObject |
| 360 | { |
| 361 | Q_OBJECT |
| 362 | Q_PROPERTY(QSizePolicy::Policy policy READ policy) |
| 363 | public: |
| 364 | QSizePolicy::Policy policy() const { return QSizePolicy::Ignored; } |
| 365 | private: |
| 366 | QtMetaEnumWrapper(QObject *parent) : QObject(parent) {} |
| 367 | }; |
| 368 | |
| 369 | class QtMetaEnumProvider |
| 370 | { |
| 371 | public: |
| 372 | QtMetaEnumProvider(); |
| 373 | |
| 374 | QStringList policyEnumNames() const { return m_policyEnumNames; } |
| 375 | QStringList languageEnumNames() const { return m_languageEnumNames; } |
| 376 | QStringList territoryEnumNames(QLocale::Language language) const { return m_territoryEnumNames.value(key: language); } |
| 377 | |
| 378 | QSizePolicy::Policy indexToSizePolicy(int index) const; |
| 379 | int sizePolicyToIndex(QSizePolicy::Policy policy) const; |
| 380 | |
| 381 | void indexToLocale(int languageIndex, int territoryIndex, QLocale::Language *language, QLocale::Territory *territory) const; |
| 382 | void localeToIndex(QLocale::Language language, QLocale::Territory territory, int *languageIndex, int *territoryIndex) const; |
| 383 | |
| 384 | private: |
| 385 | void initLocale(); |
| 386 | |
| 387 | QStringList m_policyEnumNames; |
| 388 | QStringList m_languageEnumNames; |
| 389 | QMap<QLocale::Language, QStringList> m_territoryEnumNames; |
| 390 | QMap<int, QLocale::Language> m_indexToLanguage; |
| 391 | QMap<QLocale::Language, int> m_languageToIndex; |
| 392 | QMap<int, QMap<int, QLocale::Territory> > m_indexToTerritory; |
| 393 | QMap<QLocale::Language, QMap<QLocale::Territory, int> > m_territoryToIndex; |
| 394 | QMetaEnum m_policyEnum; |
| 395 | }; |
| 396 | |
| 397 | static QList<QLocale::Territory> sortedTerritories(const QList<QLocale> &locales) |
| 398 | { |
| 399 | QMultiMap<QString, QLocale::Territory> nameToTerritory; |
| 400 | for (const QLocale &locale : locales) { |
| 401 | const auto territory = locale.territory(); |
| 402 | nameToTerritory.insert(key: QLocale::territoryToString(territory), value: territory); |
| 403 | } |
| 404 | return nameToTerritory.values(); |
| 405 | } |
| 406 | |
| 407 | void QtMetaEnumProvider::initLocale() |
| 408 | { |
| 409 | QMultiMap<QString, QLocale::Language> nameToLanguage; |
| 410 | for (int l = QLocale::C, last = QLocale::LastLanguage; l <= last; ++l) { |
| 411 | const QLocale::Language language = static_cast<QLocale::Language>(l); |
| 412 | QLocale locale(language); |
| 413 | if (locale.language() == language) |
| 414 | nameToLanguage.insert(key: QLocale::languageToString(language), value: language); |
| 415 | } |
| 416 | |
| 417 | const QLocale system = QLocale::system(); |
| 418 | if (!nameToLanguage.contains(key: QLocale::languageToString(language: system.language()))) |
| 419 | nameToLanguage.insert(key: QLocale::languageToString(language: system.language()), value: system.language()); |
| 420 | |
| 421 | const auto languages = nameToLanguage.values(); |
| 422 | for (QLocale::Language language : languages) { |
| 423 | auto locales = QLocale::matchingLocales(language, script: QLocale::AnyScript, |
| 424 | territory: QLocale::AnyTerritory); |
| 425 | |
| 426 | if (!locales.isEmpty() && !m_languageToIndex.contains(key: language)) { |
| 427 | const auto territories = sortedTerritories(locales); |
| 428 | qsizetype langIdx = m_languageEnumNames.size(); |
| 429 | m_indexToLanguage[langIdx] = language; |
| 430 | m_languageToIndex[language] = langIdx; |
| 431 | QStringList territoryNames; |
| 432 | int territoryIdx = 0; |
| 433 | for (QLocale::Territory territory : territories) { |
| 434 | territoryNames << QLocale::territoryToString(territory); |
| 435 | m_indexToTerritory[langIdx][territoryIdx] = territory; |
| 436 | m_territoryToIndex[language][territory] = territoryIdx; |
| 437 | ++territoryIdx; |
| 438 | } |
| 439 | m_languageEnumNames << QLocale::languageToString(language); |
| 440 | m_territoryEnumNames[language] = territoryNames; |
| 441 | } |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | QtMetaEnumProvider::QtMetaEnumProvider() |
| 446 | { |
| 447 | QMetaProperty p; |
| 448 | |
| 449 | p = QtMetaEnumWrapper::staticMetaObject.property( |
| 450 | index: QtMetaEnumWrapper::staticMetaObject.propertyOffset() + 0); |
| 451 | m_policyEnum = p.enumerator(); |
| 452 | const int keyCount = m_policyEnum.keyCount(); |
| 453 | for (int i = 0; i < keyCount; i++) |
| 454 | m_policyEnumNames << QLatin1StringView(m_policyEnum.key(index: i)); |
| 455 | |
| 456 | initLocale(); |
| 457 | } |
| 458 | |
| 459 | QSizePolicy::Policy QtMetaEnumProvider::indexToSizePolicy(int index) const |
| 460 | { |
| 461 | return static_cast<QSizePolicy::Policy>(m_policyEnum.value(index)); |
| 462 | } |
| 463 | |
| 464 | int QtMetaEnumProvider::sizePolicyToIndex(QSizePolicy::Policy policy) const |
| 465 | { |
| 466 | const int keyCount = m_policyEnum.keyCount(); |
| 467 | for (int i = 0; i < keyCount; i++) |
| 468 | if (indexToSizePolicy(index: i) == policy) |
| 469 | return i; |
| 470 | return -1; |
| 471 | } |
| 472 | |
| 473 | void QtMetaEnumProvider::indexToLocale(int languageIndex, int territoryIndex, QLocale::Language *language, QLocale::Territory *territory) const |
| 474 | { |
| 475 | QLocale::Language l = QLocale::C; |
| 476 | QLocale::Territory c = QLocale::AnyTerritory; |
| 477 | const auto lit = m_indexToLanguage.constFind(key: languageIndex); |
| 478 | if (lit != m_indexToLanguage.cend()) { |
| 479 | l = lit.value(); |
| 480 | const auto tit = m_indexToTerritory.constFind(key: languageIndex); |
| 481 | if (tit != m_indexToTerritory.end()) { |
| 482 | const auto tit2 = tit.value().constFind(key: territoryIndex); |
| 483 | if (tit2 != tit.value().cend()) |
| 484 | c = tit2.value(); |
| 485 | } |
| 486 | } |
| 487 | if (language) |
| 488 | *language = l; |
| 489 | if (territory) |
| 490 | *territory = c; |
| 491 | } |
| 492 | |
| 493 | void QtMetaEnumProvider::localeToIndex(QLocale::Language language, QLocale::Territory territory, int *languageIndex, int *territoryIndex) const |
| 494 | { |
| 495 | int l = -1; |
| 496 | int c = -1; |
| 497 | const auto lit = m_languageToIndex.constFind(key: language); |
| 498 | if (lit != m_languageToIndex.cend()) { |
| 499 | l = lit.value(); |
| 500 | const auto tit = m_territoryToIndex.constFind(key: language); |
| 501 | if (tit != m_territoryToIndex.cend()) { |
| 502 | const auto tit2 = tit.value().constFind(key: territory); |
| 503 | if (tit2 != tit.value().cend()) |
| 504 | c = tit2.value(); |
| 505 | } |
| 506 | } |
| 507 | |
| 508 | if (languageIndex) |
| 509 | *languageIndex = l; |
| 510 | if (territoryIndex) |
| 511 | *territoryIndex = c; |
| 512 | } |
| 513 | |
| 514 | Q_GLOBAL_STATIC(QtMetaEnumProvider, metaEnumProvider) |
| 515 | |
| 516 | // QtGroupPropertyManager |
| 517 | |
| 518 | /*! |
| 519 | \class QtGroupPropertyManager |
| 520 | \internal |
| 521 | \inmodule QtDesigner |
| 522 | \since 4.4 |
| 523 | |
| 524 | \brief The QtGroupPropertyManager provides and manages group properties. |
| 525 | |
| 526 | This class is intended to provide a grouping element without any value. |
| 527 | |
| 528 | \sa QtAbstractPropertyManager |
| 529 | */ |
| 530 | |
| 531 | /*! |
| 532 | Creates a manager with the given \a parent. |
| 533 | */ |
| 534 | QtGroupPropertyManager::QtGroupPropertyManager(QObject *parent) |
| 535 | : QtAbstractPropertyManager(parent) |
| 536 | { |
| 537 | |
| 538 | } |
| 539 | |
| 540 | /*! |
| 541 | Destroys this manager, and all the properties it has created. |
| 542 | */ |
| 543 | QtGroupPropertyManager::~QtGroupPropertyManager() = default; |
| 544 | |
| 545 | /*! |
| 546 | \reimp |
| 547 | */ |
| 548 | bool QtGroupPropertyManager::hasValue(const QtProperty *property) const |
| 549 | { |
| 550 | Q_UNUSED(property); |
| 551 | return false; |
| 552 | } |
| 553 | |
| 554 | /*! |
| 555 | \reimp |
| 556 | */ |
| 557 | void QtGroupPropertyManager::initializeProperty(QtProperty *property) |
| 558 | { |
| 559 | Q_UNUSED(property); |
| 560 | } |
| 561 | |
| 562 | /*! |
| 563 | \reimp |
| 564 | */ |
| 565 | void QtGroupPropertyManager::uninitializeProperty(QtProperty *property) |
| 566 | { |
| 567 | Q_UNUSED(property); |
| 568 | } |
| 569 | |
| 570 | // QtIntPropertyManager |
| 571 | |
| 572 | class QtIntPropertyManagerPrivate |
| 573 | { |
| 574 | QtIntPropertyManager *q_ptr = nullptr; |
| 575 | Q_DECLARE_PUBLIC(QtIntPropertyManager) |
| 576 | public: |
| 577 | |
| 578 | struct Data |
| 579 | { |
| 580 | int val{0}; |
| 581 | int minVal{-INT_MAX}; |
| 582 | int maxVal{INT_MAX}; |
| 583 | int singleStep{1}; |
| 584 | int minimumValue() const { return minVal; } |
| 585 | int maximumValue() const { return maxVal; } |
| 586 | void setMinimumValue(int newMinVal) { setSimpleMinimumData(data: this, minVal: newMinVal); } |
| 587 | void setMaximumValue(int newMaxVal) { setSimpleMaximumData(data: this, maxVal: newMaxVal); } |
| 588 | }; |
| 589 | |
| 590 | QHash<const QtProperty *, Data> m_values; |
| 591 | }; |
| 592 | |
| 593 | /*! |
| 594 | \class QtIntPropertyManager |
| 595 | \internal |
| 596 | \inmodule QtDesigner |
| 597 | \since 4.4 |
| 598 | |
| 599 | \brief The QtIntPropertyManager provides and manages int properties. |
| 600 | |
| 601 | An int property has a current value, and a range specifying the |
| 602 | valid values. The range is defined by a minimum and a maximum |
| 603 | value. |
| 604 | |
| 605 | The property's value and range can be retrieved using the value(), |
| 606 | minimum() and maximum() functions, and can be set using the |
| 607 | setValue(), setMinimum() and setMaximum() slots. Alternatively, |
| 608 | the range can be defined in one go using the setRange() slot. |
| 609 | |
| 610 | In addition, QtIntPropertyManager provides the valueChanged() signal which |
| 611 | is emitted whenever a property created by this manager changes, |
| 612 | and the rangeChanged() signal which is emitted whenever such a |
| 613 | property changes its range of valid values. |
| 614 | |
| 615 | \sa QtAbstractPropertyManager, QtSpinBoxFactory, QtSliderFactory, QtScrollBarFactory |
| 616 | */ |
| 617 | |
| 618 | /*! |
| 619 | \fn void QtIntPropertyManager::valueChanged(QtProperty *property, int value) |
| 620 | |
| 621 | This signal is emitted whenever a property created by this manager |
| 622 | changes its value, passing a pointer to the \a property and the new |
| 623 | \a value as parameters. |
| 624 | |
| 625 | \sa setValue() |
| 626 | */ |
| 627 | |
| 628 | /*! |
| 629 | \fn void QtIntPropertyManager::rangeChanged(QtProperty *property, int minimum, int maximum) |
| 630 | |
| 631 | This signal is emitted whenever a property created by this manager |
| 632 | changes its range of valid values, passing a pointer to the |
| 633 | \a property and the new \a minimum and \a maximum values. |
| 634 | |
| 635 | \sa setRange() |
| 636 | */ |
| 637 | |
| 638 | /*! |
| 639 | \fn void QtIntPropertyManager::singleStepChanged(QtProperty *property, int step) |
| 640 | |
| 641 | This signal is emitted whenever a property created by this manager |
| 642 | changes its single step property, passing a pointer to the |
| 643 | \a property and the new \a step value |
| 644 | |
| 645 | \sa setSingleStep() |
| 646 | */ |
| 647 | |
| 648 | /*! |
| 649 | Creates a manager with the given \a parent. |
| 650 | */ |
| 651 | QtIntPropertyManager::QtIntPropertyManager(QObject *parent) |
| 652 | : QtAbstractPropertyManager(parent), d_ptr(new QtIntPropertyManagerPrivate) |
| 653 | { |
| 654 | d_ptr->q_ptr = this; |
| 655 | } |
| 656 | |
| 657 | /*! |
| 658 | Destroys this manager, and all the properties it has created. |
| 659 | */ |
| 660 | QtIntPropertyManager::~QtIntPropertyManager() |
| 661 | { |
| 662 | clear(); |
| 663 | } |
| 664 | |
| 665 | /*! |
| 666 | Returns the given \a property's value. |
| 667 | |
| 668 | If the given property is not managed by this manager, this |
| 669 | function returns 0. |
| 670 | |
| 671 | \sa setValue() |
| 672 | */ |
| 673 | int QtIntPropertyManager::value(const QtProperty *property) const |
| 674 | { |
| 675 | return getValue<int>(propertyMap: d_ptr->m_values, property, defaultValue: 0); |
| 676 | } |
| 677 | |
| 678 | /*! |
| 679 | Returns the given \a property's minimum value. |
| 680 | |
| 681 | \sa setMinimum(), maximum(), setRange() |
| 682 | */ |
| 683 | int QtIntPropertyManager::minimum(const QtProperty *property) const |
| 684 | { |
| 685 | return getMinimum<int>(propertyMap: d_ptr->m_values, property, defaultValue: 0); |
| 686 | } |
| 687 | |
| 688 | /*! |
| 689 | Returns the given \a property's maximum value. |
| 690 | |
| 691 | \sa setMaximum(), minimum(), setRange() |
| 692 | */ |
| 693 | int QtIntPropertyManager::maximum(const QtProperty *property) const |
| 694 | { |
| 695 | return getMaximum<int>(propertyMap: d_ptr->m_values, property, defaultValue: 0); |
| 696 | } |
| 697 | |
| 698 | /*! |
| 699 | Returns the given \a property's step value. |
| 700 | |
| 701 | The step is typically used to increment or decrement a property value while pressing an arrow key. |
| 702 | |
| 703 | \sa setSingleStep() |
| 704 | */ |
| 705 | int QtIntPropertyManager::singleStep(const QtProperty *property) const |
| 706 | { |
| 707 | return getData<int>(propertyMap: d_ptr->m_values, data: &QtIntPropertyManagerPrivate::Data::singleStep, property, defaultValue: 0); |
| 708 | } |
| 709 | |
| 710 | /*! |
| 711 | \reimp |
| 712 | */ |
| 713 | QString QtIntPropertyManager::valueText(const QtProperty *property) const |
| 714 | { |
| 715 | const auto it = d_ptr->m_values.constFind(key: property); |
| 716 | if (it == d_ptr->m_values.constEnd()) |
| 717 | return {}; |
| 718 | return QString::number(it.value().val); |
| 719 | } |
| 720 | |
| 721 | /*! |
| 722 | \fn void QtIntPropertyManager::setValue(QtProperty *property, int value) |
| 723 | |
| 724 | Sets the value of the given \a property to \a value. |
| 725 | |
| 726 | If the specified \a value is not valid according to the given \a |
| 727 | property's range, the \a value is adjusted to the nearest valid |
| 728 | value within the range. |
| 729 | |
| 730 | \sa value(), setRange(), valueChanged() |
| 731 | */ |
| 732 | void QtIntPropertyManager::setValue(QtProperty *property, int val) |
| 733 | { |
| 734 | void (QtIntPropertyManagerPrivate::*setSubPropertyValue)(QtProperty *, int) = nullptr; |
| 735 | setValueInRange<int, QtIntPropertyManagerPrivate, QtIntPropertyManager, int>(manager: this, managerPrivate: d_ptr.data(), |
| 736 | propertyChangedSignal: &QtIntPropertyManager::propertyChanged, |
| 737 | valueChangedSignal: &QtIntPropertyManager::valueChanged, |
| 738 | property, val, setSubPropertyValue); |
| 739 | } |
| 740 | |
| 741 | /*! |
| 742 | Sets the minimum value for the given \a property to \a minVal. |
| 743 | |
| 744 | When setting the minimum value, the maximum and current values are |
| 745 | adjusted if necessary (ensuring that the range remains valid and |
| 746 | that the current value is within the range). |
| 747 | |
| 748 | \sa minimum(), setRange(), rangeChanged() |
| 749 | */ |
| 750 | void QtIntPropertyManager::setMinimum(QtProperty *property, int minVal) |
| 751 | { |
| 752 | setMinimumValue<int, QtIntPropertyManagerPrivate, QtIntPropertyManager, int, QtIntPropertyManagerPrivate::Data>(manager: this, managerPrivate: d_ptr.data(), |
| 753 | propertyChangedSignal: &QtIntPropertyManager::propertyChanged, |
| 754 | valueChangedSignal: &QtIntPropertyManager::valueChanged, |
| 755 | rangeChangedSignal: &QtIntPropertyManager::rangeChanged, |
| 756 | property, minVal); |
| 757 | } |
| 758 | |
| 759 | /*! |
| 760 | Sets the maximum value for the given \a property to \a maxVal. |
| 761 | |
| 762 | When setting maximum value, the minimum and current values are |
| 763 | adjusted if necessary (ensuring that the range remains valid and |
| 764 | that the current value is within the range). |
| 765 | |
| 766 | \sa maximum(), setRange(), rangeChanged() |
| 767 | */ |
| 768 | void QtIntPropertyManager::setMaximum(QtProperty *property, int maxVal) |
| 769 | { |
| 770 | setMaximumValue<int, QtIntPropertyManagerPrivate, QtIntPropertyManager, int, QtIntPropertyManagerPrivate::Data>(manager: this, managerPrivate: d_ptr.data(), |
| 771 | propertyChangedSignal: &QtIntPropertyManager::propertyChanged, |
| 772 | valueChangedSignal: &QtIntPropertyManager::valueChanged, |
| 773 | rangeChangedSignal: &QtIntPropertyManager::rangeChanged, |
| 774 | property, maxVal); |
| 775 | } |
| 776 | |
| 777 | /*! |
| 778 | \fn void QtIntPropertyManager::setRange(QtProperty *property, int minimum, int maximum) |
| 779 | |
| 780 | Sets the range of valid values. |
| 781 | |
| 782 | This is a convenience function defining the range of valid values |
| 783 | in one go; setting the \a minimum and \a maximum values for the |
| 784 | given \a property with a single function call. |
| 785 | |
| 786 | When setting a new range, the current value is adjusted if |
| 787 | necessary (ensuring that the value remains within range). |
| 788 | |
| 789 | \sa setMinimum(), setMaximum(), rangeChanged() |
| 790 | */ |
| 791 | void QtIntPropertyManager::setRange(QtProperty *property, int minVal, int maxVal) |
| 792 | { |
| 793 | void (QtIntPropertyManagerPrivate::*setSubPropertyRange)(QtProperty *, int, int, int) = nullptr; |
| 794 | setBorderValues<int, QtIntPropertyManagerPrivate, QtIntPropertyManager, int>(manager: this, managerPrivate: d_ptr.data(), |
| 795 | propertyChangedSignal: &QtIntPropertyManager::propertyChanged, |
| 796 | valueChangedSignal: &QtIntPropertyManager::valueChanged, |
| 797 | rangeChangedSignal: &QtIntPropertyManager::rangeChanged, |
| 798 | property, minVal, maxVal, setSubPropertyRange); |
| 799 | } |
| 800 | |
| 801 | /*! |
| 802 | Sets the step value for the given \a property to \a step. |
| 803 | |
| 804 | The step is typically used to increment or decrement a property value while pressing an arrow key. |
| 805 | |
| 806 | \sa singleStep() |
| 807 | */ |
| 808 | void QtIntPropertyManager::setSingleStep(QtProperty *property, int step) |
| 809 | { |
| 810 | const auto it = d_ptr->m_values.find(key: property); |
| 811 | if (it == d_ptr->m_values.end()) |
| 812 | return; |
| 813 | |
| 814 | QtIntPropertyManagerPrivate::Data data = it.value(); |
| 815 | |
| 816 | if (step < 0) |
| 817 | step = 0; |
| 818 | |
| 819 | if (data.singleStep == step) |
| 820 | return; |
| 821 | |
| 822 | data.singleStep = step; |
| 823 | |
| 824 | it.value() = data; |
| 825 | |
| 826 | emit singleStepChanged(property, step: data.singleStep); |
| 827 | } |
| 828 | |
| 829 | /*! |
| 830 | \reimp |
| 831 | */ |
| 832 | void QtIntPropertyManager::initializeProperty(QtProperty *property) |
| 833 | { |
| 834 | d_ptr->m_values[property] = QtIntPropertyManagerPrivate::Data(); |
| 835 | } |
| 836 | |
| 837 | /*! |
| 838 | \reimp |
| 839 | */ |
| 840 | void QtIntPropertyManager::uninitializeProperty(QtProperty *property) |
| 841 | { |
| 842 | d_ptr->m_values.remove(key: property); |
| 843 | } |
| 844 | |
| 845 | // QtDoublePropertyManager |
| 846 | |
| 847 | class QtDoublePropertyManagerPrivate |
| 848 | { |
| 849 | QtDoublePropertyManager *q_ptr = nullptr; |
| 850 | Q_DECLARE_PUBLIC(QtDoublePropertyManager) |
| 851 | public: |
| 852 | |
| 853 | struct Data |
| 854 | { |
| 855 | double val{0}; |
| 856 | double minVal{-DBL_MAX}; |
| 857 | double maxVal{DBL_MAX}; |
| 858 | double singleStep{1}; |
| 859 | int decimals{2}; |
| 860 | double minimumValue() const { return minVal; } |
| 861 | double maximumValue() const { return maxVal; } |
| 862 | void setMinimumValue(double newMinVal) { setSimpleMinimumData(data: this, minVal: newMinVal); } |
| 863 | void setMaximumValue(double newMaxVal) { setSimpleMaximumData(data: this, maxVal: newMaxVal); } |
| 864 | }; |
| 865 | |
| 866 | QHash<const QtProperty *, Data> m_values; |
| 867 | }; |
| 868 | |
| 869 | /*! |
| 870 | \class QtDoublePropertyManager |
| 871 | \internal |
| 872 | \inmodule QtDesigner |
| 873 | \since 4.4 |
| 874 | |
| 875 | \brief The QtDoublePropertyManager provides and manages double properties. |
| 876 | |
| 877 | A double property has a current value, and a range specifying the |
| 878 | valid values. The range is defined by a minimum and a maximum |
| 879 | value. |
| 880 | |
| 881 | The property's value and range can be retrieved using the value(), |
| 882 | minimum() and maximum() functions, and can be set using the |
| 883 | setValue(), setMinimum() and setMaximum() slots. |
| 884 | Alternatively, the range can be defined in one go using the |
| 885 | setRange() slot. |
| 886 | |
| 887 | In addition, QtDoublePropertyManager provides the valueChanged() signal |
| 888 | which is emitted whenever a property created by this manager |
| 889 | changes, and the rangeChanged() signal which is emitted whenever |
| 890 | such a property changes its range of valid values. |
| 891 | |
| 892 | \sa QtAbstractPropertyManager, QtDoubleSpinBoxFactory |
| 893 | */ |
| 894 | |
| 895 | /*! |
| 896 | \fn void QtDoublePropertyManager::valueChanged(QtProperty *property, double value) |
| 897 | |
| 898 | This signal is emitted whenever a property created by this manager |
| 899 | changes its value, passing a pointer to the \a property and the new |
| 900 | \a value as parameters. |
| 901 | |
| 902 | \sa setValue() |
| 903 | */ |
| 904 | |
| 905 | /*! |
| 906 | \fn void QtDoublePropertyManager::rangeChanged(QtProperty *property, double minimum, double maximum) |
| 907 | |
| 908 | This signal is emitted whenever a property created by this manager |
| 909 | changes its range of valid values, passing a pointer to the |
| 910 | \a property and the new \a minimum and \a maximum values |
| 911 | |
| 912 | \sa setRange() |
| 913 | */ |
| 914 | |
| 915 | /*! |
| 916 | \fn void QtDoublePropertyManager::decimalsChanged(QtProperty *property, int prec) |
| 917 | |
| 918 | This signal is emitted whenever a property created by this manager |
| 919 | changes its precision of value, passing a pointer to the |
| 920 | \a property and the new \a prec value |
| 921 | |
| 922 | \sa setDecimals() |
| 923 | */ |
| 924 | |
| 925 | /*! |
| 926 | \fn void QtDoublePropertyManager::singleStepChanged(QtProperty *property, double step) |
| 927 | |
| 928 | This signal is emitted whenever a property created by this manager |
| 929 | changes its single step property, passing a pointer to the |
| 930 | \a property and the new \a step value |
| 931 | |
| 932 | \sa setSingleStep() |
| 933 | */ |
| 934 | |
| 935 | /*! |
| 936 | Creates a manager with the given \a parent. |
| 937 | */ |
| 938 | QtDoublePropertyManager::QtDoublePropertyManager(QObject *parent) |
| 939 | : QtAbstractPropertyManager(parent), d_ptr(new QtDoublePropertyManagerPrivate) |
| 940 | { |
| 941 | d_ptr->q_ptr = this; |
| 942 | } |
| 943 | |
| 944 | /*! |
| 945 | Destroys this manager, and all the properties it has created. |
| 946 | */ |
| 947 | QtDoublePropertyManager::~QtDoublePropertyManager() |
| 948 | { |
| 949 | clear(); |
| 950 | } |
| 951 | |
| 952 | /*! |
| 953 | Returns the given \a property's value. |
| 954 | |
| 955 | If the given property is not managed by this manager, this |
| 956 | function returns 0. |
| 957 | |
| 958 | \sa setValue() |
| 959 | */ |
| 960 | double QtDoublePropertyManager::value(const QtProperty *property) const |
| 961 | { |
| 962 | return getValue<double>(propertyMap: d_ptr->m_values, property, defaultValue: 0.0); |
| 963 | } |
| 964 | |
| 965 | /*! |
| 966 | Returns the given \a property's minimum value. |
| 967 | |
| 968 | \sa maximum(), setRange() |
| 969 | */ |
| 970 | double QtDoublePropertyManager::minimum(const QtProperty *property) const |
| 971 | { |
| 972 | return getMinimum<double>(propertyMap: d_ptr->m_values, property, defaultValue: 0.0); |
| 973 | } |
| 974 | |
| 975 | /*! |
| 976 | Returns the given \a property's maximum value. |
| 977 | |
| 978 | \sa minimum(), setRange() |
| 979 | */ |
| 980 | double QtDoublePropertyManager::maximum(const QtProperty *property) const |
| 981 | { |
| 982 | return getMaximum<double>(propertyMap: d_ptr->m_values, property, defaultValue: 0.0); |
| 983 | } |
| 984 | |
| 985 | /*! |
| 986 | Returns the given \a property's step value. |
| 987 | |
| 988 | The step is typically used to increment or decrement a property value while pressing an arrow key. |
| 989 | |
| 990 | \sa setSingleStep() |
| 991 | */ |
| 992 | double QtDoublePropertyManager::singleStep(const QtProperty *property) const |
| 993 | { |
| 994 | return getData<double>(propertyMap: d_ptr->m_values, data: &QtDoublePropertyManagerPrivate::Data::singleStep, property, defaultValue: 0); |
| 995 | } |
| 996 | |
| 997 | /*! |
| 998 | Returns the given \a property's precision, in decimals. |
| 999 | |
| 1000 | \sa setDecimals() |
| 1001 | */ |
| 1002 | int QtDoublePropertyManager::decimals(const QtProperty *property) const |
| 1003 | { |
| 1004 | return getData<int>(propertyMap: d_ptr->m_values, data: &QtDoublePropertyManagerPrivate::Data::decimals, property, defaultValue: 0); |
| 1005 | } |
| 1006 | |
| 1007 | /*! |
| 1008 | \reimp |
| 1009 | */ |
| 1010 | QString QtDoublePropertyManager::valueText(const QtProperty *property) const |
| 1011 | { |
| 1012 | const auto it = d_ptr->m_values.constFind(key: property); |
| 1013 | if (it == d_ptr->m_values.constEnd()) |
| 1014 | return {}; |
| 1015 | return QString::number(it.value().val, format: 'f', precision: it.value().decimals); |
| 1016 | } |
| 1017 | |
| 1018 | /*! |
| 1019 | \fn void QtDoublePropertyManager::setValue(QtProperty *property, double value) |
| 1020 | |
| 1021 | Sets the value of the given \a property to \a value. |
| 1022 | |
| 1023 | If the specified \a value is not valid according to the given |
| 1024 | \a property's range, the \a value is adjusted to the nearest valid value |
| 1025 | within the range. |
| 1026 | |
| 1027 | \sa value(), setRange(), valueChanged() |
| 1028 | */ |
| 1029 | void QtDoublePropertyManager::setValue(QtProperty *property, double val) |
| 1030 | { |
| 1031 | void (QtDoublePropertyManagerPrivate::*setSubPropertyValue)(QtProperty *, double) = nullptr; |
| 1032 | setValueInRange<double, QtDoublePropertyManagerPrivate, QtDoublePropertyManager, double>(manager: this, managerPrivate: d_ptr.data(), |
| 1033 | propertyChangedSignal: &QtDoublePropertyManager::propertyChanged, |
| 1034 | valueChangedSignal: &QtDoublePropertyManager::valueChanged, |
| 1035 | property, val, setSubPropertyValue); |
| 1036 | } |
| 1037 | |
| 1038 | /*! |
| 1039 | Sets the step value for the given \a property to \a step. |
| 1040 | |
| 1041 | The step is typically used to increment or decrement a property value while pressing an arrow key. |
| 1042 | |
| 1043 | \sa singleStep() |
| 1044 | */ |
| 1045 | void QtDoublePropertyManager::setSingleStep(QtProperty *property, double step) |
| 1046 | { |
| 1047 | const auto it = d_ptr->m_values.find(key: property); |
| 1048 | if (it == d_ptr->m_values.end()) |
| 1049 | return; |
| 1050 | |
| 1051 | QtDoublePropertyManagerPrivate::Data data = it.value(); |
| 1052 | |
| 1053 | if (step < 0) |
| 1054 | step = 0; |
| 1055 | |
| 1056 | if (data.singleStep == step) |
| 1057 | return; |
| 1058 | |
| 1059 | data.singleStep = step; |
| 1060 | |
| 1061 | it.value() = data; |
| 1062 | |
| 1063 | emit singleStepChanged(property, step: data.singleStep); |
| 1064 | } |
| 1065 | |
| 1066 | /*! |
| 1067 | \fn void QtDoublePropertyManager::setDecimals(QtProperty *property, int prec) |
| 1068 | |
| 1069 | Sets the precision of the given \a property to \a prec. |
| 1070 | |
| 1071 | The valid decimal range is 0-13. The default is 2. |
| 1072 | |
| 1073 | \sa decimals() |
| 1074 | */ |
| 1075 | void QtDoublePropertyManager::setDecimals(QtProperty *property, int prec) |
| 1076 | { |
| 1077 | const auto it = d_ptr->m_values.find(key: property); |
| 1078 | if (it == d_ptr->m_values.end()) |
| 1079 | return; |
| 1080 | |
| 1081 | QtDoublePropertyManagerPrivate::Data data = it.value(); |
| 1082 | |
| 1083 | if (prec > 13) |
| 1084 | prec = 13; |
| 1085 | else if (prec < 0) |
| 1086 | prec = 0; |
| 1087 | |
| 1088 | if (data.decimals == prec) |
| 1089 | return; |
| 1090 | |
| 1091 | data.decimals = prec; |
| 1092 | |
| 1093 | it.value() = data; |
| 1094 | |
| 1095 | emit decimalsChanged(property, prec: data.decimals); |
| 1096 | } |
| 1097 | |
| 1098 | /*! |
| 1099 | Sets the minimum value for the given \a property to \a minVal. |
| 1100 | |
| 1101 | When setting the minimum value, the maximum and current values are |
| 1102 | adjusted if necessary (ensuring that the range remains valid and |
| 1103 | that the current value is within in the range). |
| 1104 | |
| 1105 | \sa minimum(), setRange(), rangeChanged() |
| 1106 | */ |
| 1107 | void QtDoublePropertyManager::setMinimum(QtProperty *property, double minVal) |
| 1108 | { |
| 1109 | setMinimumValue<double, QtDoublePropertyManagerPrivate, QtDoublePropertyManager, double, QtDoublePropertyManagerPrivate::Data>(manager: this, managerPrivate: d_ptr.data(), |
| 1110 | propertyChangedSignal: &QtDoublePropertyManager::propertyChanged, |
| 1111 | valueChangedSignal: &QtDoublePropertyManager::valueChanged, |
| 1112 | rangeChangedSignal: &QtDoublePropertyManager::rangeChanged, |
| 1113 | property, minVal); |
| 1114 | } |
| 1115 | |
| 1116 | /*! |
| 1117 | Sets the maximum value for the given \a property to \a maxVal. |
| 1118 | |
| 1119 | When setting the maximum value, the minimum and current values are |
| 1120 | adjusted if necessary (ensuring that the range remains valid and |
| 1121 | that the current value is within in the range). |
| 1122 | |
| 1123 | \sa maximum(), setRange(), rangeChanged() |
| 1124 | */ |
| 1125 | void QtDoublePropertyManager::setMaximum(QtProperty *property, double maxVal) |
| 1126 | { |
| 1127 | setMaximumValue<double, QtDoublePropertyManagerPrivate, QtDoublePropertyManager, double, QtDoublePropertyManagerPrivate::Data>(manager: this, managerPrivate: d_ptr.data(), |
| 1128 | propertyChangedSignal: &QtDoublePropertyManager::propertyChanged, |
| 1129 | valueChangedSignal: &QtDoublePropertyManager::valueChanged, |
| 1130 | rangeChangedSignal: &QtDoublePropertyManager::rangeChanged, |
| 1131 | property, maxVal); |
| 1132 | } |
| 1133 | |
| 1134 | /*! |
| 1135 | \fn void QtDoublePropertyManager::setRange(QtProperty *property, double minimum, double maximum) |
| 1136 | |
| 1137 | Sets the range of valid values. |
| 1138 | |
| 1139 | This is a convenience function defining the range of valid values |
| 1140 | in one go; setting the \a minimum and \a maximum values for the |
| 1141 | given \a property with a single function call. |
| 1142 | |
| 1143 | When setting a new range, the current value is adjusted if |
| 1144 | necessary (ensuring that the value remains within range). |
| 1145 | |
| 1146 | \sa setMinimum(), setMaximum(), rangeChanged() |
| 1147 | */ |
| 1148 | void QtDoublePropertyManager::setRange(QtProperty *property, double minVal, double maxVal) |
| 1149 | { |
| 1150 | void (QtDoublePropertyManagerPrivate::*setSubPropertyRange)(QtProperty *, double, double, double) = nullptr; |
| 1151 | setBorderValues<double, QtDoublePropertyManagerPrivate, QtDoublePropertyManager, double>(manager: this, managerPrivate: d_ptr.data(), |
| 1152 | propertyChangedSignal: &QtDoublePropertyManager::propertyChanged, |
| 1153 | valueChangedSignal: &QtDoublePropertyManager::valueChanged, |
| 1154 | rangeChangedSignal: &QtDoublePropertyManager::rangeChanged, |
| 1155 | property, minVal, maxVal, setSubPropertyRange); |
| 1156 | } |
| 1157 | |
| 1158 | /*! |
| 1159 | \reimp |
| 1160 | */ |
| 1161 | void QtDoublePropertyManager::initializeProperty(QtProperty *property) |
| 1162 | { |
| 1163 | d_ptr->m_values[property] = QtDoublePropertyManagerPrivate::Data(); |
| 1164 | } |
| 1165 | |
| 1166 | /*! |
| 1167 | \reimp |
| 1168 | */ |
| 1169 | void QtDoublePropertyManager::uninitializeProperty(QtProperty *property) |
| 1170 | { |
| 1171 | d_ptr->m_values.remove(key: property); |
| 1172 | } |
| 1173 | |
| 1174 | // QtStringPropertyManager |
| 1175 | |
| 1176 | class QtStringPropertyManagerPrivate |
| 1177 | { |
| 1178 | QtStringPropertyManager *q_ptr = nullptr; |
| 1179 | Q_DECLARE_PUBLIC(QtStringPropertyManager) |
| 1180 | public: |
| 1181 | |
| 1182 | struct Data |
| 1183 | { |
| 1184 | QString val; |
| 1185 | QRegularExpression regExp; |
| 1186 | }; |
| 1187 | |
| 1188 | QHash<const QtProperty *, Data> m_values; |
| 1189 | }; |
| 1190 | |
| 1191 | /*! |
| 1192 | \class QtStringPropertyManager |
| 1193 | \internal |
| 1194 | \inmodule QtDesigner |
| 1195 | \since 4.4 |
| 1196 | |
| 1197 | \brief The QtStringPropertyManager provides and manages QString properties. |
| 1198 | |
| 1199 | A string property's value can be retrieved using the value() |
| 1200 | function, and set using the setValue() slot. |
| 1201 | |
| 1202 | The current value can be checked against a regular expression. To |
| 1203 | set the regular expression use the setRegExp() slot, use the |
| 1204 | regExp() function to retrieve the currently set expression. |
| 1205 | |
| 1206 | In addition, QtStringPropertyManager provides the valueChanged() signal |
| 1207 | which is emitted whenever a property created by this manager |
| 1208 | changes, and the regExpChanged() signal which is emitted whenever |
| 1209 | such a property changes its currently set regular expression. |
| 1210 | |
| 1211 | \sa QtAbstractPropertyManager, QtLineEditFactory |
| 1212 | */ |
| 1213 | |
| 1214 | /*! |
| 1215 | \fn void QtStringPropertyManager::valueChanged(QtProperty *property, const QString &value) |
| 1216 | |
| 1217 | This signal is emitted whenever a property created by this manager |
| 1218 | changes its value, passing a pointer to the \a property and the |
| 1219 | new \a value as parameters. |
| 1220 | |
| 1221 | \sa setValue() |
| 1222 | */ |
| 1223 | |
| 1224 | /*! |
| 1225 | \fn void QtStringPropertyManager::regExpChanged(QtProperty *property, const QRegularExpression ®Exp) |
| 1226 | |
| 1227 | This signal is emitted whenever a property created by this manager |
| 1228 | changes its currenlty set regular expression, passing a pointer to |
| 1229 | the \a property and the new \a regExp as parameters. |
| 1230 | |
| 1231 | \sa setRegExp() |
| 1232 | */ |
| 1233 | |
| 1234 | /*! |
| 1235 | Creates a manager with the given \a parent. |
| 1236 | */ |
| 1237 | QtStringPropertyManager::QtStringPropertyManager(QObject *parent) |
| 1238 | : QtAbstractPropertyManager(parent), d_ptr(new QtStringPropertyManagerPrivate) |
| 1239 | { |
| 1240 | d_ptr->q_ptr = this; |
| 1241 | } |
| 1242 | |
| 1243 | /*! |
| 1244 | Destroys this manager, and all the properties it has created. |
| 1245 | */ |
| 1246 | QtStringPropertyManager::~QtStringPropertyManager() |
| 1247 | { |
| 1248 | clear(); |
| 1249 | } |
| 1250 | |
| 1251 | /*! |
| 1252 | Returns the given \a property's value. |
| 1253 | |
| 1254 | If the given property is not managed by this manager, this |
| 1255 | function returns an empty string. |
| 1256 | |
| 1257 | \sa setValue() |
| 1258 | */ |
| 1259 | QString QtStringPropertyManager::value(const QtProperty *property) const |
| 1260 | { |
| 1261 | return getValue<QString>(propertyMap: d_ptr->m_values, property); |
| 1262 | } |
| 1263 | |
| 1264 | /*! |
| 1265 | Returns the given \a property's currently set regular expression. |
| 1266 | |
| 1267 | If the given \a property is not managed by this manager, this |
| 1268 | function returns an empty expression. |
| 1269 | |
| 1270 | \sa setRegExp() |
| 1271 | */ |
| 1272 | QRegularExpression QtStringPropertyManager::regExp(const QtProperty *property) const |
| 1273 | { |
| 1274 | return getData<QRegularExpression>(propertyMap: d_ptr->m_values, data: &QtStringPropertyManagerPrivate::Data::regExp, property, defaultValue: QRegularExpression()); |
| 1275 | } |
| 1276 | |
| 1277 | /*! |
| 1278 | \reimp |
| 1279 | */ |
| 1280 | QString QtStringPropertyManager::valueText(const QtProperty *property) const |
| 1281 | { |
| 1282 | const auto it = d_ptr->m_values.constFind(key: property); |
| 1283 | if (it == d_ptr->m_values.constEnd()) |
| 1284 | return {}; |
| 1285 | return it.value().val; |
| 1286 | } |
| 1287 | |
| 1288 | /*! |
| 1289 | \fn void QtStringPropertyManager::setValue(QtProperty *property, const QString &value) |
| 1290 | |
| 1291 | Sets the value of the given \a property to \a value. |
| 1292 | |
| 1293 | If the specified \a value doesn't match the given \a property's |
| 1294 | regular expression, this function does nothing. |
| 1295 | |
| 1296 | \sa value(), setRegExp(), valueChanged() |
| 1297 | */ |
| 1298 | void QtStringPropertyManager::setValue(QtProperty *property, const QString &val) |
| 1299 | { |
| 1300 | const auto it = d_ptr->m_values.find(key: property); |
| 1301 | if (it == d_ptr->m_values.end()) |
| 1302 | return; |
| 1303 | |
| 1304 | QtStringPropertyManagerPrivate::Data data = it.value(); |
| 1305 | |
| 1306 | if (data.val == val) |
| 1307 | return; |
| 1308 | |
| 1309 | if (data.regExp.isValid() && !data.regExp.pattern().isEmpty() |
| 1310 | && !data.regExp.match(subject: val).hasMatch()) { |
| 1311 | return; |
| 1312 | } |
| 1313 | |
| 1314 | data.val = val; |
| 1315 | |
| 1316 | it.value() = data; |
| 1317 | |
| 1318 | emit propertyChanged(property); |
| 1319 | emit valueChanged(property, val: data.val); |
| 1320 | } |
| 1321 | |
| 1322 | /*! |
| 1323 | Sets the regular expression of the given \a property to \a regExp. |
| 1324 | |
| 1325 | \sa regExp(), setValue(), regExpChanged() |
| 1326 | */ |
| 1327 | void QtStringPropertyManager::setRegExp(QtProperty *property, const QRegularExpression ®Exp) |
| 1328 | { |
| 1329 | const auto it = d_ptr->m_values.find(key: property); |
| 1330 | if (it == d_ptr->m_values.end()) |
| 1331 | return; |
| 1332 | |
| 1333 | QtStringPropertyManagerPrivate::Data data = it.value() ; |
| 1334 | |
| 1335 | if (data.regExp == regExp) |
| 1336 | return; |
| 1337 | |
| 1338 | data.regExp = regExp; |
| 1339 | |
| 1340 | it.value() = data; |
| 1341 | |
| 1342 | emit regExpChanged(property, regExp: data.regExp); |
| 1343 | } |
| 1344 | |
| 1345 | /*! |
| 1346 | \reimp |
| 1347 | */ |
| 1348 | void QtStringPropertyManager::initializeProperty(QtProperty *property) |
| 1349 | { |
| 1350 | d_ptr->m_values[property] = QtStringPropertyManagerPrivate::Data(); |
| 1351 | } |
| 1352 | |
| 1353 | /*! |
| 1354 | \reimp |
| 1355 | */ |
| 1356 | void QtStringPropertyManager::uninitializeProperty(QtProperty *property) |
| 1357 | { |
| 1358 | d_ptr->m_values.remove(key: property); |
| 1359 | } |
| 1360 | |
| 1361 | // QtBoolPropertyManager |
| 1362 | // Return an icon containing a check box indicator |
| 1363 | static QIcon drawCheckBox(bool value) |
| 1364 | { |
| 1365 | QStyleOptionButton opt; |
| 1366 | opt.state |= value ? QStyle::State_On : QStyle::State_Off; |
| 1367 | opt.state |= QStyle::State_Enabled; |
| 1368 | const QStyle *style = QApplication::style(); |
| 1369 | // Figure out size of an indicator and make sure it is not scaled down in a list view item |
| 1370 | // by making the pixmap as big as a list view icon and centering the indicator in it. |
| 1371 | // (if it is smaller, it can't be helped) |
| 1372 | const int indicatorWidth = style->pixelMetric(metric: QStyle::PM_IndicatorWidth, option: &opt); |
| 1373 | const int indicatorHeight = style->pixelMetric(metric: QStyle::PM_IndicatorHeight, option: &opt); |
| 1374 | const int listViewIconSize = indicatorWidth; |
| 1375 | const int pixmapWidth = indicatorWidth; |
| 1376 | const int pixmapHeight = qMax(a: indicatorHeight, b: listViewIconSize); |
| 1377 | |
| 1378 | opt.rect = QRect(0, 0, indicatorWidth, indicatorHeight); |
| 1379 | QPixmap pixmap = QPixmap(pixmapWidth, pixmapHeight); |
| 1380 | pixmap.fill(fillColor: Qt::transparent); |
| 1381 | { |
| 1382 | // Center? |
| 1383 | const int xoff = (pixmapWidth > indicatorWidth) ? (pixmapWidth - indicatorWidth) / 2 : 0; |
| 1384 | const int yoff = (pixmapHeight > indicatorHeight) ? (pixmapHeight - indicatorHeight) / 2 : 0; |
| 1385 | QPainter painter(&pixmap); |
| 1386 | painter.translate(dx: xoff, dy: yoff); |
| 1387 | style->drawPrimitive(pe: QStyle::PE_IndicatorCheckBox, opt: &opt, p: &painter); |
| 1388 | } |
| 1389 | return QIcon(pixmap); |
| 1390 | } |
| 1391 | |
| 1392 | class QtBoolPropertyManagerPrivate |
| 1393 | { |
| 1394 | QtBoolPropertyManager *q_ptr = nullptr; |
| 1395 | Q_DECLARE_PUBLIC(QtBoolPropertyManager) |
| 1396 | public: |
| 1397 | QtBoolPropertyManagerPrivate(); |
| 1398 | |
| 1399 | QHash<const QtProperty *, bool> m_values; |
| 1400 | const QIcon m_checkedIcon; |
| 1401 | const QIcon m_uncheckedIcon; |
| 1402 | }; |
| 1403 | |
| 1404 | QtBoolPropertyManagerPrivate::QtBoolPropertyManagerPrivate() : |
| 1405 | m_checkedIcon(drawCheckBox(value: true)), |
| 1406 | m_uncheckedIcon(drawCheckBox(value: false)) |
| 1407 | { |
| 1408 | } |
| 1409 | |
| 1410 | /*! |
| 1411 | \class QtBoolPropertyManager |
| 1412 | \internal |
| 1413 | \inmodule QtDesigner |
| 1414 | \since 4.4 |
| 1415 | |
| 1416 | \brief The QtBoolPropertyManager class provides and manages boolean properties. |
| 1417 | |
| 1418 | The property's value can be retrieved using the value() function, |
| 1419 | and set using the setValue() slot. |
| 1420 | |
| 1421 | In addition, QtBoolPropertyManager provides the valueChanged() signal |
| 1422 | which is emitted whenever a property created by this manager |
| 1423 | changes. |
| 1424 | |
| 1425 | \sa QtAbstractPropertyManager, QtCheckBoxFactory |
| 1426 | */ |
| 1427 | |
| 1428 | /*! |
| 1429 | \fn void QtBoolPropertyManager::valueChanged(QtProperty *property, bool value) |
| 1430 | |
| 1431 | This signal is emitted whenever a property created by this manager |
| 1432 | changes its value, passing a pointer to the \a property and the |
| 1433 | new \a value as parameters. |
| 1434 | */ |
| 1435 | |
| 1436 | /*! |
| 1437 | Creates a manager with the given \a parent. |
| 1438 | */ |
| 1439 | QtBoolPropertyManager::QtBoolPropertyManager(QObject *parent) |
| 1440 | : QtAbstractPropertyManager(parent), d_ptr(new QtBoolPropertyManagerPrivate) |
| 1441 | { |
| 1442 | d_ptr->q_ptr = this; |
| 1443 | } |
| 1444 | |
| 1445 | /*! |
| 1446 | Destroys this manager, and all the properties it has created. |
| 1447 | */ |
| 1448 | QtBoolPropertyManager::~QtBoolPropertyManager() |
| 1449 | { |
| 1450 | clear(); |
| 1451 | } |
| 1452 | |
| 1453 | /*! |
| 1454 | Returns the given \a property's value. |
| 1455 | |
| 1456 | If the given \a property is not managed by \e this manager, this |
| 1457 | function returns false. |
| 1458 | |
| 1459 | \sa setValue() |
| 1460 | */ |
| 1461 | bool QtBoolPropertyManager::value(const QtProperty *property) const |
| 1462 | { |
| 1463 | return d_ptr->m_values.value(key: property, defaultValue: false); |
| 1464 | } |
| 1465 | |
| 1466 | /*! |
| 1467 | \reimp |
| 1468 | */ |
| 1469 | QString QtBoolPropertyManager::valueText(const QtProperty *property) const |
| 1470 | { |
| 1471 | const auto it = d_ptr->m_values.constFind(key: property); |
| 1472 | if (it == d_ptr->m_values.constEnd()) |
| 1473 | return {}; |
| 1474 | |
| 1475 | static const QString trueText = tr(s: "True" ); |
| 1476 | static const QString falseText = tr(s: "False" ); |
| 1477 | return it.value() ? trueText : falseText; |
| 1478 | } |
| 1479 | |
| 1480 | /*! |
| 1481 | \reimp |
| 1482 | */ |
| 1483 | QIcon QtBoolPropertyManager::valueIcon(const QtProperty *property) const |
| 1484 | { |
| 1485 | const auto it = d_ptr->m_values.constFind(key: property); |
| 1486 | if (it == d_ptr->m_values.constEnd()) |
| 1487 | return {}; |
| 1488 | |
| 1489 | return it.value() ? d_ptr->m_checkedIcon : d_ptr->m_uncheckedIcon; |
| 1490 | } |
| 1491 | |
| 1492 | /*! |
| 1493 | \fn void QtBoolPropertyManager::setValue(QtProperty *property, bool value) |
| 1494 | |
| 1495 | Sets the value of the given \a property to \a value. |
| 1496 | |
| 1497 | \sa value() |
| 1498 | */ |
| 1499 | void QtBoolPropertyManager::setValue(QtProperty *property, bool val) |
| 1500 | { |
| 1501 | setSimpleValue<bool, bool, QtBoolPropertyManager>(propertyMap&: d_ptr->m_values, manager: this, |
| 1502 | propertyChangedSignal: &QtBoolPropertyManager::propertyChanged, |
| 1503 | valueChangedSignal: &QtBoolPropertyManager::valueChanged, |
| 1504 | property, val); |
| 1505 | } |
| 1506 | |
| 1507 | /*! |
| 1508 | \reimp |
| 1509 | */ |
| 1510 | void QtBoolPropertyManager::initializeProperty(QtProperty *property) |
| 1511 | { |
| 1512 | d_ptr->m_values[property] = false; |
| 1513 | } |
| 1514 | |
| 1515 | /*! |
| 1516 | \reimp |
| 1517 | */ |
| 1518 | void QtBoolPropertyManager::uninitializeProperty(QtProperty *property) |
| 1519 | { |
| 1520 | d_ptr->m_values.remove(key: property); |
| 1521 | } |
| 1522 | |
| 1523 | // QtDatePropertyManager |
| 1524 | |
| 1525 | class QtDatePropertyManagerPrivate |
| 1526 | { |
| 1527 | QtDatePropertyManager *q_ptr = nullptr; |
| 1528 | Q_DECLARE_PUBLIC(QtDatePropertyManager) |
| 1529 | public: |
| 1530 | explicit QtDatePropertyManagerPrivate(QtDatePropertyManager *q); |
| 1531 | |
| 1532 | struct Data |
| 1533 | { |
| 1534 | QDate val{QDate::currentDate()}; |
| 1535 | QDate minVal{QDate(1752, 9, 14)}; |
| 1536 | QDate maxVal{QDate(9999, 12, 31)}; |
| 1537 | QDate minimumValue() const { return minVal; } |
| 1538 | QDate maximumValue() const { return maxVal; } |
| 1539 | void setMinimumValue(QDate newMinVal) { setSimpleMinimumData(data: this, minVal: newMinVal); } |
| 1540 | void setMaximumValue(QDate newMaxVal) { setSimpleMaximumData(data: this, maxVal: newMaxVal); } |
| 1541 | }; |
| 1542 | |
| 1543 | QString m_format; |
| 1544 | |
| 1545 | QHash<const QtProperty *, Data> m_values; |
| 1546 | }; |
| 1547 | |
| 1548 | QtDatePropertyManagerPrivate::QtDatePropertyManagerPrivate(QtDatePropertyManager *q) : |
| 1549 | q_ptr(q), |
| 1550 | m_format(QtPropertyBrowserUtils::dateFormat()) |
| 1551 | { |
| 1552 | } |
| 1553 | |
| 1554 | /*! |
| 1555 | \class QtDatePropertyManager |
| 1556 | \internal |
| 1557 | \inmodule QtDesigner |
| 1558 | \since 4.4 |
| 1559 | |
| 1560 | \brief The QtDatePropertyManager provides and manages QDate properties. |
| 1561 | |
| 1562 | A date property has a current value, and a range specifying the |
| 1563 | valid dates. The range is defined by a minimum and a maximum |
| 1564 | value. |
| 1565 | |
| 1566 | The property's values can be retrieved using the minimum(), |
| 1567 | maximum() and value() functions, and can be set using the |
| 1568 | setMinimum(), setMaximum() and setValue() slots. Alternatively, |
| 1569 | the range can be defined in one go using the setRange() slot. |
| 1570 | |
| 1571 | In addition, QtDatePropertyManager provides the valueChanged() signal |
| 1572 | which is emitted whenever a property created by this manager |
| 1573 | changes, and the rangeChanged() signal which is emitted whenever |
| 1574 | such a property changes its range of valid dates. |
| 1575 | |
| 1576 | \sa QtAbstractPropertyManager, QtDateEditFactory, QtDateTimePropertyManager |
| 1577 | */ |
| 1578 | |
| 1579 | /*! |
| 1580 | \fn void QtDatePropertyManager::valueChanged(QtProperty *property, QDate value) |
| 1581 | |
| 1582 | This signal is emitted whenever a property created by this manager |
| 1583 | changes its value, passing a pointer to the \a property and the new |
| 1584 | \a value as parameters. |
| 1585 | |
| 1586 | \sa setValue() |
| 1587 | */ |
| 1588 | |
| 1589 | /*! |
| 1590 | \fn void QtDatePropertyManager::rangeChanged(QtProperty *property, QDate minimum, QDate maximum) |
| 1591 | |
| 1592 | This signal is emitted whenever a property created by this manager |
| 1593 | changes its range of valid dates, passing a pointer to the \a |
| 1594 | property and the new \a minimum and \a maximum dates. |
| 1595 | |
| 1596 | \sa setRange() |
| 1597 | */ |
| 1598 | |
| 1599 | /*! |
| 1600 | Creates a manager with the given \a parent. |
| 1601 | */ |
| 1602 | QtDatePropertyManager::QtDatePropertyManager(QObject *parent) |
| 1603 | : QtAbstractPropertyManager(parent), d_ptr(new QtDatePropertyManagerPrivate(this)) |
| 1604 | { |
| 1605 | } |
| 1606 | |
| 1607 | /*! |
| 1608 | Destroys this manager, and all the properties it has created. |
| 1609 | */ |
| 1610 | QtDatePropertyManager::~QtDatePropertyManager() |
| 1611 | { |
| 1612 | clear(); |
| 1613 | } |
| 1614 | |
| 1615 | /*! |
| 1616 | Returns the given \a property's value. |
| 1617 | |
| 1618 | If the given \a property is not managed by \e this manager, this |
| 1619 | function returns an invalid date. |
| 1620 | |
| 1621 | \sa setValue() |
| 1622 | */ |
| 1623 | QDate QtDatePropertyManager::value(const QtProperty *property) const |
| 1624 | { |
| 1625 | return getValue<QDate>(propertyMap: d_ptr->m_values, property); |
| 1626 | } |
| 1627 | |
| 1628 | /*! |
| 1629 | Returns the given \a property's minimum date. |
| 1630 | |
| 1631 | \sa maximum(), setRange() |
| 1632 | */ |
| 1633 | QDate QtDatePropertyManager::minimum(const QtProperty *property) const |
| 1634 | { |
| 1635 | return getMinimum<QDate>(propertyMap: d_ptr->m_values, property); |
| 1636 | } |
| 1637 | |
| 1638 | /*! |
| 1639 | Returns the given \a property's maximum date. |
| 1640 | |
| 1641 | \sa minimum(), setRange() |
| 1642 | */ |
| 1643 | QDate QtDatePropertyManager::maximum(const QtProperty *property) const |
| 1644 | { |
| 1645 | return getMaximum<QDate>(propertyMap: d_ptr->m_values, property); |
| 1646 | } |
| 1647 | |
| 1648 | /*! |
| 1649 | \reimp |
| 1650 | */ |
| 1651 | QString QtDatePropertyManager::valueText(const QtProperty *property) const |
| 1652 | { |
| 1653 | const auto it = d_ptr->m_values.constFind(key: property); |
| 1654 | if (it == d_ptr->m_values.constEnd()) |
| 1655 | return {}; |
| 1656 | return it.value().val.toString(format: d_ptr->m_format); |
| 1657 | } |
| 1658 | |
| 1659 | /*! |
| 1660 | \fn void QtDatePropertyManager::setValue(QtProperty *property, QDate value) |
| 1661 | |
| 1662 | Sets the value of the given \a property to \a value. |
| 1663 | |
| 1664 | If the specified \a value is not a valid date according to the |
| 1665 | given \a property's range, the value is adjusted to the nearest |
| 1666 | valid value within the range. |
| 1667 | |
| 1668 | \sa value(), setRange(), valueChanged() |
| 1669 | */ |
| 1670 | void QtDatePropertyManager::setValue(QtProperty *property, QDate val) |
| 1671 | { |
| 1672 | void (QtDatePropertyManagerPrivate::*setSubPropertyValue)(QtProperty *, QDate) = nullptr; |
| 1673 | setValueInRange<QDate, QtDatePropertyManagerPrivate, QtDatePropertyManager, const QDate>(manager: this, managerPrivate: d_ptr.data(), |
| 1674 | propertyChangedSignal: &QtDatePropertyManager::propertyChanged, |
| 1675 | valueChangedSignal: &QtDatePropertyManager::valueChanged, |
| 1676 | property, val, setSubPropertyValue); |
| 1677 | } |
| 1678 | |
| 1679 | /*! |
| 1680 | Sets the minimum value for the given \a property to \a minVal. |
| 1681 | |
| 1682 | When setting the minimum value, the maximum and current values are |
| 1683 | adjusted if necessary (ensuring that the range remains valid and |
| 1684 | that the current value is within in the range). |
| 1685 | |
| 1686 | \sa minimum(), setRange() |
| 1687 | */ |
| 1688 | void QtDatePropertyManager::setMinimum(QtProperty *property, QDate minVal) |
| 1689 | { |
| 1690 | setMinimumValue<QDate, QtDatePropertyManagerPrivate, QtDatePropertyManager, QDate, QtDatePropertyManagerPrivate::Data>(manager: this, managerPrivate: d_ptr.data(), |
| 1691 | propertyChangedSignal: &QtDatePropertyManager::propertyChanged, |
| 1692 | valueChangedSignal: &QtDatePropertyManager::valueChanged, |
| 1693 | rangeChangedSignal: &QtDatePropertyManager::rangeChanged, |
| 1694 | property, minVal); |
| 1695 | } |
| 1696 | |
| 1697 | /*! |
| 1698 | Sets the maximum value for the given \a property to \a maxVal. |
| 1699 | |
| 1700 | When setting the maximum value, the minimum and current |
| 1701 | values are adjusted if necessary (ensuring that the range remains |
| 1702 | valid and that the current value is within in the range). |
| 1703 | |
| 1704 | \sa maximum(), setRange() |
| 1705 | */ |
| 1706 | void QtDatePropertyManager::setMaximum(QtProperty *property, QDate maxVal) |
| 1707 | { |
| 1708 | setMaximumValue<QDate, QtDatePropertyManagerPrivate, QtDatePropertyManager, QDate, QtDatePropertyManagerPrivate::Data>(manager: this, managerPrivate: d_ptr.data(), |
| 1709 | propertyChangedSignal: &QtDatePropertyManager::propertyChanged, |
| 1710 | valueChangedSignal: &QtDatePropertyManager::valueChanged, |
| 1711 | rangeChangedSignal: &QtDatePropertyManager::rangeChanged, |
| 1712 | property, maxVal); |
| 1713 | } |
| 1714 | |
| 1715 | /*! |
| 1716 | \fn void QtDatePropertyManager::setRange(QtProperty *property, QDate minimum, QDate maximum) |
| 1717 | |
| 1718 | Sets the range of valid dates. |
| 1719 | |
| 1720 | This is a convenience function defining the range of valid dates |
| 1721 | in one go; setting the \a minimum and \a maximum values for the |
| 1722 | given \a property with a single function call. |
| 1723 | |
| 1724 | When setting a new date range, the current value is adjusted if |
| 1725 | necessary (ensuring that the value remains in date range). |
| 1726 | |
| 1727 | \sa setMinimum(), setMaximum(), rangeChanged() |
| 1728 | */ |
| 1729 | void QtDatePropertyManager::setRange(QtProperty *property, QDate minVal, QDate maxVal) |
| 1730 | { |
| 1731 | void (QtDatePropertyManagerPrivate::*setSubPropertyRange)(QtProperty *, QDate, QDate, QDate) = nullptr; |
| 1732 | setBorderValues<QDate, QtDatePropertyManagerPrivate, QtDatePropertyManager, QDate>(manager: this, managerPrivate: d_ptr.data(), |
| 1733 | propertyChangedSignal: &QtDatePropertyManager::propertyChanged, |
| 1734 | valueChangedSignal: &QtDatePropertyManager::valueChanged, |
| 1735 | rangeChangedSignal: &QtDatePropertyManager::rangeChanged, |
| 1736 | property, minVal, maxVal, setSubPropertyRange); |
| 1737 | } |
| 1738 | |
| 1739 | /*! |
| 1740 | \reimp |
| 1741 | */ |
| 1742 | void QtDatePropertyManager::initializeProperty(QtProperty *property) |
| 1743 | { |
| 1744 | d_ptr->m_values[property] = QtDatePropertyManagerPrivate::Data(); |
| 1745 | } |
| 1746 | |
| 1747 | /*! |
| 1748 | \reimp |
| 1749 | */ |
| 1750 | void QtDatePropertyManager::uninitializeProperty(QtProperty *property) |
| 1751 | { |
| 1752 | d_ptr->m_values.remove(key: property); |
| 1753 | } |
| 1754 | |
| 1755 | // QtTimePropertyManager |
| 1756 | |
| 1757 | class QtTimePropertyManagerPrivate |
| 1758 | { |
| 1759 | QtTimePropertyManager *q_ptr = nullptr; |
| 1760 | Q_DECLARE_PUBLIC(QtTimePropertyManager) |
| 1761 | public: |
| 1762 | explicit QtTimePropertyManagerPrivate(QtTimePropertyManager *q); |
| 1763 | |
| 1764 | const QString m_format; |
| 1765 | |
| 1766 | QHash<const QtProperty *, QTime> m_values; |
| 1767 | }; |
| 1768 | |
| 1769 | QtTimePropertyManagerPrivate::QtTimePropertyManagerPrivate(QtTimePropertyManager *q) : |
| 1770 | q_ptr(q), |
| 1771 | m_format(QtPropertyBrowserUtils::timeFormat()) |
| 1772 | { |
| 1773 | } |
| 1774 | |
| 1775 | /*! |
| 1776 | \class QtTimePropertyManager |
| 1777 | \internal |
| 1778 | \inmodule QtDesigner |
| 1779 | \since 4.4 |
| 1780 | |
| 1781 | \brief The QtTimePropertyManager provides and manages QTime properties. |
| 1782 | |
| 1783 | A time property's value can be retrieved using the value() |
| 1784 | function, and set using the setValue() slot. |
| 1785 | |
| 1786 | In addition, QtTimePropertyManager provides the valueChanged() signal |
| 1787 | which is emitted whenever a property created by this manager |
| 1788 | changes. |
| 1789 | |
| 1790 | \sa QtAbstractPropertyManager, QtTimeEditFactory |
| 1791 | */ |
| 1792 | |
| 1793 | /*! |
| 1794 | \fn void QtTimePropertyManager::valueChanged(QtProperty *property, QTime value) |
| 1795 | |
| 1796 | This signal is emitted whenever a property created by this manager |
| 1797 | changes its value, passing a pointer to the \a property and the |
| 1798 | new \a value as parameters. |
| 1799 | |
| 1800 | \sa setValue() |
| 1801 | */ |
| 1802 | |
| 1803 | /*! |
| 1804 | Creates a manager with the given \a parent. |
| 1805 | */ |
| 1806 | QtTimePropertyManager::QtTimePropertyManager(QObject *parent) |
| 1807 | : QtAbstractPropertyManager(parent), d_ptr(new QtTimePropertyManagerPrivate(this)) |
| 1808 | { |
| 1809 | } |
| 1810 | |
| 1811 | /*! |
| 1812 | Destroys this manager, and all the properties it has created. |
| 1813 | */ |
| 1814 | QtTimePropertyManager::~QtTimePropertyManager() |
| 1815 | { |
| 1816 | clear(); |
| 1817 | } |
| 1818 | |
| 1819 | /*! |
| 1820 | Returns the given \a property's value. |
| 1821 | |
| 1822 | If the given property is not managed by this manager, this |
| 1823 | function returns an invalid time object. |
| 1824 | |
| 1825 | \sa setValue() |
| 1826 | */ |
| 1827 | QTime QtTimePropertyManager::value(const QtProperty *property) const |
| 1828 | { |
| 1829 | return d_ptr->m_values.value(key: property, defaultValue: QTime()); |
| 1830 | } |
| 1831 | |
| 1832 | /*! |
| 1833 | \reimp |
| 1834 | */ |
| 1835 | QString QtTimePropertyManager::valueText(const QtProperty *property) const |
| 1836 | { |
| 1837 | const auto it = d_ptr->m_values.constFind(key: property); |
| 1838 | if (it == d_ptr->m_values.constEnd()) |
| 1839 | return {}; |
| 1840 | return it.value().toString(format: d_ptr->m_format); |
| 1841 | } |
| 1842 | |
| 1843 | /*! |
| 1844 | \fn void QtTimePropertyManager::setValue(QtProperty *property, QTime value) |
| 1845 | |
| 1846 | Sets the value of the given \a property to \a value. |
| 1847 | |
| 1848 | \sa value(), valueChanged() |
| 1849 | */ |
| 1850 | void QtTimePropertyManager::setValue(QtProperty *property, QTime val) |
| 1851 | { |
| 1852 | setSimpleValue<QTime, QTime, QtTimePropertyManager>(propertyMap&: d_ptr->m_values, manager: this, |
| 1853 | propertyChangedSignal: &QtTimePropertyManager::propertyChanged, |
| 1854 | valueChangedSignal: &QtTimePropertyManager::valueChanged, |
| 1855 | property, val); |
| 1856 | } |
| 1857 | |
| 1858 | /*! |
| 1859 | \reimp |
| 1860 | */ |
| 1861 | void QtTimePropertyManager::initializeProperty(QtProperty *property) |
| 1862 | { |
| 1863 | d_ptr->m_values[property] = QTime::currentTime(); |
| 1864 | } |
| 1865 | |
| 1866 | /*! |
| 1867 | \reimp |
| 1868 | */ |
| 1869 | void QtTimePropertyManager::uninitializeProperty(QtProperty *property) |
| 1870 | { |
| 1871 | d_ptr->m_values.remove(key: property); |
| 1872 | } |
| 1873 | |
| 1874 | // QtDateTimePropertyManager |
| 1875 | |
| 1876 | class QtDateTimePropertyManagerPrivate |
| 1877 | { |
| 1878 | QtDateTimePropertyManager *q_ptr = nullptr; |
| 1879 | Q_DECLARE_PUBLIC(QtDateTimePropertyManager) |
| 1880 | public: |
| 1881 | explicit QtDateTimePropertyManagerPrivate(QtDateTimePropertyManager *q); |
| 1882 | |
| 1883 | const QString m_format; |
| 1884 | |
| 1885 | QHash<const QtProperty *, QDateTime> m_values; |
| 1886 | }; |
| 1887 | |
| 1888 | QtDateTimePropertyManagerPrivate::QtDateTimePropertyManagerPrivate(QtDateTimePropertyManager *q) : |
| 1889 | q_ptr(q), |
| 1890 | m_format(QtPropertyBrowserUtils::dateTimeFormat()) |
| 1891 | { |
| 1892 | } |
| 1893 | |
| 1894 | /*! \class QtDateTimePropertyManager |
| 1895 | \internal |
| 1896 | \inmodule QtDesigner |
| 1897 | \since 4.4 |
| 1898 | |
| 1899 | \brief The QtDateTimePropertyManager provides and manages QDateTime properties. |
| 1900 | |
| 1901 | A date and time property has a current value which can be |
| 1902 | retrieved using the value() function, and set using the setValue() |
| 1903 | slot. In addition, QtDateTimePropertyManager provides the |
| 1904 | valueChanged() signal which is emitted whenever a property created |
| 1905 | by this manager changes. |
| 1906 | |
| 1907 | \sa QtAbstractPropertyManager, QtDateTimeEditFactory, QtDatePropertyManager |
| 1908 | */ |
| 1909 | |
| 1910 | /*! |
| 1911 | \fn void QtDateTimePropertyManager::valueChanged(QtProperty *property, const QDateTime &value) |
| 1912 | |
| 1913 | This signal is emitted whenever a property created by this manager |
| 1914 | changes its value, passing a pointer to the \a property and the new |
| 1915 | \a value as parameters. |
| 1916 | */ |
| 1917 | |
| 1918 | /*! |
| 1919 | Creates a manager with the given \a parent. |
| 1920 | */ |
| 1921 | QtDateTimePropertyManager::QtDateTimePropertyManager(QObject *parent) |
| 1922 | : QtAbstractPropertyManager(parent), d_ptr(new QtDateTimePropertyManagerPrivate(this)) |
| 1923 | { |
| 1924 | } |
| 1925 | |
| 1926 | /*! |
| 1927 | Destroys this manager, and all the properties it has created. |
| 1928 | */ |
| 1929 | QtDateTimePropertyManager::~QtDateTimePropertyManager() |
| 1930 | { |
| 1931 | clear(); |
| 1932 | } |
| 1933 | |
| 1934 | /*! |
| 1935 | Returns the given \a property's value. |
| 1936 | |
| 1937 | If the given \a property is not managed by this manager, this |
| 1938 | function returns an invalid QDateTime object. |
| 1939 | |
| 1940 | \sa setValue() |
| 1941 | */ |
| 1942 | QDateTime QtDateTimePropertyManager::value(const QtProperty *property) const |
| 1943 | { |
| 1944 | return d_ptr->m_values.value(key: property, defaultValue: QDateTime()); |
| 1945 | } |
| 1946 | |
| 1947 | /*! |
| 1948 | \reimp |
| 1949 | */ |
| 1950 | QString QtDateTimePropertyManager::valueText(const QtProperty *property) const |
| 1951 | { |
| 1952 | const auto it = d_ptr->m_values.constFind(key: property); |
| 1953 | if (it == d_ptr->m_values.constEnd()) |
| 1954 | return {}; |
| 1955 | return it.value().toString(format: d_ptr->m_format); |
| 1956 | } |
| 1957 | |
| 1958 | /*! |
| 1959 | \fn void QtDateTimePropertyManager::setValue(QtProperty *property, const QDateTime &value) |
| 1960 | |
| 1961 | Sets the value of the given \a property to \a value. |
| 1962 | |
| 1963 | \sa value(), valueChanged() |
| 1964 | */ |
| 1965 | void QtDateTimePropertyManager::setValue(QtProperty *property, const QDateTime &val) |
| 1966 | { |
| 1967 | setSimpleValue<const QDateTime &, QDateTime, QtDateTimePropertyManager>(propertyMap&: d_ptr->m_values, manager: this, |
| 1968 | propertyChangedSignal: &QtDateTimePropertyManager::propertyChanged, |
| 1969 | valueChangedSignal: &QtDateTimePropertyManager::valueChanged, |
| 1970 | property, val); |
| 1971 | } |
| 1972 | |
| 1973 | /*! |
| 1974 | \reimp |
| 1975 | */ |
| 1976 | void QtDateTimePropertyManager::initializeProperty(QtProperty *property) |
| 1977 | { |
| 1978 | d_ptr->m_values[property] = QDateTime::currentDateTime(); |
| 1979 | } |
| 1980 | |
| 1981 | /*! |
| 1982 | \reimp |
| 1983 | */ |
| 1984 | void QtDateTimePropertyManager::uninitializeProperty(QtProperty *property) |
| 1985 | { |
| 1986 | d_ptr->m_values.remove(key: property); |
| 1987 | } |
| 1988 | |
| 1989 | // QtKeySequencePropertyManager |
| 1990 | |
| 1991 | class QtKeySequencePropertyManagerPrivate |
| 1992 | { |
| 1993 | QtKeySequencePropertyManager *q_ptr = nullptr; |
| 1994 | Q_DECLARE_PUBLIC(QtKeySequencePropertyManager) |
| 1995 | public: |
| 1996 | |
| 1997 | QString m_format; |
| 1998 | |
| 1999 | QHash<const QtProperty *, QKeySequence> m_values; |
| 2000 | }; |
| 2001 | |
| 2002 | /*! \class QtKeySequencePropertyManager |
| 2003 | \internal |
| 2004 | \inmodule QtDesigner |
| 2005 | \since 4.4 |
| 2006 | |
| 2007 | \brief The QtKeySequencePropertyManager provides and manages QKeySequence properties. |
| 2008 | |
| 2009 | A key sequence's value can be retrieved using the value() |
| 2010 | function, and set using the setValue() slot. |
| 2011 | |
| 2012 | In addition, QtKeySequencePropertyManager provides the valueChanged() signal |
| 2013 | which is emitted whenever a property created by this manager |
| 2014 | changes. |
| 2015 | |
| 2016 | \sa QtAbstractPropertyManager |
| 2017 | */ |
| 2018 | |
| 2019 | /*! |
| 2020 | \fn void QtKeySequencePropertyManager::valueChanged(QtProperty *property, const QKeySequence &value) |
| 2021 | |
| 2022 | This signal is emitted whenever a property created by this manager |
| 2023 | changes its value, passing a pointer to the \a property and the new |
| 2024 | \a value as parameters. |
| 2025 | */ |
| 2026 | |
| 2027 | /*! |
| 2028 | Creates a manager with the given \a parent. |
| 2029 | */ |
| 2030 | QtKeySequencePropertyManager::QtKeySequencePropertyManager(QObject *parent) |
| 2031 | : QtAbstractPropertyManager(parent), d_ptr(new QtKeySequencePropertyManagerPrivate) |
| 2032 | { |
| 2033 | d_ptr->q_ptr = this; |
| 2034 | } |
| 2035 | |
| 2036 | /*! |
| 2037 | Destroys this manager, and all the properties it has created. |
| 2038 | */ |
| 2039 | QtKeySequencePropertyManager::~QtKeySequencePropertyManager() |
| 2040 | { |
| 2041 | clear(); |
| 2042 | } |
| 2043 | |
| 2044 | /*! |
| 2045 | Returns the given \a property's value. |
| 2046 | |
| 2047 | If the given \a property is not managed by this manager, this |
| 2048 | function returns an empty QKeySequence object. |
| 2049 | |
| 2050 | \sa setValue() |
| 2051 | */ |
| 2052 | QKeySequence QtKeySequencePropertyManager::value(const QtProperty *property) const |
| 2053 | { |
| 2054 | return d_ptr->m_values.value(key: property, defaultValue: QKeySequence()); |
| 2055 | } |
| 2056 | |
| 2057 | /*! |
| 2058 | \reimp |
| 2059 | */ |
| 2060 | QString QtKeySequencePropertyManager::valueText(const QtProperty *property) const |
| 2061 | { |
| 2062 | const auto it = d_ptr->m_values.constFind(key: property); |
| 2063 | if (it == d_ptr->m_values.constEnd()) |
| 2064 | return {}; |
| 2065 | return it.value().toString(format: QKeySequence::NativeText); |
| 2066 | } |
| 2067 | |
| 2068 | /*! |
| 2069 | \fn void QtKeySequencePropertyManager::setValue(QtProperty *property, const QKeySequence &value) |
| 2070 | |
| 2071 | Sets the value of the given \a property to \a value. |
| 2072 | |
| 2073 | \sa value(), valueChanged() |
| 2074 | */ |
| 2075 | void QtKeySequencePropertyManager::setValue(QtProperty *property, const QKeySequence &val) |
| 2076 | { |
| 2077 | setSimpleValue<const QKeySequence &, QKeySequence, QtKeySequencePropertyManager>(propertyMap&: d_ptr->m_values, manager: this, |
| 2078 | propertyChangedSignal: &QtKeySequencePropertyManager::propertyChanged, |
| 2079 | valueChangedSignal: &QtKeySequencePropertyManager::valueChanged, |
| 2080 | property, val); |
| 2081 | } |
| 2082 | |
| 2083 | /*! |
| 2084 | \reimp |
| 2085 | */ |
| 2086 | void QtKeySequencePropertyManager::initializeProperty(QtProperty *property) |
| 2087 | { |
| 2088 | d_ptr->m_values[property] = QKeySequence(); |
| 2089 | } |
| 2090 | |
| 2091 | /*! |
| 2092 | \reimp |
| 2093 | */ |
| 2094 | void QtKeySequencePropertyManager::uninitializeProperty(QtProperty *property) |
| 2095 | { |
| 2096 | d_ptr->m_values.remove(key: property); |
| 2097 | } |
| 2098 | |
| 2099 | // QtCharPropertyManager |
| 2100 | |
| 2101 | class QtCharPropertyManagerPrivate |
| 2102 | { |
| 2103 | QtCharPropertyManager *q_ptr = nullptr; |
| 2104 | Q_DECLARE_PUBLIC(QtCharPropertyManager) |
| 2105 | public: |
| 2106 | |
| 2107 | QHash<const QtProperty *, QChar> m_values; |
| 2108 | }; |
| 2109 | |
| 2110 | /*! \class QtCharPropertyManager |
| 2111 | \internal |
| 2112 | \inmodule QtDesigner |
| 2113 | \since 4.4 |
| 2114 | |
| 2115 | \brief The QtCharPropertyManager provides and manages QChar properties. |
| 2116 | |
| 2117 | A char's value can be retrieved using the value() |
| 2118 | function, and set using the setValue() slot. |
| 2119 | |
| 2120 | In addition, QtCharPropertyManager provides the valueChanged() signal |
| 2121 | which is emitted whenever a property created by this manager |
| 2122 | changes. |
| 2123 | |
| 2124 | \sa QtAbstractPropertyManager |
| 2125 | */ |
| 2126 | |
| 2127 | /*! |
| 2128 | \fn void QtCharPropertyManager::valueChanged(QtProperty *property, const QChar &value) |
| 2129 | |
| 2130 | This signal is emitted whenever a property created by this manager |
| 2131 | changes its value, passing a pointer to the \a property and the new |
| 2132 | \a value as parameters. |
| 2133 | */ |
| 2134 | |
| 2135 | /*! |
| 2136 | Creates a manager with the given \a parent. |
| 2137 | */ |
| 2138 | QtCharPropertyManager::QtCharPropertyManager(QObject *parent) |
| 2139 | : QtAbstractPropertyManager(parent), d_ptr(new QtCharPropertyManagerPrivate) |
| 2140 | { |
| 2141 | d_ptr->q_ptr = this; |
| 2142 | } |
| 2143 | |
| 2144 | /*! |
| 2145 | Destroys this manager, and all the properties it has created. |
| 2146 | */ |
| 2147 | QtCharPropertyManager::~QtCharPropertyManager() |
| 2148 | { |
| 2149 | clear(); |
| 2150 | } |
| 2151 | |
| 2152 | /*! |
| 2153 | Returns the given \a property's value. |
| 2154 | |
| 2155 | If the given \a property is not managed by this manager, this |
| 2156 | function returns an null QChar object. |
| 2157 | |
| 2158 | \sa setValue() |
| 2159 | */ |
| 2160 | QChar QtCharPropertyManager::value(const QtProperty *property) const |
| 2161 | { |
| 2162 | return d_ptr->m_values.value(key: property, defaultValue: QChar()); |
| 2163 | } |
| 2164 | |
| 2165 | /*! |
| 2166 | \reimp |
| 2167 | */ |
| 2168 | QString QtCharPropertyManager::valueText(const QtProperty *property) const |
| 2169 | { |
| 2170 | const auto it = d_ptr->m_values.constFind(key: property); |
| 2171 | if (it == d_ptr->m_values.constEnd()) |
| 2172 | return {}; |
| 2173 | const QChar c = it.value(); |
| 2174 | return c.isNull() ? QString() : QString(c); |
| 2175 | } |
| 2176 | |
| 2177 | /*! |
| 2178 | \fn void QtCharPropertyManager::setValue(QtProperty *property, const QChar &value) |
| 2179 | |
| 2180 | Sets the value of the given \a property to \a value. |
| 2181 | |
| 2182 | \sa value(), valueChanged() |
| 2183 | */ |
| 2184 | void QtCharPropertyManager::setValue(QtProperty *property, const QChar &val) |
| 2185 | { |
| 2186 | setSimpleValue<const QChar &, QChar, QtCharPropertyManager>(propertyMap&: d_ptr->m_values, manager: this, |
| 2187 | propertyChangedSignal: &QtCharPropertyManager::propertyChanged, |
| 2188 | valueChangedSignal: &QtCharPropertyManager::valueChanged, |
| 2189 | property, val); |
| 2190 | } |
| 2191 | |
| 2192 | /*! |
| 2193 | \reimp |
| 2194 | */ |
| 2195 | void QtCharPropertyManager::initializeProperty(QtProperty *property) |
| 2196 | { |
| 2197 | d_ptr->m_values[property] = QChar(); |
| 2198 | } |
| 2199 | |
| 2200 | /*! |
| 2201 | \reimp |
| 2202 | */ |
| 2203 | void QtCharPropertyManager::uninitializeProperty(QtProperty *property) |
| 2204 | { |
| 2205 | d_ptr->m_values.remove(key: property); |
| 2206 | } |
| 2207 | |
| 2208 | // QtLocalePropertyManager |
| 2209 | |
| 2210 | class QtLocalePropertyManagerPrivate |
| 2211 | { |
| 2212 | QtLocalePropertyManager *q_ptr = nullptr; |
| 2213 | Q_DECLARE_PUBLIC(QtLocalePropertyManager) |
| 2214 | public: |
| 2215 | |
| 2216 | void slotEnumChanged(QtProperty *property, int value); |
| 2217 | void slotPropertyDestroyed(QtProperty *property); |
| 2218 | |
| 2219 | QHash<const QtProperty *, QLocale> m_values; |
| 2220 | |
| 2221 | QtEnumPropertyManager *m_enumPropertyManager = nullptr; |
| 2222 | |
| 2223 | QHash<const QtProperty *, QtProperty *> m_propertyToLanguage; |
| 2224 | QHash<const QtProperty *, QtProperty *> m_propertyToTerritory; |
| 2225 | |
| 2226 | QHash<const QtProperty *, QtProperty *> m_languageToProperty; |
| 2227 | QHash<const QtProperty *, QtProperty *> m_territoryToProperty; |
| 2228 | }; |
| 2229 | |
| 2230 | void QtLocalePropertyManagerPrivate::slotEnumChanged(QtProperty *property, int value) |
| 2231 | { |
| 2232 | if (QtProperty *prop = m_languageToProperty.value(key: property, defaultValue: nullptr)) { |
| 2233 | const QLocale loc = m_values[prop]; |
| 2234 | QLocale::Language newLanguage = loc.language(); |
| 2235 | QLocale::Territory newTerritory = loc.territory(); |
| 2236 | metaEnumProvider()->indexToLocale(languageIndex: value, territoryIndex: 0, language: &newLanguage, territory: nullptr); |
| 2237 | QLocale newLoc(newLanguage, newTerritory); |
| 2238 | q_ptr->setValue(property: prop, val: newLoc); |
| 2239 | } else if (QtProperty *prop = m_territoryToProperty.value(key: property, defaultValue: nullptr)) { |
| 2240 | const QLocale loc = m_values[prop]; |
| 2241 | QLocale::Language newLanguage = loc.language(); |
| 2242 | QLocale::Territory newTerritory = loc.territory(); |
| 2243 | metaEnumProvider()->indexToLocale(languageIndex: m_enumPropertyManager->value(property: m_propertyToLanguage.value(key: prop)), territoryIndex: value, language: &newLanguage, territory: &newTerritory); |
| 2244 | QLocale newLoc(newLanguage, newTerritory); |
| 2245 | q_ptr->setValue(property: prop, val: newLoc); |
| 2246 | } |
| 2247 | } |
| 2248 | |
| 2249 | void QtLocalePropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property) |
| 2250 | { |
| 2251 | if (QtProperty *subProp = m_languageToProperty.value(key: property, defaultValue: nullptr)) { |
| 2252 | m_propertyToLanguage[subProp] = nullptr; |
| 2253 | m_languageToProperty.remove(key: property); |
| 2254 | } else if (QtProperty *subProp = m_territoryToProperty.value(key: property, defaultValue: nullptr)) { |
| 2255 | m_propertyToTerritory[subProp] = nullptr; |
| 2256 | m_territoryToProperty.remove(key: property); |
| 2257 | } |
| 2258 | } |
| 2259 | |
| 2260 | /*! |
| 2261 | \class QtLocalePropertyManager |
| 2262 | \internal |
| 2263 | \inmodule QtDesigner |
| 2264 | \since 4.4 |
| 2265 | |
| 2266 | \brief The QtLocalePropertyManager provides and manages QLocale properties. |
| 2267 | |
| 2268 | A locale property has nested \e language and \e territory |
| 2269 | subproperties. The top-level property's value can be retrieved |
| 2270 | using the value() function, and set using the setValue() slot. |
| 2271 | |
| 2272 | The subproperties are created by QtEnumPropertyManager object. |
| 2273 | These submanager can be retrieved using the subEnumPropertyManager() |
| 2274 | function. In order to provide editing widgets for the subproperties |
| 2275 | in a property browser widget, this manager must be associated with editor factory. |
| 2276 | |
| 2277 | In addition, QtLocalePropertyManager provides the valueChanged() |
| 2278 | signal which is emitted whenever a property created by this |
| 2279 | manager changes. |
| 2280 | |
| 2281 | \sa QtAbstractPropertyManager, QtEnumPropertyManager |
| 2282 | */ |
| 2283 | |
| 2284 | /*! |
| 2285 | \fn void QtLocalePropertyManager::valueChanged(QtProperty *property, const QLocale &value) |
| 2286 | |
| 2287 | This signal is emitted whenever a property created by this manager |
| 2288 | changes its value, passing a pointer to the \a property and the |
| 2289 | new \a value as parameters. |
| 2290 | |
| 2291 | \sa setValue() |
| 2292 | */ |
| 2293 | |
| 2294 | /*! |
| 2295 | Creates a manager with the given \a parent. |
| 2296 | */ |
| 2297 | QtLocalePropertyManager::QtLocalePropertyManager(QObject *parent) |
| 2298 | : QtAbstractPropertyManager(parent), d_ptr(new QtLocalePropertyManagerPrivate) |
| 2299 | { |
| 2300 | d_ptr->q_ptr = this; |
| 2301 | |
| 2302 | d_ptr->m_enumPropertyManager = new QtEnumPropertyManager(this); |
| 2303 | connect(sender: d_ptr->m_enumPropertyManager, signal: &QtEnumPropertyManager::valueChanged, context: this, |
| 2304 | slot: [this](QtProperty *property, int value) { d_ptr->slotEnumChanged(property, value); }); |
| 2305 | connect(sender: d_ptr->m_enumPropertyManager, signal: &QtAbstractPropertyManager::propertyDestroyed, context: this, |
| 2306 | slot: [this](QtProperty *property) { d_ptr->slotPropertyDestroyed(property); }); |
| 2307 | } |
| 2308 | |
| 2309 | /*! |
| 2310 | Destroys this manager, and all the properties it has created. |
| 2311 | */ |
| 2312 | QtLocalePropertyManager::~QtLocalePropertyManager() |
| 2313 | { |
| 2314 | clear(); |
| 2315 | } |
| 2316 | |
| 2317 | /*! |
| 2318 | Returns the manager that creates the nested \e language |
| 2319 | and \e territory subproperties. |
| 2320 | |
| 2321 | In order to provide editing widgets for the mentioned subproperties |
| 2322 | in a property browser widget, this manager must be associated with |
| 2323 | an editor factory. |
| 2324 | |
| 2325 | \sa QtAbstractPropertyBrowser::setFactoryForManager() |
| 2326 | */ |
| 2327 | QtEnumPropertyManager *QtLocalePropertyManager::subEnumPropertyManager() const |
| 2328 | { |
| 2329 | return d_ptr->m_enumPropertyManager; |
| 2330 | } |
| 2331 | |
| 2332 | /*! |
| 2333 | Returns the given \a property's value. |
| 2334 | |
| 2335 | If the given property is not managed by this manager, this |
| 2336 | function returns the default locale. |
| 2337 | |
| 2338 | \sa setValue() |
| 2339 | */ |
| 2340 | QLocale QtLocalePropertyManager::value(const QtProperty *property) const |
| 2341 | { |
| 2342 | return d_ptr->m_values.value(key: property, defaultValue: QLocale()); |
| 2343 | } |
| 2344 | |
| 2345 | /*! |
| 2346 | \reimp |
| 2347 | */ |
| 2348 | QString QtLocalePropertyManager::valueText(const QtProperty *property) const |
| 2349 | { |
| 2350 | const auto it = d_ptr->m_values.constFind(key: property); |
| 2351 | if (it == d_ptr->m_values.constEnd()) |
| 2352 | return {}; |
| 2353 | |
| 2354 | const QLocale &loc = it.value(); |
| 2355 | |
| 2356 | int langIdx = 0; |
| 2357 | int territoryIdx = 0; |
| 2358 | const QtMetaEnumProvider *me = metaEnumProvider(); |
| 2359 | me->localeToIndex(language: loc.language(), territory: loc.territory(), languageIndex: &langIdx, territoryIndex: &territoryIdx); |
| 2360 | if (langIdx < 0) { |
| 2361 | qWarning(msg: "QtLocalePropertyManager::valueText: Unknown language %d" , loc.language()); |
| 2362 | return tr(s: "<Invalid>" ); |
| 2363 | } |
| 2364 | QString languageName = me->languageEnumNames().at(i: langIdx); // enable move |
| 2365 | if (territoryIdx < 0) { |
| 2366 | qWarning(msg: "QtLocalePropertyManager::valueText: Unknown territory %d for %s" , loc.territory(), qPrintable(languageName)); |
| 2367 | return languageName; |
| 2368 | } |
| 2369 | const QString territoryName = me->territoryEnumNames(language: loc.language()).at(i: territoryIdx); |
| 2370 | return tr(s: "%1, %2" ).arg(args&: languageName, args: territoryName); |
| 2371 | } |
| 2372 | |
| 2373 | /*! |
| 2374 | \fn void QtLocalePropertyManager::setValue(QtProperty *property, const QLocale &value) |
| 2375 | |
| 2376 | Sets the value of the given \a property to \a value. Nested |
| 2377 | properties are updated automatically. |
| 2378 | |
| 2379 | \sa value(), valueChanged() |
| 2380 | */ |
| 2381 | void QtLocalePropertyManager::setValue(QtProperty *property, const QLocale &val) |
| 2382 | { |
| 2383 | const auto it = d_ptr->m_values.find(key: property); |
| 2384 | if (it == d_ptr->m_values.end()) |
| 2385 | return; |
| 2386 | |
| 2387 | const QLocale &loc = it.value(); |
| 2388 | if (loc == val) |
| 2389 | return; |
| 2390 | |
| 2391 | it.value() = val; |
| 2392 | |
| 2393 | int langIdx = 0; |
| 2394 | int territoryIdx = 0; |
| 2395 | metaEnumProvider()->localeToIndex(language: val.language(), territory: val.territory(), languageIndex: &langIdx, territoryIndex: &territoryIdx); |
| 2396 | if (loc.language() != val.language()) { |
| 2397 | d_ptr->m_enumPropertyManager->setValue(property: d_ptr->m_propertyToLanguage.value(key: property), val: langIdx); |
| 2398 | d_ptr->m_enumPropertyManager->setEnumNames(property: d_ptr->m_propertyToTerritory.value(key: property), |
| 2399 | names: metaEnumProvider()->territoryEnumNames(language: val.language())); |
| 2400 | } |
| 2401 | d_ptr->m_enumPropertyManager->setValue(property: d_ptr->m_propertyToTerritory.value(key: property), val: territoryIdx); |
| 2402 | |
| 2403 | emit propertyChanged(property); |
| 2404 | emit valueChanged(property, val); |
| 2405 | } |
| 2406 | |
| 2407 | /*! |
| 2408 | \reimp |
| 2409 | */ |
| 2410 | void QtLocalePropertyManager::initializeProperty(QtProperty *property) |
| 2411 | { |
| 2412 | QLocale val; |
| 2413 | d_ptr->m_values[property] = val; |
| 2414 | |
| 2415 | int langIdx = 0; |
| 2416 | int territoryIdx = 0; |
| 2417 | metaEnumProvider()->localeToIndex(language: val.language(), territory: val.territory(), languageIndex: &langIdx, territoryIndex: &territoryIdx); |
| 2418 | |
| 2419 | QtProperty *languageProp = d_ptr->m_enumPropertyManager->addProperty(); |
| 2420 | languageProp->setPropertyName(tr(s: "Language" )); |
| 2421 | d_ptr->m_enumPropertyManager->setEnumNames(property: languageProp, names: metaEnumProvider()->languageEnumNames()); |
| 2422 | d_ptr->m_enumPropertyManager->setValue(property: languageProp, val: langIdx); |
| 2423 | d_ptr->m_propertyToLanguage[property] = languageProp; |
| 2424 | d_ptr->m_languageToProperty[languageProp] = property; |
| 2425 | property->addSubProperty(property: languageProp); |
| 2426 | |
| 2427 | QtProperty *territoryProp = d_ptr->m_enumPropertyManager->addProperty(); |
| 2428 | territoryProp->setPropertyName(tr(s: "Territory" )); |
| 2429 | d_ptr->m_enumPropertyManager->setEnumNames(property: territoryProp, names: metaEnumProvider()->territoryEnumNames(language: val.language())); |
| 2430 | d_ptr->m_enumPropertyManager->setValue(property: territoryProp, val: territoryIdx); |
| 2431 | d_ptr->m_propertyToTerritory[property] = territoryProp; |
| 2432 | d_ptr->m_territoryToProperty[territoryProp] = property; |
| 2433 | property->addSubProperty(property: territoryProp); |
| 2434 | } |
| 2435 | |
| 2436 | /*! |
| 2437 | \reimp |
| 2438 | */ |
| 2439 | void QtLocalePropertyManager::uninitializeProperty(QtProperty *property) |
| 2440 | { |
| 2441 | QtProperty *languageProp = d_ptr->m_propertyToLanguage[property]; |
| 2442 | if (languageProp) { |
| 2443 | d_ptr->m_languageToProperty.remove(key: languageProp); |
| 2444 | delete languageProp; |
| 2445 | } |
| 2446 | d_ptr->m_propertyToLanguage.remove(key: property); |
| 2447 | |
| 2448 | QtProperty *territoryProp = d_ptr->m_propertyToTerritory[property]; |
| 2449 | if (territoryProp) { |
| 2450 | d_ptr->m_territoryToProperty.remove(key: territoryProp); |
| 2451 | delete territoryProp; |
| 2452 | } |
| 2453 | d_ptr->m_propertyToTerritory.remove(key: property); |
| 2454 | |
| 2455 | d_ptr->m_values.remove(key: property); |
| 2456 | } |
| 2457 | |
| 2458 | // QtPointPropertyManager |
| 2459 | |
| 2460 | class QtPointPropertyManagerPrivate |
| 2461 | { |
| 2462 | QtPointPropertyManager *q_ptr = nullptr; |
| 2463 | Q_DECLARE_PUBLIC(QtPointPropertyManager) |
| 2464 | public: |
| 2465 | |
| 2466 | void slotIntChanged(QtProperty *property, int value); |
| 2467 | void slotPropertyDestroyed(QtProperty *property); |
| 2468 | |
| 2469 | QHash<const QtProperty *, QPoint> m_values; |
| 2470 | |
| 2471 | QtIntPropertyManager *m_intPropertyManager; |
| 2472 | |
| 2473 | QHash<const QtProperty *, QtProperty *> m_propertyToX; |
| 2474 | QHash<const QtProperty *, QtProperty *> m_propertyToY; |
| 2475 | |
| 2476 | QHash<const QtProperty *, QtProperty *> m_xToProperty; |
| 2477 | QHash<const QtProperty *, QtProperty *> m_yToProperty; |
| 2478 | }; |
| 2479 | |
| 2480 | void QtPointPropertyManagerPrivate::slotIntChanged(QtProperty *property, int value) |
| 2481 | { |
| 2482 | if (QtProperty *xprop = m_xToProperty.value(key: property, defaultValue: nullptr)) { |
| 2483 | QPoint p = m_values[xprop]; |
| 2484 | p.setX(value); |
| 2485 | q_ptr->setValue(property: xprop, val: p); |
| 2486 | } else if (QtProperty *yprop = m_yToProperty.value(key: property, defaultValue: nullptr)) { |
| 2487 | QPoint p = m_values[yprop]; |
| 2488 | p.setY(value); |
| 2489 | q_ptr->setValue(property: yprop, val: p); |
| 2490 | } |
| 2491 | } |
| 2492 | |
| 2493 | void QtPointPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property) |
| 2494 | { |
| 2495 | if (QtProperty *pointProp = m_xToProperty.value(key: property, defaultValue: nullptr)) { |
| 2496 | m_propertyToX[pointProp] = nullptr; |
| 2497 | m_xToProperty.remove(key: property); |
| 2498 | } else if (QtProperty *pointProp = m_yToProperty.value(key: property, defaultValue: nullptr)) { |
| 2499 | m_propertyToY[pointProp] = nullptr; |
| 2500 | m_yToProperty.remove(key: property); |
| 2501 | } |
| 2502 | } |
| 2503 | |
| 2504 | /*! \class QtPointPropertyManager |
| 2505 | \internal |
| 2506 | \inmodule QtDesigner |
| 2507 | \since 4.4 |
| 2508 | |
| 2509 | \brief The QtPointPropertyManager provides and manages QPoint properties. |
| 2510 | |
| 2511 | A point property has nested \e x and \e y subproperties. The |
| 2512 | top-level property's value can be retrieved using the value() |
| 2513 | function, and set using the setValue() slot. |
| 2514 | |
| 2515 | The subproperties are created by a QtIntPropertyManager object. This |
| 2516 | manager can be retrieved using the subIntPropertyManager() function. In |
| 2517 | order to provide editing widgets for the subproperties in a |
| 2518 | property browser widget, this manager must be associated with an |
| 2519 | editor factory. |
| 2520 | |
| 2521 | In addition, QtPointPropertyManager provides the valueChanged() signal which |
| 2522 | is emitted whenever a property created by this manager changes. |
| 2523 | |
| 2524 | \sa QtAbstractPropertyManager, QtIntPropertyManager, QtPointFPropertyManager |
| 2525 | */ |
| 2526 | |
| 2527 | /*! |
| 2528 | \fn void QtPointPropertyManager::valueChanged(QtProperty *property, const QPoint &value) |
| 2529 | |
| 2530 | This signal is emitted whenever a property created by this manager |
| 2531 | changes its value, passing a pointer to the \a property and the |
| 2532 | new \a value as parameters. |
| 2533 | |
| 2534 | \sa setValue() |
| 2535 | */ |
| 2536 | |
| 2537 | /*! |
| 2538 | Creates a manager with the given \a parent. |
| 2539 | */ |
| 2540 | QtPointPropertyManager::QtPointPropertyManager(QObject *parent) |
| 2541 | : QtAbstractPropertyManager(parent), d_ptr(new QtPointPropertyManagerPrivate) |
| 2542 | { |
| 2543 | d_ptr->q_ptr = this; |
| 2544 | |
| 2545 | d_ptr->m_intPropertyManager = new QtIntPropertyManager(this); |
| 2546 | connect(sender: d_ptr->m_intPropertyManager, signal: &QtIntPropertyManager::valueChanged, context: this, |
| 2547 | slot: [this](QtProperty *property, int value) { d_ptr->slotIntChanged(property, value); }); |
| 2548 | connect(sender: d_ptr->m_intPropertyManager, signal: &QtAbstractPropertyManager::propertyDestroyed, context: this, |
| 2549 | slot: [this](QtProperty *property) { d_ptr->slotPropertyDestroyed(property); }); |
| 2550 | } |
| 2551 | |
| 2552 | /*! |
| 2553 | Destroys this manager, and all the properties it has created. |
| 2554 | */ |
| 2555 | QtPointPropertyManager::~QtPointPropertyManager() |
| 2556 | { |
| 2557 | clear(); |
| 2558 | } |
| 2559 | |
| 2560 | /*! |
| 2561 | Returns the manager that creates the nested \e x and \e y |
| 2562 | subproperties. |
| 2563 | |
| 2564 | In order to provide editing widgets for the subproperties in a |
| 2565 | property browser widget, this manager must be associated with an |
| 2566 | editor factory. |
| 2567 | |
| 2568 | \sa QtAbstractPropertyBrowser::setFactoryForManager() |
| 2569 | */ |
| 2570 | QtIntPropertyManager *QtPointPropertyManager::subIntPropertyManager() const |
| 2571 | { |
| 2572 | return d_ptr->m_intPropertyManager; |
| 2573 | } |
| 2574 | |
| 2575 | /*! |
| 2576 | Returns the given \a property's value. |
| 2577 | |
| 2578 | If the given \a property is not managed by this manager, this |
| 2579 | function returns a point with coordinates (0, 0). |
| 2580 | |
| 2581 | \sa setValue() |
| 2582 | */ |
| 2583 | QPoint QtPointPropertyManager::value(const QtProperty *property) const |
| 2584 | { |
| 2585 | return d_ptr->m_values.value(key: property, defaultValue: QPoint()); |
| 2586 | } |
| 2587 | |
| 2588 | /*! |
| 2589 | \reimp |
| 2590 | */ |
| 2591 | QString QtPointPropertyManager::valueText(const QtProperty *property) const |
| 2592 | { |
| 2593 | const auto it = d_ptr->m_values.constFind(key: property); |
| 2594 | if (it == d_ptr->m_values.constEnd()) |
| 2595 | return {}; |
| 2596 | const QPoint v = it.value(); |
| 2597 | return tr(s: "(%1, %2)" ).arg(a: v.x()).arg(a: v.y()); |
| 2598 | } |
| 2599 | |
| 2600 | /*! |
| 2601 | \fn void QtPointPropertyManager::setValue(QtProperty *property, const QPoint &value) |
| 2602 | |
| 2603 | Sets the value of the given \a property to \a value. Nested |
| 2604 | properties are updated automatically. |
| 2605 | |
| 2606 | \sa value(), valueChanged() |
| 2607 | */ |
| 2608 | void QtPointPropertyManager::setValue(QtProperty *property, QPoint val) |
| 2609 | { |
| 2610 | const auto it = d_ptr->m_values.find(key: property); |
| 2611 | if (it == d_ptr->m_values.end()) |
| 2612 | return; |
| 2613 | |
| 2614 | if (it.value() == val) |
| 2615 | return; |
| 2616 | |
| 2617 | it.value() = val; |
| 2618 | d_ptr->m_intPropertyManager->setValue(property: d_ptr->m_propertyToX[property], val: val.x()); |
| 2619 | d_ptr->m_intPropertyManager->setValue(property: d_ptr->m_propertyToY[property], val: val.y()); |
| 2620 | |
| 2621 | emit propertyChanged(property); |
| 2622 | emit valueChanged(property, val); |
| 2623 | } |
| 2624 | |
| 2625 | /*! |
| 2626 | \reimp |
| 2627 | */ |
| 2628 | void QtPointPropertyManager::initializeProperty(QtProperty *property) |
| 2629 | { |
| 2630 | d_ptr->m_values[property] = QPoint(0, 0); |
| 2631 | |
| 2632 | QtProperty *xProp = d_ptr->m_intPropertyManager->addProperty(); |
| 2633 | xProp->setPropertyName(tr(s: "X" )); |
| 2634 | d_ptr->m_intPropertyManager->setValue(property: xProp, val: 0); |
| 2635 | d_ptr->m_propertyToX[property] = xProp; |
| 2636 | d_ptr->m_xToProperty[xProp] = property; |
| 2637 | property->addSubProperty(property: xProp); |
| 2638 | |
| 2639 | QtProperty *yProp = d_ptr->m_intPropertyManager->addProperty(); |
| 2640 | yProp->setPropertyName(tr(s: "Y" )); |
| 2641 | d_ptr->m_intPropertyManager->setValue(property: yProp, val: 0); |
| 2642 | d_ptr->m_propertyToY[property] = yProp; |
| 2643 | d_ptr->m_yToProperty[yProp] = property; |
| 2644 | property->addSubProperty(property: yProp); |
| 2645 | } |
| 2646 | |
| 2647 | /*! |
| 2648 | \reimp |
| 2649 | */ |
| 2650 | void QtPointPropertyManager::uninitializeProperty(QtProperty *property) |
| 2651 | { |
| 2652 | QtProperty *xProp = d_ptr->m_propertyToX[property]; |
| 2653 | if (xProp) { |
| 2654 | d_ptr->m_xToProperty.remove(key: xProp); |
| 2655 | delete xProp; |
| 2656 | } |
| 2657 | d_ptr->m_propertyToX.remove(key: property); |
| 2658 | |
| 2659 | QtProperty *yProp = d_ptr->m_propertyToY[property]; |
| 2660 | if (yProp) { |
| 2661 | d_ptr->m_yToProperty.remove(key: yProp); |
| 2662 | delete yProp; |
| 2663 | } |
| 2664 | d_ptr->m_propertyToY.remove(key: property); |
| 2665 | |
| 2666 | d_ptr->m_values.remove(key: property); |
| 2667 | } |
| 2668 | |
| 2669 | // QtPointFPropertyManager |
| 2670 | |
| 2671 | class QtPointFPropertyManagerPrivate |
| 2672 | { |
| 2673 | QtPointFPropertyManager *q_ptr = nullptr; |
| 2674 | Q_DECLARE_PUBLIC(QtPointFPropertyManager) |
| 2675 | public: |
| 2676 | |
| 2677 | struct Data |
| 2678 | { |
| 2679 | QPointF val; |
| 2680 | int decimals{2}; |
| 2681 | }; |
| 2682 | |
| 2683 | void slotDoubleChanged(QtProperty *property, double value); |
| 2684 | void slotPropertyDestroyed(QtProperty *property); |
| 2685 | |
| 2686 | QHash<const QtProperty *, Data> m_values; |
| 2687 | |
| 2688 | QtDoublePropertyManager *m_doublePropertyManager; |
| 2689 | |
| 2690 | QHash<const QtProperty *, QtProperty *> m_propertyToX; |
| 2691 | QHash<const QtProperty *, QtProperty *> m_propertyToY; |
| 2692 | |
| 2693 | QHash<const QtProperty *, QtProperty *> m_xToProperty; |
| 2694 | QHash<const QtProperty *, QtProperty *> m_yToProperty; |
| 2695 | }; |
| 2696 | |
| 2697 | void QtPointFPropertyManagerPrivate::slotDoubleChanged(QtProperty *property, double value) |
| 2698 | { |
| 2699 | if (QtProperty *prop = m_xToProperty.value(key: property, defaultValue: nullptr)) { |
| 2700 | QPointF p = m_values[prop].val; |
| 2701 | p.setX(value); |
| 2702 | q_ptr->setValue(property: prop, val: p); |
| 2703 | } else if (QtProperty *prop = m_yToProperty.value(key: property, defaultValue: nullptr)) { |
| 2704 | QPointF p = m_values[prop].val; |
| 2705 | p.setY(value); |
| 2706 | q_ptr->setValue(property: prop, val: p); |
| 2707 | } |
| 2708 | } |
| 2709 | |
| 2710 | void QtPointFPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property) |
| 2711 | { |
| 2712 | if (QtProperty *pointProp = m_xToProperty.value(key: property, defaultValue: nullptr)) { |
| 2713 | m_propertyToX[pointProp] = nullptr; |
| 2714 | m_xToProperty.remove(key: property); |
| 2715 | } else if (QtProperty *pointProp = m_yToProperty.value(key: property, defaultValue: nullptr)) { |
| 2716 | m_propertyToY[pointProp] = nullptr; |
| 2717 | m_yToProperty.remove(key: property); |
| 2718 | } |
| 2719 | } |
| 2720 | |
| 2721 | /*! \class QtPointFPropertyManager |
| 2722 | \internal |
| 2723 | \inmodule QtDesigner |
| 2724 | \since 4.4 |
| 2725 | |
| 2726 | \brief The QtPointFPropertyManager provides and manages QPointF properties. |
| 2727 | |
| 2728 | A point property has nested \e x and \e y subproperties. The |
| 2729 | top-level property's value can be retrieved using the value() |
| 2730 | function, and set using the setValue() slot. |
| 2731 | |
| 2732 | The subproperties are created by a QtDoublePropertyManager object. This |
| 2733 | manager can be retrieved using the subDoublePropertyManager() function. In |
| 2734 | order to provide editing widgets for the subproperties in a |
| 2735 | property browser widget, this manager must be associated with an |
| 2736 | editor factory. |
| 2737 | |
| 2738 | In addition, QtPointFPropertyManager provides the valueChanged() signal which |
| 2739 | is emitted whenever a property created by this manager changes. |
| 2740 | |
| 2741 | \sa QtAbstractPropertyManager, QtDoublePropertyManager, QtPointPropertyManager |
| 2742 | */ |
| 2743 | |
| 2744 | /*! |
| 2745 | \fn void QtPointFPropertyManager::valueChanged(QtProperty *property, const QPointF &value) |
| 2746 | |
| 2747 | This signal is emitted whenever a property created by this manager |
| 2748 | changes its value, passing a pointer to the \a property and the |
| 2749 | new \a value as parameters. |
| 2750 | |
| 2751 | \sa setValue() |
| 2752 | */ |
| 2753 | |
| 2754 | /*! |
| 2755 | \fn void QtPointFPropertyManager::decimalsChanged(QtProperty *property, int prec) |
| 2756 | |
| 2757 | This signal is emitted whenever a property created by this manager |
| 2758 | changes its precision of value, passing a pointer to the |
| 2759 | \a property and the new \a prec value |
| 2760 | |
| 2761 | \sa setDecimals() |
| 2762 | */ |
| 2763 | |
| 2764 | /*! |
| 2765 | Creates a manager with the given \a parent. |
| 2766 | */ |
| 2767 | QtPointFPropertyManager::QtPointFPropertyManager(QObject *parent) |
| 2768 | : QtAbstractPropertyManager(parent), d_ptr(new QtPointFPropertyManagerPrivate) |
| 2769 | { |
| 2770 | d_ptr->q_ptr = this; |
| 2771 | |
| 2772 | d_ptr->m_doublePropertyManager = new QtDoublePropertyManager(this); |
| 2773 | connect(sender: d_ptr->m_doublePropertyManager, signal: &QtDoublePropertyManager::valueChanged, context: this, |
| 2774 | slot: [this](QtProperty *property, double value) { d_ptr->slotDoubleChanged(property, value); }); |
| 2775 | connect(sender: d_ptr->m_doublePropertyManager, signal: &QtAbstractPropertyManager::propertyDestroyed, context: this, |
| 2776 | slot: [this](QtProperty *property) { d_ptr->slotPropertyDestroyed(property); }); |
| 2777 | } |
| 2778 | |
| 2779 | /*! |
| 2780 | Destroys this manager, and all the properties it has created. |
| 2781 | */ |
| 2782 | QtPointFPropertyManager::~QtPointFPropertyManager() |
| 2783 | { |
| 2784 | clear(); |
| 2785 | } |
| 2786 | |
| 2787 | /*! |
| 2788 | Returns the manager that creates the nested \e x and \e y |
| 2789 | subproperties. |
| 2790 | |
| 2791 | In order to provide editing widgets for the subproperties in a |
| 2792 | property browser widget, this manager must be associated with an |
| 2793 | editor factory. |
| 2794 | |
| 2795 | \sa QtAbstractPropertyBrowser::setFactoryForManager() |
| 2796 | */ |
| 2797 | QtDoublePropertyManager *QtPointFPropertyManager::subDoublePropertyManager() const |
| 2798 | { |
| 2799 | return d_ptr->m_doublePropertyManager; |
| 2800 | } |
| 2801 | |
| 2802 | /*! |
| 2803 | Returns the given \a property's value. |
| 2804 | |
| 2805 | If the given \a property is not managed by this manager, this |
| 2806 | function returns a point with coordinates (0, 0). |
| 2807 | |
| 2808 | \sa setValue() |
| 2809 | */ |
| 2810 | QPointF QtPointFPropertyManager::value(const QtProperty *property) const |
| 2811 | { |
| 2812 | return getValue<QPointF>(propertyMap: d_ptr->m_values, property); |
| 2813 | } |
| 2814 | |
| 2815 | /*! |
| 2816 | Returns the given \a property's precision, in decimals. |
| 2817 | |
| 2818 | \sa setDecimals() |
| 2819 | */ |
| 2820 | int QtPointFPropertyManager::decimals(const QtProperty *property) const |
| 2821 | { |
| 2822 | return getData<int>(propertyMap: d_ptr->m_values, data: &QtPointFPropertyManagerPrivate::Data::decimals, property, defaultValue: 0); |
| 2823 | } |
| 2824 | |
| 2825 | /*! |
| 2826 | \reimp |
| 2827 | */ |
| 2828 | QString QtPointFPropertyManager::valueText(const QtProperty *property) const |
| 2829 | { |
| 2830 | const auto it = d_ptr->m_values.constFind(key: property); |
| 2831 | if (it == d_ptr->m_values.constEnd()) |
| 2832 | return {}; |
| 2833 | const QPointF v = it.value().val; |
| 2834 | const int dec = it.value().decimals; |
| 2835 | return tr(s: "(%1, %2)" ).arg(args: QString::number(v.x(), format: 'f', precision: dec), |
| 2836 | args: QString::number(v.y(), format: 'f', precision: dec)); |
| 2837 | } |
| 2838 | |
| 2839 | /*! |
| 2840 | \fn void QtPointFPropertyManager::setValue(QtProperty *property, const QPointF &value) |
| 2841 | |
| 2842 | Sets the value of the given \a property to \a value. Nested |
| 2843 | properties are updated automatically. |
| 2844 | |
| 2845 | \sa value(), valueChanged() |
| 2846 | */ |
| 2847 | void QtPointFPropertyManager::setValue(QtProperty *property, QPointF val) |
| 2848 | { |
| 2849 | const auto it = d_ptr->m_values.find(key: property); |
| 2850 | if (it == d_ptr->m_values.end()) |
| 2851 | return; |
| 2852 | |
| 2853 | if (it.value().val == val) |
| 2854 | return; |
| 2855 | |
| 2856 | it.value().val = val; |
| 2857 | d_ptr->m_doublePropertyManager->setValue(property: d_ptr->m_propertyToX[property], val: val.x()); |
| 2858 | d_ptr->m_doublePropertyManager->setValue(property: d_ptr->m_propertyToY[property], val: val.y()); |
| 2859 | |
| 2860 | emit propertyChanged(property); |
| 2861 | emit valueChanged(property, val); |
| 2862 | } |
| 2863 | |
| 2864 | /*! |
| 2865 | \fn void QtPointFPropertyManager::setDecimals(QtProperty *property, int prec) |
| 2866 | |
| 2867 | Sets the precision of the given \a property to \a prec. |
| 2868 | |
| 2869 | The valid decimal range is 0-13. The default is 2. |
| 2870 | |
| 2871 | \sa decimals() |
| 2872 | */ |
| 2873 | void QtPointFPropertyManager::setDecimals(QtProperty *property, int prec) |
| 2874 | { |
| 2875 | const auto it = d_ptr->m_values.find(key: property); |
| 2876 | if (it == d_ptr->m_values.end()) |
| 2877 | return; |
| 2878 | |
| 2879 | QtPointFPropertyManagerPrivate::Data data = it.value(); |
| 2880 | |
| 2881 | if (prec > 13) |
| 2882 | prec = 13; |
| 2883 | else if (prec < 0) |
| 2884 | prec = 0; |
| 2885 | |
| 2886 | if (data.decimals == prec) |
| 2887 | return; |
| 2888 | |
| 2889 | data.decimals = prec; |
| 2890 | d_ptr->m_doublePropertyManager->setDecimals(property: d_ptr->m_propertyToX[property], prec); |
| 2891 | d_ptr->m_doublePropertyManager->setDecimals(property: d_ptr->m_propertyToY[property], prec); |
| 2892 | |
| 2893 | it.value() = data; |
| 2894 | |
| 2895 | emit decimalsChanged(property, prec: data.decimals); |
| 2896 | } |
| 2897 | |
| 2898 | /*! |
| 2899 | \reimp |
| 2900 | */ |
| 2901 | void QtPointFPropertyManager::initializeProperty(QtProperty *property) |
| 2902 | { |
| 2903 | d_ptr->m_values[property] = QtPointFPropertyManagerPrivate::Data(); |
| 2904 | |
| 2905 | QtProperty *xProp = d_ptr->m_doublePropertyManager->addProperty(); |
| 2906 | xProp->setPropertyName(tr(s: "X" )); |
| 2907 | d_ptr->m_doublePropertyManager->setDecimals(property: xProp, prec: decimals(property)); |
| 2908 | d_ptr->m_doublePropertyManager->setValue(property: xProp, val: 0); |
| 2909 | d_ptr->m_propertyToX[property] = xProp; |
| 2910 | d_ptr->m_xToProperty[xProp] = property; |
| 2911 | property->addSubProperty(property: xProp); |
| 2912 | |
| 2913 | QtProperty *yProp = d_ptr->m_doublePropertyManager->addProperty(); |
| 2914 | yProp->setPropertyName(tr(s: "Y" )); |
| 2915 | d_ptr->m_doublePropertyManager->setDecimals(property: yProp, prec: decimals(property)); |
| 2916 | d_ptr->m_doublePropertyManager->setValue(property: yProp, val: 0); |
| 2917 | d_ptr->m_propertyToY[property] = yProp; |
| 2918 | d_ptr->m_yToProperty[yProp] = property; |
| 2919 | property->addSubProperty(property: yProp); |
| 2920 | } |
| 2921 | |
| 2922 | /*! |
| 2923 | \reimp |
| 2924 | */ |
| 2925 | void QtPointFPropertyManager::uninitializeProperty(QtProperty *property) |
| 2926 | { |
| 2927 | QtProperty *xProp = d_ptr->m_propertyToX[property]; |
| 2928 | if (xProp) { |
| 2929 | d_ptr->m_xToProperty.remove(key: xProp); |
| 2930 | delete xProp; |
| 2931 | } |
| 2932 | d_ptr->m_propertyToX.remove(key: property); |
| 2933 | |
| 2934 | QtProperty *yProp = d_ptr->m_propertyToY[property]; |
| 2935 | if (yProp) { |
| 2936 | d_ptr->m_yToProperty.remove(key: yProp); |
| 2937 | delete yProp; |
| 2938 | } |
| 2939 | d_ptr->m_propertyToY.remove(key: property); |
| 2940 | |
| 2941 | d_ptr->m_values.remove(key: property); |
| 2942 | } |
| 2943 | |
| 2944 | // QtSizePropertyManager |
| 2945 | |
| 2946 | class QtSizePropertyManagerPrivate |
| 2947 | { |
| 2948 | QtSizePropertyManager *q_ptr = nullptr; |
| 2949 | Q_DECLARE_PUBLIC(QtSizePropertyManager) |
| 2950 | public: |
| 2951 | |
| 2952 | void slotIntChanged(QtProperty *property, int value); |
| 2953 | void slotPropertyDestroyed(QtProperty *property); |
| 2954 | void setValue(QtProperty *property, QSize val); |
| 2955 | void setRange(QtProperty *property, |
| 2956 | QSize minVal, QSize maxVal, QSize val); |
| 2957 | |
| 2958 | struct Data |
| 2959 | { |
| 2960 | QSize val{0, 0}; |
| 2961 | QSize minVal{0, 0}; |
| 2962 | QSize maxVal{INT_MAX, INT_MAX}; |
| 2963 | QSize minimumValue() const { return minVal; } |
| 2964 | QSize maximumValue() const { return maxVal; } |
| 2965 | void setMinimumValue(QSize newMinVal) { setSizeMinimumData(data: this, newMinVal); } |
| 2966 | void setMaximumValue(QSize newMaxVal) { setSizeMaximumData(data: this, newMaxVal); } |
| 2967 | }; |
| 2968 | |
| 2969 | QHash<const QtProperty *, Data> m_values; |
| 2970 | |
| 2971 | QtIntPropertyManager *m_intPropertyManager; |
| 2972 | |
| 2973 | QHash<const QtProperty *, QtProperty *> m_propertyToW; |
| 2974 | QHash<const QtProperty *, QtProperty *> m_propertyToH; |
| 2975 | |
| 2976 | QHash<const QtProperty *, QtProperty *> m_wToProperty; |
| 2977 | QHash<const QtProperty *, QtProperty *> m_hToProperty; |
| 2978 | }; |
| 2979 | |
| 2980 | void QtSizePropertyManagerPrivate::slotIntChanged(QtProperty *property, int value) |
| 2981 | { |
| 2982 | if (QtProperty *prop = m_wToProperty.value(key: property, defaultValue: nullptr)) { |
| 2983 | QSize s = m_values[prop].val; |
| 2984 | s.setWidth(value); |
| 2985 | q_ptr->setValue(property: prop, val: s); |
| 2986 | } else if (QtProperty *prop = m_hToProperty.value(key: property, defaultValue: nullptr)) { |
| 2987 | QSize s = m_values[prop].val; |
| 2988 | s.setHeight(value); |
| 2989 | q_ptr->setValue(property: prop, val: s); |
| 2990 | } |
| 2991 | } |
| 2992 | |
| 2993 | void QtSizePropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property) |
| 2994 | { |
| 2995 | if (QtProperty *pointProp = m_wToProperty.value(key: property, defaultValue: nullptr)) { |
| 2996 | m_propertyToW[pointProp] = nullptr; |
| 2997 | m_wToProperty.remove(key: property); |
| 2998 | } else if (QtProperty *pointProp = m_hToProperty.value(key: property, defaultValue: nullptr)) { |
| 2999 | m_propertyToH[pointProp] = nullptr; |
| 3000 | m_hToProperty.remove(key: property); |
| 3001 | } |
| 3002 | } |
| 3003 | |
| 3004 | void QtSizePropertyManagerPrivate::setValue(QtProperty *property, QSize val) |
| 3005 | { |
| 3006 | m_intPropertyManager->setValue(property: m_propertyToW.value(key: property), val: val.width()); |
| 3007 | m_intPropertyManager->setValue(property: m_propertyToH.value(key: property), val: val.height()); |
| 3008 | } |
| 3009 | |
| 3010 | void QtSizePropertyManagerPrivate::setRange(QtProperty *property, |
| 3011 | QSize minVal, QSize maxVal, QSize val) |
| 3012 | { |
| 3013 | QtProperty *wProperty = m_propertyToW.value(key: property); |
| 3014 | QtProperty *hProperty = m_propertyToH.value(key: property); |
| 3015 | m_intPropertyManager->setRange(property: wProperty, minVal: minVal.width(), maxVal: maxVal.width()); |
| 3016 | m_intPropertyManager->setValue(property: wProperty, val: val.width()); |
| 3017 | m_intPropertyManager->setRange(property: hProperty, minVal: minVal.height(), maxVal: maxVal.height()); |
| 3018 | m_intPropertyManager->setValue(property: hProperty, val: val.height()); |
| 3019 | } |
| 3020 | |
| 3021 | /*! |
| 3022 | \class QtSizePropertyManager |
| 3023 | \internal |
| 3024 | \inmodule QtDesigner |
| 3025 | \since 4.4 |
| 3026 | |
| 3027 | \brief The QtSizePropertyManager provides and manages QSize properties. |
| 3028 | |
| 3029 | A size property has nested \e width and \e height |
| 3030 | subproperties. The top-level property's value can be retrieved |
| 3031 | using the value() function, and set using the setValue() slot. |
| 3032 | |
| 3033 | The subproperties are created by a QtIntPropertyManager object. This |
| 3034 | manager can be retrieved using the subIntPropertyManager() function. In |
| 3035 | order to provide editing widgets for the subproperties in a |
| 3036 | property browser widget, this manager must be associated with an |
| 3037 | editor factory. |
| 3038 | |
| 3039 | A size property also has a range of valid values defined by a |
| 3040 | minimum size and a maximum size. These sizes can be retrieved |
| 3041 | using the minimum() and the maximum() functions, and set using the |
| 3042 | setMinimum() and setMaximum() slots. Alternatively, the range can |
| 3043 | be defined in one go using the setRange() slot. |
| 3044 | |
| 3045 | In addition, QtSizePropertyManager provides the valueChanged() signal |
| 3046 | which is emitted whenever a property created by this manager |
| 3047 | changes, and the rangeChanged() signal which is emitted whenever |
| 3048 | such a property changes its range of valid sizes. |
| 3049 | |
| 3050 | \sa QtAbstractPropertyManager, QtIntPropertyManager, QtSizeFPropertyManager |
| 3051 | */ |
| 3052 | |
| 3053 | /*! |
| 3054 | \fn void QtSizePropertyManager::valueChanged(QtProperty *property, const QSize &value) |
| 3055 | |
| 3056 | This signal is emitted whenever a property created by this manager |
| 3057 | changes its value, passing a pointer to the \a property and the new |
| 3058 | \a value as parameters. |
| 3059 | |
| 3060 | \sa setValue() |
| 3061 | */ |
| 3062 | |
| 3063 | /*! |
| 3064 | \fn void QtSizePropertyManager::rangeChanged(QtProperty *property, const QSize &minimum, const QSize &maximum) |
| 3065 | |
| 3066 | This signal is emitted whenever a property created by this manager |
| 3067 | changes its range of valid sizes, passing a pointer to the \a |
| 3068 | property and the new \a minimum and \a maximum sizes. |
| 3069 | |
| 3070 | \sa setRange() |
| 3071 | */ |
| 3072 | |
| 3073 | /*! |
| 3074 | Creates a manager with the given \a parent. |
| 3075 | */ |
| 3076 | QtSizePropertyManager::QtSizePropertyManager(QObject *parent) |
| 3077 | : QtAbstractPropertyManager(parent), d_ptr(new QtSizePropertyManagerPrivate) |
| 3078 | { |
| 3079 | d_ptr->q_ptr = this; |
| 3080 | |
| 3081 | d_ptr->m_intPropertyManager = new QtIntPropertyManager(this); |
| 3082 | connect(sender: d_ptr->m_intPropertyManager, signal: &QtIntPropertyManager::valueChanged, context: this, |
| 3083 | slot: [this](QtProperty *property, int value) { d_ptr->slotIntChanged(property, value); }); |
| 3084 | connect(sender: d_ptr->m_intPropertyManager, signal: &QtAbstractPropertyManager::propertyDestroyed, context: this, |
| 3085 | slot: [this](QtProperty *property) { d_ptr->slotPropertyDestroyed(property); }); |
| 3086 | } |
| 3087 | |
| 3088 | /*! |
| 3089 | Destroys this manager, and all the properties it has created. |
| 3090 | */ |
| 3091 | QtSizePropertyManager::~QtSizePropertyManager() |
| 3092 | { |
| 3093 | clear(); |
| 3094 | } |
| 3095 | |
| 3096 | /*! |
| 3097 | Returns the manager that creates the nested \e width and \e height |
| 3098 | subproperties. |
| 3099 | |
| 3100 | In order to provide editing widgets for the \e width and \e height |
| 3101 | properties in a property browser widget, this manager must be |
| 3102 | associated with an editor factory. |
| 3103 | |
| 3104 | \sa QtAbstractPropertyBrowser::setFactoryForManager() |
| 3105 | */ |
| 3106 | QtIntPropertyManager *QtSizePropertyManager::subIntPropertyManager() const |
| 3107 | { |
| 3108 | return d_ptr->m_intPropertyManager; |
| 3109 | } |
| 3110 | |
| 3111 | /*! |
| 3112 | Returns the given \a property's value. |
| 3113 | |
| 3114 | If the given \a property is not managed by this manager, this |
| 3115 | function returns an invalid size |
| 3116 | |
| 3117 | \sa setValue() |
| 3118 | */ |
| 3119 | QSize QtSizePropertyManager::value(const QtProperty *property) const |
| 3120 | { |
| 3121 | return getValue<QSize>(propertyMap: d_ptr->m_values, property); |
| 3122 | } |
| 3123 | |
| 3124 | /*! |
| 3125 | Returns the given \a property's minimum size value. |
| 3126 | |
| 3127 | \sa setMinimum(), maximum(), setRange() |
| 3128 | */ |
| 3129 | QSize QtSizePropertyManager::minimum(const QtProperty *property) const |
| 3130 | { |
| 3131 | return getMinimum<QSize>(propertyMap: d_ptr->m_values, property); |
| 3132 | } |
| 3133 | |
| 3134 | /*! |
| 3135 | Returns the given \a property's maximum size value. |
| 3136 | |
| 3137 | \sa setMaximum(), minimum(), setRange() |
| 3138 | */ |
| 3139 | QSize QtSizePropertyManager::maximum(const QtProperty *property) const |
| 3140 | { |
| 3141 | return getMaximum<QSize>(propertyMap: d_ptr->m_values, property); |
| 3142 | } |
| 3143 | |
| 3144 | /*! |
| 3145 | \reimp |
| 3146 | */ |
| 3147 | QString QtSizePropertyManager::valueText(const QtProperty *property) const |
| 3148 | { |
| 3149 | const auto it = d_ptr->m_values.constFind(key: property); |
| 3150 | if (it == d_ptr->m_values.constEnd()) |
| 3151 | return {}; |
| 3152 | const QSize v = it.value().val; |
| 3153 | return tr(s: "%1 x %2" ).arg(a: v.width()).arg(a: v.height()); |
| 3154 | } |
| 3155 | |
| 3156 | /*! |
| 3157 | \fn void QtSizePropertyManager::setValue(QtProperty *property, const QSize &value) |
| 3158 | |
| 3159 | Sets the value of the given \a property to \a value. |
| 3160 | |
| 3161 | If the specified \a value is not valid according to the given \a |
| 3162 | property's size range, the \a value is adjusted to the nearest |
| 3163 | valid value within the size range. |
| 3164 | |
| 3165 | \sa value(), setRange(), valueChanged() |
| 3166 | */ |
| 3167 | void QtSizePropertyManager::setValue(QtProperty *property, QSize val) |
| 3168 | { |
| 3169 | setValueInRange<QSize, QtSizePropertyManagerPrivate, QtSizePropertyManager, const QSize>(manager: this, managerPrivate: d_ptr.data(), |
| 3170 | propertyChangedSignal: &QtSizePropertyManager::propertyChanged, |
| 3171 | valueChangedSignal: &QtSizePropertyManager::valueChanged, |
| 3172 | property, val, setSubPropertyValue: &QtSizePropertyManagerPrivate::setValue); |
| 3173 | } |
| 3174 | |
| 3175 | /*! |
| 3176 | Sets the minimum size value for the given \a property to \a minVal. |
| 3177 | |
| 3178 | When setting the minimum size value, the maximum and current |
| 3179 | values are adjusted if necessary (ensuring that the size range |
| 3180 | remains valid and that the current value is within the range). |
| 3181 | |
| 3182 | \sa minimum(), setRange(), rangeChanged() |
| 3183 | */ |
| 3184 | void QtSizePropertyManager::setMinimum(QtProperty *property, QSize minVal) |
| 3185 | { |
| 3186 | setBorderValue<QSize, QtSizePropertyManagerPrivate, QtSizePropertyManager, QSize, QtSizePropertyManagerPrivate::Data>(manager: this, managerPrivate: d_ptr.data(), |
| 3187 | propertyChangedSignal: &QtSizePropertyManager::propertyChanged, |
| 3188 | valueChangedSignal: &QtSizePropertyManager::valueChanged, |
| 3189 | rangeChangedSignal: &QtSizePropertyManager::rangeChanged, |
| 3190 | property, |
| 3191 | getRangeVal: &QtSizePropertyManagerPrivate::Data::minimumValue, |
| 3192 | setRangeVal: &QtSizePropertyManagerPrivate::Data::setMinimumValue, |
| 3193 | borderVal: minVal, setSubPropertyRange: &QtSizePropertyManagerPrivate::setRange); |
| 3194 | } |
| 3195 | |
| 3196 | /*! |
| 3197 | Sets the maximum size value for the given \a property to \a maxVal. |
| 3198 | |
| 3199 | When setting the maximum size value, the minimum and current |
| 3200 | values are adjusted if necessary (ensuring that the size range |
| 3201 | remains valid and that the current value is within the range). |
| 3202 | |
| 3203 | \sa maximum(), setRange(), rangeChanged() |
| 3204 | */ |
| 3205 | void QtSizePropertyManager::setMaximum(QtProperty *property, QSize maxVal) |
| 3206 | { |
| 3207 | setBorderValue<QSize, QtSizePropertyManagerPrivate, QtSizePropertyManager, QSize, QtSizePropertyManagerPrivate::Data>(manager: this, managerPrivate: d_ptr.data(), |
| 3208 | propertyChangedSignal: &QtSizePropertyManager::propertyChanged, |
| 3209 | valueChangedSignal: &QtSizePropertyManager::valueChanged, |
| 3210 | rangeChangedSignal: &QtSizePropertyManager::rangeChanged, |
| 3211 | property, |
| 3212 | getRangeVal: &QtSizePropertyManagerPrivate::Data::maximumValue, |
| 3213 | setRangeVal: &QtSizePropertyManagerPrivate::Data::setMaximumValue, |
| 3214 | borderVal: maxVal, setSubPropertyRange: &QtSizePropertyManagerPrivate::setRange); |
| 3215 | } |
| 3216 | |
| 3217 | /*! |
| 3218 | \fn void QtSizePropertyManager::setRange(QtProperty *property, const QSize &minimum, const QSize &maximum) |
| 3219 | |
| 3220 | Sets the range of valid values. |
| 3221 | |
| 3222 | This is a convenience function defining the range of valid values |
| 3223 | in one go; setting the \a minimum and \a maximum values for the |
| 3224 | given \a property with a single function call. |
| 3225 | |
| 3226 | When setting a new range, the current value is adjusted if |
| 3227 | necessary (ensuring that the value remains within the range). |
| 3228 | |
| 3229 | \sa setMinimum(), setMaximum(), rangeChanged() |
| 3230 | */ |
| 3231 | void QtSizePropertyManager::setRange(QtProperty *property, QSize minVal, QSize maxVal) |
| 3232 | { |
| 3233 | setBorderValues<QSize, QtSizePropertyManagerPrivate, QtSizePropertyManager, QSize>(manager: this, managerPrivate: d_ptr.data(), |
| 3234 | propertyChangedSignal: &QtSizePropertyManager::propertyChanged, |
| 3235 | valueChangedSignal: &QtSizePropertyManager::valueChanged, |
| 3236 | rangeChangedSignal: &QtSizePropertyManager::rangeChanged, |
| 3237 | property, minVal, maxVal, setSubPropertyRange: &QtSizePropertyManagerPrivate::setRange); |
| 3238 | } |
| 3239 | |
| 3240 | /*! |
| 3241 | \reimp |
| 3242 | */ |
| 3243 | void QtSizePropertyManager::initializeProperty(QtProperty *property) |
| 3244 | { |
| 3245 | d_ptr->m_values[property] = QtSizePropertyManagerPrivate::Data(); |
| 3246 | |
| 3247 | QtProperty *wProp = d_ptr->m_intPropertyManager->addProperty(); |
| 3248 | wProp->setPropertyName(tr(s: "Width" )); |
| 3249 | d_ptr->m_intPropertyManager->setValue(property: wProp, val: 0); |
| 3250 | d_ptr->m_intPropertyManager->setMinimum(property: wProp, minVal: 0); |
| 3251 | d_ptr->m_propertyToW[property] = wProp; |
| 3252 | d_ptr->m_wToProperty[wProp] = property; |
| 3253 | property->addSubProperty(property: wProp); |
| 3254 | |
| 3255 | QtProperty *hProp = d_ptr->m_intPropertyManager->addProperty(); |
| 3256 | hProp->setPropertyName(tr(s: "Height" )); |
| 3257 | d_ptr->m_intPropertyManager->setValue(property: hProp, val: 0); |
| 3258 | d_ptr->m_intPropertyManager->setMinimum(property: hProp, minVal: 0); |
| 3259 | d_ptr->m_propertyToH[property] = hProp; |
| 3260 | d_ptr->m_hToProperty[hProp] = property; |
| 3261 | property->addSubProperty(property: hProp); |
| 3262 | } |
| 3263 | |
| 3264 | /*! |
| 3265 | \reimp |
| 3266 | */ |
| 3267 | void QtSizePropertyManager::uninitializeProperty(QtProperty *property) |
| 3268 | { |
| 3269 | QtProperty *wProp = d_ptr->m_propertyToW[property]; |
| 3270 | if (wProp) { |
| 3271 | d_ptr->m_wToProperty.remove(key: wProp); |
| 3272 | delete wProp; |
| 3273 | } |
| 3274 | d_ptr->m_propertyToW.remove(key: property); |
| 3275 | |
| 3276 | QtProperty *hProp = d_ptr->m_propertyToH[property]; |
| 3277 | if (hProp) { |
| 3278 | d_ptr->m_hToProperty.remove(key: hProp); |
| 3279 | delete hProp; |
| 3280 | } |
| 3281 | d_ptr->m_propertyToH.remove(key: property); |
| 3282 | |
| 3283 | d_ptr->m_values.remove(key: property); |
| 3284 | } |
| 3285 | |
| 3286 | // QtSizeFPropertyManager |
| 3287 | |
| 3288 | class QtSizeFPropertyManagerPrivate |
| 3289 | { |
| 3290 | QtSizeFPropertyManager *q_ptr = nullptr; |
| 3291 | Q_DECLARE_PUBLIC(QtSizeFPropertyManager) |
| 3292 | public: |
| 3293 | |
| 3294 | void slotDoubleChanged(QtProperty *property, double value); |
| 3295 | void slotPropertyDestroyed(QtProperty *property); |
| 3296 | void setValue(QtProperty *property, QSizeF val); |
| 3297 | void setRange(QtProperty *property, |
| 3298 | QSizeF minVal, QSizeF maxVal, QSizeF val); |
| 3299 | |
| 3300 | struct Data |
| 3301 | { |
| 3302 | QSizeF val{0, 0}; |
| 3303 | QSizeF minVal{0, 0}; |
| 3304 | QSizeF maxVal{std::numeric_limits<qreal>::max(), std::numeric_limits<qreal>::max()}; |
| 3305 | int decimals{2}; |
| 3306 | QSizeF minimumValue() const { return minVal; } |
| 3307 | QSizeF maximumValue() const { return maxVal; } |
| 3308 | void setMinimumValue(QSizeF newMinVal) { setSizeMinimumData(data: this, newMinVal); } |
| 3309 | void setMaximumValue(QSizeF newMaxVal) { setSizeMaximumData(data: this, newMaxVal); } |
| 3310 | }; |
| 3311 | |
| 3312 | QHash<const QtProperty *, Data> m_values; |
| 3313 | |
| 3314 | QtDoublePropertyManager *m_doublePropertyManager; |
| 3315 | |
| 3316 | QHash<const QtProperty *, QtProperty *> m_propertyToW; |
| 3317 | QHash<const QtProperty *, QtProperty *> m_propertyToH; |
| 3318 | |
| 3319 | QHash<const QtProperty *, QtProperty *> m_wToProperty; |
| 3320 | QHash<const QtProperty *, QtProperty *> m_hToProperty; |
| 3321 | }; |
| 3322 | |
| 3323 | void QtSizeFPropertyManagerPrivate::slotDoubleChanged(QtProperty *property, double value) |
| 3324 | { |
| 3325 | if (QtProperty *prop = m_wToProperty.value(key: property, defaultValue: nullptr)) { |
| 3326 | QSizeF s = m_values[prop].val; |
| 3327 | s.setWidth(value); |
| 3328 | q_ptr->setValue(property: prop, val: s); |
| 3329 | } else if (QtProperty *prop = m_hToProperty.value(key: property, defaultValue: nullptr)) { |
| 3330 | QSizeF s = m_values[prop].val; |
| 3331 | s.setHeight(value); |
| 3332 | q_ptr->setValue(property: prop, val: s); |
| 3333 | } |
| 3334 | } |
| 3335 | |
| 3336 | void QtSizeFPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property) |
| 3337 | { |
| 3338 | if (QtProperty *pointProp = m_wToProperty.value(key: property, defaultValue: nullptr)) { |
| 3339 | m_propertyToW[pointProp] = nullptr; |
| 3340 | m_wToProperty.remove(key: property); |
| 3341 | } else if (QtProperty *pointProp = m_hToProperty.value(key: property, defaultValue: nullptr)) { |
| 3342 | m_propertyToH[pointProp] = nullptr; |
| 3343 | m_hToProperty.remove(key: property); |
| 3344 | } |
| 3345 | } |
| 3346 | |
| 3347 | void QtSizeFPropertyManagerPrivate::setValue(QtProperty *property, QSizeF val) |
| 3348 | { |
| 3349 | m_doublePropertyManager->setValue(property: m_propertyToW.value(key: property), val: val.width()); |
| 3350 | m_doublePropertyManager->setValue(property: m_propertyToH.value(key: property), val: val.height()); |
| 3351 | } |
| 3352 | |
| 3353 | void QtSizeFPropertyManagerPrivate::setRange(QtProperty *property, |
| 3354 | QSizeF minVal, QSizeF maxVal, QSizeF val) |
| 3355 | { |
| 3356 | m_doublePropertyManager->setRange(property: m_propertyToW[property], minVal: minVal.width(), maxVal: maxVal.width()); |
| 3357 | m_doublePropertyManager->setValue(property: m_propertyToW[property], val: val.width()); |
| 3358 | m_doublePropertyManager->setRange(property: m_propertyToH[property], minVal: minVal.height(), maxVal: maxVal.height()); |
| 3359 | m_doublePropertyManager->setValue(property: m_propertyToH[property], val: val.height()); |
| 3360 | } |
| 3361 | |
| 3362 | /*! |
| 3363 | \class QtSizeFPropertyManager |
| 3364 | \internal |
| 3365 | \inmodule QtDesigner |
| 3366 | \since 4.4 |
| 3367 | |
| 3368 | \brief The QtSizeFPropertyManager provides and manages QSizeF properties. |
| 3369 | |
| 3370 | A size property has nested \e width and \e height |
| 3371 | subproperties. The top-level property's value can be retrieved |
| 3372 | using the value() function, and set using the setValue() slot. |
| 3373 | |
| 3374 | The subproperties are created by a QtDoublePropertyManager object. This |
| 3375 | manager can be retrieved using the subDoublePropertyManager() function. In |
| 3376 | order to provide editing widgets for the subproperties in a |
| 3377 | property browser widget, this manager must be associated with an |
| 3378 | editor factory. |
| 3379 | |
| 3380 | A size property also has a range of valid values defined by a |
| 3381 | minimum size and a maximum size. These sizes can be retrieved |
| 3382 | using the minimum() and the maximum() functions, and set using the |
| 3383 | setMinimum() and setMaximum() slots. Alternatively, the range can |
| 3384 | be defined in one go using the setRange() slot. |
| 3385 | |
| 3386 | In addition, QtSizeFPropertyManager provides the valueChanged() signal |
| 3387 | which is emitted whenever a property created by this manager |
| 3388 | changes, and the rangeChanged() signal which is emitted whenever |
| 3389 | such a property changes its range of valid sizes. |
| 3390 | |
| 3391 | \sa QtAbstractPropertyManager, QtDoublePropertyManager, QtSizePropertyManager |
| 3392 | */ |
| 3393 | |
| 3394 | /*! |
| 3395 | \fn void QtSizeFPropertyManager::valueChanged(QtProperty *property, const QSizeF &value) |
| 3396 | |
| 3397 | This signal is emitted whenever a property created by this manager |
| 3398 | changes its value, passing a pointer to the \a property and the new |
| 3399 | \a value as parameters. |
| 3400 | |
| 3401 | \sa setValue() |
| 3402 | */ |
| 3403 | |
| 3404 | /*! |
| 3405 | \fn void QtSizeFPropertyManager::rangeChanged(QtProperty *property, const QSizeF &minimum, const QSizeF &maximum) |
| 3406 | |
| 3407 | This signal is emitted whenever a property created by this manager |
| 3408 | changes its range of valid sizes, passing a pointer to the \a |
| 3409 | property and the new \a minimum and \a maximum sizes. |
| 3410 | |
| 3411 | \sa setRange() |
| 3412 | */ |
| 3413 | |
| 3414 | /*! |
| 3415 | \fn void QtSizeFPropertyManager::decimalsChanged(QtProperty *property, int prec) |
| 3416 | |
| 3417 | This signal is emitted whenever a property created by this manager |
| 3418 | changes its precision of value, passing a pointer to the |
| 3419 | \a property and the new \a prec value |
| 3420 | |
| 3421 | \sa setDecimals() |
| 3422 | */ |
| 3423 | |
| 3424 | /*! |
| 3425 | Creates a manager with the given \a parent. |
| 3426 | */ |
| 3427 | QtSizeFPropertyManager::QtSizeFPropertyManager(QObject *parent) |
| 3428 | : QtAbstractPropertyManager(parent), d_ptr(new QtSizeFPropertyManagerPrivate) |
| 3429 | { |
| 3430 | d_ptr->q_ptr = this; |
| 3431 | |
| 3432 | d_ptr->m_doublePropertyManager = new QtDoublePropertyManager(this); |
| 3433 | connect(sender: d_ptr->m_doublePropertyManager, signal: &QtDoublePropertyManager::valueChanged, context: this, |
| 3434 | slot: [this](QtProperty *property, double value) { d_ptr->slotDoubleChanged(property, value); }); |
| 3435 | connect(sender: d_ptr->m_doublePropertyManager, signal: &QtAbstractPropertyManager::propertyDestroyed, context: this, |
| 3436 | slot: [this](QtProperty *property) { d_ptr->slotPropertyDestroyed(property); }); |
| 3437 | } |
| 3438 | |
| 3439 | /*! |
| 3440 | Destroys this manager, and all the properties it has created. |
| 3441 | */ |
| 3442 | QtSizeFPropertyManager::~QtSizeFPropertyManager() |
| 3443 | { |
| 3444 | clear(); |
| 3445 | } |
| 3446 | |
| 3447 | /*! |
| 3448 | Returns the manager that creates the nested \e width and \e height |
| 3449 | subproperties. |
| 3450 | |
| 3451 | In order to provide editing widgets for the \e width and \e height |
| 3452 | properties in a property browser widget, this manager must be |
| 3453 | associated with an editor factory. |
| 3454 | |
| 3455 | \sa QtAbstractPropertyBrowser::setFactoryForManager() |
| 3456 | */ |
| 3457 | QtDoublePropertyManager *QtSizeFPropertyManager::subDoublePropertyManager() const |
| 3458 | { |
| 3459 | return d_ptr->m_doublePropertyManager; |
| 3460 | } |
| 3461 | |
| 3462 | /*! |
| 3463 | Returns the given \a property's value. |
| 3464 | |
| 3465 | If the given \a property is not managed by this manager, this |
| 3466 | function returns an invalid size |
| 3467 | |
| 3468 | \sa setValue() |
| 3469 | */ |
| 3470 | QSizeF QtSizeFPropertyManager::value(const QtProperty *property) const |
| 3471 | { |
| 3472 | return getValue<QSizeF>(propertyMap: d_ptr->m_values, property); |
| 3473 | } |
| 3474 | |
| 3475 | /*! |
| 3476 | Returns the given \a property's precision, in decimals. |
| 3477 | |
| 3478 | \sa setDecimals() |
| 3479 | */ |
| 3480 | int QtSizeFPropertyManager::decimals(const QtProperty *property) const |
| 3481 | { |
| 3482 | return getData<int>(propertyMap: d_ptr->m_values, data: &QtSizeFPropertyManagerPrivate::Data::decimals, property, defaultValue: 0); |
| 3483 | } |
| 3484 | |
| 3485 | /*! |
| 3486 | Returns the given \a property's minimum size value. |
| 3487 | |
| 3488 | \sa setMinimum(), maximum(), setRange() |
| 3489 | */ |
| 3490 | QSizeF QtSizeFPropertyManager::minimum(const QtProperty *property) const |
| 3491 | { |
| 3492 | return getMinimum<QSizeF>(propertyMap: d_ptr->m_values, property); |
| 3493 | } |
| 3494 | |
| 3495 | /*! |
| 3496 | Returns the given \a property's maximum size value. |
| 3497 | |
| 3498 | \sa setMaximum(), minimum(), setRange() |
| 3499 | */ |
| 3500 | QSizeF QtSizeFPropertyManager::maximum(const QtProperty *property) const |
| 3501 | { |
| 3502 | return getMaximum<QSizeF>(propertyMap: d_ptr->m_values, property); |
| 3503 | } |
| 3504 | |
| 3505 | /*! |
| 3506 | \reimp |
| 3507 | */ |
| 3508 | QString QtSizeFPropertyManager::valueText(const QtProperty *property) const |
| 3509 | { |
| 3510 | const auto it = d_ptr->m_values.constFind(key: property); |
| 3511 | if (it == d_ptr->m_values.constEnd()) |
| 3512 | return {}; |
| 3513 | const QSizeF v = it.value().val; |
| 3514 | const int dec = it.value().decimals; |
| 3515 | return tr(s: "%1 x %2" ).arg(args: QString::number(v.width(), format: 'f', precision: dec), |
| 3516 | args: QString::number(v.height(), format: 'f', precision: dec)); |
| 3517 | } |
| 3518 | |
| 3519 | /*! |
| 3520 | \fn void QtSizeFPropertyManager::setValue(QtProperty *property, const QSizeF &value) |
| 3521 | |
| 3522 | Sets the value of the given \a property to \a value. |
| 3523 | |
| 3524 | If the specified \a value is not valid according to the given \a |
| 3525 | property's size range, the \a value is adjusted to the nearest |
| 3526 | valid value within the size range. |
| 3527 | |
| 3528 | \sa value(), setRange(), valueChanged() |
| 3529 | */ |
| 3530 | void QtSizeFPropertyManager::setValue(QtProperty *property, QSizeF val) |
| 3531 | { |
| 3532 | setValueInRange<QSizeF, QtSizeFPropertyManagerPrivate, QtSizeFPropertyManager, QSizeF>(manager: this, managerPrivate: d_ptr.data(), |
| 3533 | propertyChangedSignal: &QtSizeFPropertyManager::propertyChanged, |
| 3534 | valueChangedSignal: &QtSizeFPropertyManager::valueChanged, |
| 3535 | property, val, setSubPropertyValue: &QtSizeFPropertyManagerPrivate::setValue); |
| 3536 | } |
| 3537 | |
| 3538 | /*! |
| 3539 | \fn void QtSizeFPropertyManager::setDecimals(QtProperty *property, int prec) |
| 3540 | |
| 3541 | Sets the precision of the given \a property to \a prec. |
| 3542 | |
| 3543 | The valid decimal range is 0-13. The default is 2. |
| 3544 | |
| 3545 | \sa decimals() |
| 3546 | */ |
| 3547 | void QtSizeFPropertyManager::setDecimals(QtProperty *property, int prec) |
| 3548 | { |
| 3549 | const auto it = d_ptr->m_values.find(key: property); |
| 3550 | if (it == d_ptr->m_values.end()) |
| 3551 | return; |
| 3552 | |
| 3553 | QtSizeFPropertyManagerPrivate::Data data = it.value(); |
| 3554 | |
| 3555 | if (prec > 13) |
| 3556 | prec = 13; |
| 3557 | else if (prec < 0) |
| 3558 | prec = 0; |
| 3559 | |
| 3560 | if (data.decimals == prec) |
| 3561 | return; |
| 3562 | |
| 3563 | data.decimals = prec; |
| 3564 | d_ptr->m_doublePropertyManager->setDecimals(property: d_ptr->m_propertyToW[property], prec); |
| 3565 | d_ptr->m_doublePropertyManager->setDecimals(property: d_ptr->m_propertyToH[property], prec); |
| 3566 | |
| 3567 | it.value() = data; |
| 3568 | |
| 3569 | emit decimalsChanged(property, prec: data.decimals); |
| 3570 | } |
| 3571 | |
| 3572 | /*! |
| 3573 | Sets the minimum size value for the given \a property to \a minVal. |
| 3574 | |
| 3575 | When setting the minimum size value, the maximum and current |
| 3576 | values are adjusted if necessary (ensuring that the size range |
| 3577 | remains valid and that the current value is within the range). |
| 3578 | |
| 3579 | \sa minimum(), setRange(), rangeChanged() |
| 3580 | */ |
| 3581 | void QtSizeFPropertyManager::setMinimum(QtProperty *property, QSizeF minVal) |
| 3582 | { |
| 3583 | setBorderValue<QSizeF, QtSizeFPropertyManagerPrivate, QtSizeFPropertyManager, QSizeF, QtSizeFPropertyManagerPrivate::Data>(manager: this, managerPrivate: d_ptr.data(), |
| 3584 | propertyChangedSignal: &QtSizeFPropertyManager::propertyChanged, |
| 3585 | valueChangedSignal: &QtSizeFPropertyManager::valueChanged, |
| 3586 | rangeChangedSignal: &QtSizeFPropertyManager::rangeChanged, |
| 3587 | property, |
| 3588 | getRangeVal: &QtSizeFPropertyManagerPrivate::Data::minimumValue, |
| 3589 | setRangeVal: &QtSizeFPropertyManagerPrivate::Data::setMinimumValue, |
| 3590 | borderVal: minVal, setSubPropertyRange: &QtSizeFPropertyManagerPrivate::setRange); |
| 3591 | } |
| 3592 | |
| 3593 | /*! |
| 3594 | Sets the maximum size value for the given \a property to \a maxVal. |
| 3595 | |
| 3596 | When setting the maximum size value, the minimum and current |
| 3597 | values are adjusted if necessary (ensuring that the size range |
| 3598 | remains valid and that the current value is within the range). |
| 3599 | |
| 3600 | \sa maximum(), setRange(), rangeChanged() |
| 3601 | */ |
| 3602 | void QtSizeFPropertyManager::setMaximum(QtProperty *property, QSizeF maxVal) |
| 3603 | { |
| 3604 | setBorderValue<QSizeF, QtSizeFPropertyManagerPrivate, QtSizeFPropertyManager, QSizeF, QtSizeFPropertyManagerPrivate::Data>(manager: this, managerPrivate: d_ptr.data(), |
| 3605 | propertyChangedSignal: &QtSizeFPropertyManager::propertyChanged, |
| 3606 | valueChangedSignal: &QtSizeFPropertyManager::valueChanged, |
| 3607 | rangeChangedSignal: &QtSizeFPropertyManager::rangeChanged, |
| 3608 | property, |
| 3609 | getRangeVal: &QtSizeFPropertyManagerPrivate::Data::maximumValue, |
| 3610 | setRangeVal: &QtSizeFPropertyManagerPrivate::Data::setMaximumValue, |
| 3611 | borderVal: maxVal, setSubPropertyRange: &QtSizeFPropertyManagerPrivate::setRange); |
| 3612 | } |
| 3613 | |
| 3614 | /*! |
| 3615 | \fn void QtSizeFPropertyManager::setRange(QtProperty *property, const QSizeF &minimum, const QSizeF &maximum) |
| 3616 | |
| 3617 | Sets the range of valid values. |
| 3618 | |
| 3619 | This is a convenience function defining the range of valid values |
| 3620 | in one go; setting the \a minimum and \a maximum values for the |
| 3621 | given \a property with a single function call. |
| 3622 | |
| 3623 | When setting a new range, the current value is adjusted if |
| 3624 | necessary (ensuring that the value remains within the range). |
| 3625 | |
| 3626 | \sa setMinimum(), setMaximum(), rangeChanged() |
| 3627 | */ |
| 3628 | void QtSizeFPropertyManager::setRange(QtProperty *property, QSizeF minVal, QSizeF maxVal) |
| 3629 | { |
| 3630 | setBorderValues<QSizeF, QtSizeFPropertyManagerPrivate, QtSizeFPropertyManager, QSizeF>(manager: this, managerPrivate: d_ptr.data(), |
| 3631 | propertyChangedSignal: &QtSizeFPropertyManager::propertyChanged, |
| 3632 | valueChangedSignal: &QtSizeFPropertyManager::valueChanged, |
| 3633 | rangeChangedSignal: &QtSizeFPropertyManager::rangeChanged, |
| 3634 | property, minVal, maxVal, setSubPropertyRange: &QtSizeFPropertyManagerPrivate::setRange); |
| 3635 | } |
| 3636 | |
| 3637 | /*! |
| 3638 | \reimp |
| 3639 | */ |
| 3640 | void QtSizeFPropertyManager::initializeProperty(QtProperty *property) |
| 3641 | { |
| 3642 | d_ptr->m_values[property] = QtSizeFPropertyManagerPrivate::Data(); |
| 3643 | |
| 3644 | QtProperty *wProp = d_ptr->m_doublePropertyManager->addProperty(); |
| 3645 | wProp->setPropertyName(tr(s: "Width" )); |
| 3646 | d_ptr->m_doublePropertyManager->setDecimals(property: wProp, prec: decimals(property)); |
| 3647 | d_ptr->m_doublePropertyManager->setValue(property: wProp, val: 0); |
| 3648 | d_ptr->m_doublePropertyManager->setMinimum(property: wProp, minVal: 0); |
| 3649 | d_ptr->m_propertyToW[property] = wProp; |
| 3650 | d_ptr->m_wToProperty[wProp] = property; |
| 3651 | property->addSubProperty(property: wProp); |
| 3652 | |
| 3653 | QtProperty *hProp = d_ptr->m_doublePropertyManager->addProperty(); |
| 3654 | hProp->setPropertyName(tr(s: "Height" )); |
| 3655 | d_ptr->m_doublePropertyManager->setDecimals(property: hProp, prec: decimals(property)); |
| 3656 | d_ptr->m_doublePropertyManager->setValue(property: hProp, val: 0); |
| 3657 | d_ptr->m_doublePropertyManager->setMinimum(property: hProp, minVal: 0); |
| 3658 | d_ptr->m_propertyToH[property] = hProp; |
| 3659 | d_ptr->m_hToProperty[hProp] = property; |
| 3660 | property->addSubProperty(property: hProp); |
| 3661 | } |
| 3662 | |
| 3663 | /*! |
| 3664 | \reimp |
| 3665 | */ |
| 3666 | void QtSizeFPropertyManager::uninitializeProperty(QtProperty *property) |
| 3667 | { |
| 3668 | QtProperty *wProp = d_ptr->m_propertyToW[property]; |
| 3669 | if (wProp) { |
| 3670 | d_ptr->m_wToProperty.remove(key: wProp); |
| 3671 | delete wProp; |
| 3672 | } |
| 3673 | d_ptr->m_propertyToW.remove(key: property); |
| 3674 | |
| 3675 | QtProperty *hProp = d_ptr->m_propertyToH[property]; |
| 3676 | if (hProp) { |
| 3677 | d_ptr->m_hToProperty.remove(key: hProp); |
| 3678 | delete hProp; |
| 3679 | } |
| 3680 | d_ptr->m_propertyToH.remove(key: property); |
| 3681 | |
| 3682 | d_ptr->m_values.remove(key: property); |
| 3683 | } |
| 3684 | |
| 3685 | // QtRectPropertyManager |
| 3686 | |
| 3687 | class QtRectPropertyManagerPrivate |
| 3688 | { |
| 3689 | QtRectPropertyManager *q_ptr = nullptr; |
| 3690 | Q_DECLARE_PUBLIC(QtRectPropertyManager) |
| 3691 | public: |
| 3692 | |
| 3693 | void slotIntChanged(QtProperty *property, int value); |
| 3694 | void slotPropertyDestroyed(QtProperty *property); |
| 3695 | void setConstraint(QtProperty *property, QRect constraint, QRect val); |
| 3696 | |
| 3697 | struct Data |
| 3698 | { |
| 3699 | QRect val{0, 0, 0, 0}; |
| 3700 | QRect constraint; |
| 3701 | }; |
| 3702 | |
| 3703 | QHash<const QtProperty *, Data> m_values; |
| 3704 | |
| 3705 | QtIntPropertyManager *m_intPropertyManager; |
| 3706 | |
| 3707 | QHash<const QtProperty *, QtProperty *> m_propertyToX; |
| 3708 | QHash<const QtProperty *, QtProperty *> m_propertyToY; |
| 3709 | QHash<const QtProperty *, QtProperty *> m_propertyToW; |
| 3710 | QHash<const QtProperty *, QtProperty *> m_propertyToH; |
| 3711 | |
| 3712 | QHash<const QtProperty *, QtProperty *> m_xToProperty; |
| 3713 | QHash<const QtProperty *, QtProperty *> m_yToProperty; |
| 3714 | QHash<const QtProperty *, QtProperty *> m_wToProperty; |
| 3715 | QHash<const QtProperty *, QtProperty *> m_hToProperty; |
| 3716 | }; |
| 3717 | |
| 3718 | void QtRectPropertyManagerPrivate::slotIntChanged(QtProperty *property, int value) |
| 3719 | { |
| 3720 | if (QtProperty *prop = m_xToProperty.value(key: property, defaultValue: nullptr)) { |
| 3721 | QRect r = m_values[prop].val; |
| 3722 | r.moveLeft(pos: value); |
| 3723 | q_ptr->setValue(property: prop, val: r); |
| 3724 | } else if (QtProperty *prop = m_yToProperty.value(key: property)) { |
| 3725 | QRect r = m_values[prop].val; |
| 3726 | r.moveTop(pos: value); |
| 3727 | q_ptr->setValue(property: prop, val: r); |
| 3728 | } else if (QtProperty *prop = m_wToProperty.value(key: property, defaultValue: nullptr)) { |
| 3729 | Data data = m_values[prop]; |
| 3730 | QRect r = data.val; |
| 3731 | r.setWidth(value); |
| 3732 | if (!data.constraint.isNull() && data.constraint.x() + data.constraint.width() < r.x() + r.width()) { |
| 3733 | r.moveLeft(pos: data.constraint.left() + data.constraint.width() - r.width()); |
| 3734 | } |
| 3735 | q_ptr->setValue(property: prop, val: r); |
| 3736 | } else if (QtProperty *prop = m_hToProperty.value(key: property, defaultValue: nullptr)) { |
| 3737 | Data data = m_values[prop]; |
| 3738 | QRect r = data.val; |
| 3739 | r.setHeight(value); |
| 3740 | if (!data.constraint.isNull() && data.constraint.y() + data.constraint.height() < r.y() + r.height()) { |
| 3741 | r.moveTop(pos: data.constraint.top() + data.constraint.height() - r.height()); |
| 3742 | } |
| 3743 | q_ptr->setValue(property: prop, val: r); |
| 3744 | } |
| 3745 | } |
| 3746 | |
| 3747 | void QtRectPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property) |
| 3748 | { |
| 3749 | if (QtProperty *pointProp = m_xToProperty.value(key: property, defaultValue: nullptr)) { |
| 3750 | m_propertyToX[pointProp] = nullptr; |
| 3751 | m_xToProperty.remove(key: property); |
| 3752 | } else if (QtProperty *pointProp = m_yToProperty.value(key: property, defaultValue: nullptr)) { |
| 3753 | m_propertyToY[pointProp] = nullptr; |
| 3754 | m_yToProperty.remove(key: property); |
| 3755 | } else if (QtProperty *pointProp = m_wToProperty.value(key: property, defaultValue: nullptr)) { |
| 3756 | m_propertyToW[pointProp] = nullptr; |
| 3757 | m_wToProperty.remove(key: property); |
| 3758 | } else if (QtProperty *pointProp = m_hToProperty.value(key: property, defaultValue: nullptr)) { |
| 3759 | m_propertyToH[pointProp] = nullptr; |
| 3760 | m_hToProperty.remove(key: property); |
| 3761 | } |
| 3762 | } |
| 3763 | |
| 3764 | void QtRectPropertyManagerPrivate::setConstraint(QtProperty *property, |
| 3765 | QRect constraint, QRect val) |
| 3766 | { |
| 3767 | const bool isNull = constraint.isNull(); |
| 3768 | const int left = isNull ? INT_MIN : constraint.left(); |
| 3769 | const int right = isNull ? INT_MAX : constraint.left() + constraint.width(); |
| 3770 | const int top = isNull ? INT_MIN : constraint.top(); |
| 3771 | const int bottom = isNull ? INT_MAX : constraint.top() + constraint.height(); |
| 3772 | const int width = isNull ? INT_MAX : constraint.width(); |
| 3773 | const int height = isNull ? INT_MAX : constraint.height(); |
| 3774 | |
| 3775 | m_intPropertyManager->setRange(property: m_propertyToX[property], minVal: left, maxVal: right); |
| 3776 | m_intPropertyManager->setRange(property: m_propertyToY[property], minVal: top, maxVal: bottom); |
| 3777 | m_intPropertyManager->setRange(property: m_propertyToW[property], minVal: 0, maxVal: width); |
| 3778 | m_intPropertyManager->setRange(property: m_propertyToH[property], minVal: 0, maxVal: height); |
| 3779 | |
| 3780 | m_intPropertyManager->setValue(property: m_propertyToX[property], val: val.x()); |
| 3781 | m_intPropertyManager->setValue(property: m_propertyToY[property], val: val.y()); |
| 3782 | m_intPropertyManager->setValue(property: m_propertyToW[property], val: val.width()); |
| 3783 | m_intPropertyManager->setValue(property: m_propertyToH[property], val: val.height()); |
| 3784 | } |
| 3785 | |
| 3786 | /*! |
| 3787 | \class QtRectPropertyManager |
| 3788 | \internal |
| 3789 | \inmodule QtDesigner |
| 3790 | \since 4.4 |
| 3791 | |
| 3792 | \brief The QtRectPropertyManager provides and manages QRect properties. |
| 3793 | |
| 3794 | A rectangle property has nested \e x, \e y, \e width and \e height |
| 3795 | subproperties. The top-level property's value can be retrieved |
| 3796 | using the value() function, and set using the setValue() slot. |
| 3797 | |
| 3798 | The subproperties are created by a QtIntPropertyManager object. This |
| 3799 | manager can be retrieved using the subIntPropertyManager() function. In |
| 3800 | order to provide editing widgets for the subproperties in a |
| 3801 | property browser widget, this manager must be associated with an |
| 3802 | editor factory. |
| 3803 | |
| 3804 | A rectangle property also has a constraint rectangle which can be |
| 3805 | retrieved using the constraint() function, and set using the |
| 3806 | setConstraint() slot. |
| 3807 | |
| 3808 | In addition, QtRectPropertyManager provides the valueChanged() signal |
| 3809 | which is emitted whenever a property created by this manager |
| 3810 | changes, and the constraintChanged() signal which is emitted |
| 3811 | whenever such a property changes its constraint rectangle. |
| 3812 | |
| 3813 | \sa QtAbstractPropertyManager, QtIntPropertyManager, QtRectFPropertyManager |
| 3814 | */ |
| 3815 | |
| 3816 | /*! |
| 3817 | \fn void QtRectPropertyManager::valueChanged(QtProperty *property, const QRect &value) |
| 3818 | |
| 3819 | This signal is emitted whenever a property created by this manager |
| 3820 | changes its value, passing a pointer to the \a property and the new |
| 3821 | \a value as parameters. |
| 3822 | |
| 3823 | \sa setValue() |
| 3824 | */ |
| 3825 | |
| 3826 | /*! |
| 3827 | \fn void QtRectPropertyManager::constraintChanged(QtProperty *property, const QRect &constraint) |
| 3828 | |
| 3829 | This signal is emitted whenever property changes its constraint |
| 3830 | rectangle, passing a pointer to the \a property and the new \a |
| 3831 | constraint rectangle as parameters. |
| 3832 | |
| 3833 | \sa setConstraint() |
| 3834 | */ |
| 3835 | |
| 3836 | /*! |
| 3837 | Creates a manager with the given \a parent. |
| 3838 | */ |
| 3839 | QtRectPropertyManager::QtRectPropertyManager(QObject *parent) |
| 3840 | : QtAbstractPropertyManager(parent), d_ptr(new QtRectPropertyManagerPrivate) |
| 3841 | { |
| 3842 | d_ptr->q_ptr = this; |
| 3843 | |
| 3844 | d_ptr->m_intPropertyManager = new QtIntPropertyManager(this); |
| 3845 | connect(sender: d_ptr->m_intPropertyManager, signal: &QtIntPropertyManager::valueChanged, context: this, |
| 3846 | slot: [this](QtProperty *property, int value) { d_ptr->slotIntChanged(property, value); }); |
| 3847 | connect(sender: d_ptr->m_intPropertyManager, signal: &QtAbstractPropertyManager::propertyDestroyed, context: this, |
| 3848 | slot: [this](QtProperty *property) { d_ptr->slotPropertyDestroyed(property); }); |
| 3849 | } |
| 3850 | |
| 3851 | /*! |
| 3852 | Destroys this manager, and all the properties it has created. |
| 3853 | */ |
| 3854 | QtRectPropertyManager::~QtRectPropertyManager() |
| 3855 | { |
| 3856 | clear(); |
| 3857 | } |
| 3858 | |
| 3859 | /*! |
| 3860 | Returns the manager that creates the nested \e x, \e y, \e width |
| 3861 | and \e height subproperties. |
| 3862 | |
| 3863 | In order to provide editing widgets for the mentioned |
| 3864 | subproperties in a property browser widget, this manager must be |
| 3865 | associated with an editor factory. |
| 3866 | |
| 3867 | \sa QtAbstractPropertyBrowser::setFactoryForManager() |
| 3868 | */ |
| 3869 | QtIntPropertyManager *QtRectPropertyManager::subIntPropertyManager() const |
| 3870 | { |
| 3871 | return d_ptr->m_intPropertyManager; |
| 3872 | } |
| 3873 | |
| 3874 | /*! |
| 3875 | Returns the given \a property's value. |
| 3876 | |
| 3877 | If the given \a property is not managed by this manager, this |
| 3878 | function returns an invalid rectangle. |
| 3879 | |
| 3880 | \sa setValue(), constraint() |
| 3881 | */ |
| 3882 | QRect QtRectPropertyManager::value(const QtProperty *property) const |
| 3883 | { |
| 3884 | return getValue<QRect>(propertyMap: d_ptr->m_values, property); |
| 3885 | } |
| 3886 | |
| 3887 | /*! |
| 3888 | Returns the given \a property's constraining rectangle. If returned value is null QRect it means there is no constraint applied. |
| 3889 | |
| 3890 | \sa value(), setConstraint() |
| 3891 | */ |
| 3892 | QRect QtRectPropertyManager::constraint(const QtProperty *property) const |
| 3893 | { |
| 3894 | return getData<QRect>(propertyMap: d_ptr->m_values, data: &QtRectPropertyManagerPrivate::Data::constraint, property, defaultValue: QRect()); |
| 3895 | } |
| 3896 | |
| 3897 | /*! |
| 3898 | \reimp |
| 3899 | */ |
| 3900 | QString QtRectPropertyManager::valueText(const QtProperty *property) const |
| 3901 | { |
| 3902 | const auto it = d_ptr->m_values.constFind(key: property); |
| 3903 | if (it == d_ptr->m_values.constEnd()) |
| 3904 | return {}; |
| 3905 | const QRect v = it.value().val; |
| 3906 | return tr(s: "[(%1, %2), %3 x %4]" ).arg(a: v.x()) .arg(a: v.y()) |
| 3907 | .arg(a: v.width()).arg(a: v.height()); |
| 3908 | } |
| 3909 | |
| 3910 | /*! |
| 3911 | \fn void QtRectPropertyManager::setValue(QtProperty *property, const QRect &value) |
| 3912 | |
| 3913 | Sets the value of the given \a property to \a value. Nested |
| 3914 | properties are updated automatically. |
| 3915 | |
| 3916 | If the specified \a value is not inside the given \a property's |
| 3917 | constraining rectangle, the value is adjusted accordingly to fit |
| 3918 | within the constraint. |
| 3919 | |
| 3920 | \sa value(), setConstraint(), valueChanged() |
| 3921 | */ |
| 3922 | void QtRectPropertyManager::setValue(QtProperty *property, QRect val) |
| 3923 | { |
| 3924 | const auto it = d_ptr->m_values.find(key: property); |
| 3925 | if (it == d_ptr->m_values.end()) |
| 3926 | return; |
| 3927 | |
| 3928 | QtRectPropertyManagerPrivate::Data data = it.value(); |
| 3929 | |
| 3930 | QRect newRect = val.normalized(); |
| 3931 | if (!data.constraint.isNull() && !data.constraint.contains(r: newRect)) { |
| 3932 | const QRect r1 = data.constraint; |
| 3933 | const QRect r2 = newRect; |
| 3934 | newRect.setLeft(qMax(a: r1.left(), b: r2.left())); |
| 3935 | newRect.setRight(qMin(a: r1.right(), b: r2.right())); |
| 3936 | newRect.setTop(qMax(a: r1.top(), b: r2.top())); |
| 3937 | newRect.setBottom(qMin(a: r1.bottom(), b: r2.bottom())); |
| 3938 | if (newRect.width() < 0 || newRect.height() < 0) |
| 3939 | return; |
| 3940 | } |
| 3941 | |
| 3942 | if (data.val == newRect) |
| 3943 | return; |
| 3944 | |
| 3945 | data.val = newRect; |
| 3946 | |
| 3947 | it.value() = data; |
| 3948 | d_ptr->m_intPropertyManager->setValue(property: d_ptr->m_propertyToX[property], val: newRect.x()); |
| 3949 | d_ptr->m_intPropertyManager->setValue(property: d_ptr->m_propertyToY[property], val: newRect.y()); |
| 3950 | d_ptr->m_intPropertyManager->setValue(property: d_ptr->m_propertyToW[property], val: newRect.width()); |
| 3951 | d_ptr->m_intPropertyManager->setValue(property: d_ptr->m_propertyToH[property], val: newRect.height()); |
| 3952 | |
| 3953 | emit propertyChanged(property); |
| 3954 | emit valueChanged(property, val: data.val); |
| 3955 | } |
| 3956 | |
| 3957 | /*! |
| 3958 | Sets the given \a property's constraining rectangle to \a |
| 3959 | constraint. |
| 3960 | |
| 3961 | When setting the constraint, the current value is adjusted if |
| 3962 | necessary (ensuring that the current rectangle value is inside the |
| 3963 | constraint). In order to reset the constraint pass a null QRect value. |
| 3964 | |
| 3965 | \sa setValue(), constraint(), constraintChanged() |
| 3966 | */ |
| 3967 | void QtRectPropertyManager::setConstraint(QtProperty *property, QRect constraint) |
| 3968 | { |
| 3969 | const auto it = d_ptr->m_values.find(key: property); |
| 3970 | if (it == d_ptr->m_values.end()) |
| 3971 | return; |
| 3972 | |
| 3973 | QtRectPropertyManagerPrivate::Data data = it.value(); |
| 3974 | |
| 3975 | QRect newConstraint = constraint.normalized(); |
| 3976 | if (data.constraint == newConstraint) |
| 3977 | return; |
| 3978 | |
| 3979 | const QRect oldVal = data.val; |
| 3980 | |
| 3981 | data.constraint = newConstraint; |
| 3982 | |
| 3983 | if (!data.constraint.isNull() && !data.constraint.contains(r: oldVal)) { |
| 3984 | QRect r1 = data.constraint; |
| 3985 | QRect r2 = data.val; |
| 3986 | |
| 3987 | if (r2.width() > r1.width()) |
| 3988 | r2.setWidth(r1.width()); |
| 3989 | if (r2.height() > r1.height()) |
| 3990 | r2.setHeight(r1.height()); |
| 3991 | if (r2.left() < r1.left()) |
| 3992 | r2.moveLeft(pos: r1.left()); |
| 3993 | else if (r2.right() > r1.right()) |
| 3994 | r2.moveRight(pos: r1.right()); |
| 3995 | if (r2.top() < r1.top()) |
| 3996 | r2.moveTop(pos: r1.top()); |
| 3997 | else if (r2.bottom() > r1.bottom()) |
| 3998 | r2.moveBottom(pos: r1.bottom()); |
| 3999 | |
| 4000 | data.val = r2; |
| 4001 | } |
| 4002 | |
| 4003 | it.value() = data; |
| 4004 | |
| 4005 | emit constraintChanged(property, constraint: data.constraint); |
| 4006 | |
| 4007 | d_ptr->setConstraint(property, constraint: data.constraint, val: data.val); |
| 4008 | |
| 4009 | if (data.val == oldVal) |
| 4010 | return; |
| 4011 | |
| 4012 | emit propertyChanged(property); |
| 4013 | emit valueChanged(property, val: data.val); |
| 4014 | } |
| 4015 | |
| 4016 | /*! |
| 4017 | \reimp |
| 4018 | */ |
| 4019 | void QtRectPropertyManager::initializeProperty(QtProperty *property) |
| 4020 | { |
| 4021 | d_ptr->m_values[property] = QtRectPropertyManagerPrivate::Data(); |
| 4022 | |
| 4023 | QtProperty *xProp = d_ptr->m_intPropertyManager->addProperty(); |
| 4024 | xProp->setPropertyName(tr(s: "X" )); |
| 4025 | d_ptr->m_intPropertyManager->setValue(property: xProp, val: 0); |
| 4026 | d_ptr->m_propertyToX[property] = xProp; |
| 4027 | d_ptr->m_xToProperty[xProp] = property; |
| 4028 | property->addSubProperty(property: xProp); |
| 4029 | |
| 4030 | QtProperty *yProp = d_ptr->m_intPropertyManager->addProperty(); |
| 4031 | yProp->setPropertyName(tr(s: "Y" )); |
| 4032 | d_ptr->m_intPropertyManager->setValue(property: yProp, val: 0); |
| 4033 | d_ptr->m_propertyToY[property] = yProp; |
| 4034 | d_ptr->m_yToProperty[yProp] = property; |
| 4035 | property->addSubProperty(property: yProp); |
| 4036 | |
| 4037 | QtProperty *wProp = d_ptr->m_intPropertyManager->addProperty(); |
| 4038 | wProp->setPropertyName(tr(s: "Width" )); |
| 4039 | d_ptr->m_intPropertyManager->setValue(property: wProp, val: 0); |
| 4040 | d_ptr->m_intPropertyManager->setMinimum(property: wProp, minVal: 0); |
| 4041 | d_ptr->m_propertyToW[property] = wProp; |
| 4042 | d_ptr->m_wToProperty[wProp] = property; |
| 4043 | property->addSubProperty(property: wProp); |
| 4044 | |
| 4045 | QtProperty *hProp = d_ptr->m_intPropertyManager->addProperty(); |
| 4046 | hProp->setPropertyName(tr(s: "Height" )); |
| 4047 | d_ptr->m_intPropertyManager->setValue(property: hProp, val: 0); |
| 4048 | d_ptr->m_intPropertyManager->setMinimum(property: hProp, minVal: 0); |
| 4049 | d_ptr->m_propertyToH[property] = hProp; |
| 4050 | d_ptr->m_hToProperty[hProp] = property; |
| 4051 | property->addSubProperty(property: hProp); |
| 4052 | } |
| 4053 | |
| 4054 | /*! |
| 4055 | \reimp |
| 4056 | */ |
| 4057 | void QtRectPropertyManager::uninitializeProperty(QtProperty *property) |
| 4058 | { |
| 4059 | QtProperty *xProp = d_ptr->m_propertyToX[property]; |
| 4060 | if (xProp) { |
| 4061 | d_ptr->m_xToProperty.remove(key: xProp); |
| 4062 | delete xProp; |
| 4063 | } |
| 4064 | d_ptr->m_propertyToX.remove(key: property); |
| 4065 | |
| 4066 | QtProperty *yProp = d_ptr->m_propertyToY[property]; |
| 4067 | if (yProp) { |
| 4068 | d_ptr->m_yToProperty.remove(key: yProp); |
| 4069 | delete yProp; |
| 4070 | } |
| 4071 | d_ptr->m_propertyToY.remove(key: property); |
| 4072 | |
| 4073 | QtProperty *wProp = d_ptr->m_propertyToW[property]; |
| 4074 | if (wProp) { |
| 4075 | d_ptr->m_wToProperty.remove(key: wProp); |
| 4076 | delete wProp; |
| 4077 | } |
| 4078 | d_ptr->m_propertyToW.remove(key: property); |
| 4079 | |
| 4080 | QtProperty *hProp = d_ptr->m_propertyToH[property]; |
| 4081 | if (hProp) { |
| 4082 | d_ptr->m_hToProperty.remove(key: hProp); |
| 4083 | delete hProp; |
| 4084 | } |
| 4085 | d_ptr->m_propertyToH.remove(key: property); |
| 4086 | |
| 4087 | d_ptr->m_values.remove(key: property); |
| 4088 | } |
| 4089 | |
| 4090 | // QtRectFPropertyManager |
| 4091 | |
| 4092 | class QtRectFPropertyManagerPrivate |
| 4093 | { |
| 4094 | QtRectFPropertyManager *q_ptr = nullptr; |
| 4095 | Q_DECLARE_PUBLIC(QtRectFPropertyManager) |
| 4096 | public: |
| 4097 | |
| 4098 | void slotDoubleChanged(QtProperty *property, double value); |
| 4099 | void slotPropertyDestroyed(QtProperty *property); |
| 4100 | void setConstraint(QtProperty *property, const QRectF &constraint, const QRectF &val); |
| 4101 | |
| 4102 | struct Data |
| 4103 | { |
| 4104 | QRectF val{0, 0, 0, 0}; |
| 4105 | QRectF constraint; |
| 4106 | int decimals{2}; |
| 4107 | }; |
| 4108 | |
| 4109 | QHash<const QtProperty *, Data> m_values; |
| 4110 | |
| 4111 | QtDoublePropertyManager *m_doublePropertyManager; |
| 4112 | |
| 4113 | QHash<const QtProperty *, QtProperty *> m_propertyToX; |
| 4114 | QHash<const QtProperty *, QtProperty *> m_propertyToY; |
| 4115 | QHash<const QtProperty *, QtProperty *> m_propertyToW; |
| 4116 | QHash<const QtProperty *, QtProperty *> m_propertyToH; |
| 4117 | |
| 4118 | QHash<const QtProperty *, QtProperty *> m_xToProperty; |
| 4119 | QHash<const QtProperty *, QtProperty *> m_yToProperty; |
| 4120 | QHash<const QtProperty *, QtProperty *> m_wToProperty; |
| 4121 | QHash<const QtProperty *, QtProperty *> m_hToProperty; |
| 4122 | }; |
| 4123 | |
| 4124 | void QtRectFPropertyManagerPrivate::slotDoubleChanged(QtProperty *property, double value) |
| 4125 | { |
| 4126 | if (QtProperty *prop = m_xToProperty.value(key: property, defaultValue: nullptr)) { |
| 4127 | QRectF r = m_values[prop].val; |
| 4128 | r.moveLeft(pos: value); |
| 4129 | q_ptr->setValue(property: prop, val: r); |
| 4130 | } else if (QtProperty *prop = m_yToProperty.value(key: property, defaultValue: nullptr)) { |
| 4131 | QRectF r = m_values[prop].val; |
| 4132 | r.moveTop(pos: value); |
| 4133 | q_ptr->setValue(property: prop, val: r); |
| 4134 | } else if (QtProperty *prop = m_wToProperty.value(key: property, defaultValue: nullptr)) { |
| 4135 | Data data = m_values[prop]; |
| 4136 | QRectF r = data.val; |
| 4137 | r.setWidth(value); |
| 4138 | if (!data.constraint.isNull() && data.constraint.x() + data.constraint.width() < r.x() + r.width()) { |
| 4139 | r.moveLeft(pos: data.constraint.left() + data.constraint.width() - r.width()); |
| 4140 | } |
| 4141 | q_ptr->setValue(property: prop, val: r); |
| 4142 | } else if (QtProperty *prop = m_hToProperty.value(key: property, defaultValue: nullptr)) { |
| 4143 | Data data = m_values[prop]; |
| 4144 | QRectF r = data.val; |
| 4145 | r.setHeight(value); |
| 4146 | if (!data.constraint.isNull() && data.constraint.y() + data.constraint.height() < r.y() + r.height()) { |
| 4147 | r.moveTop(pos: data.constraint.top() + data.constraint.height() - r.height()); |
| 4148 | } |
| 4149 | q_ptr->setValue(property: prop, val: r); |
| 4150 | } |
| 4151 | } |
| 4152 | |
| 4153 | void QtRectFPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property) |
| 4154 | { |
| 4155 | if (QtProperty *pointProp = m_xToProperty.value(key: property, defaultValue: nullptr)) { |
| 4156 | m_propertyToX[pointProp] = nullptr; |
| 4157 | m_xToProperty.remove(key: property); |
| 4158 | } else if (QtProperty *pointProp = m_yToProperty.value(key: property, defaultValue: nullptr)) { |
| 4159 | m_propertyToY[pointProp] = nullptr; |
| 4160 | m_yToProperty.remove(key: property); |
| 4161 | } else if (QtProperty *pointProp = m_wToProperty.value(key: property, defaultValue: nullptr)) { |
| 4162 | m_propertyToW[pointProp] = nullptr; |
| 4163 | m_wToProperty.remove(key: property); |
| 4164 | } else if (QtProperty *pointProp = m_hToProperty.value(key: property, defaultValue: nullptr)) { |
| 4165 | m_propertyToH[pointProp] = nullptr; |
| 4166 | m_hToProperty.remove(key: property); |
| 4167 | } |
| 4168 | } |
| 4169 | |
| 4170 | void QtRectFPropertyManagerPrivate::setConstraint(QtProperty *property, |
| 4171 | const QRectF &constraint, const QRectF &val) |
| 4172 | { |
| 4173 | const bool isNull = constraint.isNull(); |
| 4174 | const float left = isNull ? FLT_MIN : constraint.left(); |
| 4175 | const float right = isNull ? FLT_MAX : constraint.left() + constraint.width(); |
| 4176 | const float top = isNull ? FLT_MIN : constraint.top(); |
| 4177 | const float bottom = isNull ? FLT_MAX : constraint.top() + constraint.height(); |
| 4178 | const float width = isNull ? FLT_MAX : constraint.width(); |
| 4179 | const float height = isNull ? FLT_MAX : constraint.height(); |
| 4180 | |
| 4181 | m_doublePropertyManager->setRange(property: m_propertyToX[property], minVal: left, maxVal: right); |
| 4182 | m_doublePropertyManager->setRange(property: m_propertyToY[property], minVal: top, maxVal: bottom); |
| 4183 | m_doublePropertyManager->setRange(property: m_propertyToW[property], minVal: 0, maxVal: width); |
| 4184 | m_doublePropertyManager->setRange(property: m_propertyToH[property], minVal: 0, maxVal: height); |
| 4185 | |
| 4186 | m_doublePropertyManager->setValue(property: m_propertyToX[property], val: val.x()); |
| 4187 | m_doublePropertyManager->setValue(property: m_propertyToY[property], val: val.y()); |
| 4188 | m_doublePropertyManager->setValue(property: m_propertyToW[property], val: val.width()); |
| 4189 | m_doublePropertyManager->setValue(property: m_propertyToH[property], val: val.height()); |
| 4190 | } |
| 4191 | |
| 4192 | /*! |
| 4193 | \class QtRectFPropertyManager |
| 4194 | \internal |
| 4195 | \inmodule QtDesigner |
| 4196 | \since 4.4 |
| 4197 | |
| 4198 | \brief The QtRectFPropertyManager provides and manages QRectF properties. |
| 4199 | |
| 4200 | A rectangle property has nested \e x, \e y, \e width and \e height |
| 4201 | subproperties. The top-level property's value can be retrieved |
| 4202 | using the value() function, and set using the setValue() slot. |
| 4203 | |
| 4204 | The subproperties are created by a QtDoublePropertyManager object. This |
| 4205 | manager can be retrieved using the subDoublePropertyManager() function. In |
| 4206 | order to provide editing widgets for the subproperties in a |
| 4207 | property browser widget, this manager must be associated with an |
| 4208 | editor factory. |
| 4209 | |
| 4210 | A rectangle property also has a constraint rectangle which can be |
| 4211 | retrieved using the constraint() function, and set using the |
| 4212 | setConstraint() slot. |
| 4213 | |
| 4214 | In addition, QtRectFPropertyManager provides the valueChanged() signal |
| 4215 | which is emitted whenever a property created by this manager |
| 4216 | changes, and the constraintChanged() signal which is emitted |
| 4217 | whenever such a property changes its constraint rectangle. |
| 4218 | |
| 4219 | \sa QtAbstractPropertyManager, QtDoublePropertyManager, QtRectPropertyManager |
| 4220 | */ |
| 4221 | |
| 4222 | /*! |
| 4223 | \fn void QtRectFPropertyManager::valueChanged(QtProperty *property, const QRectF &value) |
| 4224 | |
| 4225 | This signal is emitted whenever a property created by this manager |
| 4226 | changes its value, passing a pointer to the \a property and the new |
| 4227 | \a value as parameters. |
| 4228 | |
| 4229 | \sa setValue() |
| 4230 | */ |
| 4231 | |
| 4232 | /*! |
| 4233 | \fn void QtRectFPropertyManager::constraintChanged(QtProperty *property, const QRectF &constraint) |
| 4234 | |
| 4235 | This signal is emitted whenever property changes its constraint |
| 4236 | rectangle, passing a pointer to the \a property and the new \a |
| 4237 | constraint rectangle as parameters. |
| 4238 | |
| 4239 | \sa setConstraint() |
| 4240 | */ |
| 4241 | |
| 4242 | /*! |
| 4243 | \fn void QtRectFPropertyManager::decimalsChanged(QtProperty *property, int prec) |
| 4244 | |
| 4245 | This signal is emitted whenever a property created by this manager |
| 4246 | changes its precision of value, passing a pointer to the |
| 4247 | \a property and the new \a prec value |
| 4248 | |
| 4249 | \sa setDecimals() |
| 4250 | */ |
| 4251 | |
| 4252 | /*! |
| 4253 | Creates a manager with the given \a parent. |
| 4254 | */ |
| 4255 | QtRectFPropertyManager::QtRectFPropertyManager(QObject *parent) |
| 4256 | : QtAbstractPropertyManager(parent), d_ptr(new QtRectFPropertyManagerPrivate) |
| 4257 | { |
| 4258 | d_ptr->q_ptr = this; |
| 4259 | |
| 4260 | d_ptr->m_doublePropertyManager = new QtDoublePropertyManager(this); |
| 4261 | connect(sender: d_ptr->m_doublePropertyManager, signal: &QtDoublePropertyManager::valueChanged, context: this, |
| 4262 | slot: [this](QtProperty *property, double value) { d_ptr->slotDoubleChanged(property, value); }); |
| 4263 | connect(sender: d_ptr->m_doublePropertyManager, signal: &QtAbstractPropertyManager::propertyDestroyed, context: this, |
| 4264 | slot: [this](QtProperty *property) { d_ptr->slotPropertyDestroyed(property); }); |
| 4265 | } |
| 4266 | |
| 4267 | /*! |
| 4268 | Destroys this manager, and all the properties it has created. |
| 4269 | */ |
| 4270 | QtRectFPropertyManager::~QtRectFPropertyManager() |
| 4271 | { |
| 4272 | clear(); |
| 4273 | } |
| 4274 | |
| 4275 | /*! |
| 4276 | Returns the manager that creates the nested \e x, \e y, \e width |
| 4277 | and \e height subproperties. |
| 4278 | |
| 4279 | In order to provide editing widgets for the mentioned |
| 4280 | subproperties in a property browser widget, this manager must be |
| 4281 | associated with an editor factory. |
| 4282 | |
| 4283 | \sa QtAbstractPropertyBrowser::setFactoryForManager() |
| 4284 | */ |
| 4285 | QtDoublePropertyManager *QtRectFPropertyManager::subDoublePropertyManager() const |
| 4286 | { |
| 4287 | return d_ptr->m_doublePropertyManager; |
| 4288 | } |
| 4289 | |
| 4290 | /*! |
| 4291 | Returns the given \a property's value. |
| 4292 | |
| 4293 | If the given \a property is not managed by this manager, this |
| 4294 | function returns an invalid rectangle. |
| 4295 | |
| 4296 | \sa setValue(), constraint() |
| 4297 | */ |
| 4298 | QRectF QtRectFPropertyManager::value(const QtProperty *property) const |
| 4299 | { |
| 4300 | return getValue<QRectF>(propertyMap: d_ptr->m_values, property); |
| 4301 | } |
| 4302 | |
| 4303 | /*! |
| 4304 | Returns the given \a property's precision, in decimals. |
| 4305 | |
| 4306 | \sa setDecimals() |
| 4307 | */ |
| 4308 | int QtRectFPropertyManager::decimals(const QtProperty *property) const |
| 4309 | { |
| 4310 | return getData<int>(propertyMap: d_ptr->m_values, data: &QtRectFPropertyManagerPrivate::Data::decimals, property, defaultValue: 0); |
| 4311 | } |
| 4312 | |
| 4313 | /*! |
| 4314 | Returns the given \a property's constraining rectangle. If returned value is null QRectF it means there is no constraint applied. |
| 4315 | |
| 4316 | \sa value(), setConstraint() |
| 4317 | */ |
| 4318 | QRectF QtRectFPropertyManager::constraint(const QtProperty *property) const |
| 4319 | { |
| 4320 | return getData<QRectF>(propertyMap: d_ptr->m_values, data: &QtRectFPropertyManagerPrivate::Data::constraint, property, defaultValue: QRect()); |
| 4321 | } |
| 4322 | |
| 4323 | /*! |
| 4324 | \reimp |
| 4325 | */ |
| 4326 | QString QtRectFPropertyManager::valueText(const QtProperty *property) const |
| 4327 | { |
| 4328 | const auto it = d_ptr->m_values.constFind(key: property); |
| 4329 | if (it == d_ptr->m_values.constEnd()) |
| 4330 | return {}; |
| 4331 | const QRectF v = it.value().val; |
| 4332 | const int dec = it.value().decimals; |
| 4333 | return QString(tr(s: "[(%1, %2), %3 x %4]" ).arg(args: QString::number(v.x(), format: 'f', precision: dec), |
| 4334 | args: QString::number(v.y(), format: 'f', precision: dec), |
| 4335 | args: QString::number(v.width(), format: 'f', precision: dec), |
| 4336 | args: QString::number(v.height(), format: 'f', precision: dec))); |
| 4337 | } |
| 4338 | |
| 4339 | /*! |
| 4340 | \fn void QtRectFPropertyManager::setValue(QtProperty *property, const QRectF &value) |
| 4341 | |
| 4342 | Sets the value of the given \a property to \a value. Nested |
| 4343 | properties are updated automatically. |
| 4344 | |
| 4345 | If the specified \a value is not inside the given \a property's |
| 4346 | constraining rectangle, the value is adjusted accordingly to fit |
| 4347 | within the constraint. |
| 4348 | |
| 4349 | \sa value(), setConstraint(), valueChanged() |
| 4350 | */ |
| 4351 | void QtRectFPropertyManager::setValue(QtProperty *property, const QRectF &val) |
| 4352 | { |
| 4353 | const auto it = d_ptr->m_values.find(key: property); |
| 4354 | if (it == d_ptr->m_values.end()) |
| 4355 | return; |
| 4356 | |
| 4357 | QtRectFPropertyManagerPrivate::Data data = it.value(); |
| 4358 | |
| 4359 | QRectF newRect = val.normalized(); |
| 4360 | if (!data.constraint.isNull() && !data.constraint.contains(r: newRect)) { |
| 4361 | const QRectF r1 = data.constraint; |
| 4362 | const QRectF r2 = newRect; |
| 4363 | newRect.setLeft(qMax(a: r1.left(), b: r2.left())); |
| 4364 | newRect.setRight(qMin(a: r1.right(), b: r2.right())); |
| 4365 | newRect.setTop(qMax(a: r1.top(), b: r2.top())); |
| 4366 | newRect.setBottom(qMin(a: r1.bottom(), b: r2.bottom())); |
| 4367 | if (newRect.width() < 0 || newRect.height() < 0) |
| 4368 | return; |
| 4369 | } |
| 4370 | |
| 4371 | if (data.val == newRect) |
| 4372 | return; |
| 4373 | |
| 4374 | data.val = newRect; |
| 4375 | |
| 4376 | it.value() = data; |
| 4377 | d_ptr->m_doublePropertyManager->setValue(property: d_ptr->m_propertyToX[property], val: newRect.x()); |
| 4378 | d_ptr->m_doublePropertyManager->setValue(property: d_ptr->m_propertyToY[property], val: newRect.y()); |
| 4379 | d_ptr->m_doublePropertyManager->setValue(property: d_ptr->m_propertyToW[property], val: newRect.width()); |
| 4380 | d_ptr->m_doublePropertyManager->setValue(property: d_ptr->m_propertyToH[property], val: newRect.height()); |
| 4381 | |
| 4382 | emit propertyChanged(property); |
| 4383 | emit valueChanged(property, val: data.val); |
| 4384 | } |
| 4385 | |
| 4386 | /*! |
| 4387 | Sets the given \a property's constraining rectangle to \a |
| 4388 | constraint. |
| 4389 | |
| 4390 | When setting the constraint, the current value is adjusted if |
| 4391 | necessary (ensuring that the current rectangle value is inside the |
| 4392 | constraint). In order to reset the constraint pass a null QRectF value. |
| 4393 | |
| 4394 | \sa setValue(), constraint(), constraintChanged() |
| 4395 | */ |
| 4396 | void QtRectFPropertyManager::setConstraint(QtProperty *property, const QRectF &constraint) |
| 4397 | { |
| 4398 | const auto it = d_ptr->m_values.find(key: property); |
| 4399 | if (it == d_ptr->m_values.end()) |
| 4400 | return; |
| 4401 | |
| 4402 | QtRectFPropertyManagerPrivate::Data data = it.value(); |
| 4403 | |
| 4404 | QRectF newConstraint = constraint.normalized(); |
| 4405 | if (data.constraint == newConstraint) |
| 4406 | return; |
| 4407 | |
| 4408 | const QRectF oldVal = data.val; |
| 4409 | |
| 4410 | data.constraint = newConstraint; |
| 4411 | |
| 4412 | if (!data.constraint.isNull() && !data.constraint.contains(r: oldVal)) { |
| 4413 | QRectF r1 = data.constraint; |
| 4414 | QRectF r2 = data.val; |
| 4415 | |
| 4416 | if (r2.width() > r1.width()) |
| 4417 | r2.setWidth(r1.width()); |
| 4418 | if (r2.height() > r1.height()) |
| 4419 | r2.setHeight(r1.height()); |
| 4420 | if (r2.left() < r1.left()) |
| 4421 | r2.moveLeft(pos: r1.left()); |
| 4422 | else if (r2.right() > r1.right()) |
| 4423 | r2.moveRight(pos: r1.right()); |
| 4424 | if (r2.top() < r1.top()) |
| 4425 | r2.moveTop(pos: r1.top()); |
| 4426 | else if (r2.bottom() > r1.bottom()) |
| 4427 | r2.moveBottom(pos: r1.bottom()); |
| 4428 | |
| 4429 | data.val = r2; |
| 4430 | } |
| 4431 | |
| 4432 | it.value() = data; |
| 4433 | |
| 4434 | emit constraintChanged(property, constraint: data.constraint); |
| 4435 | |
| 4436 | d_ptr->setConstraint(property, constraint: data.constraint, val: data.val); |
| 4437 | |
| 4438 | if (data.val == oldVal) |
| 4439 | return; |
| 4440 | |
| 4441 | emit propertyChanged(property); |
| 4442 | emit valueChanged(property, val: data.val); |
| 4443 | } |
| 4444 | |
| 4445 | /*! |
| 4446 | \fn void QtRectFPropertyManager::setDecimals(QtProperty *property, int prec) |
| 4447 | |
| 4448 | Sets the precision of the given \a property to \a prec. |
| 4449 | |
| 4450 | The valid decimal range is 0-13. The default is 2. |
| 4451 | |
| 4452 | \sa decimals() |
| 4453 | */ |
| 4454 | void QtRectFPropertyManager::setDecimals(QtProperty *property, int prec) |
| 4455 | { |
| 4456 | const auto it = d_ptr->m_values.find(key: property); |
| 4457 | if (it == d_ptr->m_values.end()) |
| 4458 | return; |
| 4459 | |
| 4460 | QtRectFPropertyManagerPrivate::Data data = it.value(); |
| 4461 | |
| 4462 | if (prec > 13) |
| 4463 | prec = 13; |
| 4464 | else if (prec < 0) |
| 4465 | prec = 0; |
| 4466 | |
| 4467 | if (data.decimals == prec) |
| 4468 | return; |
| 4469 | |
| 4470 | data.decimals = prec; |
| 4471 | d_ptr->m_doublePropertyManager->setDecimals(property: d_ptr->m_propertyToX[property], prec); |
| 4472 | d_ptr->m_doublePropertyManager->setDecimals(property: d_ptr->m_propertyToY[property], prec); |
| 4473 | d_ptr->m_doublePropertyManager->setDecimals(property: d_ptr->m_propertyToW[property], prec); |
| 4474 | d_ptr->m_doublePropertyManager->setDecimals(property: d_ptr->m_propertyToH[property], prec); |
| 4475 | |
| 4476 | it.value() = data; |
| 4477 | |
| 4478 | emit decimalsChanged(property, prec: data.decimals); |
| 4479 | } |
| 4480 | |
| 4481 | /*! |
| 4482 | \reimp |
| 4483 | */ |
| 4484 | void QtRectFPropertyManager::initializeProperty(QtProperty *property) |
| 4485 | { |
| 4486 | d_ptr->m_values[property] = QtRectFPropertyManagerPrivate::Data(); |
| 4487 | |
| 4488 | QtProperty *xProp = d_ptr->m_doublePropertyManager->addProperty(); |
| 4489 | xProp->setPropertyName(tr(s: "X" )); |
| 4490 | d_ptr->m_doublePropertyManager->setDecimals(property: xProp, prec: decimals(property)); |
| 4491 | d_ptr->m_doublePropertyManager->setValue(property: xProp, val: 0); |
| 4492 | d_ptr->m_propertyToX[property] = xProp; |
| 4493 | d_ptr->m_xToProperty[xProp] = property; |
| 4494 | property->addSubProperty(property: xProp); |
| 4495 | |
| 4496 | QtProperty *yProp = d_ptr->m_doublePropertyManager->addProperty(); |
| 4497 | yProp->setPropertyName(tr(s: "Y" )); |
| 4498 | d_ptr->m_doublePropertyManager->setDecimals(property: yProp, prec: decimals(property)); |
| 4499 | d_ptr->m_doublePropertyManager->setValue(property: yProp, val: 0); |
| 4500 | d_ptr->m_propertyToY[property] = yProp; |
| 4501 | d_ptr->m_yToProperty[yProp] = property; |
| 4502 | property->addSubProperty(property: yProp); |
| 4503 | |
| 4504 | QtProperty *wProp = d_ptr->m_doublePropertyManager->addProperty(); |
| 4505 | wProp->setPropertyName(tr(s: "Width" )); |
| 4506 | d_ptr->m_doublePropertyManager->setDecimals(property: wProp, prec: decimals(property)); |
| 4507 | d_ptr->m_doublePropertyManager->setValue(property: wProp, val: 0); |
| 4508 | d_ptr->m_doublePropertyManager->setMinimum(property: wProp, minVal: 0); |
| 4509 | d_ptr->m_propertyToW[property] = wProp; |
| 4510 | d_ptr->m_wToProperty[wProp] = property; |
| 4511 | property->addSubProperty(property: wProp); |
| 4512 | |
| 4513 | QtProperty *hProp = d_ptr->m_doublePropertyManager->addProperty(); |
| 4514 | hProp->setPropertyName(tr(s: "Height" )); |
| 4515 | d_ptr->m_doublePropertyManager->setDecimals(property: hProp, prec: decimals(property)); |
| 4516 | d_ptr->m_doublePropertyManager->setValue(property: hProp, val: 0); |
| 4517 | d_ptr->m_doublePropertyManager->setMinimum(property: hProp, minVal: 0); |
| 4518 | d_ptr->m_propertyToH[property] = hProp; |
| 4519 | d_ptr->m_hToProperty[hProp] = property; |
| 4520 | property->addSubProperty(property: hProp); |
| 4521 | } |
| 4522 | |
| 4523 | /*! |
| 4524 | \reimp |
| 4525 | */ |
| 4526 | void QtRectFPropertyManager::uninitializeProperty(QtProperty *property) |
| 4527 | { |
| 4528 | QtProperty *xProp = d_ptr->m_propertyToX[property]; |
| 4529 | if (xProp) { |
| 4530 | d_ptr->m_xToProperty.remove(key: xProp); |
| 4531 | delete xProp; |
| 4532 | } |
| 4533 | d_ptr->m_propertyToX.remove(key: property); |
| 4534 | |
| 4535 | QtProperty *yProp = d_ptr->m_propertyToY[property]; |
| 4536 | if (yProp) { |
| 4537 | d_ptr->m_yToProperty.remove(key: yProp); |
| 4538 | delete yProp; |
| 4539 | } |
| 4540 | d_ptr->m_propertyToY.remove(key: property); |
| 4541 | |
| 4542 | QtProperty *wProp = d_ptr->m_propertyToW[property]; |
| 4543 | if (wProp) { |
| 4544 | d_ptr->m_wToProperty.remove(key: wProp); |
| 4545 | delete wProp; |
| 4546 | } |
| 4547 | d_ptr->m_propertyToW.remove(key: property); |
| 4548 | |
| 4549 | QtProperty *hProp = d_ptr->m_propertyToH[property]; |
| 4550 | if (hProp) { |
| 4551 | d_ptr->m_hToProperty.remove(key: hProp); |
| 4552 | delete hProp; |
| 4553 | } |
| 4554 | d_ptr->m_propertyToH.remove(key: property); |
| 4555 | |
| 4556 | d_ptr->m_values.remove(key: property); |
| 4557 | } |
| 4558 | |
| 4559 | // QtEnumPropertyManager |
| 4560 | |
| 4561 | class QtEnumPropertyManagerPrivate |
| 4562 | { |
| 4563 | QtEnumPropertyManager *q_ptr = nullptr; |
| 4564 | Q_DECLARE_PUBLIC(QtEnumPropertyManager) |
| 4565 | public: |
| 4566 | |
| 4567 | struct Data |
| 4568 | { |
| 4569 | int val{-1}; |
| 4570 | QStringList enumNames; |
| 4571 | QMap<int, QIcon> enumIcons; |
| 4572 | }; |
| 4573 | |
| 4574 | QHash<const QtProperty *, Data> m_values; |
| 4575 | }; |
| 4576 | |
| 4577 | /*! |
| 4578 | \class QtEnumPropertyManager |
| 4579 | \internal |
| 4580 | \inmodule QtDesigner |
| 4581 | \since 4.4 |
| 4582 | |
| 4583 | \brief The QtEnumPropertyManager provides and manages enum properties. |
| 4584 | |
| 4585 | Each enum property has an associated list of enum names which can |
| 4586 | be retrieved using the enumNames() function, and set using the |
| 4587 | corresponding setEnumNames() function. An enum property's value is |
| 4588 | represented by an index in this list, and can be retrieved and set |
| 4589 | using the value() and setValue() slots respectively. |
| 4590 | |
| 4591 | Each enum value can also have an associated icon. The mapping from |
| 4592 | values to icons can be set using the setEnumIcons() function and |
| 4593 | queried with the enumIcons() function. |
| 4594 | |
| 4595 | In addition, QtEnumPropertyManager provides the valueChanged() signal |
| 4596 | which is emitted whenever a property created by this manager |
| 4597 | changes. The enumNamesChanged() or enumIconsChanged() signal is emitted |
| 4598 | whenever the list of enum names or icons is altered. |
| 4599 | |
| 4600 | \sa QtAbstractPropertyManager, QtEnumEditorFactory |
| 4601 | */ |
| 4602 | |
| 4603 | /*! |
| 4604 | \fn void QtEnumPropertyManager::valueChanged(QtProperty *property, int value) |
| 4605 | |
| 4606 | This signal is emitted whenever a property created by this manager |
| 4607 | changes its value, passing a pointer to the \a property and the new |
| 4608 | \a value as parameters. |
| 4609 | |
| 4610 | \sa setValue() |
| 4611 | */ |
| 4612 | |
| 4613 | /*! |
| 4614 | \fn void QtEnumPropertyManager::enumNamesChanged(QtProperty *property, const QStringList &names) |
| 4615 | |
| 4616 | This signal is emitted whenever a property created by this manager |
| 4617 | changes its enum names, passing a pointer to the \a property and |
| 4618 | the new \a names as parameters. |
| 4619 | |
| 4620 | \sa setEnumNames() |
| 4621 | */ |
| 4622 | |
| 4623 | /*! |
| 4624 | \fn void QtEnumPropertyManager::enumIconsChanged(QtProperty *property, const QMap<int, QIcon> &icons) |
| 4625 | |
| 4626 | This signal is emitted whenever a property created by this manager |
| 4627 | changes its enum icons, passing a pointer to the \a property and |
| 4628 | the new mapping of values to \a icons as parameters. |
| 4629 | |
| 4630 | \sa setEnumIcons() |
| 4631 | */ |
| 4632 | |
| 4633 | /*! |
| 4634 | Creates a manager with the given \a parent. |
| 4635 | */ |
| 4636 | QtEnumPropertyManager::QtEnumPropertyManager(QObject *parent) |
| 4637 | : QtAbstractPropertyManager(parent), d_ptr(new QtEnumPropertyManagerPrivate) |
| 4638 | { |
| 4639 | d_ptr->q_ptr = this; |
| 4640 | } |
| 4641 | |
| 4642 | /*! |
| 4643 | Destroys this manager, and all the properties it has created. |
| 4644 | */ |
| 4645 | QtEnumPropertyManager::~QtEnumPropertyManager() |
| 4646 | { |
| 4647 | clear(); |
| 4648 | } |
| 4649 | |
| 4650 | /*! |
| 4651 | Returns the given \a property's value which is an index in the |
| 4652 | list returned by enumNames() |
| 4653 | |
| 4654 | If the given property is not managed by this manager, this |
| 4655 | function returns -1. |
| 4656 | |
| 4657 | \sa enumNames(), setValue() |
| 4658 | */ |
| 4659 | int QtEnumPropertyManager::value(const QtProperty *property) const |
| 4660 | { |
| 4661 | return getValue<int>(propertyMap: d_ptr->m_values, property, defaultValue: -1); |
| 4662 | } |
| 4663 | |
| 4664 | /*! |
| 4665 | Returns the given \a property's list of enum names. |
| 4666 | |
| 4667 | \sa value(), setEnumNames() |
| 4668 | */ |
| 4669 | QStringList QtEnumPropertyManager::enumNames(const QtProperty *property) const |
| 4670 | { |
| 4671 | return getData<QStringList>(propertyMap: d_ptr->m_values, data: &QtEnumPropertyManagerPrivate::Data::enumNames, property, defaultValue: QStringList()); |
| 4672 | } |
| 4673 | |
| 4674 | /*! |
| 4675 | Returns the given \a property's map of enum values to their icons. |
| 4676 | |
| 4677 | \sa value(), setEnumIcons() |
| 4678 | */ |
| 4679 | QMap<int, QIcon> QtEnumPropertyManager::enumIcons(const QtProperty *property) const |
| 4680 | { |
| 4681 | return getData<QMap<int, QIcon> >(propertyMap: d_ptr->m_values, data: &QtEnumPropertyManagerPrivate::Data::enumIcons, property, defaultValue: QMap<int, QIcon>()); |
| 4682 | } |
| 4683 | |
| 4684 | /*! |
| 4685 | \reimp |
| 4686 | */ |
| 4687 | QString QtEnumPropertyManager::valueText(const QtProperty *property) const |
| 4688 | { |
| 4689 | const auto it = d_ptr->m_values.constFind(key: property); |
| 4690 | if (it == d_ptr->m_values.constEnd()) |
| 4691 | return {}; |
| 4692 | |
| 4693 | const QtEnumPropertyManagerPrivate::Data &data = it.value(); |
| 4694 | |
| 4695 | const int v = data.val; |
| 4696 | if (v >= 0 && v < data.enumNames.size()) |
| 4697 | return data.enumNames.at(i: v); |
| 4698 | return {}; |
| 4699 | } |
| 4700 | |
| 4701 | /*! |
| 4702 | \reimp |
| 4703 | */ |
| 4704 | QIcon QtEnumPropertyManager::valueIcon(const QtProperty *property) const |
| 4705 | { |
| 4706 | const auto it = d_ptr->m_values.constFind(key: property); |
| 4707 | if (it == d_ptr->m_values.constEnd()) |
| 4708 | return {}; |
| 4709 | |
| 4710 | const QtEnumPropertyManagerPrivate::Data &data = it.value(); |
| 4711 | |
| 4712 | const int v = data.val; |
| 4713 | return data.enumIcons.value(key: v); |
| 4714 | } |
| 4715 | |
| 4716 | /*! |
| 4717 | \fn void QtEnumPropertyManager::setValue(QtProperty *property, int value) |
| 4718 | |
| 4719 | Sets the value of the given \a property to \a value. |
| 4720 | |
| 4721 | The specified \a value must be less than the size of the given \a |
| 4722 | property's enumNames() list, and larger than (or equal to) 0. |
| 4723 | |
| 4724 | \sa value(), valueChanged() |
| 4725 | */ |
| 4726 | void QtEnumPropertyManager::setValue(QtProperty *property, int val) |
| 4727 | { |
| 4728 | const auto it = d_ptr->m_values.find(key: property); |
| 4729 | if (it == d_ptr->m_values.end()) |
| 4730 | return; |
| 4731 | |
| 4732 | QtEnumPropertyManagerPrivate::Data data = it.value(); |
| 4733 | |
| 4734 | if (val >= data.enumNames.size()) |
| 4735 | return; |
| 4736 | |
| 4737 | if (val < 0 && !data.enumNames.empty()) |
| 4738 | return; |
| 4739 | |
| 4740 | if (val < 0) |
| 4741 | val = -1; |
| 4742 | |
| 4743 | if (data.val == val) |
| 4744 | return; |
| 4745 | |
| 4746 | data.val = val; |
| 4747 | |
| 4748 | it.value() = data; |
| 4749 | |
| 4750 | emit propertyChanged(property); |
| 4751 | emit valueChanged(property, val: data.val); |
| 4752 | } |
| 4753 | |
| 4754 | /*! |
| 4755 | Sets the given \a property's list of enum names to \a |
| 4756 | enumNames. The \a property's current value is reset to 0 |
| 4757 | indicating the first item of the list. |
| 4758 | |
| 4759 | If the specified \a enumNames list is empty, the \a property's |
| 4760 | current value is set to -1. |
| 4761 | |
| 4762 | \sa enumNames(), enumNamesChanged() |
| 4763 | */ |
| 4764 | void QtEnumPropertyManager::setEnumNames(QtProperty *property, const QStringList &enumNames) |
| 4765 | { |
| 4766 | const auto it = d_ptr->m_values.find(key: property); |
| 4767 | if (it == d_ptr->m_values.end()) |
| 4768 | return; |
| 4769 | |
| 4770 | QtEnumPropertyManagerPrivate::Data data = it.value(); |
| 4771 | |
| 4772 | if (data.enumNames == enumNames) |
| 4773 | return; |
| 4774 | |
| 4775 | data.enumNames = enumNames; |
| 4776 | |
| 4777 | data.val = -1; |
| 4778 | |
| 4779 | if (!enumNames.empty()) |
| 4780 | data.val = 0; |
| 4781 | |
| 4782 | it.value() = data; |
| 4783 | |
| 4784 | emit enumNamesChanged(property, names: data.enumNames); |
| 4785 | |
| 4786 | emit propertyChanged(property); |
| 4787 | emit valueChanged(property, val: data.val); |
| 4788 | } |
| 4789 | |
| 4790 | /*! |
| 4791 | Sets the given \a property's map of enum values to their icons to \a |
| 4792 | enumIcons. |
| 4793 | |
| 4794 | Each enum value can have associated icon. This association is represented with passed \a enumIcons map. |
| 4795 | |
| 4796 | \sa enumNames(), enumNamesChanged() |
| 4797 | */ |
| 4798 | void QtEnumPropertyManager::setEnumIcons(QtProperty *property, const QMap<int, QIcon> &enumIcons) |
| 4799 | { |
| 4800 | const auto it = d_ptr->m_values.find(key: property); |
| 4801 | if (it == d_ptr->m_values.end()) |
| 4802 | return; |
| 4803 | |
| 4804 | it.value().enumIcons = enumIcons; |
| 4805 | |
| 4806 | emit enumIconsChanged(property, icons: it.value().enumIcons); |
| 4807 | |
| 4808 | emit propertyChanged(property); |
| 4809 | } |
| 4810 | |
| 4811 | /*! |
| 4812 | \reimp |
| 4813 | */ |
| 4814 | void QtEnumPropertyManager::initializeProperty(QtProperty *property) |
| 4815 | { |
| 4816 | d_ptr->m_values[property] = QtEnumPropertyManagerPrivate::Data(); |
| 4817 | } |
| 4818 | |
| 4819 | /*! |
| 4820 | \reimp |
| 4821 | */ |
| 4822 | void QtEnumPropertyManager::uninitializeProperty(QtProperty *property) |
| 4823 | { |
| 4824 | d_ptr->m_values.remove(key: property); |
| 4825 | } |
| 4826 | |
| 4827 | // QtFlagPropertyManager |
| 4828 | |
| 4829 | class QtFlagPropertyManagerPrivate |
| 4830 | { |
| 4831 | QtFlagPropertyManager *q_ptr = nullptr; |
| 4832 | Q_DECLARE_PUBLIC(QtFlagPropertyManager) |
| 4833 | public: |
| 4834 | |
| 4835 | void slotBoolChanged(QtProperty *property, bool value); |
| 4836 | void slotPropertyDestroyed(QtProperty *property); |
| 4837 | |
| 4838 | struct Data |
| 4839 | { |
| 4840 | int val{-1}; |
| 4841 | QStringList flagNames; |
| 4842 | }; |
| 4843 | |
| 4844 | QHash<const QtProperty *, Data> m_values; |
| 4845 | |
| 4846 | QtBoolPropertyManager *m_boolPropertyManager; |
| 4847 | |
| 4848 | QHash<const QtProperty *, QList<QtProperty *>> m_propertyToFlags; |
| 4849 | |
| 4850 | QHash<const QtProperty *, QtProperty *> m_flagToProperty; |
| 4851 | }; |
| 4852 | |
| 4853 | void QtFlagPropertyManagerPrivate::slotBoolChanged(QtProperty *property, bool value) |
| 4854 | { |
| 4855 | QtProperty *prop = m_flagToProperty.value(key: property, defaultValue: nullptr); |
| 4856 | if (prop == nullptr) |
| 4857 | return; |
| 4858 | |
| 4859 | const auto pfit = m_propertyToFlags.constFind(key: prop); |
| 4860 | if (pfit == m_propertyToFlags.constEnd()) |
| 4861 | return; |
| 4862 | int level = 0; |
| 4863 | for (QtProperty *p : pfit.value()) { |
| 4864 | if (p == property) { |
| 4865 | int v = m_values[prop].val; |
| 4866 | if (value) { |
| 4867 | v |= (1 << level); |
| 4868 | } else { |
| 4869 | v &= ~(1 << level); |
| 4870 | } |
| 4871 | q_ptr->setValue(property: prop, val: v); |
| 4872 | return; |
| 4873 | } |
| 4874 | level++; |
| 4875 | } |
| 4876 | } |
| 4877 | |
| 4878 | void QtFlagPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property) |
| 4879 | { |
| 4880 | QtProperty *flagProperty = m_flagToProperty.value(key: property, defaultValue: nullptr); |
| 4881 | if (flagProperty == nullptr) |
| 4882 | return; |
| 4883 | |
| 4884 | m_propertyToFlags[flagProperty].replace(i: m_propertyToFlags[flagProperty].indexOf(t: property), t: nullptr); |
| 4885 | m_flagToProperty.remove(key: property); |
| 4886 | } |
| 4887 | |
| 4888 | /*! |
| 4889 | \class QtFlagPropertyManager |
| 4890 | \internal |
| 4891 | \inmodule QtDesigner |
| 4892 | \since 4.4 |
| 4893 | |
| 4894 | \brief The QtFlagPropertyManager provides and manages flag properties. |
| 4895 | |
| 4896 | Each flag property has an associated list of flag names which can |
| 4897 | be retrieved using the flagNames() function, and set using the |
| 4898 | corresponding setFlagNames() function. |
| 4899 | |
| 4900 | The flag manager provides properties with nested boolean |
| 4901 | subproperties representing each flag, i.e. a flag property's value |
| 4902 | is the binary combination of the subproperties' values. A |
| 4903 | property's value can be retrieved and set using the value() and |
| 4904 | setValue() slots respectively. The combination of flags is represented |
| 4905 | by single int value - that's why it's possible to store up to |
| 4906 | 32 independent flags in one flag property. |
| 4907 | |
| 4908 | The subproperties are created by a QtBoolPropertyManager object. This |
| 4909 | manager can be retrieved using the subBoolPropertyManager() function. In |
| 4910 | order to provide editing widgets for the subproperties in a |
| 4911 | property browser widget, this manager must be associated with an |
| 4912 | editor factory. |
| 4913 | |
| 4914 | In addition, QtFlagPropertyManager provides the valueChanged() signal |
| 4915 | which is emitted whenever a property created by this manager |
| 4916 | changes, and the flagNamesChanged() signal which is emitted |
| 4917 | whenever the list of flag names is altered. |
| 4918 | |
| 4919 | \sa QtAbstractPropertyManager, QtBoolPropertyManager |
| 4920 | */ |
| 4921 | |
| 4922 | /*! |
| 4923 | \fn void QtFlagPropertyManager::valueChanged(QtProperty *property, int value) |
| 4924 | |
| 4925 | This signal is emitted whenever a property created by this manager |
| 4926 | changes its value, passing a pointer to the \a property and the new |
| 4927 | \a value as parameters. |
| 4928 | |
| 4929 | \sa setValue() |
| 4930 | */ |
| 4931 | |
| 4932 | /*! |
| 4933 | \fn void QtFlagPropertyManager::flagNamesChanged(QtProperty *property, const QStringList &names) |
| 4934 | |
| 4935 | This signal is emitted whenever a property created by this manager |
| 4936 | changes its flag names, passing a pointer to the \a property and the |
| 4937 | new \a names as parameters. |
| 4938 | |
| 4939 | \sa setFlagNames() |
| 4940 | */ |
| 4941 | |
| 4942 | /*! |
| 4943 | Creates a manager with the given \a parent. |
| 4944 | */ |
| 4945 | QtFlagPropertyManager::QtFlagPropertyManager(QObject *parent) |
| 4946 | : QtAbstractPropertyManager(parent), d_ptr(new QtFlagPropertyManagerPrivate) |
| 4947 | { |
| 4948 | d_ptr->q_ptr = this; |
| 4949 | |
| 4950 | d_ptr->m_boolPropertyManager = new QtBoolPropertyManager(this); |
| 4951 | connect(sender: d_ptr->m_boolPropertyManager, signal: &QtBoolPropertyManager::valueChanged, context: this, |
| 4952 | slot: [this](QtProperty *property, bool value) { d_ptr->slotBoolChanged(property, value); }); |
| 4953 | connect(sender: d_ptr->m_boolPropertyManager, signal: &QtAbstractPropertyManager::propertyDestroyed, context: this, |
| 4954 | slot: [this](QtProperty *property) { d_ptr->slotPropertyDestroyed(property); }); |
| 4955 | } |
| 4956 | |
| 4957 | /*! |
| 4958 | Destroys this manager, and all the properties it has created. |
| 4959 | */ |
| 4960 | QtFlagPropertyManager::~QtFlagPropertyManager() |
| 4961 | { |
| 4962 | clear(); |
| 4963 | } |
| 4964 | |
| 4965 | /*! |
| 4966 | Returns the manager that produces the nested boolean subproperties |
| 4967 | representing each flag. |
| 4968 | |
| 4969 | In order to provide editing widgets for the subproperties in a |
| 4970 | property browser widget, this manager must be associated with an |
| 4971 | editor factory. |
| 4972 | |
| 4973 | \sa QtAbstractPropertyBrowser::setFactoryForManager() |
| 4974 | */ |
| 4975 | QtBoolPropertyManager *QtFlagPropertyManager::subBoolPropertyManager() const |
| 4976 | { |
| 4977 | return d_ptr->m_boolPropertyManager; |
| 4978 | } |
| 4979 | |
| 4980 | /*! |
| 4981 | Returns the given \a property's value. |
| 4982 | |
| 4983 | If the given property is not managed by this manager, this |
| 4984 | function returns 0. |
| 4985 | |
| 4986 | \sa flagNames(), setValue() |
| 4987 | */ |
| 4988 | int QtFlagPropertyManager::value(const QtProperty *property) const |
| 4989 | { |
| 4990 | return getValue<int>(propertyMap: d_ptr->m_values, property, defaultValue: 0); |
| 4991 | } |
| 4992 | |
| 4993 | /*! |
| 4994 | Returns the given \a property's list of flag names. |
| 4995 | |
| 4996 | \sa value(), setFlagNames() |
| 4997 | */ |
| 4998 | QStringList QtFlagPropertyManager::flagNames(const QtProperty *property) const |
| 4999 | { |
| 5000 | return getData<QStringList>(propertyMap: d_ptr->m_values, data: &QtFlagPropertyManagerPrivate::Data::flagNames, property, defaultValue: QStringList()); |
| 5001 | } |
| 5002 | |
| 5003 | /*! |
| 5004 | \reimp |
| 5005 | */ |
| 5006 | QString QtFlagPropertyManager::valueText(const QtProperty *property) const |
| 5007 | { |
| 5008 | const auto it = d_ptr->m_values.constFind(key: property); |
| 5009 | if (it == d_ptr->m_values.constEnd()) |
| 5010 | return {}; |
| 5011 | |
| 5012 | const QtFlagPropertyManagerPrivate::Data &data = it.value(); |
| 5013 | |
| 5014 | QString str; |
| 5015 | int level = 0; |
| 5016 | const QChar bar = QLatin1Char('|'); |
| 5017 | for (const auto &name : data.flagNames) { |
| 5018 | if (data.val & (1 << level)) { |
| 5019 | if (!str.isEmpty()) |
| 5020 | str += bar; |
| 5021 | str += name; |
| 5022 | } |
| 5023 | |
| 5024 | level++; |
| 5025 | } |
| 5026 | return str; |
| 5027 | } |
| 5028 | |
| 5029 | /*! |
| 5030 | \fn void QtFlagPropertyManager::setValue(QtProperty *property, int value) |
| 5031 | |
| 5032 | Sets the value of the given \a property to \a value. Nested |
| 5033 | properties are updated automatically. |
| 5034 | |
| 5035 | The specified \a value must be less than the binary combination of |
| 5036 | the property's flagNames() list size (i.e. less than 2\sup n, |
| 5037 | where \c n is the size of the list) and larger than (or equal to) |
| 5038 | 0. |
| 5039 | |
| 5040 | \sa value(), valueChanged() |
| 5041 | */ |
| 5042 | void QtFlagPropertyManager::setValue(QtProperty *property, int val) |
| 5043 | { |
| 5044 | const auto it = d_ptr->m_values.find(key: property); |
| 5045 | if (it == d_ptr->m_values.end()) |
| 5046 | return; |
| 5047 | |
| 5048 | QtFlagPropertyManagerPrivate::Data data = it.value(); |
| 5049 | |
| 5050 | if (data.val == val) |
| 5051 | return; |
| 5052 | |
| 5053 | if (val > (1 << data.flagNames.size()) - 1) |
| 5054 | return; |
| 5055 | |
| 5056 | if (val < 0) |
| 5057 | return; |
| 5058 | |
| 5059 | data.val = val; |
| 5060 | |
| 5061 | it.value() = data; |
| 5062 | |
| 5063 | const auto pfit = d_ptr->m_propertyToFlags.constFind(key: property); |
| 5064 | int level = 0; |
| 5065 | if (pfit != d_ptr->m_propertyToFlags.constEnd()) { |
| 5066 | for (QtProperty *prop : pfit.value()) { |
| 5067 | if (prop) |
| 5068 | d_ptr->m_boolPropertyManager->setValue(property: prop, val: val & (1 << level)); |
| 5069 | level++; |
| 5070 | } |
| 5071 | } |
| 5072 | |
| 5073 | emit propertyChanged(property); |
| 5074 | emit valueChanged(property, val: data.val); |
| 5075 | } |
| 5076 | |
| 5077 | /*! |
| 5078 | Sets the given \a property's list of flag names to \a flagNames. The |
| 5079 | property's current value is reset to 0 indicating the first item |
| 5080 | of the list. |
| 5081 | |
| 5082 | \sa flagNames(), flagNamesChanged() |
| 5083 | */ |
| 5084 | void QtFlagPropertyManager::setFlagNames(QtProperty *property, const QStringList &flagNames) |
| 5085 | { |
| 5086 | const auto it = d_ptr->m_values.find(key: property); |
| 5087 | if (it == d_ptr->m_values.end()) |
| 5088 | return; |
| 5089 | |
| 5090 | QtFlagPropertyManagerPrivate::Data data = it.value(); |
| 5091 | |
| 5092 | if (data.flagNames == flagNames) |
| 5093 | return; |
| 5094 | |
| 5095 | data.flagNames = flagNames; |
| 5096 | data.val = 0; |
| 5097 | |
| 5098 | it.value() = data; |
| 5099 | |
| 5100 | const auto pfit = d_ptr->m_propertyToFlags.find(key: property); |
| 5101 | if (pfit != d_ptr->m_propertyToFlags.end()) { |
| 5102 | for (QtProperty *prop : std::as_const(t&: pfit.value())) { |
| 5103 | if (prop) { |
| 5104 | delete prop; |
| 5105 | d_ptr->m_flagToProperty.remove(key: prop); |
| 5106 | } |
| 5107 | } |
| 5108 | pfit.value().clear(); |
| 5109 | } |
| 5110 | |
| 5111 | for (const QString &flagName : flagNames) { |
| 5112 | QtProperty *prop = d_ptr->m_boolPropertyManager->addProperty(); |
| 5113 | prop->setPropertyName(flagName); |
| 5114 | property->addSubProperty(property: prop); |
| 5115 | d_ptr->m_propertyToFlags[property].append(t: prop); |
| 5116 | d_ptr->m_flagToProperty[prop] = property; |
| 5117 | } |
| 5118 | |
| 5119 | emit flagNamesChanged(property, names: data.flagNames); |
| 5120 | |
| 5121 | emit propertyChanged(property); |
| 5122 | emit valueChanged(property, val: data.val); |
| 5123 | } |
| 5124 | |
| 5125 | /*! |
| 5126 | \reimp |
| 5127 | */ |
| 5128 | void QtFlagPropertyManager::initializeProperty(QtProperty *property) |
| 5129 | { |
| 5130 | d_ptr->m_values[property] = QtFlagPropertyManagerPrivate::Data(); |
| 5131 | |
| 5132 | d_ptr->m_propertyToFlags[property] = QList<QtProperty *>(); |
| 5133 | } |
| 5134 | |
| 5135 | /*! |
| 5136 | \reimp |
| 5137 | */ |
| 5138 | void QtFlagPropertyManager::uninitializeProperty(QtProperty *property) |
| 5139 | { |
| 5140 | const auto it = d_ptr->m_propertyToFlags.find(key: property); |
| 5141 | if (it != d_ptr->m_propertyToFlags.end()) { |
| 5142 | for (QtProperty *prop : std::as_const(t&: it.value())) { |
| 5143 | if (prop) { |
| 5144 | d_ptr->m_flagToProperty.remove(key: prop); |
| 5145 | delete prop; |
| 5146 | } |
| 5147 | } |
| 5148 | } |
| 5149 | d_ptr->m_propertyToFlags.erase(it); |
| 5150 | |
| 5151 | d_ptr->m_values.remove(key: property); |
| 5152 | } |
| 5153 | |
| 5154 | // QtSizePolicyPropertyManager |
| 5155 | |
| 5156 | class QtSizePolicyPropertyManagerPrivate |
| 5157 | { |
| 5158 | QtSizePolicyPropertyManager *q_ptr = nullptr; |
| 5159 | Q_DECLARE_PUBLIC(QtSizePolicyPropertyManager) |
| 5160 | public: |
| 5161 | |
| 5162 | void slotIntChanged(QtProperty *property, int value); |
| 5163 | void slotEnumChanged(QtProperty *property, int value); |
| 5164 | void slotPropertyDestroyed(QtProperty *property); |
| 5165 | |
| 5166 | QHash<const QtProperty *, QSizePolicy> m_values; |
| 5167 | |
| 5168 | QtIntPropertyManager *m_intPropertyManager = nullptr; |
| 5169 | QtEnumPropertyManager *m_enumPropertyManager = nullptr; |
| 5170 | |
| 5171 | QHash<const QtProperty *, QtProperty *> m_propertyToHPolicy; |
| 5172 | QHash<const QtProperty *, QtProperty *> m_propertyToVPolicy; |
| 5173 | QHash<const QtProperty *, QtProperty *> m_propertyToHStretch; |
| 5174 | QHash<const QtProperty *, QtProperty *> m_propertyToVStretch; |
| 5175 | |
| 5176 | QHash<const QtProperty *, QtProperty *> m_hPolicyToProperty; |
| 5177 | QHash<const QtProperty *, QtProperty *> m_vPolicyToProperty; |
| 5178 | QHash<const QtProperty *, QtProperty *> m_hStretchToProperty; |
| 5179 | QHash<const QtProperty *, QtProperty *> m_vStretchToProperty; |
| 5180 | }; |
| 5181 | |
| 5182 | void QtSizePolicyPropertyManagerPrivate::slotIntChanged(QtProperty *property, int value) |
| 5183 | { |
| 5184 | if (QtProperty *prop = m_hStretchToProperty.value(key: property, defaultValue: nullptr)) { |
| 5185 | QSizePolicy sp = m_values[prop]; |
| 5186 | sp.setHorizontalStretch(value); |
| 5187 | q_ptr->setValue(property: prop, val: sp); |
| 5188 | } else if (QtProperty *prop = m_vStretchToProperty.value(key: property, defaultValue: nullptr)) { |
| 5189 | QSizePolicy sp = m_values[prop]; |
| 5190 | sp.setVerticalStretch(value); |
| 5191 | q_ptr->setValue(property: prop, val: sp); |
| 5192 | } |
| 5193 | } |
| 5194 | |
| 5195 | void QtSizePolicyPropertyManagerPrivate::slotEnumChanged(QtProperty *property, int value) |
| 5196 | { |
| 5197 | if (QtProperty *prop = m_hPolicyToProperty.value(key: property, defaultValue: nullptr)) { |
| 5198 | QSizePolicy sp = m_values[prop]; |
| 5199 | sp.setHorizontalPolicy(metaEnumProvider()->indexToSizePolicy(index: value)); |
| 5200 | q_ptr->setValue(property: prop, val: sp); |
| 5201 | } else if (QtProperty *prop = m_vPolicyToProperty.value(key: property, defaultValue: nullptr)) { |
| 5202 | QSizePolicy sp = m_values[prop]; |
| 5203 | sp.setVerticalPolicy(metaEnumProvider()->indexToSizePolicy(index: value)); |
| 5204 | q_ptr->setValue(property: prop, val: sp); |
| 5205 | } |
| 5206 | } |
| 5207 | |
| 5208 | void QtSizePolicyPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property) |
| 5209 | { |
| 5210 | if (QtProperty *pointProp = m_hStretchToProperty.value(key: property, defaultValue: nullptr)) { |
| 5211 | m_propertyToHStretch[pointProp] = nullptr; |
| 5212 | m_hStretchToProperty.remove(key: property); |
| 5213 | } else if (QtProperty *pointProp = m_vStretchToProperty.value(key: property, defaultValue: nullptr)) { |
| 5214 | m_propertyToVStretch[pointProp] = nullptr; |
| 5215 | m_vStretchToProperty.remove(key: property); |
| 5216 | } else if (QtProperty *pointProp = m_hPolicyToProperty.value(key: property, defaultValue: nullptr)) { |
| 5217 | m_propertyToHPolicy[pointProp] = nullptr; |
| 5218 | m_hPolicyToProperty.remove(key: property); |
| 5219 | } else if (QtProperty *pointProp = m_vPolicyToProperty.value(key: property, defaultValue: nullptr)) { |
| 5220 | m_propertyToVPolicy[pointProp] = nullptr; |
| 5221 | m_vPolicyToProperty.remove(key: property); |
| 5222 | } |
| 5223 | } |
| 5224 | |
| 5225 | /*! |
| 5226 | \class QtSizePolicyPropertyManager |
| 5227 | \internal |
| 5228 | \inmodule QtDesigner |
| 5229 | \since 4.4 |
| 5230 | |
| 5231 | \brief The QtSizePolicyPropertyManager provides and manages QSizePolicy properties. |
| 5232 | |
| 5233 | A size policy property has nested \e horizontalPolicy, \e |
| 5234 | verticalPolicy, \e horizontalStretch and \e verticalStretch |
| 5235 | subproperties. The top-level property's value can be retrieved |
| 5236 | using the value() function, and set using the setValue() slot. |
| 5237 | |
| 5238 | The subproperties are created by QtIntPropertyManager and QtEnumPropertyManager |
| 5239 | objects. These managers can be retrieved using the subIntPropertyManager() |
| 5240 | and subEnumPropertyManager() functions respectively. In order to provide |
| 5241 | editing widgets for the subproperties in a property browser widget, |
| 5242 | these managers must be associated with editor factories. |
| 5243 | |
| 5244 | In addition, QtSizePolicyPropertyManager provides the valueChanged() |
| 5245 | signal which is emitted whenever a property created by this |
| 5246 | manager changes. |
| 5247 | |
| 5248 | \sa QtAbstractPropertyManager, QtIntPropertyManager, QtEnumPropertyManager |
| 5249 | */ |
| 5250 | |
| 5251 | /*! |
| 5252 | \fn void QtSizePolicyPropertyManager::valueChanged(QtProperty *property, const QSizePolicy &value) |
| 5253 | |
| 5254 | This signal is emitted whenever a property created by this manager |
| 5255 | changes its value, passing a pointer to the \a property and the |
| 5256 | new \a value as parameters. |
| 5257 | |
| 5258 | \sa setValue() |
| 5259 | */ |
| 5260 | |
| 5261 | /*! |
| 5262 | Creates a manager with the given \a parent. |
| 5263 | */ |
| 5264 | QtSizePolicyPropertyManager::QtSizePolicyPropertyManager(QObject *parent) |
| 5265 | : QtAbstractPropertyManager(parent), d_ptr(new QtSizePolicyPropertyManagerPrivate) |
| 5266 | { |
| 5267 | d_ptr->q_ptr = this; |
| 5268 | |
| 5269 | d_ptr->m_intPropertyManager = new QtIntPropertyManager(this); |
| 5270 | connect(sender: d_ptr->m_intPropertyManager, signal: &QtIntPropertyManager::valueChanged, context: this, |
| 5271 | slot: [this](QtProperty *property, int value) { d_ptr->slotIntChanged(property, value); }); |
| 5272 | connect(sender: d_ptr->m_intPropertyManager, signal: &QtAbstractPropertyManager::propertyDestroyed, context: this, |
| 5273 | slot: [this](QtProperty *property) { d_ptr->slotPropertyDestroyed(property); }); |
| 5274 | |
| 5275 | d_ptr->m_enumPropertyManager = new QtEnumPropertyManager(this); |
| 5276 | connect(sender: d_ptr->m_enumPropertyManager, signal: &QtEnumPropertyManager::valueChanged, context: this, |
| 5277 | slot: [this](QtProperty *property, int value) { d_ptr->slotEnumChanged(property, value); }); |
| 5278 | connect(sender: d_ptr->m_enumPropertyManager, signal: &QtEnumPropertyManager::propertyDestroyed, context: this, |
| 5279 | slot: [this](QtProperty *property) { d_ptr->slotPropertyDestroyed(property); }); |
| 5280 | } |
| 5281 | |
| 5282 | /*! |
| 5283 | Destroys this manager, and all the properties it has created. |
| 5284 | */ |
| 5285 | QtSizePolicyPropertyManager::~QtSizePolicyPropertyManager() |
| 5286 | { |
| 5287 | clear(); |
| 5288 | } |
| 5289 | |
| 5290 | /*! |
| 5291 | Returns the manager that creates the nested \e horizontalStretch |
| 5292 | and \e verticalStretch subproperties. |
| 5293 | |
| 5294 | In order to provide editing widgets for the mentioned subproperties |
| 5295 | in a property browser widget, this manager must be associated with |
| 5296 | an editor factory. |
| 5297 | |
| 5298 | \sa QtAbstractPropertyBrowser::setFactoryForManager() |
| 5299 | */ |
| 5300 | QtIntPropertyManager *QtSizePolicyPropertyManager::subIntPropertyManager() const |
| 5301 | { |
| 5302 | return d_ptr->m_intPropertyManager; |
| 5303 | } |
| 5304 | |
| 5305 | /*! |
| 5306 | Returns the manager that creates the nested \e horizontalPolicy |
| 5307 | and \e verticalPolicy subproperties. |
| 5308 | |
| 5309 | In order to provide editing widgets for the mentioned subproperties |
| 5310 | in a property browser widget, this manager must be associated with |
| 5311 | an editor factory. |
| 5312 | |
| 5313 | \sa QtAbstractPropertyBrowser::setFactoryForManager() |
| 5314 | */ |
| 5315 | QtEnumPropertyManager *QtSizePolicyPropertyManager::subEnumPropertyManager() const |
| 5316 | { |
| 5317 | return d_ptr->m_enumPropertyManager; |
| 5318 | } |
| 5319 | |
| 5320 | /*! |
| 5321 | Returns the given \a property's value. |
| 5322 | |
| 5323 | If the given property is not managed by this manager, this |
| 5324 | function returns the default size policy. |
| 5325 | |
| 5326 | \sa setValue() |
| 5327 | */ |
| 5328 | QSizePolicy QtSizePolicyPropertyManager::value(const QtProperty *property) const |
| 5329 | { |
| 5330 | return d_ptr->m_values.value(key: property, defaultValue: QSizePolicy()); |
| 5331 | } |
| 5332 | |
| 5333 | /*! |
| 5334 | \reimp |
| 5335 | */ |
| 5336 | QString QtSizePolicyPropertyManager::valueText(const QtProperty *property) const |
| 5337 | { |
| 5338 | const auto it = d_ptr->m_values.constFind(key: property); |
| 5339 | if (it == d_ptr->m_values.constEnd()) |
| 5340 | return {}; |
| 5341 | |
| 5342 | const QSizePolicy sp = it.value(); |
| 5343 | const QtMetaEnumProvider *mep = metaEnumProvider(); |
| 5344 | const int hIndex = mep->sizePolicyToIndex(policy: sp.horizontalPolicy()); |
| 5345 | const int vIndex = mep->sizePolicyToIndex(policy: sp.verticalPolicy()); |
| 5346 | //! Unknown size policy on reading invalid uic3 files |
| 5347 | const QString hPolicy = hIndex != -1 ? mep->policyEnumNames().at(i: hIndex) : tr(s: "<Invalid>" ); |
| 5348 | const QString vPolicy = vIndex != -1 ? mep->policyEnumNames().at(i: vIndex) : tr(s: "<Invalid>" ); |
| 5349 | const QString str = tr(s: "[%1, %2, %3, %4]" ).arg(args: hPolicy, args: vPolicy).arg(a: sp.horizontalStretch()).arg(a: sp.verticalStretch()); |
| 5350 | return str; |
| 5351 | } |
| 5352 | |
| 5353 | /*! |
| 5354 | \fn void QtSizePolicyPropertyManager::setValue(QtProperty *property, const QSizePolicy &value) |
| 5355 | |
| 5356 | Sets the value of the given \a property to \a value. Nested |
| 5357 | properties are updated automatically. |
| 5358 | |
| 5359 | \sa value(), valueChanged() |
| 5360 | */ |
| 5361 | void QtSizePolicyPropertyManager::setValue(QtProperty *property, QSizePolicy val) |
| 5362 | { |
| 5363 | const auto it = d_ptr->m_values.find(key: property); |
| 5364 | if (it == d_ptr->m_values.end()) |
| 5365 | return; |
| 5366 | |
| 5367 | if (it.value() == val) |
| 5368 | return; |
| 5369 | |
| 5370 | it.value() = val; |
| 5371 | |
| 5372 | d_ptr->m_enumPropertyManager->setValue(property: d_ptr->m_propertyToHPolicy[property], |
| 5373 | val: metaEnumProvider()->sizePolicyToIndex(policy: val.horizontalPolicy())); |
| 5374 | d_ptr->m_enumPropertyManager->setValue(property: d_ptr->m_propertyToVPolicy[property], |
| 5375 | val: metaEnumProvider()->sizePolicyToIndex(policy: val.verticalPolicy())); |
| 5376 | d_ptr->m_intPropertyManager->setValue(property: d_ptr->m_propertyToHStretch[property], |
| 5377 | val: val.horizontalStretch()); |
| 5378 | d_ptr->m_intPropertyManager->setValue(property: d_ptr->m_propertyToVStretch[property], |
| 5379 | val: val.verticalStretch()); |
| 5380 | |
| 5381 | emit propertyChanged(property); |
| 5382 | emit valueChanged(property, val); |
| 5383 | } |
| 5384 | |
| 5385 | /*! |
| 5386 | \reimp |
| 5387 | */ |
| 5388 | void QtSizePolicyPropertyManager::initializeProperty(QtProperty *property) |
| 5389 | { |
| 5390 | QSizePolicy val; |
| 5391 | d_ptr->m_values[property] = val; |
| 5392 | |
| 5393 | QtProperty *hPolicyProp = d_ptr->m_enumPropertyManager->addProperty(); |
| 5394 | hPolicyProp->setPropertyName(tr(s: "Horizontal Policy" )); |
| 5395 | d_ptr->m_enumPropertyManager->setEnumNames(property: hPolicyProp, enumNames: metaEnumProvider()->policyEnumNames()); |
| 5396 | d_ptr->m_enumPropertyManager->setValue(property: hPolicyProp, |
| 5397 | val: metaEnumProvider()->sizePolicyToIndex(policy: val.horizontalPolicy())); |
| 5398 | d_ptr->m_propertyToHPolicy[property] = hPolicyProp; |
| 5399 | d_ptr->m_hPolicyToProperty[hPolicyProp] = property; |
| 5400 | property->addSubProperty(property: hPolicyProp); |
| 5401 | |
| 5402 | QtProperty *vPolicyProp = d_ptr->m_enumPropertyManager->addProperty(); |
| 5403 | vPolicyProp->setPropertyName(tr(s: "Vertical Policy" )); |
| 5404 | d_ptr->m_enumPropertyManager->setEnumNames(property: vPolicyProp, enumNames: metaEnumProvider()->policyEnumNames()); |
| 5405 | d_ptr->m_enumPropertyManager->setValue(property: vPolicyProp, |
| 5406 | val: metaEnumProvider()->sizePolicyToIndex(policy: val.verticalPolicy())); |
| 5407 | d_ptr->m_propertyToVPolicy[property] = vPolicyProp; |
| 5408 | d_ptr->m_vPolicyToProperty[vPolicyProp] = property; |
| 5409 | property->addSubProperty(property: vPolicyProp); |
| 5410 | |
| 5411 | QtProperty *hStretchProp = d_ptr->m_intPropertyManager->addProperty(); |
| 5412 | hStretchProp->setPropertyName(tr(s: "Horizontal Stretch" )); |
| 5413 | d_ptr->m_intPropertyManager->setValue(property: hStretchProp, val: val.horizontalStretch()); |
| 5414 | d_ptr->m_intPropertyManager->setRange(property: hStretchProp, minVal: 0, maxVal: 0xff); |
| 5415 | d_ptr->m_propertyToHStretch[property] = hStretchProp; |
| 5416 | d_ptr->m_hStretchToProperty[hStretchProp] = property; |
| 5417 | property->addSubProperty(property: hStretchProp); |
| 5418 | |
| 5419 | QtProperty *vStretchProp = d_ptr->m_intPropertyManager->addProperty(); |
| 5420 | vStretchProp->setPropertyName(tr(s: "Vertical Stretch" )); |
| 5421 | d_ptr->m_intPropertyManager->setValue(property: vStretchProp, val: val.verticalStretch()); |
| 5422 | d_ptr->m_intPropertyManager->setRange(property: vStretchProp, minVal: 0, maxVal: 0xff); |
| 5423 | d_ptr->m_propertyToVStretch[property] = vStretchProp; |
| 5424 | d_ptr->m_vStretchToProperty[vStretchProp] = property; |
| 5425 | property->addSubProperty(property: vStretchProp); |
| 5426 | |
| 5427 | } |
| 5428 | |
| 5429 | /*! |
| 5430 | \reimp |
| 5431 | */ |
| 5432 | void QtSizePolicyPropertyManager::uninitializeProperty(QtProperty *property) |
| 5433 | { |
| 5434 | QtProperty *hPolicyProp = d_ptr->m_propertyToHPolicy[property]; |
| 5435 | if (hPolicyProp) { |
| 5436 | d_ptr->m_hPolicyToProperty.remove(key: hPolicyProp); |
| 5437 | delete hPolicyProp; |
| 5438 | } |
| 5439 | d_ptr->m_propertyToHPolicy.remove(key: property); |
| 5440 | |
| 5441 | QtProperty *vPolicyProp = d_ptr->m_propertyToVPolicy[property]; |
| 5442 | if (vPolicyProp) { |
| 5443 | d_ptr->m_vPolicyToProperty.remove(key: vPolicyProp); |
| 5444 | delete vPolicyProp; |
| 5445 | } |
| 5446 | d_ptr->m_propertyToVPolicy.remove(key: property); |
| 5447 | |
| 5448 | QtProperty *hStretchProp = d_ptr->m_propertyToHStretch[property]; |
| 5449 | if (hStretchProp) { |
| 5450 | d_ptr->m_hStretchToProperty.remove(key: hStretchProp); |
| 5451 | delete hStretchProp; |
| 5452 | } |
| 5453 | d_ptr->m_propertyToHStretch.remove(key: property); |
| 5454 | |
| 5455 | QtProperty *vStretchProp = d_ptr->m_propertyToVStretch[property]; |
| 5456 | if (vStretchProp) { |
| 5457 | d_ptr->m_vStretchToProperty.remove(key: vStretchProp); |
| 5458 | delete vStretchProp; |
| 5459 | } |
| 5460 | d_ptr->m_propertyToVStretch.remove(key: property); |
| 5461 | |
| 5462 | d_ptr->m_values.remove(key: property); |
| 5463 | } |
| 5464 | |
| 5465 | // QtFontPropertyManager: |
| 5466 | // QtFontPropertyManagerPrivate has a mechanism for reacting |
| 5467 | // to QApplication::fontDatabaseChanged() [4.5], which is emitted |
| 5468 | // when someone loads an application font. The signals are compressed |
| 5469 | // using a timer with interval 0, which then causes the family |
| 5470 | // enumeration manager to re-set its strings and index values |
| 5471 | // for each property. |
| 5472 | |
| 5473 | class QtFontPropertyManagerPrivate |
| 5474 | { |
| 5475 | QtFontPropertyManager *q_ptr = nullptr; |
| 5476 | Q_DECLARE_PUBLIC(QtFontPropertyManager) |
| 5477 | public: |
| 5478 | |
| 5479 | void slotIntChanged(QtProperty *property, int value); |
| 5480 | void slotEnumChanged(QtProperty *property, int value); |
| 5481 | void slotBoolChanged(QtProperty *property, bool value); |
| 5482 | void slotPropertyDestroyed(QtProperty *property); |
| 5483 | void slotFontDatabaseChanged(); |
| 5484 | void slotFontDatabaseDelayedChange(); |
| 5485 | |
| 5486 | QStringList m_familyNames; |
| 5487 | |
| 5488 | QHash<const QtProperty *, QFont> m_values; |
| 5489 | |
| 5490 | QtIntPropertyManager *m_intPropertyManager; |
| 5491 | QtEnumPropertyManager *m_enumPropertyManager; |
| 5492 | QtBoolPropertyManager *m_boolPropertyManager; |
| 5493 | |
| 5494 | QHash<const QtProperty *, QtProperty *> m_propertyToFamily; |
| 5495 | QHash<const QtProperty *, QtProperty *> m_propertyToPointSize; |
| 5496 | QHash<const QtProperty *, QtProperty *> m_propertyToBold; |
| 5497 | QHash<const QtProperty *, QtProperty *> m_propertyToItalic; |
| 5498 | QHash<const QtProperty *, QtProperty *> m_propertyToUnderline; |
| 5499 | QHash<const QtProperty *, QtProperty *> m_propertyToStrikeOut; |
| 5500 | QHash<const QtProperty *, QtProperty *> m_propertyToKerning; |
| 5501 | QHash<const QtProperty *, QtProperty *> m_propertyToWeight; |
| 5502 | |
| 5503 | QHash<const QtProperty *, QtProperty *> m_familyToProperty; |
| 5504 | QHash<const QtProperty *, QtProperty *> m_pointSizeToProperty; |
| 5505 | QHash<const QtProperty *, QtProperty *> m_boldToProperty; |
| 5506 | QHash<const QtProperty *, QtProperty *> m_italicToProperty; |
| 5507 | QHash<const QtProperty *, QtProperty *> m_underlineToProperty; |
| 5508 | QHash<const QtProperty *, QtProperty *> m_strikeOutToProperty; |
| 5509 | QHash<const QtProperty *, QtProperty *> m_kerningToProperty; |
| 5510 | QHash<const QtProperty *, QtProperty *> m_weightToProperty; |
| 5511 | |
| 5512 | bool m_settingValue = false; |
| 5513 | QTimer *m_fontDatabaseChangeTimer = nullptr; |
| 5514 | }; |
| 5515 | |
| 5516 | void QtFontPropertyManagerPrivate::slotIntChanged(QtProperty *property, int value) |
| 5517 | { |
| 5518 | if (m_settingValue) |
| 5519 | return; |
| 5520 | if (QtProperty *prop = m_pointSizeToProperty.value(key: property, defaultValue: nullptr)) { |
| 5521 | QFont f = m_values[prop]; |
| 5522 | f.setPointSize(value); |
| 5523 | q_ptr->setValue(property: prop, val: f); |
| 5524 | } |
| 5525 | } |
| 5526 | |
| 5527 | void QtFontPropertyManagerPrivate::slotEnumChanged(QtProperty *property, int value) |
| 5528 | { |
| 5529 | if (m_settingValue) |
| 5530 | return; |
| 5531 | if (QtProperty *prop = m_familyToProperty.value(key: property, defaultValue: nullptr)) { |
| 5532 | QFont f = m_values[prop]; |
| 5533 | f.setFamily(m_familyNames.at(i: value)); |
| 5534 | q_ptr->setValue(property: prop, val: f); |
| 5535 | } else if (auto *prop = m_weightToProperty.value(key: property, defaultValue: nullptr)) { |
| 5536 | QFont f = m_values[prop]; |
| 5537 | f.setWeight(weightFromIndex(i: value)); |
| 5538 | q_ptr->setValue(property: prop, val: f); |
| 5539 | } |
| 5540 | } |
| 5541 | |
| 5542 | void QtFontPropertyManagerPrivate::slotBoolChanged(QtProperty *property, bool value) |
| 5543 | { |
| 5544 | if (m_settingValue) |
| 5545 | return; |
| 5546 | if (QtProperty *prop = m_boldToProperty.value(key: property, defaultValue: nullptr)) { |
| 5547 | QFont f = m_values[prop]; |
| 5548 | f.setBold(value); |
| 5549 | q_ptr->setValue(property: prop, val: f); |
| 5550 | } else if (QtProperty *prop = m_italicToProperty.value(key: property, defaultValue: nullptr)) { |
| 5551 | QFont f = m_values[prop]; |
| 5552 | f.setItalic(value); |
| 5553 | q_ptr->setValue(property: prop, val: f); |
| 5554 | } else if (QtProperty *prop = m_underlineToProperty.value(key: property, defaultValue: nullptr)) { |
| 5555 | QFont f = m_values[prop]; |
| 5556 | f.setUnderline(value); |
| 5557 | q_ptr->setValue(property: prop, val: f); |
| 5558 | } else if (QtProperty *prop = m_strikeOutToProperty.value(key: property, defaultValue: nullptr)) { |
| 5559 | QFont f = m_values[prop]; |
| 5560 | f.setStrikeOut(value); |
| 5561 | q_ptr->setValue(property: prop, val: f); |
| 5562 | } else if (QtProperty *prop = m_kerningToProperty.value(key: property, defaultValue: nullptr)) { |
| 5563 | QFont f = m_values[prop]; |
| 5564 | f.setKerning(value); |
| 5565 | q_ptr->setValue(property: prop, val: f); |
| 5566 | } |
| 5567 | } |
| 5568 | |
| 5569 | void QtFontPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property) |
| 5570 | { |
| 5571 | if (QtProperty *pointProp = m_pointSizeToProperty.value(key: property, defaultValue: nullptr)) { |
| 5572 | m_propertyToPointSize[pointProp] = nullptr; |
| 5573 | m_pointSizeToProperty.remove(key: property); |
| 5574 | } else if (QtProperty *pointProp = m_familyToProperty.value(key: property, defaultValue: nullptr)) { |
| 5575 | m_propertyToFamily[pointProp] = nullptr; |
| 5576 | m_familyToProperty.remove(key: property); |
| 5577 | } else if (QtProperty *pointProp = m_boldToProperty.value(key: property, defaultValue: nullptr)) { |
| 5578 | m_propertyToBold[pointProp] = nullptr; |
| 5579 | m_boldToProperty.remove(key: property); |
| 5580 | } else if (QtProperty *pointProp = m_italicToProperty.value(key: property, defaultValue: nullptr)) { |
| 5581 | m_propertyToItalic[pointProp] = nullptr; |
| 5582 | m_italicToProperty.remove(key: property); |
| 5583 | } else if (QtProperty *pointProp = m_underlineToProperty.value(key: property, defaultValue: nullptr)) { |
| 5584 | m_propertyToUnderline[pointProp] = nullptr; |
| 5585 | m_underlineToProperty.remove(key: property); |
| 5586 | } else if (QtProperty *pointProp = m_strikeOutToProperty.value(key: property, defaultValue: nullptr)) { |
| 5587 | m_propertyToStrikeOut[pointProp] = nullptr; |
| 5588 | m_strikeOutToProperty.remove(key: property); |
| 5589 | } else if (QtProperty *pointProp = m_kerningToProperty.value(key: property, defaultValue: nullptr)) { |
| 5590 | m_propertyToKerning[pointProp] = nullptr; |
| 5591 | m_kerningToProperty.remove(key: property); |
| 5592 | } else if (QtProperty *weightProp = m_weightToProperty.value(key: property, defaultValue: nullptr)) { |
| 5593 | m_propertyToWeight[weightProp] = nullptr; |
| 5594 | m_weightToProperty.remove(key: property); |
| 5595 | } |
| 5596 | } |
| 5597 | |
| 5598 | void QtFontPropertyManagerPrivate::slotFontDatabaseChanged() |
| 5599 | { |
| 5600 | if (!m_fontDatabaseChangeTimer) { |
| 5601 | m_fontDatabaseChangeTimer = new QTimer(q_ptr); |
| 5602 | m_fontDatabaseChangeTimer->setInterval(0); |
| 5603 | m_fontDatabaseChangeTimer->setSingleShot(true); |
| 5604 | QObject::connect(sender: m_fontDatabaseChangeTimer, signal: &QTimer::timeout, context: q_ptr, |
| 5605 | slot: [this] { slotFontDatabaseDelayedChange(); }); |
| 5606 | } |
| 5607 | if (!m_fontDatabaseChangeTimer->isActive()) |
| 5608 | m_fontDatabaseChangeTimer->start(); |
| 5609 | } |
| 5610 | |
| 5611 | void QtFontPropertyManagerPrivate::slotFontDatabaseDelayedChange() |
| 5612 | { |
| 5613 | // rescan available font names |
| 5614 | const QStringList oldFamilies = m_familyNames; |
| 5615 | m_familyNames = QFontDatabase::families(); |
| 5616 | |
| 5617 | // Adapt all existing properties |
| 5618 | if (!m_propertyToFamily.isEmpty()) { |
| 5619 | for (QtProperty *familyProp : std::as_const(t&: m_propertyToFamily)) { |
| 5620 | const int oldIdx = m_enumPropertyManager->value(property: familyProp); |
| 5621 | qsizetype newIdx = m_familyNames.indexOf(str: oldFamilies.at(i: oldIdx)); |
| 5622 | if (newIdx < 0) |
| 5623 | newIdx = 0; |
| 5624 | m_enumPropertyManager->setEnumNames(property: familyProp, enumNames: m_familyNames); |
| 5625 | m_enumPropertyManager->setValue(property: familyProp, val: newIdx); |
| 5626 | } |
| 5627 | } |
| 5628 | } |
| 5629 | |
| 5630 | /*! |
| 5631 | \class QtFontPropertyManager |
| 5632 | \internal |
| 5633 | \inmodule QtDesigner |
| 5634 | \since 4.4 |
| 5635 | |
| 5636 | \brief The QtFontPropertyManager provides and manages QFont properties. |
| 5637 | |
| 5638 | A font property has nested \e family, \e pointSize, \e bold, \e |
| 5639 | italic, \e underline, \e strikeOut and \e kerning subproperties. The top-level |
| 5640 | property's value can be retrieved using the value() function, and |
| 5641 | set using the setValue() slot. |
| 5642 | |
| 5643 | The subproperties are created by QtIntPropertyManager, QtEnumPropertyManager and |
| 5644 | QtBoolPropertyManager objects. These managers can be retrieved using the |
| 5645 | corresponding subIntPropertyManager(), subEnumPropertyManager() and |
| 5646 | subBoolPropertyManager() functions. In order to provide editing widgets |
| 5647 | for the subproperties in a property browser widget, these managers |
| 5648 | must be associated with editor factories. |
| 5649 | |
| 5650 | In addition, QtFontPropertyManager provides the valueChanged() signal |
| 5651 | which is emitted whenever a property created by this manager |
| 5652 | changes. |
| 5653 | |
| 5654 | \sa QtAbstractPropertyManager, QtEnumPropertyManager, QtIntPropertyManager, QtBoolPropertyManager |
| 5655 | */ |
| 5656 | |
| 5657 | /*! |
| 5658 | \fn void QtFontPropertyManager::valueChanged(QtProperty *property, const QFont &value) |
| 5659 | |
| 5660 | This signal is emitted whenever a property created by this manager |
| 5661 | changes its value, passing a pointer to the \a property and the |
| 5662 | new \a value as parameters. |
| 5663 | |
| 5664 | \sa setValue() |
| 5665 | */ |
| 5666 | |
| 5667 | /*! |
| 5668 | Creates a manager with the given \a parent. |
| 5669 | */ |
| 5670 | QtFontPropertyManager::QtFontPropertyManager(QObject *parent) |
| 5671 | : QtAbstractPropertyManager(parent), d_ptr(new QtFontPropertyManagerPrivate) |
| 5672 | { |
| 5673 | d_ptr->q_ptr = this; |
| 5674 | QObject::connect(qApp, signal: &QGuiApplication::fontDatabaseChanged, context: this, |
| 5675 | slot: [this] { d_ptr->slotFontDatabaseChanged(); }); |
| 5676 | |
| 5677 | d_ptr->m_intPropertyManager = new QtIntPropertyManager(this); |
| 5678 | connect(sender: d_ptr->m_intPropertyManager, signal: &QtIntPropertyManager::valueChanged, context: this, |
| 5679 | slot: [this](QtProperty *property, int value) { d_ptr->slotIntChanged(property, value); }); |
| 5680 | connect(sender: d_ptr->m_intPropertyManager, signal: &QtAbstractPropertyManager::propertyDestroyed, context: this, |
| 5681 | slot: [this](QtProperty *property) { d_ptr->slotPropertyDestroyed(property); }); |
| 5682 | |
| 5683 | d_ptr->m_enumPropertyManager = new QtEnumPropertyManager(this); |
| 5684 | connect(sender: d_ptr->m_enumPropertyManager, signal: &QtEnumPropertyManager::valueChanged, context: this, |
| 5685 | slot: [this](QtProperty *property, int value) { d_ptr->slotEnumChanged(property, value); }); |
| 5686 | connect(sender: d_ptr->m_enumPropertyManager, signal: &QtAbstractPropertyManager::propertyDestroyed, context: this, |
| 5687 | slot: [this](QtProperty *property) { d_ptr->slotPropertyDestroyed(property); }); |
| 5688 | |
| 5689 | d_ptr->m_boolPropertyManager = new QtBoolPropertyManager(this); |
| 5690 | connect(sender: d_ptr->m_boolPropertyManager, signal: &QtBoolPropertyManager::valueChanged, context: this, |
| 5691 | slot: [this](QtProperty *property, bool value) { d_ptr->slotBoolChanged(property, value); }); |
| 5692 | connect(sender: d_ptr->m_boolPropertyManager, signal: &QtAbstractPropertyManager::propertyDestroyed, context: this, |
| 5693 | slot: [this](QtProperty *property) { d_ptr->slotPropertyDestroyed(property); }); |
| 5694 | } |
| 5695 | |
| 5696 | /*! |
| 5697 | Destroys this manager, and all the properties it has created. |
| 5698 | */ |
| 5699 | QtFontPropertyManager::~QtFontPropertyManager() |
| 5700 | { |
| 5701 | clear(); |
| 5702 | } |
| 5703 | |
| 5704 | /*! |
| 5705 | Returns the manager that creates the \e pointSize subproperty. |
| 5706 | |
| 5707 | In order to provide editing widgets for the \e pointSize property |
| 5708 | in a property browser widget, this manager must be associated |
| 5709 | with an editor factory. |
| 5710 | |
| 5711 | \sa QtAbstractPropertyBrowser::setFactoryForManager() |
| 5712 | */ |
| 5713 | QtIntPropertyManager *QtFontPropertyManager::subIntPropertyManager() const |
| 5714 | { |
| 5715 | return d_ptr->m_intPropertyManager; |
| 5716 | } |
| 5717 | |
| 5718 | /*! |
| 5719 | Returns the manager that create the \e family subproperty. |
| 5720 | |
| 5721 | In order to provide editing widgets for the \e family property |
| 5722 | in a property browser widget, this manager must be associated |
| 5723 | with an editor factory. |
| 5724 | |
| 5725 | \sa QtAbstractPropertyBrowser::setFactoryForManager() |
| 5726 | */ |
| 5727 | QtEnumPropertyManager *QtFontPropertyManager::subEnumPropertyManager() const |
| 5728 | { |
| 5729 | return d_ptr->m_enumPropertyManager; |
| 5730 | } |
| 5731 | |
| 5732 | /*! |
| 5733 | Returns the manager that creates the \e bold, \e italic, \e underline, |
| 5734 | \e strikeOut and \e kerning subproperties. |
| 5735 | |
| 5736 | In order to provide editing widgets for the mentioned properties |
| 5737 | in a property browser widget, this manager must be associated with |
| 5738 | an editor factory. |
| 5739 | |
| 5740 | \sa QtAbstractPropertyBrowser::setFactoryForManager() |
| 5741 | */ |
| 5742 | QtBoolPropertyManager *QtFontPropertyManager::subBoolPropertyManager() const |
| 5743 | { |
| 5744 | return d_ptr->m_boolPropertyManager; |
| 5745 | } |
| 5746 | |
| 5747 | /*! |
| 5748 | Returns the given \a property's value. |
| 5749 | |
| 5750 | If the given property is not managed by this manager, this |
| 5751 | function returns a font object that uses the application's default |
| 5752 | font. |
| 5753 | |
| 5754 | \sa setValue() |
| 5755 | */ |
| 5756 | QFont QtFontPropertyManager::value(const QtProperty *property) const |
| 5757 | { |
| 5758 | return d_ptr->m_values.value(key: property, defaultValue: QFont()); |
| 5759 | } |
| 5760 | |
| 5761 | /*! |
| 5762 | \reimp |
| 5763 | */ |
| 5764 | QString QtFontPropertyManager::valueText(const QtProperty *property) const |
| 5765 | { |
| 5766 | const auto it = d_ptr->m_values.constFind(key: property); |
| 5767 | if (it == d_ptr->m_values.constEnd()) |
| 5768 | return {}; |
| 5769 | |
| 5770 | return QtPropertyBrowserUtils::fontValueText(f: it.value()); |
| 5771 | } |
| 5772 | |
| 5773 | /*! |
| 5774 | \reimp |
| 5775 | */ |
| 5776 | QIcon QtFontPropertyManager::valueIcon(const QtProperty *property) const |
| 5777 | { |
| 5778 | const auto it = d_ptr->m_values.constFind(key: property); |
| 5779 | if (it == d_ptr->m_values.constEnd()) |
| 5780 | return {}; |
| 5781 | |
| 5782 | return QtPropertyBrowserUtils::fontValueIcon(f: it.value()); |
| 5783 | } |
| 5784 | |
| 5785 | /*! |
| 5786 | \fn void QtFontPropertyManager::setValue(QtProperty *property, const QFont &value) |
| 5787 | |
| 5788 | Sets the value of the given \a property to \a value. Nested |
| 5789 | properties are updated automatically. |
| 5790 | |
| 5791 | \sa value(), valueChanged() |
| 5792 | */ |
| 5793 | void QtFontPropertyManager::setValue(QtProperty *property, const QFont &val) |
| 5794 | { |
| 5795 | const auto it = d_ptr->m_values.find(key: property); |
| 5796 | if (it == d_ptr->m_values.end()) |
| 5797 | return; |
| 5798 | |
| 5799 | const QFont &oldVal = it.value(); |
| 5800 | if (oldVal == val && oldVal.resolveMask() == val.resolveMask()) |
| 5801 | return; |
| 5802 | |
| 5803 | it.value() = val; |
| 5804 | |
| 5805 | qsizetype idx = d_ptr->m_familyNames.indexOf(str: val.family()); |
| 5806 | if (idx == -1) |
| 5807 | idx = 0; |
| 5808 | bool settingValue = d_ptr->m_settingValue; |
| 5809 | d_ptr->m_settingValue = true; |
| 5810 | d_ptr->m_enumPropertyManager->setValue(property: d_ptr->m_propertyToFamily[property], val: idx); |
| 5811 | d_ptr->m_intPropertyManager->setValue(property: d_ptr->m_propertyToPointSize[property], val: val.pointSize()); |
| 5812 | d_ptr->m_boolPropertyManager->setValue(property: d_ptr->m_propertyToBold[property], val: val.bold()); |
| 5813 | d_ptr->m_boolPropertyManager->setValue(property: d_ptr->m_propertyToItalic[property], val: val.italic()); |
| 5814 | d_ptr->m_boolPropertyManager->setValue(property: d_ptr->m_propertyToUnderline[property], val: val.underline()); |
| 5815 | d_ptr->m_boolPropertyManager->setValue(property: d_ptr->m_propertyToStrikeOut[property], val: val.strikeOut()); |
| 5816 | d_ptr->m_boolPropertyManager->setValue(property: d_ptr->m_propertyToKerning[property], val: val.kerning()); |
| 5817 | d_ptr->m_enumPropertyManager->setValue(property: d_ptr->m_propertyToWeight[property], |
| 5818 | val: indexOfFontWeight(w: val.weight())); |
| 5819 | d_ptr->m_settingValue = settingValue; |
| 5820 | |
| 5821 | emit propertyChanged(property); |
| 5822 | emit valueChanged(property, val); |
| 5823 | } |
| 5824 | |
| 5825 | static QStringList fontWeightNames() |
| 5826 | { |
| 5827 | static const DisambiguatedTranslation weightsC[] = { |
| 5828 | QT_TRANSLATE_NOOP3("FontPropertyManager" , "Thin" , "QFont::Weight combo" ), |
| 5829 | QT_TRANSLATE_NOOP3("FontPropertyManager" , "ExtraLight" , "QFont::Weight combo" ), |
| 5830 | QT_TRANSLATE_NOOP3("FontPropertyManager" , "Light" , "QFont::Weight combo" ), |
| 5831 | QT_TRANSLATE_NOOP3("FontPropertyManager" , "Normal" , "QFont::Weight combo" ), |
| 5832 | QT_TRANSLATE_NOOP3("FontPropertyManager" , "Medium" , "QFont::Weight combo" ), |
| 5833 | QT_TRANSLATE_NOOP3("FontPropertyManager" , "DemiBold" , "QFont::Weight combo" ), |
| 5834 | QT_TRANSLATE_NOOP3("FontPropertyManager" , "Bold" , "QFont::Weight combo" ), |
| 5835 | QT_TRANSLATE_NOOP3("FontPropertyManager" , "ExtraBold" , "QFont::Weight combo" ), |
| 5836 | QT_TRANSLATE_NOOP3("FontPropertyManager" , "Black" , "QFont::Weight combo" ) |
| 5837 | }; |
| 5838 | |
| 5839 | QStringList result; |
| 5840 | for (const auto &w : weightsC) |
| 5841 | result.append(t: QCoreApplication::translate(context: "FontPropertyManager" , key: w.first, disambiguation: w.second)); |
| 5842 | return result; |
| 5843 | } |
| 5844 | |
| 5845 | /*! |
| 5846 | \reimp |
| 5847 | */ |
| 5848 | void QtFontPropertyManager::initializeProperty(QtProperty *property) |
| 5849 | { |
| 5850 | QFont val; |
| 5851 | d_ptr->m_values[property] = val; |
| 5852 | |
| 5853 | QtProperty *familyProp = d_ptr->m_enumPropertyManager->addProperty(); |
| 5854 | familyProp->setPropertyName(tr(s: "Family" )); |
| 5855 | if (d_ptr->m_familyNames.isEmpty()) |
| 5856 | d_ptr->m_familyNames = QFontDatabase::families(); |
| 5857 | d_ptr->m_enumPropertyManager->setEnumNames(property: familyProp, enumNames: d_ptr->m_familyNames); |
| 5858 | qsizetype idx = d_ptr->m_familyNames.indexOf(str: val.family()); |
| 5859 | if (idx == -1) |
| 5860 | idx = 0; |
| 5861 | d_ptr->m_enumPropertyManager->setValue(property: familyProp, val: idx); |
| 5862 | d_ptr->m_propertyToFamily[property] = familyProp; |
| 5863 | d_ptr->m_familyToProperty[familyProp] = property; |
| 5864 | property->addSubProperty(property: familyProp); |
| 5865 | |
| 5866 | QtProperty *pointSizeProp = d_ptr->m_intPropertyManager->addProperty(); |
| 5867 | pointSizeProp->setPropertyName(tr(s: "Point Size" )); |
| 5868 | d_ptr->m_intPropertyManager->setValue(property: pointSizeProp, val: val.pointSize()); |
| 5869 | d_ptr->m_intPropertyManager->setMinimum(property: pointSizeProp, minVal: 1); |
| 5870 | d_ptr->m_propertyToPointSize[property] = pointSizeProp; |
| 5871 | d_ptr->m_pointSizeToProperty[pointSizeProp] = property; |
| 5872 | property->addSubProperty(property: pointSizeProp); |
| 5873 | |
| 5874 | QtProperty *boldProp = d_ptr->m_boolPropertyManager->addProperty(); |
| 5875 | boldProp->setPropertyName(tr(s: "Bold" , c: "Bold toggle" )); |
| 5876 | d_ptr->m_boolPropertyManager->setValue(property: boldProp, val: val.bold()); |
| 5877 | d_ptr->m_propertyToBold[property] = boldProp; |
| 5878 | d_ptr->m_boldToProperty[boldProp] = property; |
| 5879 | property->addSubProperty(property: boldProp); |
| 5880 | |
| 5881 | QtProperty *italicProp = d_ptr->m_boolPropertyManager->addProperty(); |
| 5882 | italicProp->setPropertyName(tr(s: "Italic" )); |
| 5883 | d_ptr->m_boolPropertyManager->setValue(property: italicProp, val: val.italic()); |
| 5884 | d_ptr->m_propertyToItalic[property] = italicProp; |
| 5885 | d_ptr->m_italicToProperty[italicProp] = property; |
| 5886 | property->addSubProperty(property: italicProp); |
| 5887 | |
| 5888 | QtProperty *underlineProp = d_ptr->m_boolPropertyManager->addProperty(); |
| 5889 | underlineProp->setPropertyName(tr(s: "Underline" )); |
| 5890 | d_ptr->m_boolPropertyManager->setValue(property: underlineProp, val: val.underline()); |
| 5891 | d_ptr->m_propertyToUnderline[property] = underlineProp; |
| 5892 | d_ptr->m_underlineToProperty[underlineProp] = property; |
| 5893 | property->addSubProperty(property: underlineProp); |
| 5894 | |
| 5895 | QtProperty *strikeOutProp = d_ptr->m_boolPropertyManager->addProperty(); |
| 5896 | strikeOutProp->setPropertyName(tr(s: "Strikeout" )); |
| 5897 | d_ptr->m_boolPropertyManager->setValue(property: strikeOutProp, val: val.strikeOut()); |
| 5898 | d_ptr->m_propertyToStrikeOut[property] = strikeOutProp; |
| 5899 | d_ptr->m_strikeOutToProperty[strikeOutProp] = property; |
| 5900 | property->addSubProperty(property: strikeOutProp); |
| 5901 | |
| 5902 | QtProperty *kerningProp = d_ptr->m_boolPropertyManager->addProperty(); |
| 5903 | kerningProp->setPropertyName(tr(s: "Kerning" )); |
| 5904 | d_ptr->m_boolPropertyManager->setValue(property: kerningProp, val: val.kerning()); |
| 5905 | d_ptr->m_propertyToKerning[property] = kerningProp; |
| 5906 | d_ptr->m_kerningToProperty[kerningProp] = property; |
| 5907 | property->addSubProperty(property: kerningProp); |
| 5908 | |
| 5909 | auto *weightProp = d_ptr->m_enumPropertyManager->addProperty(); |
| 5910 | weightProp->setPropertyName(tr(s: "Weight" )); |
| 5911 | static const QStringList weightNames = fontWeightNames(); |
| 5912 | d_ptr->m_enumPropertyManager->setEnumNames(property: weightProp, enumNames: weightNames); |
| 5913 | d_ptr->m_enumPropertyManager->setValue(property: weightProp, val: indexOfFontWeight(w: val.weight())); |
| 5914 | d_ptr->m_propertyToWeight[property] = weightProp; |
| 5915 | d_ptr->m_weightToProperty[weightProp] = property; |
| 5916 | property->addSubProperty(property: weightProp); |
| 5917 | } |
| 5918 | |
| 5919 | /*! |
| 5920 | \reimp |
| 5921 | */ |
| 5922 | void QtFontPropertyManager::uninitializeProperty(QtProperty *property) |
| 5923 | { |
| 5924 | QtProperty *familyProp = d_ptr->m_propertyToFamily[property]; |
| 5925 | if (familyProp) { |
| 5926 | d_ptr->m_familyToProperty.remove(key: familyProp); |
| 5927 | delete familyProp; |
| 5928 | } |
| 5929 | d_ptr->m_propertyToFamily.remove(key: property); |
| 5930 | |
| 5931 | QtProperty *pointSizeProp = d_ptr->m_propertyToPointSize[property]; |
| 5932 | if (pointSizeProp) { |
| 5933 | d_ptr->m_pointSizeToProperty.remove(key: pointSizeProp); |
| 5934 | delete pointSizeProp; |
| 5935 | } |
| 5936 | d_ptr->m_propertyToPointSize.remove(key: property); |
| 5937 | |
| 5938 | QtProperty *boldProp = d_ptr->m_propertyToBold[property]; |
| 5939 | if (boldProp) { |
| 5940 | d_ptr->m_boldToProperty.remove(key: boldProp); |
| 5941 | delete boldProp; |
| 5942 | } |
| 5943 | d_ptr->m_propertyToBold.remove(key: property); |
| 5944 | |
| 5945 | QtProperty *italicProp = d_ptr->m_propertyToItalic[property]; |
| 5946 | if (italicProp) { |
| 5947 | d_ptr->m_italicToProperty.remove(key: italicProp); |
| 5948 | delete italicProp; |
| 5949 | } |
| 5950 | d_ptr->m_propertyToItalic.remove(key: property); |
| 5951 | |
| 5952 | QtProperty *underlineProp = d_ptr->m_propertyToUnderline[property]; |
| 5953 | if (underlineProp) { |
| 5954 | d_ptr->m_underlineToProperty.remove(key: underlineProp); |
| 5955 | delete underlineProp; |
| 5956 | } |
| 5957 | d_ptr->m_propertyToUnderline.remove(key: property); |
| 5958 | |
| 5959 | QtProperty *strikeOutProp = d_ptr->m_propertyToStrikeOut[property]; |
| 5960 | if (strikeOutProp) { |
| 5961 | d_ptr->m_strikeOutToProperty.remove(key: strikeOutProp); |
| 5962 | delete strikeOutProp; |
| 5963 | } |
| 5964 | d_ptr->m_propertyToStrikeOut.remove(key: property); |
| 5965 | |
| 5966 | QtProperty *kerningProp = d_ptr->m_propertyToKerning[property]; |
| 5967 | if (kerningProp) { |
| 5968 | d_ptr->m_kerningToProperty.remove(key: kerningProp); |
| 5969 | delete kerningProp; |
| 5970 | } |
| 5971 | d_ptr->m_propertyToKerning.remove(key: property); |
| 5972 | |
| 5973 | if (auto weightProp = d_ptr->m_propertyToWeight[property]) { |
| 5974 | d_ptr->m_weightToProperty.remove(key: weightProp); |
| 5975 | delete weightProp; |
| 5976 | } |
| 5977 | |
| 5978 | d_ptr->m_values.remove(key: property); |
| 5979 | } |
| 5980 | |
| 5981 | // QtColorPropertyManager |
| 5982 | |
| 5983 | class QtColorPropertyManagerPrivate |
| 5984 | { |
| 5985 | QtColorPropertyManager *q_ptr = nullptr; |
| 5986 | Q_DECLARE_PUBLIC(QtColorPropertyManager) |
| 5987 | public: |
| 5988 | |
| 5989 | void slotIntChanged(QtProperty *property, int value); |
| 5990 | void slotPropertyDestroyed(QtProperty *property); |
| 5991 | |
| 5992 | QHash<const QtProperty *, QColor> m_values; |
| 5993 | |
| 5994 | QtIntPropertyManager *m_intPropertyManager; |
| 5995 | |
| 5996 | QHash<const QtProperty *, QtProperty *> m_propertyToR; |
| 5997 | QHash<const QtProperty *, QtProperty *> m_propertyToG; |
| 5998 | QHash<const QtProperty *, QtProperty *> m_propertyToB; |
| 5999 | QHash<const QtProperty *, QtProperty *> m_propertyToA; |
| 6000 | |
| 6001 | QHash<const QtProperty *, QtProperty *> m_rToProperty; |
| 6002 | QHash<const QtProperty *, QtProperty *> m_gToProperty; |
| 6003 | QHash<const QtProperty *, QtProperty *> m_bToProperty; |
| 6004 | QHash<const QtProperty *, QtProperty *> m_aToProperty; |
| 6005 | }; |
| 6006 | |
| 6007 | void QtColorPropertyManagerPrivate::slotIntChanged(QtProperty *property, int value) |
| 6008 | { |
| 6009 | if (QtProperty *prop = m_rToProperty.value(key: property, defaultValue: nullptr)) { |
| 6010 | QColor c = m_values[prop]; |
| 6011 | c.setRed(value); |
| 6012 | q_ptr->setValue(property: prop, val: c); |
| 6013 | } else if (QtProperty *prop = m_gToProperty.value(key: property, defaultValue: nullptr)) { |
| 6014 | QColor c = m_values[prop]; |
| 6015 | c.setGreen(value); |
| 6016 | q_ptr->setValue(property: prop, val: c); |
| 6017 | } else if (QtProperty *prop = m_bToProperty.value(key: property, defaultValue: nullptr)) { |
| 6018 | QColor c = m_values[prop]; |
| 6019 | c.setBlue(value); |
| 6020 | q_ptr->setValue(property: prop, val: c); |
| 6021 | } else if (QtProperty *prop = m_aToProperty.value(key: property, defaultValue: nullptr)) { |
| 6022 | QColor c = m_values[prop]; |
| 6023 | c.setAlpha(value); |
| 6024 | q_ptr->setValue(property: prop, val: c); |
| 6025 | } |
| 6026 | } |
| 6027 | |
| 6028 | void QtColorPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property) |
| 6029 | { |
| 6030 | if (QtProperty *pointProp = m_rToProperty.value(key: property, defaultValue: nullptr)) { |
| 6031 | m_propertyToR[pointProp] = nullptr; |
| 6032 | m_rToProperty.remove(key: property); |
| 6033 | } else if (QtProperty *pointProp = m_gToProperty.value(key: property, defaultValue: nullptr)) { |
| 6034 | m_propertyToG[pointProp] = nullptr; |
| 6035 | m_gToProperty.remove(key: property); |
| 6036 | } else if (QtProperty *pointProp = m_bToProperty.value(key: property, defaultValue: nullptr)) { |
| 6037 | m_propertyToB[pointProp] = nullptr; |
| 6038 | m_bToProperty.remove(key: property); |
| 6039 | } else if (QtProperty *pointProp = m_aToProperty.value(key: property, defaultValue: nullptr)) { |
| 6040 | m_propertyToA[pointProp] = nullptr; |
| 6041 | m_aToProperty.remove(key: property); |
| 6042 | } |
| 6043 | } |
| 6044 | |
| 6045 | /*! |
| 6046 | \class QtColorPropertyManager |
| 6047 | \internal |
| 6048 | \inmodule QtDesigner |
| 6049 | \since 4.4 |
| 6050 | |
| 6051 | \brief The QtColorPropertyManager provides and manages QColor properties. |
| 6052 | |
| 6053 | A color property has nested \e red, \e green and \e blue |
| 6054 | subproperties. The top-level property's value can be retrieved |
| 6055 | using the value() function, and set using the setValue() slot. |
| 6056 | |
| 6057 | The subproperties are created by a QtIntPropertyManager object. This |
| 6058 | manager can be retrieved using the subIntPropertyManager() function. In |
| 6059 | order to provide editing widgets for the subproperties in a |
| 6060 | property browser widget, this manager must be associated with an |
| 6061 | editor factory. |
| 6062 | |
| 6063 | In addition, QtColorPropertyManager provides the valueChanged() signal |
| 6064 | which is emitted whenever a property created by this manager |
| 6065 | changes. |
| 6066 | |
| 6067 | \sa QtAbstractPropertyManager, QtAbstractPropertyBrowser, QtIntPropertyManager |
| 6068 | */ |
| 6069 | |
| 6070 | /*! |
| 6071 | \fn void QtColorPropertyManager::valueChanged(QtProperty *property, const QColor &value) |
| 6072 | |
| 6073 | This signal is emitted whenever a property created by this manager |
| 6074 | changes its value, passing a pointer to the \a property and the new |
| 6075 | \a value as parameters. |
| 6076 | |
| 6077 | \sa setValue() |
| 6078 | */ |
| 6079 | |
| 6080 | /*! |
| 6081 | Creates a manager with the given \a parent. |
| 6082 | */ |
| 6083 | QtColorPropertyManager::QtColorPropertyManager(QObject *parent) |
| 6084 | : QtAbstractPropertyManager(parent), d_ptr(new QtColorPropertyManagerPrivate) |
| 6085 | { |
| 6086 | d_ptr->q_ptr = this; |
| 6087 | |
| 6088 | d_ptr->m_intPropertyManager = new QtIntPropertyManager(this); |
| 6089 | connect(sender: d_ptr->m_intPropertyManager, signal: &QtIntPropertyManager::valueChanged, context: this, |
| 6090 | slot: [this](QtProperty *property, int value) { d_ptr->slotIntChanged(property, value); }); |
| 6091 | connect(sender: d_ptr->m_intPropertyManager, signal: &QtAbstractPropertyManager::propertyDestroyed, context: this, |
| 6092 | slot: [this](QtProperty *property) { d_ptr->slotPropertyDestroyed(property); }); |
| 6093 | } |
| 6094 | |
| 6095 | /*! |
| 6096 | Destroys this manager, and all the properties it has created. |
| 6097 | */ |
| 6098 | QtColorPropertyManager::~QtColorPropertyManager() |
| 6099 | { |
| 6100 | clear(); |
| 6101 | } |
| 6102 | |
| 6103 | /*! |
| 6104 | Returns the manager that produces the nested \e red, \e green and |
| 6105 | \e blue subproperties. |
| 6106 | |
| 6107 | In order to provide editing widgets for the subproperties in a |
| 6108 | property browser widget, this manager must be associated with an |
| 6109 | editor factory. |
| 6110 | |
| 6111 | \sa QtAbstractPropertyBrowser::setFactoryForManager() |
| 6112 | */ |
| 6113 | QtIntPropertyManager *QtColorPropertyManager::subIntPropertyManager() const |
| 6114 | { |
| 6115 | return d_ptr->m_intPropertyManager; |
| 6116 | } |
| 6117 | |
| 6118 | /*! |
| 6119 | Returns the given \a property's value. |
| 6120 | |
| 6121 | If the given \a property is not managed by \e this manager, this |
| 6122 | function returns an invalid color. |
| 6123 | |
| 6124 | \sa setValue() |
| 6125 | */ |
| 6126 | QColor QtColorPropertyManager::value(const QtProperty *property) const |
| 6127 | { |
| 6128 | return d_ptr->m_values.value(key: property, defaultValue: QColor()); |
| 6129 | } |
| 6130 | |
| 6131 | /*! |
| 6132 | \reimp |
| 6133 | */ |
| 6134 | |
| 6135 | QString QtColorPropertyManager::valueText(const QtProperty *property) const |
| 6136 | { |
| 6137 | const auto it = d_ptr->m_values.constFind(key: property); |
| 6138 | if (it == d_ptr->m_values.constEnd()) |
| 6139 | return {}; |
| 6140 | |
| 6141 | return QtPropertyBrowserUtils::colorValueText(c: it.value()); |
| 6142 | } |
| 6143 | |
| 6144 | /*! |
| 6145 | \reimp |
| 6146 | */ |
| 6147 | |
| 6148 | QIcon QtColorPropertyManager::valueIcon(const QtProperty *property) const |
| 6149 | { |
| 6150 | const auto it = d_ptr->m_values.constFind(key: property); |
| 6151 | if (it == d_ptr->m_values.constEnd()) |
| 6152 | return {}; |
| 6153 | return QtPropertyBrowserUtils::brushValueIcon(b: QBrush(it.value())); |
| 6154 | } |
| 6155 | |
| 6156 | /*! |
| 6157 | \fn void QtColorPropertyManager::setValue(QtProperty *property, const QColor &value) |
| 6158 | |
| 6159 | Sets the value of the given \a property to \a value. Nested |
| 6160 | properties are updated automatically. |
| 6161 | |
| 6162 | \sa value(), valueChanged() |
| 6163 | */ |
| 6164 | void QtColorPropertyManager::setValue(QtProperty *property, QColor val) |
| 6165 | { |
| 6166 | const auto it = d_ptr->m_values.find(key: property); |
| 6167 | if (it == d_ptr->m_values.end()) |
| 6168 | return; |
| 6169 | |
| 6170 | if (it.value() == val) |
| 6171 | return; |
| 6172 | |
| 6173 | it.value() = val; |
| 6174 | |
| 6175 | d_ptr->m_intPropertyManager->setValue(property: d_ptr->m_propertyToR[property], val: val.red()); |
| 6176 | d_ptr->m_intPropertyManager->setValue(property: d_ptr->m_propertyToG[property], val: val.green()); |
| 6177 | d_ptr->m_intPropertyManager->setValue(property: d_ptr->m_propertyToB[property], val: val.blue()); |
| 6178 | d_ptr->m_intPropertyManager->setValue(property: d_ptr->m_propertyToA[property], val: val.alpha()); |
| 6179 | |
| 6180 | emit propertyChanged(property); |
| 6181 | emit valueChanged(property, val); |
| 6182 | } |
| 6183 | |
| 6184 | /*! |
| 6185 | \reimp |
| 6186 | */ |
| 6187 | void QtColorPropertyManager::initializeProperty(QtProperty *property) |
| 6188 | { |
| 6189 | QColor val; |
| 6190 | d_ptr->m_values[property] = val; |
| 6191 | |
| 6192 | QtProperty *rProp = d_ptr->m_intPropertyManager->addProperty(); |
| 6193 | rProp->setPropertyName(tr(s: "Red" )); |
| 6194 | d_ptr->m_intPropertyManager->setValue(property: rProp, val: val.red()); |
| 6195 | d_ptr->m_intPropertyManager->setRange(property: rProp, minVal: 0, maxVal: 0xFF); |
| 6196 | d_ptr->m_propertyToR[property] = rProp; |
| 6197 | d_ptr->m_rToProperty[rProp] = property; |
| 6198 | property->addSubProperty(property: rProp); |
| 6199 | |
| 6200 | QtProperty *gProp = d_ptr->m_intPropertyManager->addProperty(); |
| 6201 | gProp->setPropertyName(tr(s: "Green" )); |
| 6202 | d_ptr->m_intPropertyManager->setValue(property: gProp, val: val.green()); |
| 6203 | d_ptr->m_intPropertyManager->setRange(property: gProp, minVal: 0, maxVal: 0xFF); |
| 6204 | d_ptr->m_propertyToG[property] = gProp; |
| 6205 | d_ptr->m_gToProperty[gProp] = property; |
| 6206 | property->addSubProperty(property: gProp); |
| 6207 | |
| 6208 | QtProperty *bProp = d_ptr->m_intPropertyManager->addProperty(); |
| 6209 | bProp->setPropertyName(tr(s: "Blue" )); |
| 6210 | d_ptr->m_intPropertyManager->setValue(property: bProp, val: val.blue()); |
| 6211 | d_ptr->m_intPropertyManager->setRange(property: bProp, minVal: 0, maxVal: 0xFF); |
| 6212 | d_ptr->m_propertyToB[property] = bProp; |
| 6213 | d_ptr->m_bToProperty[bProp] = property; |
| 6214 | property->addSubProperty(property: bProp); |
| 6215 | |
| 6216 | QtProperty *aProp = d_ptr->m_intPropertyManager->addProperty(); |
| 6217 | aProp->setPropertyName(tr(s: "Alpha" )); |
| 6218 | d_ptr->m_intPropertyManager->setValue(property: aProp, val: val.alpha()); |
| 6219 | d_ptr->m_intPropertyManager->setRange(property: aProp, minVal: 0, maxVal: 0xFF); |
| 6220 | d_ptr->m_propertyToA[property] = aProp; |
| 6221 | d_ptr->m_aToProperty[aProp] = property; |
| 6222 | property->addSubProperty(property: aProp); |
| 6223 | } |
| 6224 | |
| 6225 | /*! |
| 6226 | \reimp |
| 6227 | */ |
| 6228 | void QtColorPropertyManager::uninitializeProperty(QtProperty *property) |
| 6229 | { |
| 6230 | QtProperty *rProp = d_ptr->m_propertyToR[property]; |
| 6231 | if (rProp) { |
| 6232 | d_ptr->m_rToProperty.remove(key: rProp); |
| 6233 | delete rProp; |
| 6234 | } |
| 6235 | d_ptr->m_propertyToR.remove(key: property); |
| 6236 | |
| 6237 | QtProperty *gProp = d_ptr->m_propertyToG[property]; |
| 6238 | if (gProp) { |
| 6239 | d_ptr->m_gToProperty.remove(key: gProp); |
| 6240 | delete gProp; |
| 6241 | } |
| 6242 | d_ptr->m_propertyToG.remove(key: property); |
| 6243 | |
| 6244 | QtProperty *bProp = d_ptr->m_propertyToB[property]; |
| 6245 | if (bProp) { |
| 6246 | d_ptr->m_bToProperty.remove(key: bProp); |
| 6247 | delete bProp; |
| 6248 | } |
| 6249 | d_ptr->m_propertyToB.remove(key: property); |
| 6250 | |
| 6251 | QtProperty *aProp = d_ptr->m_propertyToA[property]; |
| 6252 | if (aProp) { |
| 6253 | d_ptr->m_aToProperty.remove(key: aProp); |
| 6254 | delete aProp; |
| 6255 | } |
| 6256 | d_ptr->m_propertyToA.remove(key: property); |
| 6257 | |
| 6258 | d_ptr->m_values.remove(key: property); |
| 6259 | } |
| 6260 | |
| 6261 | // QtCursorPropertyManager |
| 6262 | |
| 6263 | class QtCursorPropertyManagerPrivate |
| 6264 | { |
| 6265 | QtCursorPropertyManager *q_ptr = nullptr; |
| 6266 | Q_DECLARE_PUBLIC(QtCursorPropertyManager) |
| 6267 | public: |
| 6268 | QHash<const QtProperty *, QCursor> m_values; |
| 6269 | }; |
| 6270 | |
| 6271 | /*! |
| 6272 | \class QtCursorPropertyManager |
| 6273 | \internal |
| 6274 | \inmodule QtDesigner |
| 6275 | \since 4.4 |
| 6276 | |
| 6277 | \brief The QtCursorPropertyManager provides and manages QCursor properties. |
| 6278 | |
| 6279 | A cursor property has a current value which can be |
| 6280 | retrieved using the value() function, and set using the setValue() |
| 6281 | slot. In addition, QtCursorPropertyManager provides the |
| 6282 | valueChanged() signal which is emitted whenever a property created |
| 6283 | by this manager changes. |
| 6284 | |
| 6285 | \sa QtAbstractPropertyManager |
| 6286 | */ |
| 6287 | |
| 6288 | /*! |
| 6289 | \fn void QtCursorPropertyManager::valueChanged(QtProperty *property, const QCursor &value) |
| 6290 | |
| 6291 | This signal is emitted whenever a property created by this manager |
| 6292 | changes its value, passing a pointer to the \a property and the new |
| 6293 | \a value as parameters. |
| 6294 | |
| 6295 | \sa setValue() |
| 6296 | */ |
| 6297 | |
| 6298 | /*! |
| 6299 | Creates a manager with the given \a parent. |
| 6300 | */ |
| 6301 | QtCursorPropertyManager::QtCursorPropertyManager(QObject *parent) |
| 6302 | : QtAbstractPropertyManager(parent), d_ptr(new QtCursorPropertyManagerPrivate) |
| 6303 | { |
| 6304 | d_ptr->q_ptr = this; |
| 6305 | } |
| 6306 | |
| 6307 | /*! |
| 6308 | Destroys this manager, and all the properties it has created. |
| 6309 | */ |
| 6310 | QtCursorPropertyManager::~QtCursorPropertyManager() |
| 6311 | { |
| 6312 | clear(); |
| 6313 | } |
| 6314 | |
| 6315 | /*! |
| 6316 | Returns the given \a property's value. |
| 6317 | |
| 6318 | If the given \a property is not managed by this manager, this |
| 6319 | function returns a default QCursor object. |
| 6320 | |
| 6321 | \sa setValue() |
| 6322 | */ |
| 6323 | #ifndef QT_NO_CURSOR |
| 6324 | QCursor QtCursorPropertyManager::value(const QtProperty *property) const |
| 6325 | { |
| 6326 | return d_ptr->m_values.value(key: property, defaultValue: QCursor()); |
| 6327 | } |
| 6328 | #endif |
| 6329 | |
| 6330 | /*! |
| 6331 | \reimp |
| 6332 | */ |
| 6333 | QString QtCursorPropertyManager::valueText(const QtProperty *property) const |
| 6334 | { |
| 6335 | const auto it = d_ptr->m_values.constFind(key: property); |
| 6336 | if (it == d_ptr->m_values.constEnd()) |
| 6337 | return {}; |
| 6338 | |
| 6339 | return QtCursorDatabase::instance()->cursorToShapeName(cursor: it.value()); |
| 6340 | } |
| 6341 | |
| 6342 | /*! |
| 6343 | \reimp |
| 6344 | */ |
| 6345 | QIcon QtCursorPropertyManager::valueIcon(const QtProperty *property) const |
| 6346 | { |
| 6347 | const auto it = d_ptr->m_values.constFind(key: property); |
| 6348 | if (it == d_ptr->m_values.constEnd()) |
| 6349 | return {}; |
| 6350 | |
| 6351 | return QtCursorDatabase::instance()->cursorToShapeIcon(cursor: it.value()); |
| 6352 | } |
| 6353 | |
| 6354 | /*! |
| 6355 | \fn void QtCursorPropertyManager::setValue(QtProperty *property, const QCursor &value) |
| 6356 | |
| 6357 | Sets the value of the given \a property to \a value. |
| 6358 | |
| 6359 | \sa value(), valueChanged() |
| 6360 | */ |
| 6361 | void QtCursorPropertyManager::setValue(QtProperty *property, const QCursor &value) |
| 6362 | { |
| 6363 | #ifndef QT_NO_CURSOR |
| 6364 | const auto it = d_ptr->m_values.find(key: property); |
| 6365 | if (it == d_ptr->m_values.end()) |
| 6366 | return; |
| 6367 | |
| 6368 | if (it.value().shape() == value.shape() && value.shape() != Qt::BitmapCursor) |
| 6369 | return; |
| 6370 | |
| 6371 | it.value() = value; |
| 6372 | |
| 6373 | emit propertyChanged(property); |
| 6374 | emit valueChanged(property, val: value); |
| 6375 | #endif |
| 6376 | } |
| 6377 | |
| 6378 | /*! |
| 6379 | \reimp |
| 6380 | */ |
| 6381 | void QtCursorPropertyManager::initializeProperty(QtProperty *property) |
| 6382 | { |
| 6383 | #ifndef QT_NO_CURSOR |
| 6384 | d_ptr->m_values[property] = QCursor(); |
| 6385 | #endif |
| 6386 | } |
| 6387 | |
| 6388 | /*! |
| 6389 | \reimp |
| 6390 | */ |
| 6391 | void QtCursorPropertyManager::uninitializeProperty(QtProperty *property) |
| 6392 | { |
| 6393 | d_ptr->m_values.remove(key: property); |
| 6394 | } |
| 6395 | |
| 6396 | QT_END_NAMESPACE |
| 6397 | |
| 6398 | #include "moc_qtpropertymanager_p.cpp" |
| 6399 | #include "qtpropertymanager.moc" |
| 6400 | |