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