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

source code of qttools/src/shared/qtpropertybrowser/qtpropertymanager.cpp