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