source: trunk/tools/shared/qtpropertybrowser/qtpropertymanager.cpp@ 651

Last change on this file since 651 was 651, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.2 sources.

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