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