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