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