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