1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the tools applications of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at [email protected].
|
---|
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 | const QLocale loc = it.value();
|
---|
2403 |
|
---|
2404 | int langIdx = 0;
|
---|
2405 | int countryIdx = 0;
|
---|
2406 | const QtMetaEnumProvider *me = metaEnumProvider();
|
---|
2407 | me->localeToIndex(loc.language(), loc.country(), &langIdx, &countryIdx);
|
---|
2408 | if (langIdx < 0) {
|
---|
2409 | qWarning("QtLocalePropertyManager::valueText: Unknown language %d", loc.language());
|
---|
2410 | return tr("<Invalid>");
|
---|
2411 | }
|
---|
2412 | const QString languageName = me->languageEnumNames().at(langIdx);
|
---|
2413 | if (countryIdx < 0) {
|
---|
2414 | qWarning("QtLocalePropertyManager::valueText: Unknown country %d for %s", loc.country(), qPrintable(languageName));
|
---|
2415 | return languageName;
|
---|
2416 | }
|
---|
2417 | const QString countryName = me->countryEnumNames(loc.language()).at(countryIdx);
|
---|
2418 | return tr("%1, %2").arg(languageName, countryName);
|
---|
2419 | }
|
---|
2420 |
|
---|
2421 | /*!
|
---|
2422 | \fn void QtLocalePropertyManager::setValue(QtProperty *property, const QLocale &value)
|
---|
2423 |
|
---|
2424 | Sets the value of the given \a property to \a value. Nested
|
---|
2425 | properties are updated automatically.
|
---|
2426 |
|
---|
2427 | \sa value(), valueChanged()
|
---|
2428 | */
|
---|
2429 | void QtLocalePropertyManager::setValue(QtProperty *property, const QLocale &val)
|
---|
2430 | {
|
---|
2431 | const QtLocalePropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
---|
2432 | if (it == d_ptr->m_values.end())
|
---|
2433 | return;
|
---|
2434 |
|
---|
2435 | const QLocale loc = it.value();
|
---|
2436 | if (loc == val)
|
---|
2437 | return;
|
---|
2438 |
|
---|
2439 | it.value() = val;
|
---|
2440 |
|
---|
2441 | int langIdx = 0;
|
---|
2442 | int countryIdx = 0;
|
---|
2443 | metaEnumProvider()->localeToIndex(val.language(), val.country(), &langIdx, &countryIdx);
|
---|
2444 | if (loc.language() != val.language()) {
|
---|
2445 | d_ptr->m_enumPropertyManager->setValue(d_ptr->m_propertyToLanguage.value(property), langIdx);
|
---|
2446 | d_ptr->m_enumPropertyManager->setEnumNames(d_ptr->m_propertyToCountry.value(property),
|
---|
2447 | metaEnumProvider()->countryEnumNames(val.language()));
|
---|
2448 | }
|
---|
2449 | d_ptr->m_enumPropertyManager->setValue(d_ptr->m_propertyToCountry.value(property), countryIdx);
|
---|
2450 |
|
---|
2451 | emit propertyChanged(property);
|
---|
2452 | emit valueChanged(property, val);
|
---|
2453 | }
|
---|
2454 |
|
---|
2455 | /*!
|
---|
2456 | \reimp
|
---|
2457 | */
|
---|
2458 | void QtLocalePropertyManager::initializeProperty(QtProperty *property)
|
---|
2459 | {
|
---|
2460 | QLocale val;
|
---|
2461 | d_ptr->m_values[property] = val;
|
---|
2462 |
|
---|
2463 | int langIdx = 0;
|
---|
2464 | int countryIdx = 0;
|
---|
2465 | metaEnumProvider()->localeToIndex(val.language(), val.country(), &langIdx, &countryIdx);
|
---|
2466 |
|
---|
2467 | QtProperty *languageProp = d_ptr->m_enumPropertyManager->addProperty();
|
---|
2468 | languageProp->setPropertyName(tr("Language"));
|
---|
2469 | d_ptr->m_enumPropertyManager->setEnumNames(languageProp, metaEnumProvider()->languageEnumNames());
|
---|
2470 | d_ptr->m_enumPropertyManager->setValue(languageProp, langIdx);
|
---|
2471 | d_ptr->m_propertyToLanguage[property] = languageProp;
|
---|
2472 | d_ptr->m_languageToProperty[languageProp] = property;
|
---|
2473 | property->addSubProperty(languageProp);
|
---|
2474 |
|
---|
2475 | QtProperty *countryProp = d_ptr->m_enumPropertyManager->addProperty();
|
---|
2476 | countryProp->setPropertyName(tr("Country"));
|
---|
2477 | d_ptr->m_enumPropertyManager->setEnumNames(countryProp, metaEnumProvider()->countryEnumNames(val.language()));
|
---|
2478 | d_ptr->m_enumPropertyManager->setValue(countryProp, countryIdx);
|
---|
2479 | d_ptr->m_propertyToCountry[property] = countryProp;
|
---|
2480 | d_ptr->m_countryToProperty[countryProp] = property;
|
---|
2481 | property->addSubProperty(countryProp);
|
---|
2482 | }
|
---|
2483 |
|
---|
2484 | /*!
|
---|
2485 | \reimp
|
---|
2486 | */
|
---|
2487 | void QtLocalePropertyManager::uninitializeProperty(QtProperty *property)
|
---|
2488 | {
|
---|
2489 | QtProperty *languageProp = d_ptr->m_propertyToLanguage[property];
|
---|
2490 | if (languageProp) {
|
---|
2491 | d_ptr->m_languageToProperty.remove(languageProp);
|
---|
2492 | delete languageProp;
|
---|
2493 | }
|
---|
2494 | d_ptr->m_propertyToLanguage.remove(property);
|
---|
2495 |
|
---|
2496 | QtProperty *countryProp = d_ptr->m_propertyToCountry[property];
|
---|
2497 | if (countryProp) {
|
---|
2498 | d_ptr->m_countryToProperty.remove(countryProp);
|
---|
2499 | delete countryProp;
|
---|
2500 | }
|
---|
2501 | d_ptr->m_propertyToCountry.remove(property);
|
---|
2502 |
|
---|
2503 | d_ptr->m_values.remove(property);
|
---|
2504 | }
|
---|
2505 |
|
---|
2506 | // QtPointPropertyManager
|
---|
2507 |
|
---|
2508 | class QtPointPropertyManagerPrivate
|
---|
2509 | {
|
---|
2510 | QtPointPropertyManager *q_ptr;
|
---|
2511 | Q_DECLARE_PUBLIC(QtPointPropertyManager)
|
---|
2512 | public:
|
---|
2513 |
|
---|
2514 | void slotIntChanged(QtProperty *property, int value);
|
---|
2515 | void slotPropertyDestroyed(QtProperty *property);
|
---|
2516 |
|
---|
2517 | typedef QMap<const QtProperty *, QPoint> PropertyValueMap;
|
---|
2518 | PropertyValueMap m_values;
|
---|
2519 |
|
---|
2520 | QtIntPropertyManager *m_intPropertyManager;
|
---|
2521 |
|
---|
2522 | QMap<const QtProperty *, QtProperty *> m_propertyToX;
|
---|
2523 | QMap<const QtProperty *, QtProperty *> m_propertyToY;
|
---|
2524 |
|
---|
2525 | QMap<const QtProperty *, QtProperty *> m_xToProperty;
|
---|
2526 | QMap<const QtProperty *, QtProperty *> m_yToProperty;
|
---|
2527 | };
|
---|
2528 |
|
---|
2529 | void QtPointPropertyManagerPrivate::slotIntChanged(QtProperty *property, int value)
|
---|
2530 | {
|
---|
2531 | if (QtProperty *xprop = m_xToProperty.value(property, 0)) {
|
---|
2532 | QPoint p = m_values[xprop];
|
---|
2533 | p.setX(value);
|
---|
2534 | q_ptr->setValue(xprop, p);
|
---|
2535 | } else if (QtProperty *yprop = m_yToProperty.value(property, 0)) {
|
---|
2536 | QPoint p = m_values[yprop];
|
---|
2537 | p.setY(value);
|
---|
2538 | q_ptr->setValue(yprop, p);
|
---|
2539 | }
|
---|
2540 | }
|
---|
2541 |
|
---|
2542 | void QtPointPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
|
---|
2543 | {
|
---|
2544 | if (QtProperty *pointProp = m_xToProperty.value(property, 0)) {
|
---|
2545 | m_propertyToX[pointProp] = 0;
|
---|
2546 | m_xToProperty.remove(property);
|
---|
2547 | } else if (QtProperty *pointProp = m_yToProperty.value(property, 0)) {
|
---|
2548 | m_propertyToY[pointProp] = 0;
|
---|
2549 | m_yToProperty.remove(property);
|
---|
2550 | }
|
---|
2551 | }
|
---|
2552 |
|
---|
2553 | /*! \class QtPointPropertyManager
|
---|
2554 | \internal
|
---|
2555 | \inmodule QtDesigner
|
---|
2556 | \since 4.4
|
---|
2557 |
|
---|
2558 | \brief The QtPointPropertyManager provides and manages QPoint properties.
|
---|
2559 |
|
---|
2560 | A point property has nested \e x and \e y subproperties. The
|
---|
2561 | top-level property's value can be retrieved using the value()
|
---|
2562 | function, and set using the setValue() slot.
|
---|
2563 |
|
---|
2564 | The subproperties are created by a QtIntPropertyManager object. This
|
---|
2565 | manager can be retrieved using the subIntPropertyManager() function. In
|
---|
2566 | order to provide editing widgets for the subproperties in a
|
---|
2567 | property browser widget, this manager must be associated with an
|
---|
2568 | editor factory.
|
---|
2569 |
|
---|
2570 | In addition, QtPointPropertyManager provides the valueChanged() signal which
|
---|
2571 | is emitted whenever a property created by this manager changes.
|
---|
2572 |
|
---|
2573 | \sa QtAbstractPropertyManager, QtIntPropertyManager, QtPointFPropertyManager
|
---|
2574 | */
|
---|
2575 |
|
---|
2576 | /*!
|
---|
2577 | \fn void QtPointPropertyManager::valueChanged(QtProperty *property, const QPoint &value)
|
---|
2578 |
|
---|
2579 | This signal is emitted whenever a property created by this manager
|
---|
2580 | changes its value, passing a pointer to the \a property and the
|
---|
2581 | new \a value as parameters.
|
---|
2582 |
|
---|
2583 | \sa setValue()
|
---|
2584 | */
|
---|
2585 |
|
---|
2586 | /*!
|
---|
2587 | Creates a manager with the given \a parent.
|
---|
2588 | */
|
---|
2589 | QtPointPropertyManager::QtPointPropertyManager(QObject *parent)
|
---|
2590 | : QtAbstractPropertyManager(parent), d_ptr(new QtPointPropertyManagerPrivate)
|
---|
2591 | {
|
---|
2592 | d_ptr->q_ptr = this;
|
---|
2593 |
|
---|
2594 | d_ptr->m_intPropertyManager = new QtIntPropertyManager(this);
|
---|
2595 | connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty*,int)),
|
---|
2596 | this, SLOT(slotIntChanged(QtProperty*,int)));
|
---|
2597 | connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
|
---|
2598 | this, SLOT(slotPropertyDestroyed(QtProperty*)));
|
---|
2599 | }
|
---|
2600 |
|
---|
2601 | /*!
|
---|
2602 | Destroys this manager, and all the properties it has created.
|
---|
2603 | */
|
---|
2604 | QtPointPropertyManager::~QtPointPropertyManager()
|
---|
2605 | {
|
---|
2606 | clear();
|
---|
2607 | }
|
---|
2608 |
|
---|
2609 | /*!
|
---|
2610 | Returns the manager that creates the nested \e x and \e y
|
---|
2611 | subproperties.
|
---|
2612 |
|
---|
2613 | In order to provide editing widgets for the subproperties in a
|
---|
2614 | property browser widget, this manager must be associated with an
|
---|
2615 | editor factory.
|
---|
2616 |
|
---|
2617 | \sa QtAbstractPropertyBrowser::setFactoryForManager()
|
---|
2618 | */
|
---|
2619 | QtIntPropertyManager *QtPointPropertyManager::subIntPropertyManager() const
|
---|
2620 | {
|
---|
2621 | return d_ptr->m_intPropertyManager;
|
---|
2622 | }
|
---|
2623 |
|
---|
2624 | /*!
|
---|
2625 | Returns the given \a property's value.
|
---|
2626 |
|
---|
2627 | If the given \a property is not managed by this manager, this
|
---|
2628 | function returns a point with coordinates (0, 0).
|
---|
2629 |
|
---|
2630 | \sa setValue()
|
---|
2631 | */
|
---|
2632 | QPoint QtPointPropertyManager::value(const QtProperty *property) const
|
---|
2633 | {
|
---|
2634 | return d_ptr->m_values.value(property, QPoint());
|
---|
2635 | }
|
---|
2636 |
|
---|
2637 | /*!
|
---|
2638 | \reimp
|
---|
2639 | */
|
---|
2640 | QString QtPointPropertyManager::valueText(const QtProperty *property) const
|
---|
2641 | {
|
---|
2642 | const QtPointPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
---|
2643 | if (it == d_ptr->m_values.constEnd())
|
---|
2644 | return QString();
|
---|
2645 | const QPoint v = it.value();
|
---|
2646 | return tr("(%1, %2)").arg(QString::number(v.x()))
|
---|
2647 | .arg(QString::number(v.y()));
|
---|
2648 | }
|
---|
2649 |
|
---|
2650 | /*!
|
---|
2651 | \fn void QtPointPropertyManager::setValue(QtProperty *property, const QPoint &value)
|
---|
2652 |
|
---|
2653 | Sets the value of the given \a property to \a value. Nested
|
---|
2654 | properties are updated automatically.
|
---|
2655 |
|
---|
2656 | \sa value(), valueChanged()
|
---|
2657 | */
|
---|
2658 | void QtPointPropertyManager::setValue(QtProperty *property, const QPoint &val)
|
---|
2659 | {
|
---|
2660 | const QtPointPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
---|
2661 | if (it == d_ptr->m_values.end())
|
---|
2662 | return;
|
---|
2663 |
|
---|
2664 | if (it.value() == val)
|
---|
2665 | return;
|
---|
2666 |
|
---|
2667 | it.value() = val;
|
---|
2668 | d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToX[property], val.x());
|
---|
2669 | d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToY[property], val.y());
|
---|
2670 |
|
---|
2671 | emit propertyChanged(property);
|
---|
2672 | emit valueChanged(property, val);
|
---|
2673 | }
|
---|
2674 |
|
---|
2675 | /*!
|
---|
2676 | \reimp
|
---|
2677 | */
|
---|
2678 | void QtPointPropertyManager::initializeProperty(QtProperty *property)
|
---|
2679 | {
|
---|
2680 | d_ptr->m_values[property] = QPoint(0, 0);
|
---|
2681 |
|
---|
2682 | QtProperty *xProp = d_ptr->m_intPropertyManager->addProperty();
|
---|
2683 | xProp->setPropertyName(tr("X"));
|
---|
2684 | d_ptr->m_intPropertyManager->setValue(xProp, 0);
|
---|
2685 | d_ptr->m_propertyToX[property] = xProp;
|
---|
2686 | d_ptr->m_xToProperty[xProp] = property;
|
---|
2687 | property->addSubProperty(xProp);
|
---|
2688 |
|
---|
2689 | QtProperty *yProp = d_ptr->m_intPropertyManager->addProperty();
|
---|
2690 | yProp->setPropertyName(tr("Y"));
|
---|
2691 | d_ptr->m_intPropertyManager->setValue(yProp, 0);
|
---|
2692 | d_ptr->m_propertyToY[property] = yProp;
|
---|
2693 | d_ptr->m_yToProperty[yProp] = property;
|
---|
2694 | property->addSubProperty(yProp);
|
---|
2695 | }
|
---|
2696 |
|
---|
2697 | /*!
|
---|
2698 | \reimp
|
---|
2699 | */
|
---|
2700 | void QtPointPropertyManager::uninitializeProperty(QtProperty *property)
|
---|
2701 | {
|
---|
2702 | QtProperty *xProp = d_ptr->m_propertyToX[property];
|
---|
2703 | if (xProp) {
|
---|
2704 | d_ptr->m_xToProperty.remove(xProp);
|
---|
2705 | delete xProp;
|
---|
2706 | }
|
---|
2707 | d_ptr->m_propertyToX.remove(property);
|
---|
2708 |
|
---|
2709 | QtProperty *yProp = d_ptr->m_propertyToY[property];
|
---|
2710 | if (yProp) {
|
---|
2711 | d_ptr->m_yToProperty.remove(yProp);
|
---|
2712 | delete yProp;
|
---|
2713 | }
|
---|
2714 | d_ptr->m_propertyToY.remove(property);
|
---|
2715 |
|
---|
2716 | d_ptr->m_values.remove(property);
|
---|
2717 | }
|
---|
2718 |
|
---|
2719 | // QtPointFPropertyManager
|
---|
2720 |
|
---|
2721 | class QtPointFPropertyManagerPrivate
|
---|
2722 | {
|
---|
2723 | QtPointFPropertyManager *q_ptr;
|
---|
2724 | Q_DECLARE_PUBLIC(QtPointFPropertyManager)
|
---|
2725 | public:
|
---|
2726 |
|
---|
2727 | struct Data
|
---|
2728 | {
|
---|
2729 | Data() : decimals(2) {}
|
---|
2730 | QPointF val;
|
---|
2731 | int decimals;
|
---|
2732 | };
|
---|
2733 |
|
---|
2734 | void slotDoubleChanged(QtProperty *property, double value);
|
---|
2735 | void slotPropertyDestroyed(QtProperty *property);
|
---|
2736 |
|
---|
2737 | typedef QMap<const QtProperty *, Data> PropertyValueMap;
|
---|
2738 | PropertyValueMap m_values;
|
---|
2739 |
|
---|
2740 | QtDoublePropertyManager *m_doublePropertyManager;
|
---|
2741 |
|
---|
2742 | QMap<const QtProperty *, QtProperty *> m_propertyToX;
|
---|
2743 | QMap<const QtProperty *, QtProperty *> m_propertyToY;
|
---|
2744 |
|
---|
2745 | QMap<const QtProperty *, QtProperty *> m_xToProperty;
|
---|
2746 | QMap<const QtProperty *, QtProperty *> m_yToProperty;
|
---|
2747 | };
|
---|
2748 |
|
---|
2749 | void QtPointFPropertyManagerPrivate::slotDoubleChanged(QtProperty *property, double value)
|
---|
2750 | {
|
---|
2751 | if (QtProperty *prop = m_xToProperty.value(property, 0)) {
|
---|
2752 | QPointF p = m_values[prop].val;
|
---|
2753 | p.setX(value);
|
---|
2754 | q_ptr->setValue(prop, p);
|
---|
2755 | } else if (QtProperty *prop = m_yToProperty.value(property, 0)) {
|
---|
2756 | QPointF p = m_values[prop].val;
|
---|
2757 | p.setY(value);
|
---|
2758 | q_ptr->setValue(prop, p);
|
---|
2759 | }
|
---|
2760 | }
|
---|
2761 |
|
---|
2762 | void QtPointFPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
|
---|
2763 | {
|
---|
2764 | if (QtProperty *pointProp = m_xToProperty.value(property, 0)) {
|
---|
2765 | m_propertyToX[pointProp] = 0;
|
---|
2766 | m_xToProperty.remove(property);
|
---|
2767 | } else if (QtProperty *pointProp = m_yToProperty.value(property, 0)) {
|
---|
2768 | m_propertyToY[pointProp] = 0;
|
---|
2769 | m_yToProperty.remove(property);
|
---|
2770 | }
|
---|
2771 | }
|
---|
2772 |
|
---|
2773 | /*! \class QtPointFPropertyManager
|
---|
2774 | \internal
|
---|
2775 | \inmodule QtDesigner
|
---|
2776 | \since 4.4
|
---|
2777 |
|
---|
2778 | \brief The QtPointFPropertyManager provides and manages QPointF properties.
|
---|
2779 |
|
---|
2780 | A point property has nested \e x and \e y subproperties. The
|
---|
2781 | top-level property's value can be retrieved using the value()
|
---|
2782 | function, and set using the setValue() slot.
|
---|
2783 |
|
---|
2784 | The subproperties are created by a QtDoublePropertyManager object. This
|
---|
2785 | manager can be retrieved using the subDoublePropertyManager() function. In
|
---|
2786 | order to provide editing widgets for the subproperties in a
|
---|
2787 | property browser widget, this manager must be associated with an
|
---|
2788 | editor factory.
|
---|
2789 |
|
---|
2790 | In addition, QtPointFPropertyManager provides the valueChanged() signal which
|
---|
2791 | is emitted whenever a property created by this manager changes.
|
---|
2792 |
|
---|
2793 | \sa QtAbstractPropertyManager, QtDoublePropertyManager, QtPointPropertyManager
|
---|
2794 | */
|
---|
2795 |
|
---|
2796 | /*!
|
---|
2797 | \fn void QtPointFPropertyManager::valueChanged(QtProperty *property, const QPointF &value)
|
---|
2798 |
|
---|
2799 | This signal is emitted whenever a property created by this manager
|
---|
2800 | changes its value, passing a pointer to the \a property and the
|
---|
2801 | new \a value as parameters.
|
---|
2802 |
|
---|
2803 | \sa setValue()
|
---|
2804 | */
|
---|
2805 |
|
---|
2806 | /*!
|
---|
2807 | \fn void QtPointFPropertyManager::decimalsChanged(QtProperty *property, int prec)
|
---|
2808 |
|
---|
2809 | This signal is emitted whenever a property created by this manager
|
---|
2810 | changes its precision of value, passing a pointer to the
|
---|
2811 | \a property and the new \a prec value
|
---|
2812 |
|
---|
2813 | \sa setDecimals()
|
---|
2814 | */
|
---|
2815 |
|
---|
2816 | /*!
|
---|
2817 | Creates a manager with the given \a parent.
|
---|
2818 | */
|
---|
2819 | QtPointFPropertyManager::QtPointFPropertyManager(QObject *parent)
|
---|
2820 | : QtAbstractPropertyManager(parent), d_ptr(new QtPointFPropertyManagerPrivate)
|
---|
2821 | {
|
---|
2822 | d_ptr->q_ptr = this;
|
---|
2823 |
|
---|
2824 | d_ptr->m_doublePropertyManager = new QtDoublePropertyManager(this);
|
---|
2825 | connect(d_ptr->m_doublePropertyManager, SIGNAL(valueChanged(QtProperty*,double)),
|
---|
2826 | this, SLOT(slotDoubleChanged(QtProperty*,double)));
|
---|
2827 | connect(d_ptr->m_doublePropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
|
---|
2828 | this, SLOT(slotPropertyDestroyed(QtProperty*)));
|
---|
2829 | }
|
---|
2830 |
|
---|
2831 | /*!
|
---|
2832 | Destroys this manager, and all the properties it has created.
|
---|
2833 | */
|
---|
2834 | QtPointFPropertyManager::~QtPointFPropertyManager()
|
---|
2835 | {
|
---|
2836 | clear();
|
---|
2837 | }
|
---|
2838 |
|
---|
2839 | /*!
|
---|
2840 | Returns the manager that creates the nested \e x and \e y
|
---|
2841 | subproperties.
|
---|
2842 |
|
---|
2843 | In order to provide editing widgets for the subproperties in a
|
---|
2844 | property browser widget, this manager must be associated with an
|
---|
2845 | editor factory.
|
---|
2846 |
|
---|
2847 | \sa QtAbstractPropertyBrowser::setFactoryForManager()
|
---|
2848 | */
|
---|
2849 | QtDoublePropertyManager *QtPointFPropertyManager::subDoublePropertyManager() const
|
---|
2850 | {
|
---|
2851 | return d_ptr->m_doublePropertyManager;
|
---|
2852 | }
|
---|
2853 |
|
---|
2854 | /*!
|
---|
2855 | Returns the given \a property's value.
|
---|
2856 |
|
---|
2857 | If the given \a property is not managed by this manager, this
|
---|
2858 | function returns a point with coordinates (0, 0).
|
---|
2859 |
|
---|
2860 | \sa setValue()
|
---|
2861 | */
|
---|
2862 | QPointF QtPointFPropertyManager::value(const QtProperty *property) const
|
---|
2863 | {
|
---|
2864 | return getValue<QPointF>(d_ptr->m_values, property);
|
---|
2865 | }
|
---|
2866 |
|
---|
2867 | /*!
|
---|
2868 | Returns the given \a property's precision, in decimals.
|
---|
2869 |
|
---|
2870 | \sa setDecimals()
|
---|
2871 | */
|
---|
2872 | int QtPointFPropertyManager::decimals(const QtProperty *property) const
|
---|
2873 | {
|
---|
2874 | return getData<int>(d_ptr->m_values, &QtPointFPropertyManagerPrivate::Data::decimals, property, 0);
|
---|
2875 | }
|
---|
2876 |
|
---|
2877 | /*!
|
---|
2878 | \reimp
|
---|
2879 | */
|
---|
2880 | QString QtPointFPropertyManager::valueText(const QtProperty *property) const
|
---|
2881 | {
|
---|
2882 | const QtPointFPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
---|
2883 | if (it == d_ptr->m_values.constEnd())
|
---|
2884 | return QString();
|
---|
2885 | const QPointF v = it.value().val;
|
---|
2886 | const int dec = it.value().decimals;
|
---|
2887 | return tr("(%1, %2)").arg(QString::number(v.x(), 'f', dec))
|
---|
2888 | .arg(QString::number(v.y(), 'f', dec));
|
---|
2889 | }
|
---|
2890 |
|
---|
2891 | /*!
|
---|
2892 | \fn void QtPointFPropertyManager::setValue(QtProperty *property, const QPointF &value)
|
---|
2893 |
|
---|
2894 | Sets the value of the given \a property to \a value. Nested
|
---|
2895 | properties are updated automatically.
|
---|
2896 |
|
---|
2897 | \sa value(), valueChanged()
|
---|
2898 | */
|
---|
2899 | void QtPointFPropertyManager::setValue(QtProperty *property, const QPointF &val)
|
---|
2900 | {
|
---|
2901 | const QtPointFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
---|
2902 | if (it == d_ptr->m_values.end())
|
---|
2903 | return;
|
---|
2904 |
|
---|
2905 | if (it.value().val == val)
|
---|
2906 | return;
|
---|
2907 |
|
---|
2908 | it.value().val = val;
|
---|
2909 | d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToX[property], val.x());
|
---|
2910 | d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToY[property], val.y());
|
---|
2911 |
|
---|
2912 | emit propertyChanged(property);
|
---|
2913 | emit valueChanged(property, val);
|
---|
2914 | }
|
---|
2915 |
|
---|
2916 | /*!
|
---|
2917 | \fn void QtPointFPropertyManager::setDecimals(QtProperty *property, int prec)
|
---|
2918 |
|
---|
2919 | Sets the precision of the given \a property to \a prec.
|
---|
2920 |
|
---|
2921 | The valid decimal range is 0-13. The default is 2.
|
---|
2922 |
|
---|
2923 | \sa decimals()
|
---|
2924 | */
|
---|
2925 | void QtPointFPropertyManager::setDecimals(QtProperty *property, int prec)
|
---|
2926 | {
|
---|
2927 | const QtPointFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
---|
2928 | if (it == d_ptr->m_values.end())
|
---|
2929 | return;
|
---|
2930 |
|
---|
2931 | QtPointFPropertyManagerPrivate::Data data = it.value();
|
---|
2932 |
|
---|
2933 | if (prec > 13)
|
---|
2934 | prec = 13;
|
---|
2935 | else if (prec < 0)
|
---|
2936 | prec = 0;
|
---|
2937 |
|
---|
2938 | if (data.decimals == prec)
|
---|
2939 | return;
|
---|
2940 |
|
---|
2941 | data.decimals = prec;
|
---|
2942 | d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToX[property], prec);
|
---|
2943 | d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToY[property], prec);
|
---|
2944 |
|
---|
2945 | it.value() = data;
|
---|
2946 |
|
---|
2947 | emit decimalsChanged(property, data.decimals);
|
---|
2948 | }
|
---|
2949 |
|
---|
2950 | /*!
|
---|
2951 | \reimp
|
---|
2952 | */
|
---|
2953 | void QtPointFPropertyManager::initializeProperty(QtProperty *property)
|
---|
2954 | {
|
---|
2955 | d_ptr->m_values[property] = QtPointFPropertyManagerPrivate::Data();
|
---|
2956 |
|
---|
2957 | QtProperty *xProp = d_ptr->m_doublePropertyManager->addProperty();
|
---|
2958 | xProp->setPropertyName(tr("X"));
|
---|
2959 | d_ptr->m_doublePropertyManager->setDecimals(xProp, decimals(property));
|
---|
2960 | d_ptr->m_doublePropertyManager->setValue(xProp, 0);
|
---|
2961 | d_ptr->m_propertyToX[property] = xProp;
|
---|
2962 | d_ptr->m_xToProperty[xProp] = property;
|
---|
2963 | property->addSubProperty(xProp);
|
---|
2964 |
|
---|
2965 | QtProperty *yProp = d_ptr->m_doublePropertyManager->addProperty();
|
---|
2966 | yProp->setPropertyName(tr("Y"));
|
---|
2967 | d_ptr->m_doublePropertyManager->setDecimals(yProp, decimals(property));
|
---|
2968 | d_ptr->m_doublePropertyManager->setValue(yProp, 0);
|
---|
2969 | d_ptr->m_propertyToY[property] = yProp;
|
---|
2970 | d_ptr->m_yToProperty[yProp] = property;
|
---|
2971 | property->addSubProperty(yProp);
|
---|
2972 | }
|
---|
2973 |
|
---|
2974 | /*!
|
---|
2975 | \reimp
|
---|
2976 | */
|
---|
2977 | void QtPointFPropertyManager::uninitializeProperty(QtProperty *property)
|
---|
2978 | {
|
---|
2979 | QtProperty *xProp = d_ptr->m_propertyToX[property];
|
---|
2980 | if (xProp) {
|
---|
2981 | d_ptr->m_xToProperty.remove(xProp);
|
---|
2982 | delete xProp;
|
---|
2983 | }
|
---|
2984 | d_ptr->m_propertyToX.remove(property);
|
---|
2985 |
|
---|
2986 | QtProperty *yProp = d_ptr->m_propertyToY[property];
|
---|
2987 | if (yProp) {
|
---|
2988 | d_ptr->m_yToProperty.remove(yProp);
|
---|
2989 | delete yProp;
|
---|
2990 | }
|
---|
2991 | d_ptr->m_propertyToY.remove(property);
|
---|
2992 |
|
---|
2993 | d_ptr->m_values.remove(property);
|
---|
2994 | }
|
---|
2995 |
|
---|
2996 | // QtSizePropertyManager
|
---|
2997 |
|
---|
2998 | class QtSizePropertyManagerPrivate
|
---|
2999 | {
|
---|
3000 | QtSizePropertyManager *q_ptr;
|
---|
3001 | Q_DECLARE_PUBLIC(QtSizePropertyManager)
|
---|
3002 | public:
|
---|
3003 |
|
---|
3004 | void slotIntChanged(QtProperty *property, int value);
|
---|
3005 | void slotPropertyDestroyed(QtProperty *property);
|
---|
3006 | void setValue(QtProperty *property, const QSize &val);
|
---|
3007 | void setRange(QtProperty *property,
|
---|
3008 | const QSize &minVal, const QSize &maxVal, const QSize &val);
|
---|
3009 |
|
---|
3010 | struct Data
|
---|
3011 | {
|
---|
3012 | Data() : val(QSize(0, 0)), minVal(QSize(0, 0)), maxVal(QSize(INT_MAX, INT_MAX)) {}
|
---|
3013 | QSize val;
|
---|
3014 | QSize minVal;
|
---|
3015 | QSize maxVal;
|
---|
3016 | QSize minimumValue() const { return minVal; }
|
---|
3017 | QSize maximumValue() const { return maxVal; }
|
---|
3018 | void setMinimumValue(const QSize &newMinVal) { setSizeMinimumData(this, newMinVal); }
|
---|
3019 | void setMaximumValue(const QSize &newMaxVal) { setSizeMaximumData(this, newMaxVal); }
|
---|
3020 | };
|
---|
3021 |
|
---|
3022 | typedef QMap<const QtProperty *, Data> PropertyValueMap;
|
---|
3023 | PropertyValueMap m_values;
|
---|
3024 |
|
---|
3025 | QtIntPropertyManager *m_intPropertyManager;
|
---|
3026 |
|
---|
3027 | QMap<const QtProperty *, QtProperty *> m_propertyToW;
|
---|
3028 | QMap<const QtProperty *, QtProperty *> m_propertyToH;
|
---|
3029 |
|
---|
3030 | QMap<const QtProperty *, QtProperty *> m_wToProperty;
|
---|
3031 | QMap<const QtProperty *, QtProperty *> m_hToProperty;
|
---|
3032 | };
|
---|
3033 |
|
---|
3034 | void QtSizePropertyManagerPrivate::slotIntChanged(QtProperty *property, int value)
|
---|
3035 | {
|
---|
3036 | if (QtProperty *prop = m_wToProperty.value(property, 0)) {
|
---|
3037 | QSize s = m_values[prop].val;
|
---|
3038 | s.setWidth(value);
|
---|
3039 | q_ptr->setValue(prop, s);
|
---|
3040 | } else if (QtProperty *prop = m_hToProperty.value(property, 0)) {
|
---|
3041 | QSize s = m_values[prop].val;
|
---|
3042 | s.setHeight(value);
|
---|
3043 | q_ptr->setValue(prop, s);
|
---|
3044 | }
|
---|
3045 | }
|
---|
3046 |
|
---|
3047 | void QtSizePropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
|
---|
3048 | {
|
---|
3049 | if (QtProperty *pointProp = m_wToProperty.value(property, 0)) {
|
---|
3050 | m_propertyToW[pointProp] = 0;
|
---|
3051 | m_wToProperty.remove(property);
|
---|
3052 | } else if (QtProperty *pointProp = m_hToProperty.value(property, 0)) {
|
---|
3053 | m_propertyToH[pointProp] = 0;
|
---|
3054 | m_hToProperty.remove(property);
|
---|
3055 | }
|
---|
3056 | }
|
---|
3057 |
|
---|
3058 | void QtSizePropertyManagerPrivate::setValue(QtProperty *property, const QSize &val)
|
---|
3059 | {
|
---|
3060 | m_intPropertyManager->setValue(m_propertyToW.value(property), val.width());
|
---|
3061 | m_intPropertyManager->setValue(m_propertyToH.value(property), val.height());
|
---|
3062 | }
|
---|
3063 |
|
---|
3064 | void QtSizePropertyManagerPrivate::setRange(QtProperty *property,
|
---|
3065 | const QSize &minVal, const QSize &maxVal, const QSize &val)
|
---|
3066 | {
|
---|
3067 | QtProperty *wProperty = m_propertyToW.value(property);
|
---|
3068 | QtProperty *hProperty = m_propertyToH.value(property);
|
---|
3069 | m_intPropertyManager->setRange(wProperty, minVal.width(), maxVal.width());
|
---|
3070 | m_intPropertyManager->setValue(wProperty, val.width());
|
---|
3071 | m_intPropertyManager->setRange(hProperty, minVal.height(), maxVal.height());
|
---|
3072 | m_intPropertyManager->setValue(hProperty, val.height());
|
---|
3073 | }
|
---|
3074 |
|
---|
3075 | /*!
|
---|
3076 | \class QtSizePropertyManager
|
---|
3077 | \internal
|
---|
3078 | \inmodule QtDesigner
|
---|
3079 | \since 4.4
|
---|
3080 |
|
---|
3081 | \brief The QtSizePropertyManager provides and manages QSize properties.
|
---|
3082 |
|
---|
3083 | A size property has nested \e width and \e height
|
---|
3084 | subproperties. The top-level property's value can be retrieved
|
---|
3085 | using the value() function, and set using the setValue() slot.
|
---|
3086 |
|
---|
3087 | The subproperties are created by a QtIntPropertyManager object. This
|
---|
3088 | manager can be retrieved using the subIntPropertyManager() function. In
|
---|
3089 | order to provide editing widgets for the subproperties in a
|
---|
3090 | property browser widget, this manager must be associated with an
|
---|
3091 | editor factory.
|
---|
3092 |
|
---|
3093 | A size property also has a range of valid values defined by a
|
---|
3094 | minimum size and a maximum size. These sizes can be retrieved
|
---|
3095 | using the minimum() and the maximum() functions, and set using the
|
---|
3096 | setMinimum() and setMaximum() slots. Alternatively, the range can
|
---|
3097 | be defined in one go using the setRange() slot.
|
---|
3098 |
|
---|
3099 | In addition, QtSizePropertyManager provides the valueChanged() signal
|
---|
3100 | which is emitted whenever a property created by this manager
|
---|
3101 | changes, and the rangeChanged() signal which is emitted whenever
|
---|
3102 | such a property changes its range of valid sizes.
|
---|
3103 |
|
---|
3104 | \sa QtAbstractPropertyManager, QtIntPropertyManager, QtSizeFPropertyManager
|
---|
3105 | */
|
---|
3106 |
|
---|
3107 | /*!
|
---|
3108 | \fn void QtSizePropertyManager::valueChanged(QtProperty *property, const QSize &value)
|
---|
3109 |
|
---|
3110 | This signal is emitted whenever a property created by this manager
|
---|
3111 | changes its value, passing a pointer to the \a property and the new
|
---|
3112 | \a value as parameters.
|
---|
3113 |
|
---|
3114 | \sa setValue()
|
---|
3115 | */
|
---|
3116 |
|
---|
3117 | /*!
|
---|
3118 | \fn void QtSizePropertyManager::rangeChanged(QtProperty *property, const QSize &minimum, const QSize &maximum)
|
---|
3119 |
|
---|
3120 | This signal is emitted whenever a property created by this manager
|
---|
3121 | changes its range of valid sizes, passing a pointer to the \a
|
---|
3122 | property and the new \a minimum and \a maximum sizes.
|
---|
3123 |
|
---|
3124 | \sa setRange()
|
---|
3125 | */
|
---|
3126 |
|
---|
3127 | /*!
|
---|
3128 | Creates a manager with the given \a parent.
|
---|
3129 | */
|
---|
3130 | QtSizePropertyManager::QtSizePropertyManager(QObject *parent)
|
---|
3131 | : QtAbstractPropertyManager(parent), d_ptr(new QtSizePropertyManagerPrivate)
|
---|
3132 | {
|
---|
3133 | d_ptr->q_ptr = this;
|
---|
3134 |
|
---|
3135 | d_ptr->m_intPropertyManager = new QtIntPropertyManager(this);
|
---|
3136 | connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty*,int)),
|
---|
3137 | this, SLOT(slotIntChanged(QtProperty*,int)));
|
---|
3138 | connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
|
---|
3139 | this, SLOT(slotPropertyDestroyed(QtProperty*)));
|
---|
3140 | }
|
---|
3141 |
|
---|
3142 | /*!
|
---|
3143 | Destroys this manager, and all the properties it has created.
|
---|
3144 | */
|
---|
3145 | QtSizePropertyManager::~QtSizePropertyManager()
|
---|
3146 | {
|
---|
3147 | clear();
|
---|
3148 | }
|
---|
3149 |
|
---|
3150 | /*!
|
---|
3151 | Returns the manager that creates the nested \e width and \e height
|
---|
3152 | subproperties.
|
---|
3153 |
|
---|
3154 | In order to provide editing widgets for the \e width and \e height
|
---|
3155 | properties in a property browser widget, this manager must be
|
---|
3156 | associated with an editor factory.
|
---|
3157 |
|
---|
3158 | \sa QtAbstractPropertyBrowser::setFactoryForManager()
|
---|
3159 | */
|
---|
3160 | QtIntPropertyManager *QtSizePropertyManager::subIntPropertyManager() const
|
---|
3161 | {
|
---|
3162 | return d_ptr->m_intPropertyManager;
|
---|
3163 | }
|
---|
3164 |
|
---|
3165 | /*!
|
---|
3166 | Returns the given \a property's value.
|
---|
3167 |
|
---|
3168 | If the given \a property is not managed by this manager, this
|
---|
3169 | function returns an invalid size
|
---|
3170 |
|
---|
3171 | \sa setValue()
|
---|
3172 | */
|
---|
3173 | QSize QtSizePropertyManager::value(const QtProperty *property) const
|
---|
3174 | {
|
---|
3175 | return getValue<QSize>(d_ptr->m_values, property);
|
---|
3176 | }
|
---|
3177 |
|
---|
3178 | /*!
|
---|
3179 | Returns the given \a property's minimum size value.
|
---|
3180 |
|
---|
3181 | \sa setMinimum(), maximum(), setRange()
|
---|
3182 | */
|
---|
3183 | QSize QtSizePropertyManager::minimum(const QtProperty *property) const
|
---|
3184 | {
|
---|
3185 | return getMinimum<QSize>(d_ptr->m_values, property);
|
---|
3186 | }
|
---|
3187 |
|
---|
3188 | /*!
|
---|
3189 | Returns the given \a property's maximum size value.
|
---|
3190 |
|
---|
3191 | \sa setMaximum(), minimum(), setRange()
|
---|
3192 | */
|
---|
3193 | QSize QtSizePropertyManager::maximum(const QtProperty *property) const
|
---|
3194 | {
|
---|
3195 | return getMaximum<QSize>(d_ptr->m_values, property);
|
---|
3196 | }
|
---|
3197 |
|
---|
3198 | /*!
|
---|
3199 | \reimp
|
---|
3200 | */
|
---|
3201 | QString QtSizePropertyManager::valueText(const QtProperty *property) const
|
---|
3202 | {
|
---|
3203 | const QtSizePropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
---|
3204 | if (it == d_ptr->m_values.constEnd())
|
---|
3205 | return QString();
|
---|
3206 | const QSize v = it.value().val;
|
---|
3207 | return tr("%1 x %2").arg(QString::number(v.width()))
|
---|
3208 | .arg(QString::number(v.height()));
|
---|
3209 | }
|
---|
3210 |
|
---|
3211 | /*!
|
---|
3212 | \fn void QtSizePropertyManager::setValue(QtProperty *property, const QSize &value)
|
---|
3213 |
|
---|
3214 | Sets the value of the given \a property to \a value.
|
---|
3215 |
|
---|
3216 | If the specified \a value is not valid according to the given \a
|
---|
3217 | property's size range, the \a value is adjusted to the nearest
|
---|
3218 | valid value within the size range.
|
---|
3219 |
|
---|
3220 | \sa value(), setRange(), valueChanged()
|
---|
3221 | */
|
---|
3222 | void QtSizePropertyManager::setValue(QtProperty *property, const QSize &val)
|
---|
3223 | {
|
---|
3224 | setValueInRange<const QSize &, QtSizePropertyManagerPrivate, QtSizePropertyManager, const QSize>(this, d_ptr.data(),
|
---|
3225 | &QtSizePropertyManager::propertyChanged,
|
---|
3226 | &QtSizePropertyManager::valueChanged,
|
---|
3227 | property, val, &QtSizePropertyManagerPrivate::setValue);
|
---|
3228 | }
|
---|
3229 |
|
---|
3230 | /*!
|
---|
3231 | Sets the minimum size value for the given \a property to \a minVal.
|
---|
3232 |
|
---|
3233 | When setting the minimum size value, the maximum and current
|
---|
3234 | values are adjusted if necessary (ensuring that the size range
|
---|
3235 | remains valid and that the current value is within the range).
|
---|
3236 |
|
---|
3237 | \sa minimum(), setRange(), rangeChanged()
|
---|
3238 | */
|
---|
3239 | void QtSizePropertyManager::setMinimum(QtProperty *property, const QSize &minVal)
|
---|
3240 | {
|
---|
3241 | setBorderValue<const QSize &, QtSizePropertyManagerPrivate, QtSizePropertyManager, QSize, QtSizePropertyManagerPrivate::Data>(this, d_ptr.data(),
|
---|
3242 | &QtSizePropertyManager::propertyChanged,
|
---|
3243 | &QtSizePropertyManager::valueChanged,
|
---|
3244 | &QtSizePropertyManager::rangeChanged,
|
---|
3245 | property,
|
---|
3246 | &QtSizePropertyManagerPrivate::Data::minimumValue,
|
---|
3247 | &QtSizePropertyManagerPrivate::Data::setMinimumValue,
|
---|
3248 | minVal, &QtSizePropertyManagerPrivate::setRange);
|
---|
3249 | }
|
---|
3250 |
|
---|
3251 | /*!
|
---|
3252 | Sets the maximum size value for the given \a property to \a maxVal.
|
---|
3253 |
|
---|
3254 | When setting the maximum size value, the minimum and current
|
---|
3255 | values are adjusted if necessary (ensuring that the size range
|
---|
3256 | remains valid and that the current value is within the range).
|
---|
3257 |
|
---|
3258 | \sa maximum(), setRange(), rangeChanged()
|
---|
3259 | */
|
---|
3260 | void QtSizePropertyManager::setMaximum(QtProperty *property, const QSize &maxVal)
|
---|
3261 | {
|
---|
3262 | setBorderValue<const QSize &, QtSizePropertyManagerPrivate, QtSizePropertyManager, QSize, QtSizePropertyManagerPrivate::Data>(this, d_ptr.data(),
|
---|
3263 | &QtSizePropertyManager::propertyChanged,
|
---|
3264 | &QtSizePropertyManager::valueChanged,
|
---|
3265 | &QtSizePropertyManager::rangeChanged,
|
---|
3266 | property,
|
---|
3267 | &QtSizePropertyManagerPrivate::Data::maximumValue,
|
---|
3268 | &QtSizePropertyManagerPrivate::Data::setMaximumValue,
|
---|
3269 | maxVal, &QtSizePropertyManagerPrivate::setRange);
|
---|
3270 | }
|
---|
3271 |
|
---|
3272 | /*!
|
---|
3273 | \fn void QtSizePropertyManager::setRange(QtProperty *property, const QSize &minimum, const QSize &maximum)
|
---|
3274 |
|
---|
3275 | Sets the range of valid values.
|
---|
3276 |
|
---|
3277 | This is a convenience function defining the range of valid values
|
---|
3278 | in one go; setting the \a minimum and \a maximum values for the
|
---|
3279 | given \a property with a single function call.
|
---|
3280 |
|
---|
3281 | When setting a new range, the current value is adjusted if
|
---|
3282 | necessary (ensuring that the value remains within the range).
|
---|
3283 |
|
---|
3284 | \sa setMinimum(), setMaximum(), rangeChanged()
|
---|
3285 | */
|
---|
3286 | void QtSizePropertyManager::setRange(QtProperty *property, const QSize &minVal, const QSize &maxVal)
|
---|
3287 | {
|
---|
3288 | setBorderValues<const QSize &, QtSizePropertyManagerPrivate, QtSizePropertyManager, QSize>(this, d_ptr.data(),
|
---|
3289 | &QtSizePropertyManager::propertyChanged,
|
---|
3290 | &QtSizePropertyManager::valueChanged,
|
---|
3291 | &QtSizePropertyManager::rangeChanged,
|
---|
3292 | property, minVal, maxVal, &QtSizePropertyManagerPrivate::setRange);
|
---|
3293 | }
|
---|
3294 |
|
---|
3295 | /*!
|
---|
3296 | \reimp
|
---|
3297 | */
|
---|
3298 | void QtSizePropertyManager::initializeProperty(QtProperty *property)
|
---|
3299 | {
|
---|
3300 | d_ptr->m_values[property] = QtSizePropertyManagerPrivate::Data();
|
---|
3301 |
|
---|
3302 | QtProperty *wProp = d_ptr->m_intPropertyManager->addProperty();
|
---|
3303 | wProp->setPropertyName(tr("Width"));
|
---|
3304 | d_ptr->m_intPropertyManager->setValue(wProp, 0);
|
---|
3305 | d_ptr->m_intPropertyManager->setMinimum(wProp, 0);
|
---|
3306 | d_ptr->m_propertyToW[property] = wProp;
|
---|
3307 | d_ptr->m_wToProperty[wProp] = property;
|
---|
3308 | property->addSubProperty(wProp);
|
---|
3309 |
|
---|
3310 | QtProperty *hProp = d_ptr->m_intPropertyManager->addProperty();
|
---|
3311 | hProp->setPropertyName(tr("Height"));
|
---|
3312 | d_ptr->m_intPropertyManager->setValue(hProp, 0);
|
---|
3313 | d_ptr->m_intPropertyManager->setMinimum(hProp, 0);
|
---|
3314 | d_ptr->m_propertyToH[property] = hProp;
|
---|
3315 | d_ptr->m_hToProperty[hProp] = property;
|
---|
3316 | property->addSubProperty(hProp);
|
---|
3317 | }
|
---|
3318 |
|
---|
3319 | /*!
|
---|
3320 | \reimp
|
---|
3321 | */
|
---|
3322 | void QtSizePropertyManager::uninitializeProperty(QtProperty *property)
|
---|
3323 | {
|
---|
3324 | QtProperty *wProp = d_ptr->m_propertyToW[property];
|
---|
3325 | if (wProp) {
|
---|
3326 | d_ptr->m_wToProperty.remove(wProp);
|
---|
3327 | delete wProp;
|
---|
3328 | }
|
---|
3329 | d_ptr->m_propertyToW.remove(property);
|
---|
3330 |
|
---|
3331 | QtProperty *hProp = d_ptr->m_propertyToH[property];
|
---|
3332 | if (hProp) {
|
---|
3333 | d_ptr->m_hToProperty.remove(hProp);
|
---|
3334 | delete hProp;
|
---|
3335 | }
|
---|
3336 | d_ptr->m_propertyToH.remove(property);
|
---|
3337 |
|
---|
3338 | d_ptr->m_values.remove(property);
|
---|
3339 | }
|
---|
3340 |
|
---|
3341 | // QtSizeFPropertyManager
|
---|
3342 |
|
---|
3343 | class QtSizeFPropertyManagerPrivate
|
---|
3344 | {
|
---|
3345 | QtSizeFPropertyManager *q_ptr;
|
---|
3346 | Q_DECLARE_PUBLIC(QtSizeFPropertyManager)
|
---|
3347 | public:
|
---|
3348 |
|
---|
3349 | void slotDoubleChanged(QtProperty *property, double value);
|
---|
3350 | void slotPropertyDestroyed(QtProperty *property);
|
---|
3351 | void setValue(QtProperty *property, const QSizeF &val);
|
---|
3352 | void setRange(QtProperty *property,
|
---|
3353 | const QSizeF &minVal, const QSizeF &maxVal, const QSizeF &val);
|
---|
3354 |
|
---|
3355 | struct Data
|
---|
3356 | {
|
---|
3357 | Data() : val(QSizeF(0, 0)), minVal(QSizeF(0, 0)), maxVal(QSizeF(INT_MAX, INT_MAX)), decimals(2) {}
|
---|
3358 | QSizeF val;
|
---|
3359 | QSizeF minVal;
|
---|
3360 | QSizeF maxVal;
|
---|
3361 | int decimals;
|
---|
3362 | QSizeF minimumValue() const { return minVal; }
|
---|
3363 | QSizeF maximumValue() const { return maxVal; }
|
---|
3364 | void setMinimumValue(const QSizeF &newMinVal) { setSizeMinimumData(this, newMinVal); }
|
---|
3365 | void setMaximumValue(const QSizeF &newMaxVal) { setSizeMaximumData(this, newMaxVal); }
|
---|
3366 | };
|
---|
3367 |
|
---|
3368 | typedef QMap<const QtProperty *, Data> PropertyValueMap;
|
---|
3369 | PropertyValueMap m_values;
|
---|
3370 |
|
---|
3371 | QtDoublePropertyManager *m_doublePropertyManager;
|
---|
3372 |
|
---|
3373 | QMap<const QtProperty *, QtProperty *> m_propertyToW;
|
---|
3374 | QMap<const QtProperty *, QtProperty *> m_propertyToH;
|
---|
3375 |
|
---|
3376 | QMap<const QtProperty *, QtProperty *> m_wToProperty;
|
---|
3377 | QMap<const QtProperty *, QtProperty *> m_hToProperty;
|
---|
3378 | };
|
---|
3379 |
|
---|
3380 | void QtSizeFPropertyManagerPrivate::slotDoubleChanged(QtProperty *property, double value)
|
---|
3381 | {
|
---|
3382 | if (QtProperty *prop = m_wToProperty.value(property, 0)) {
|
---|
3383 | QSizeF s = m_values[prop].val;
|
---|
3384 | s.setWidth(value);
|
---|
3385 | q_ptr->setValue(prop, s);
|
---|
3386 | } else if (QtProperty *prop = m_hToProperty.value(property, 0)) {
|
---|
3387 | QSizeF s = m_values[prop].val;
|
---|
3388 | s.setHeight(value);
|
---|
3389 | q_ptr->setValue(prop, s);
|
---|
3390 | }
|
---|
3391 | }
|
---|
3392 |
|
---|
3393 | void QtSizeFPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
|
---|
3394 | {
|
---|
3395 | if (QtProperty *pointProp = m_wToProperty.value(property, 0)) {
|
---|
3396 | m_propertyToW[pointProp] = 0;
|
---|
3397 | m_wToProperty.remove(property);
|
---|
3398 | } else if (QtProperty *pointProp = m_hToProperty.value(property, 0)) {
|
---|
3399 | m_propertyToH[pointProp] = 0;
|
---|
3400 | m_hToProperty.remove(property);
|
---|
3401 | }
|
---|
3402 | }
|
---|
3403 |
|
---|
3404 | void QtSizeFPropertyManagerPrivate::setValue(QtProperty *property, const QSizeF &val)
|
---|
3405 | {
|
---|
3406 | m_doublePropertyManager->setValue(m_propertyToW.value(property), val.width());
|
---|
3407 | m_doublePropertyManager->setValue(m_propertyToH.value(property), val.height());
|
---|
3408 | }
|
---|
3409 |
|
---|
3410 | void QtSizeFPropertyManagerPrivate::setRange(QtProperty *property,
|
---|
3411 | const QSizeF &minVal, const QSizeF &maxVal, const QSizeF &val)
|
---|
3412 | {
|
---|
3413 | m_doublePropertyManager->setRange(m_propertyToW[property], minVal.width(), maxVal.width());
|
---|
3414 | m_doublePropertyManager->setValue(m_propertyToW[property], val.width());
|
---|
3415 | m_doublePropertyManager->setRange(m_propertyToH[property], minVal.height(), maxVal.height());
|
---|
3416 | m_doublePropertyManager->setValue(m_propertyToH[property], val.height());
|
---|
3417 | }
|
---|
3418 |
|
---|
3419 | /*!
|
---|
3420 | \class QtSizeFPropertyManager
|
---|
3421 | \internal
|
---|
3422 | \inmodule QtDesigner
|
---|
3423 | \since 4.4
|
---|
3424 |
|
---|
3425 | \brief The QtSizeFPropertyManager provides and manages QSizeF properties.
|
---|
3426 |
|
---|
3427 | A size property has nested \e width and \e height
|
---|
3428 | subproperties. The top-level property's value can be retrieved
|
---|
3429 | using the value() function, and set using the setValue() slot.
|
---|
3430 |
|
---|
3431 | The subproperties are created by a QtDoublePropertyManager object. This
|
---|
3432 | manager can be retrieved using the subDoublePropertyManager() function. In
|
---|
3433 | order to provide editing widgets for the subproperties in a
|
---|
3434 | property browser widget, this manager must be associated with an
|
---|
3435 | editor factory.
|
---|
3436 |
|
---|
3437 | A size property also has a range of valid values defined by a
|
---|
3438 | minimum size and a maximum size. These sizes can be retrieved
|
---|
3439 | using the minimum() and the maximum() functions, and set using the
|
---|
3440 | setMinimum() and setMaximum() slots. Alternatively, the range can
|
---|
3441 | be defined in one go using the setRange() slot.
|
---|
3442 |
|
---|
3443 | In addition, QtSizeFPropertyManager provides the valueChanged() signal
|
---|
3444 | which is emitted whenever a property created by this manager
|
---|
3445 | changes, and the rangeChanged() signal which is emitted whenever
|
---|
3446 | such a property changes its range of valid sizes.
|
---|
3447 |
|
---|
3448 | \sa QtAbstractPropertyManager, QtDoublePropertyManager, QtSizePropertyManager
|
---|
3449 | */
|
---|
3450 |
|
---|
3451 | /*!
|
---|
3452 | \fn void QtSizeFPropertyManager::valueChanged(QtProperty *property, const QSizeF &value)
|
---|
3453 |
|
---|
3454 | This signal is emitted whenever a property created by this manager
|
---|
3455 | changes its value, passing a pointer to the \a property and the new
|
---|
3456 | \a value as parameters.
|
---|
3457 |
|
---|
3458 | \sa setValue()
|
---|
3459 | */
|
---|
3460 |
|
---|
3461 | /*!
|
---|
3462 | \fn void QtSizeFPropertyManager::rangeChanged(QtProperty *property, const QSizeF &minimum, const QSizeF &maximum)
|
---|
3463 |
|
---|
3464 | This signal is emitted whenever a property created by this manager
|
---|
3465 | changes its range of valid sizes, passing a pointer to the \a
|
---|
3466 | property and the new \a minimum and \a maximum sizes.
|
---|
3467 |
|
---|
3468 | \sa setRange()
|
---|
3469 | */
|
---|
3470 |
|
---|
3471 | /*!
|
---|
3472 | \fn void QtSizeFPropertyManager::decimalsChanged(QtProperty *property, int prec)
|
---|
3473 |
|
---|
3474 | This signal is emitted whenever a property created by this manager
|
---|
3475 | changes its precision of value, passing a pointer to the
|
---|
3476 | \a property and the new \a prec value
|
---|
3477 |
|
---|
3478 | \sa setDecimals()
|
---|
3479 | */
|
---|
3480 |
|
---|
3481 | /*!
|
---|
3482 | Creates a manager with the given \a parent.
|
---|
3483 | */
|
---|
3484 | QtSizeFPropertyManager::QtSizeFPropertyManager(QObject *parent)
|
---|
3485 | : QtAbstractPropertyManager(parent), d_ptr(new QtSizeFPropertyManagerPrivate)
|
---|
3486 | {
|
---|
3487 | d_ptr->q_ptr = this;
|
---|
3488 |
|
---|
3489 | d_ptr->m_doublePropertyManager = new QtDoublePropertyManager(this);
|
---|
3490 | connect(d_ptr->m_doublePropertyManager, SIGNAL(valueChanged(QtProperty*,double)),
|
---|
3491 | this, SLOT(slotDoubleChanged(QtProperty*,double)));
|
---|
3492 | connect(d_ptr->m_doublePropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
|
---|
3493 | this, SLOT(slotPropertyDestroyed(QtProperty*)));
|
---|
3494 | }
|
---|
3495 |
|
---|
3496 | /*!
|
---|
3497 | Destroys this manager, and all the properties it has created.
|
---|
3498 | */
|
---|
3499 | QtSizeFPropertyManager::~QtSizeFPropertyManager()
|
---|
3500 | {
|
---|
3501 | clear();
|
---|
3502 | }
|
---|
3503 |
|
---|
3504 | /*!
|
---|
3505 | Returns the manager that creates the nested \e width and \e height
|
---|
3506 | subproperties.
|
---|
3507 |
|
---|
3508 | In order to provide editing widgets for the \e width and \e height
|
---|
3509 | properties in a property browser widget, this manager must be
|
---|
3510 | associated with an editor factory.
|
---|
3511 |
|
---|
3512 | \sa QtAbstractPropertyBrowser::setFactoryForManager()
|
---|
3513 | */
|
---|
3514 | QtDoublePropertyManager *QtSizeFPropertyManager::subDoublePropertyManager() const
|
---|
3515 | {
|
---|
3516 | return d_ptr->m_doublePropertyManager;
|
---|
3517 | }
|
---|
3518 |
|
---|
3519 | /*!
|
---|
3520 | Returns the given \a property's value.
|
---|
3521 |
|
---|
3522 | If the given \a property is not managed by this manager, this
|
---|
3523 | function returns an invalid size
|
---|
3524 |
|
---|
3525 | \sa setValue()
|
---|
3526 | */
|
---|
3527 | QSizeF QtSizeFPropertyManager::value(const QtProperty *property) const
|
---|
3528 | {
|
---|
3529 | return getValue<QSizeF>(d_ptr->m_values, property);
|
---|
3530 | }
|
---|
3531 |
|
---|
3532 | /*!
|
---|
3533 | Returns the given \a property's precision, in decimals.
|
---|
3534 |
|
---|
3535 | \sa setDecimals()
|
---|
3536 | */
|
---|
3537 | int QtSizeFPropertyManager::decimals(const QtProperty *property) const
|
---|
3538 | {
|
---|
3539 | return getData<int>(d_ptr->m_values, &QtSizeFPropertyManagerPrivate::Data::decimals, property, 0);
|
---|
3540 | }
|
---|
3541 |
|
---|
3542 | /*!
|
---|
3543 | Returns the given \a property's minimum size value.
|
---|
3544 |
|
---|
3545 | \sa setMinimum(), maximum(), setRange()
|
---|
3546 | */
|
---|
3547 | QSizeF QtSizeFPropertyManager::minimum(const QtProperty *property) const
|
---|
3548 | {
|
---|
3549 | return getMinimum<QSizeF>(d_ptr->m_values, property);
|
---|
3550 | }
|
---|
3551 |
|
---|
3552 | /*!
|
---|
3553 | Returns the given \a property's maximum size value.
|
---|
3554 |
|
---|
3555 | \sa setMaximum(), minimum(), setRange()
|
---|
3556 | */
|
---|
3557 | QSizeF QtSizeFPropertyManager::maximum(const QtProperty *property) const
|
---|
3558 | {
|
---|
3559 | return getMaximum<QSizeF>(d_ptr->m_values, property);
|
---|
3560 | }
|
---|
3561 |
|
---|
3562 | /*!
|
---|
3563 | \reimp
|
---|
3564 | */
|
---|
3565 | QString QtSizeFPropertyManager::valueText(const QtProperty *property) const
|
---|
3566 | {
|
---|
3567 | const QtSizeFPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
---|
3568 | if (it == d_ptr->m_values.constEnd())
|
---|
3569 | return QString();
|
---|
3570 | const QSizeF v = it.value().val;
|
---|
3571 | const int dec = it.value().decimals;
|
---|
3572 | return tr("%1 x %2").arg(QString::number(v.width(), 'f', dec))
|
---|
3573 | .arg(QString::number(v.height(), 'f', dec));
|
---|
3574 | }
|
---|
3575 |
|
---|
3576 | /*!
|
---|
3577 | \fn void QtSizeFPropertyManager::setValue(QtProperty *property, const QSizeF &value)
|
---|
3578 |
|
---|
3579 | Sets the value of the given \a property to \a value.
|
---|
3580 |
|
---|
3581 | If the specified \a value is not valid according to the given \a
|
---|
3582 | property's size range, the \a value is adjusted to the nearest
|
---|
3583 | valid value within the size range.
|
---|
3584 |
|
---|
3585 | \sa value(), setRange(), valueChanged()
|
---|
3586 | */
|
---|
3587 | void QtSizeFPropertyManager::setValue(QtProperty *property, const QSizeF &val)
|
---|
3588 | {
|
---|
3589 | setValueInRange<const QSizeF &, QtSizeFPropertyManagerPrivate, QtSizeFPropertyManager, QSizeF>(this, d_ptr.data(),
|
---|
3590 | &QtSizeFPropertyManager::propertyChanged,
|
---|
3591 | &QtSizeFPropertyManager::valueChanged,
|
---|
3592 | property, val, &QtSizeFPropertyManagerPrivate::setValue);
|
---|
3593 | }
|
---|
3594 |
|
---|
3595 | /*!
|
---|
3596 | \fn void QtSizeFPropertyManager::setDecimals(QtProperty *property, int prec)
|
---|
3597 |
|
---|
3598 | Sets the precision of the given \a property to \a prec.
|
---|
3599 |
|
---|
3600 | The valid decimal range is 0-13. The default is 2.
|
---|
3601 |
|
---|
3602 | \sa decimals()
|
---|
3603 | */
|
---|
3604 | void QtSizeFPropertyManager::setDecimals(QtProperty *property, int prec)
|
---|
3605 | {
|
---|
3606 | const QtSizeFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
---|
3607 | if (it == d_ptr->m_values.end())
|
---|
3608 | return;
|
---|
3609 |
|
---|
3610 | QtSizeFPropertyManagerPrivate::Data data = it.value();
|
---|
3611 |
|
---|
3612 | if (prec > 13)
|
---|
3613 | prec = 13;
|
---|
3614 | else if (prec < 0)
|
---|
3615 | prec = 0;
|
---|
3616 |
|
---|
3617 | if (data.decimals == prec)
|
---|
3618 | return;
|
---|
3619 |
|
---|
3620 | data.decimals = prec;
|
---|
3621 | d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToW[property], prec);
|
---|
3622 | d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToH[property], prec);
|
---|
3623 |
|
---|
3624 | it.value() = data;
|
---|
3625 |
|
---|
3626 | emit decimalsChanged(property, data.decimals);
|
---|
3627 | }
|
---|
3628 |
|
---|
3629 | /*!
|
---|
3630 | Sets the minimum size value for the given \a property to \a minVal.
|
---|
3631 |
|
---|
3632 | When setting the minimum size value, the maximum and current
|
---|
3633 | values are adjusted if necessary (ensuring that the size range
|
---|
3634 | remains valid and that the current value is within the range).
|
---|
3635 |
|
---|
3636 | \sa minimum(), setRange(), rangeChanged()
|
---|
3637 | */
|
---|
3638 | void QtSizeFPropertyManager::setMinimum(QtProperty *property, const QSizeF &minVal)
|
---|
3639 | {
|
---|
3640 | setBorderValue<const QSizeF &, QtSizeFPropertyManagerPrivate, QtSizeFPropertyManager, QSizeF, QtSizeFPropertyManagerPrivate::Data>(this, d_ptr.data(),
|
---|
3641 | &QtSizeFPropertyManager::propertyChanged,
|
---|
3642 | &QtSizeFPropertyManager::valueChanged,
|
---|
3643 | &QtSizeFPropertyManager::rangeChanged,
|
---|
3644 | property,
|
---|
3645 | &QtSizeFPropertyManagerPrivate::Data::minimumValue,
|
---|
3646 | &QtSizeFPropertyManagerPrivate::Data::setMinimumValue,
|
---|
3647 | minVal, &QtSizeFPropertyManagerPrivate::setRange);
|
---|
3648 | }
|
---|
3649 |
|
---|
3650 | /*!
|
---|
3651 | Sets the maximum size value for the given \a property to \a maxVal.
|
---|
3652 |
|
---|
3653 | When setting the maximum size value, the minimum and current
|
---|
3654 | values are adjusted if necessary (ensuring that the size range
|
---|
3655 | remains valid and that the current value is within the range).
|
---|
3656 |
|
---|
3657 | \sa maximum(), setRange(), rangeChanged()
|
---|
3658 | */
|
---|
3659 | void QtSizeFPropertyManager::setMaximum(QtProperty *property, const QSizeF &maxVal)
|
---|
3660 | {
|
---|
3661 | setBorderValue<const QSizeF &, QtSizeFPropertyManagerPrivate, QtSizeFPropertyManager, QSizeF, QtSizeFPropertyManagerPrivate::Data>(this, d_ptr.data(),
|
---|
3662 | &QtSizeFPropertyManager::propertyChanged,
|
---|
3663 | &QtSizeFPropertyManager::valueChanged,
|
---|
3664 | &QtSizeFPropertyManager::rangeChanged,
|
---|
3665 | property,
|
---|
3666 | &QtSizeFPropertyManagerPrivate::Data::maximumValue,
|
---|
3667 | &QtSizeFPropertyManagerPrivate::Data::setMaximumValue,
|
---|
3668 | maxVal, &QtSizeFPropertyManagerPrivate::setRange);
|
---|
3669 | }
|
---|
3670 |
|
---|
3671 | /*!
|
---|
3672 | \fn void QtSizeFPropertyManager::setRange(QtProperty *property, const QSizeF &minimum, const QSizeF &maximum)
|
---|
3673 |
|
---|
3674 | Sets the range of valid values.
|
---|
3675 |
|
---|
3676 | This is a convenience function defining the range of valid values
|
---|
3677 | in one go; setting the \a minimum and \a maximum values for the
|
---|
3678 | given \a property with a single function call.
|
---|
3679 |
|
---|
3680 | When setting a new range, the current value is adjusted if
|
---|
3681 | necessary (ensuring that the value remains within the range).
|
---|
3682 |
|
---|
3683 | \sa setMinimum(), setMaximum(), rangeChanged()
|
---|
3684 | */
|
---|
3685 | void QtSizeFPropertyManager::setRange(QtProperty *property, const QSizeF &minVal, const QSizeF &maxVal)
|
---|
3686 | {
|
---|
3687 | setBorderValues<const QSizeF &, QtSizeFPropertyManagerPrivate, QtSizeFPropertyManager, QSizeF>(this, d_ptr.data(),
|
---|
3688 | &QtSizeFPropertyManager::propertyChanged,
|
---|
3689 | &QtSizeFPropertyManager::valueChanged,
|
---|
3690 | &QtSizeFPropertyManager::rangeChanged,
|
---|
3691 | property, minVal, maxVal, &QtSizeFPropertyManagerPrivate::setRange);
|
---|
3692 | }
|
---|
3693 |
|
---|
3694 | /*!
|
---|
3695 | \reimp
|
---|
3696 | */
|
---|
3697 | void QtSizeFPropertyManager::initializeProperty(QtProperty *property)
|
---|
3698 | {
|
---|
3699 | d_ptr->m_values[property] = QtSizeFPropertyManagerPrivate::Data();
|
---|
3700 |
|
---|
3701 | QtProperty *wProp = d_ptr->m_doublePropertyManager->addProperty();
|
---|
3702 | wProp->setPropertyName(tr("Width"));
|
---|
3703 | d_ptr->m_doublePropertyManager->setDecimals(wProp, decimals(property));
|
---|
3704 | d_ptr->m_doublePropertyManager->setValue(wProp, 0);
|
---|
3705 | d_ptr->m_doublePropertyManager->setMinimum(wProp, 0);
|
---|
3706 | d_ptr->m_propertyToW[property] = wProp;
|
---|
3707 | d_ptr->m_wToProperty[wProp] = property;
|
---|
3708 | property->addSubProperty(wProp);
|
---|
3709 |
|
---|
3710 | QtProperty *hProp = d_ptr->m_doublePropertyManager->addProperty();
|
---|
3711 | hProp->setPropertyName(tr("Height"));
|
---|
3712 | d_ptr->m_doublePropertyManager->setDecimals(hProp, decimals(property));
|
---|
3713 | d_ptr->m_doublePropertyManager->setValue(hProp, 0);
|
---|
3714 | d_ptr->m_doublePropertyManager->setMinimum(hProp, 0);
|
---|
3715 | d_ptr->m_propertyToH[property] = hProp;
|
---|
3716 | d_ptr->m_hToProperty[hProp] = property;
|
---|
3717 | property->addSubProperty(hProp);
|
---|
3718 | }
|
---|
3719 |
|
---|
3720 | /*!
|
---|
3721 | \reimp
|
---|
3722 | */
|
---|
3723 | void QtSizeFPropertyManager::uninitializeProperty(QtProperty *property)
|
---|
3724 | {
|
---|
3725 | QtProperty *wProp = d_ptr->m_propertyToW[property];
|
---|
3726 | if (wProp) {
|
---|
3727 | d_ptr->m_wToProperty.remove(wProp);
|
---|
3728 | delete wProp;
|
---|
3729 | }
|
---|
3730 | d_ptr->m_propertyToW.remove(property);
|
---|
3731 |
|
---|
3732 | QtProperty *hProp = d_ptr->m_propertyToH[property];
|
---|
3733 | if (hProp) {
|
---|
3734 | d_ptr->m_hToProperty.remove(hProp);
|
---|
3735 | delete hProp;
|
---|
3736 | }
|
---|
3737 | d_ptr->m_propertyToH.remove(property);
|
---|
3738 |
|
---|
3739 | d_ptr->m_values.remove(property);
|
---|
3740 | }
|
---|
3741 |
|
---|
3742 | // QtRectPropertyManager
|
---|
3743 |
|
---|
3744 | class QtRectPropertyManagerPrivate
|
---|
3745 | {
|
---|
3746 | QtRectPropertyManager *q_ptr;
|
---|
3747 | Q_DECLARE_PUBLIC(QtRectPropertyManager)
|
---|
3748 | public:
|
---|
3749 |
|
---|
3750 | void slotIntChanged(QtProperty *property, int value);
|
---|
3751 | void slotPropertyDestroyed(QtProperty *property);
|
---|
3752 | void setConstraint(QtProperty *property, const QRect &constraint, const QRect &val);
|
---|
3753 |
|
---|
3754 | struct Data
|
---|
3755 | {
|
---|
3756 | Data() : val(0, 0, 0, 0) {}
|
---|
3757 | QRect val;
|
---|
3758 | QRect constraint;
|
---|
3759 | };
|
---|
3760 |
|
---|
3761 | typedef QMap<const QtProperty *, Data> PropertyValueMap;
|
---|
3762 | PropertyValueMap m_values;
|
---|
3763 |
|
---|
3764 | QtIntPropertyManager *m_intPropertyManager;
|
---|
3765 |
|
---|
3766 | QMap<const QtProperty *, QtProperty *> m_propertyToX;
|
---|
3767 | QMap<const QtProperty *, QtProperty *> m_propertyToY;
|
---|
3768 | QMap<const QtProperty *, QtProperty *> m_propertyToW;
|
---|
3769 | QMap<const QtProperty *, QtProperty *> m_propertyToH;
|
---|
3770 |
|
---|
3771 | QMap<const QtProperty *, QtProperty *> m_xToProperty;
|
---|
3772 | QMap<const QtProperty *, QtProperty *> m_yToProperty;
|
---|
3773 | QMap<const QtProperty *, QtProperty *> m_wToProperty;
|
---|
3774 | QMap<const QtProperty *, QtProperty *> m_hToProperty;
|
---|
3775 | };
|
---|
3776 |
|
---|
3777 | void QtRectPropertyManagerPrivate::slotIntChanged(QtProperty *property, int value)
|
---|
3778 | {
|
---|
3779 | if (QtProperty *prop = m_xToProperty.value(property, 0)) {
|
---|
3780 | QRect r = m_values[prop].val;
|
---|
3781 | r.moveLeft(value);
|
---|
3782 | q_ptr->setValue(prop, r);
|
---|
3783 | } else if (QtProperty *prop = m_yToProperty.value(property)) {
|
---|
3784 | QRect r = m_values[prop].val;
|
---|
3785 | r.moveTop(value);
|
---|
3786 | q_ptr->setValue(prop, r);
|
---|
3787 | } else if (QtProperty *prop = m_wToProperty.value(property, 0)) {
|
---|
3788 | Data data = m_values[prop];
|
---|
3789 | QRect r = data.val;
|
---|
3790 | r.setWidth(value);
|
---|
3791 | if (!data.constraint.isNull() && data.constraint.x() + data.constraint.width() < r.x() + r.width()) {
|
---|
3792 | r.moveLeft(data.constraint.left() + data.constraint.width() - r.width());
|
---|
3793 | }
|
---|
3794 | q_ptr->setValue(prop, r);
|
---|
3795 | } else if (QtProperty *prop = m_hToProperty.value(property, 0)) {
|
---|
3796 | Data data = m_values[prop];
|
---|
3797 | QRect r = data.val;
|
---|
3798 | r.setHeight(value);
|
---|
3799 | if (!data.constraint.isNull() && data.constraint.y() + data.constraint.height() < r.y() + r.height()) {
|
---|
3800 | r.moveTop(data.constraint.top() + data.constraint.height() - r.height());
|
---|
3801 | }
|
---|
3802 | q_ptr->setValue(prop, r);
|
---|
3803 | }
|
---|
3804 | }
|
---|
3805 |
|
---|
3806 | void QtRectPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
|
---|
3807 | {
|
---|
3808 | if (QtProperty *pointProp = m_xToProperty.value(property, 0)) {
|
---|
3809 | m_propertyToX[pointProp] = 0;
|
---|
3810 | m_xToProperty.remove(property);
|
---|
3811 | } else if (QtProperty *pointProp = m_yToProperty.value(property, 0)) {
|
---|
3812 | m_propertyToY[pointProp] = 0;
|
---|
3813 | m_yToProperty.remove(property);
|
---|
3814 | } else if (QtProperty *pointProp = m_wToProperty.value(property, 0)) {
|
---|
3815 | m_propertyToW[pointProp] = 0;
|
---|
3816 | m_wToProperty.remove(property);
|
---|
3817 | } else if (QtProperty *pointProp = m_hToProperty.value(property, 0)) {
|
---|
3818 | m_propertyToH[pointProp] = 0;
|
---|
3819 | m_hToProperty.remove(property);
|
---|
3820 | }
|
---|
3821 | }
|
---|
3822 |
|
---|
3823 | void QtRectPropertyManagerPrivate::setConstraint(QtProperty *property,
|
---|
3824 | const QRect &constraint, const QRect &val)
|
---|
3825 | {
|
---|
3826 | const bool isNull = constraint.isNull();
|
---|
3827 | const int left = isNull ? INT_MIN : constraint.left();
|
---|
3828 | const int right = isNull ? INT_MAX : constraint.left() + constraint.width();
|
---|
3829 | const int top = isNull ? INT_MIN : constraint.top();
|
---|
3830 | const int bottom = isNull ? INT_MAX : constraint.top() + constraint.height();
|
---|
3831 | const int width = isNull ? INT_MAX : constraint.width();
|
---|
3832 | const int height = isNull ? INT_MAX : constraint.height();
|
---|
3833 |
|
---|
3834 | m_intPropertyManager->setRange(m_propertyToX[property], left, right);
|
---|
3835 | m_intPropertyManager->setRange(m_propertyToY[property], top, bottom);
|
---|
3836 | m_intPropertyManager->setRange(m_propertyToW[property], 0, width);
|
---|
3837 | m_intPropertyManager->setRange(m_propertyToH[property], 0, height);
|
---|
3838 |
|
---|
3839 | m_intPropertyManager->setValue(m_propertyToX[property], val.x());
|
---|
3840 | m_intPropertyManager->setValue(m_propertyToY[property], val.y());
|
---|
3841 | m_intPropertyManager->setValue(m_propertyToW[property], val.width());
|
---|
3842 | m_intPropertyManager->setValue(m_propertyToH[property], val.height());
|
---|
3843 | }
|
---|
3844 |
|
---|
3845 | /*!
|
---|
3846 | \class QtRectPropertyManager
|
---|
3847 | \internal
|
---|
3848 | \inmodule QtDesigner
|
---|
3849 | \since 4.4
|
---|
3850 |
|
---|
3851 | \brief The QtRectPropertyManager provides and manages QRect properties.
|
---|
3852 |
|
---|
3853 | A rectangle property has nested \e x, \e y, \e width and \e height
|
---|
3854 | subproperties. The top-level property's value can be retrieved
|
---|
3855 | using the value() function, and set using the setValue() slot.
|
---|
3856 |
|
---|
3857 | The subproperties are created by a QtIntPropertyManager object. This
|
---|
3858 | manager can be retrieved using the subIntPropertyManager() function. In
|
---|
3859 | order to provide editing widgets for the subproperties in a
|
---|
3860 | property browser widget, this manager must be associated with an
|
---|
3861 | editor factory.
|
---|
3862 |
|
---|
3863 | A rectangle property also has a constraint rectangle which can be
|
---|
3864 | retrieved using the constraint() function, and set using the
|
---|
3865 | setConstraint() slot.
|
---|
3866 |
|
---|
3867 | In addition, QtRectPropertyManager provides the valueChanged() signal
|
---|
3868 | which is emitted whenever a property created by this manager
|
---|
3869 | changes, and the constraintChanged() signal which is emitted
|
---|
3870 | whenever such a property changes its constraint rectangle.
|
---|
3871 |
|
---|
3872 | \sa QtAbstractPropertyManager, QtIntPropertyManager, QtRectFPropertyManager
|
---|
3873 | */
|
---|
3874 |
|
---|
3875 | /*!
|
---|
3876 | \fn void QtRectPropertyManager::valueChanged(QtProperty *property, const QRect &value)
|
---|
3877 |
|
---|
3878 | This signal is emitted whenever a property created by this manager
|
---|
3879 | changes its value, passing a pointer to the \a property and the new
|
---|
3880 | \a value as parameters.
|
---|
3881 |
|
---|
3882 | \sa setValue()
|
---|
3883 | */
|
---|
3884 |
|
---|
3885 | /*!
|
---|
3886 | \fn void QtRectPropertyManager::constraintChanged(QtProperty *property, const QRect &constraint)
|
---|
3887 |
|
---|
3888 | This signal is emitted whenever property changes its constraint
|
---|
3889 | rectangle, passing a pointer to the \a property and the new \a
|
---|
3890 | constraint rectangle as parameters.
|
---|
3891 |
|
---|
3892 | \sa setConstraint()
|
---|
3893 | */
|
---|
3894 |
|
---|
3895 | /*!
|
---|
3896 | Creates a manager with the given \a parent.
|
---|
3897 | */
|
---|
3898 | QtRectPropertyManager::QtRectPropertyManager(QObject *parent)
|
---|
3899 | : QtAbstractPropertyManager(parent), d_ptr(new QtRectPropertyManagerPrivate)
|
---|
3900 | {
|
---|
3901 | d_ptr->q_ptr = this;
|
---|
3902 |
|
---|
3903 | d_ptr->m_intPropertyManager = new QtIntPropertyManager(this);
|
---|
3904 | connect(d_ptr->m_intPropertyManager, SIGNAL(valueChanged(QtProperty*,int)),
|
---|
3905 | this, SLOT(slotIntChanged(QtProperty*,int)));
|
---|
3906 | connect(d_ptr->m_intPropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
|
---|
3907 | this, SLOT(slotPropertyDestroyed(QtProperty*)));
|
---|
3908 | }
|
---|
3909 |
|
---|
3910 | /*!
|
---|
3911 | Destroys this manager, and all the properties it has created.
|
---|
3912 | */
|
---|
3913 | QtRectPropertyManager::~QtRectPropertyManager()
|
---|
3914 | {
|
---|
3915 | clear();
|
---|
3916 | }
|
---|
3917 |
|
---|
3918 | /*!
|
---|
3919 | Returns the manager that creates the nested \e x, \e y, \e width
|
---|
3920 | and \e height subproperties.
|
---|
3921 |
|
---|
3922 | In order to provide editing widgets for the mentioned
|
---|
3923 | subproperties in a property browser widget, this manager must be
|
---|
3924 | associated with an editor factory.
|
---|
3925 |
|
---|
3926 | \sa QtAbstractPropertyBrowser::setFactoryForManager()
|
---|
3927 | */
|
---|
3928 | QtIntPropertyManager *QtRectPropertyManager::subIntPropertyManager() const
|
---|
3929 | {
|
---|
3930 | return d_ptr->m_intPropertyManager;
|
---|
3931 | }
|
---|
3932 |
|
---|
3933 | /*!
|
---|
3934 | Returns the given \a property's value.
|
---|
3935 |
|
---|
3936 | If the given \a property is not managed by this manager, this
|
---|
3937 | function returns an invalid rectangle.
|
---|
3938 |
|
---|
3939 | \sa setValue(), constraint()
|
---|
3940 | */
|
---|
3941 | QRect QtRectPropertyManager::value(const QtProperty *property) const
|
---|
3942 | {
|
---|
3943 | return getValue<QRect>(d_ptr->m_values, property);
|
---|
3944 | }
|
---|
3945 |
|
---|
3946 | /*!
|
---|
3947 | Returns the given \a property's constraining rectangle. If returned value is null QRect it means there is no constraint applied.
|
---|
3948 |
|
---|
3949 | \sa value(), setConstraint()
|
---|
3950 | */
|
---|
3951 | QRect QtRectPropertyManager::constraint(const QtProperty *property) const
|
---|
3952 | {
|
---|
3953 | return getData<QRect>(d_ptr->m_values, &QtRectPropertyManagerPrivate::Data::constraint, property, QRect());
|
---|
3954 | }
|
---|
3955 |
|
---|
3956 | /*!
|
---|
3957 | \reimp
|
---|
3958 | */
|
---|
3959 | QString QtRectPropertyManager::valueText(const QtProperty *property) const
|
---|
3960 | {
|
---|
3961 | const QtRectPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
---|
3962 | if (it == d_ptr->m_values.constEnd())
|
---|
3963 | return QString();
|
---|
3964 | const QRect v = it.value().val;
|
---|
3965 | return tr("[(%1, %2), %3 x %4]").arg(QString::number(v.x()))
|
---|
3966 | .arg(QString::number(v.y()))
|
---|
3967 | .arg(QString::number(v.width()))
|
---|
3968 | .arg(QString::number(v.height()));
|
---|
3969 | }
|
---|
3970 |
|
---|
3971 | /*!
|
---|
3972 | \fn void QtRectPropertyManager::setValue(QtProperty *property, const QRect &value)
|
---|
3973 |
|
---|
3974 | Sets the value of the given \a property to \a value. Nested
|
---|
3975 | properties are updated automatically.
|
---|
3976 |
|
---|
3977 | If the specified \a value is not inside the given \a property's
|
---|
3978 | constraining rectangle, the value is adjusted accordingly to fit
|
---|
3979 | within the constraint.
|
---|
3980 |
|
---|
3981 | \sa value(), setConstraint(), valueChanged()
|
---|
3982 | */
|
---|
3983 | void QtRectPropertyManager::setValue(QtProperty *property, const QRect &val)
|
---|
3984 | {
|
---|
3985 | const QtRectPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
---|
3986 | if (it == d_ptr->m_values.end())
|
---|
3987 | return;
|
---|
3988 |
|
---|
3989 | QtRectPropertyManagerPrivate::Data data = it.value();
|
---|
3990 |
|
---|
3991 | QRect newRect = val.normalized();
|
---|
3992 | if (!data.constraint.isNull() && !data.constraint.contains(newRect)) {
|
---|
3993 | const QRect r1 = data.constraint;
|
---|
3994 | const QRect r2 = newRect;
|
---|
3995 | newRect.setLeft(qMax(r1.left(), r2.left()));
|
---|
3996 | newRect.setRight(qMin(r1.right(), r2.right()));
|
---|
3997 | newRect.setTop(qMax(r1.top(), r2.top()));
|
---|
3998 | newRect.setBottom(qMin(r1.bottom(), r2.bottom()));
|
---|
3999 | if (newRect.width() < 0 || newRect.height() < 0)
|
---|
4000 | return;
|
---|
4001 | }
|
---|
4002 |
|
---|
4003 | if (data.val == newRect)
|
---|
4004 | return;
|
---|
4005 |
|
---|
4006 | data.val = newRect;
|
---|
4007 |
|
---|
4008 | it.value() = data;
|
---|
4009 | d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToX[property], newRect.x());
|
---|
4010 | d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToY[property], newRect.y());
|
---|
4011 | d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToW[property], newRect.width());
|
---|
4012 | d_ptr->m_intPropertyManager->setValue(d_ptr->m_propertyToH[property], newRect.height());
|
---|
4013 |
|
---|
4014 | emit propertyChanged(property);
|
---|
4015 | emit valueChanged(property, data.val);
|
---|
4016 | }
|
---|
4017 |
|
---|
4018 | /*!
|
---|
4019 | Sets the given \a property's constraining rectangle to \a
|
---|
4020 | constraint.
|
---|
4021 |
|
---|
4022 | When setting the constraint, the current value is adjusted if
|
---|
4023 | necessary (ensuring that the current rectangle value is inside the
|
---|
4024 | constraint). In order to reset the constraint pass a null QRect value.
|
---|
4025 |
|
---|
4026 | \sa setValue(), constraint(), constraintChanged()
|
---|
4027 | */
|
---|
4028 | void QtRectPropertyManager::setConstraint(QtProperty *property, const QRect &constraint)
|
---|
4029 | {
|
---|
4030 | const QtRectPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
---|
4031 | if (it == d_ptr->m_values.end())
|
---|
4032 | return;
|
---|
4033 |
|
---|
4034 | QtRectPropertyManagerPrivate::Data data = it.value();
|
---|
4035 |
|
---|
4036 | QRect newConstraint = constraint.normalized();
|
---|
4037 | if (data.constraint == newConstraint)
|
---|
4038 | return;
|
---|
4039 |
|
---|
4040 | const QRect oldVal = data.val;
|
---|
4041 |
|
---|
4042 | data.constraint = newConstraint;
|
---|
4043 |
|
---|
4044 | if (!data.constraint.isNull() && !data.constraint.contains(oldVal)) {
|
---|
4045 | QRect r1 = data.constraint;
|
---|
4046 | QRect r2 = data.val;
|
---|
4047 |
|
---|
4048 | if (r2.width() > r1.width())
|
---|
4049 | r2.setWidth(r1.width());
|
---|
4050 | if (r2.height() > r1.height())
|
---|
4051 | r2.setHeight(r1.height());
|
---|
4052 | if (r2.left() < r1.left())
|
---|
4053 | r2.moveLeft(r1.left());
|
---|
4054 | else if (r2.right() > r1.right())
|
---|
4055 | r2.moveRight(r1.right());
|
---|
4056 | if (r2.top() < r1.top())
|
---|
4057 | r2.moveTop(r1.top());
|
---|
4058 | else if (r2.bottom() > r1.bottom())
|
---|
4059 | r2.moveBottom(r1.bottom());
|
---|
4060 |
|
---|
4061 | data.val = r2;
|
---|
4062 | }
|
---|
4063 |
|
---|
4064 | it.value() = data;
|
---|
4065 |
|
---|
4066 | emit constraintChanged(property, data.constraint);
|
---|
4067 |
|
---|
4068 | d_ptr->setConstraint(property, data.constraint, data.val);
|
---|
4069 |
|
---|
4070 | if (data.val == oldVal)
|
---|
4071 | return;
|
---|
4072 |
|
---|
4073 | emit propertyChanged(property);
|
---|
4074 | emit valueChanged(property, data.val);
|
---|
4075 | }
|
---|
4076 |
|
---|
4077 | /*!
|
---|
4078 | \reimp
|
---|
4079 | */
|
---|
4080 | void QtRectPropertyManager::initializeProperty(QtProperty *property)
|
---|
4081 | {
|
---|
4082 | d_ptr->m_values[property] = QtRectPropertyManagerPrivate::Data();
|
---|
4083 |
|
---|
4084 | QtProperty *xProp = d_ptr->m_intPropertyManager->addProperty();
|
---|
4085 | xProp->setPropertyName(tr("X"));
|
---|
4086 | d_ptr->m_intPropertyManager->setValue(xProp, 0);
|
---|
4087 | d_ptr->m_propertyToX[property] = xProp;
|
---|
4088 | d_ptr->m_xToProperty[xProp] = property;
|
---|
4089 | property->addSubProperty(xProp);
|
---|
4090 |
|
---|
4091 | QtProperty *yProp = d_ptr->m_intPropertyManager->addProperty();
|
---|
4092 | yProp->setPropertyName(tr("Y"));
|
---|
4093 | d_ptr->m_intPropertyManager->setValue(yProp, 0);
|
---|
4094 | d_ptr->m_propertyToY[property] = yProp;
|
---|
4095 | d_ptr->m_yToProperty[yProp] = property;
|
---|
4096 | property->addSubProperty(yProp);
|
---|
4097 |
|
---|
4098 | QtProperty *wProp = d_ptr->m_intPropertyManager->addProperty();
|
---|
4099 | wProp->setPropertyName(tr("Width"));
|
---|
4100 | d_ptr->m_intPropertyManager->setValue(wProp, 0);
|
---|
4101 | d_ptr->m_intPropertyManager->setMinimum(wProp, 0);
|
---|
4102 | d_ptr->m_propertyToW[property] = wProp;
|
---|
4103 | d_ptr->m_wToProperty[wProp] = property;
|
---|
4104 | property->addSubProperty(wProp);
|
---|
4105 |
|
---|
4106 | QtProperty *hProp = d_ptr->m_intPropertyManager->addProperty();
|
---|
4107 | hProp->setPropertyName(tr("Height"));
|
---|
4108 | d_ptr->m_intPropertyManager->setValue(hProp, 0);
|
---|
4109 | d_ptr->m_intPropertyManager->setMinimum(hProp, 0);
|
---|
4110 | d_ptr->m_propertyToH[property] = hProp;
|
---|
4111 | d_ptr->m_hToProperty[hProp] = property;
|
---|
4112 | property->addSubProperty(hProp);
|
---|
4113 | }
|
---|
4114 |
|
---|
4115 | /*!
|
---|
4116 | \reimp
|
---|
4117 | */
|
---|
4118 | void QtRectPropertyManager::uninitializeProperty(QtProperty *property)
|
---|
4119 | {
|
---|
4120 | QtProperty *xProp = d_ptr->m_propertyToX[property];
|
---|
4121 | if (xProp) {
|
---|
4122 | d_ptr->m_xToProperty.remove(xProp);
|
---|
4123 | delete xProp;
|
---|
4124 | }
|
---|
4125 | d_ptr->m_propertyToX.remove(property);
|
---|
4126 |
|
---|
4127 | QtProperty *yProp = d_ptr->m_propertyToY[property];
|
---|
4128 | if (yProp) {
|
---|
4129 | d_ptr->m_yToProperty.remove(yProp);
|
---|
4130 | delete yProp;
|
---|
4131 | }
|
---|
4132 | d_ptr->m_propertyToY.remove(property);
|
---|
4133 |
|
---|
4134 | QtProperty *wProp = d_ptr->m_propertyToW[property];
|
---|
4135 | if (wProp) {
|
---|
4136 | d_ptr->m_wToProperty.remove(wProp);
|
---|
4137 | delete wProp;
|
---|
4138 | }
|
---|
4139 | d_ptr->m_propertyToW.remove(property);
|
---|
4140 |
|
---|
4141 | QtProperty *hProp = d_ptr->m_propertyToH[property];
|
---|
4142 | if (hProp) {
|
---|
4143 | d_ptr->m_hToProperty.remove(hProp);
|
---|
4144 | delete hProp;
|
---|
4145 | }
|
---|
4146 | d_ptr->m_propertyToH.remove(property);
|
---|
4147 |
|
---|
4148 | d_ptr->m_values.remove(property);
|
---|
4149 | }
|
---|
4150 |
|
---|
4151 | // QtRectFPropertyManager
|
---|
4152 |
|
---|
4153 | class QtRectFPropertyManagerPrivate
|
---|
4154 | {
|
---|
4155 | QtRectFPropertyManager *q_ptr;
|
---|
4156 | Q_DECLARE_PUBLIC(QtRectFPropertyManager)
|
---|
4157 | public:
|
---|
4158 |
|
---|
4159 | void slotDoubleChanged(QtProperty *property, double value);
|
---|
4160 | void slotPropertyDestroyed(QtProperty *property);
|
---|
4161 | void setConstraint(QtProperty *property, const QRectF &constraint, const QRectF &val);
|
---|
4162 |
|
---|
4163 | struct Data
|
---|
4164 | {
|
---|
4165 | Data() : val(0, 0, 0, 0), decimals(2) {}
|
---|
4166 | QRectF val;
|
---|
4167 | QRectF constraint;
|
---|
4168 | int decimals;
|
---|
4169 | };
|
---|
4170 |
|
---|
4171 | typedef QMap<const QtProperty *, Data> PropertyValueMap;
|
---|
4172 | PropertyValueMap m_values;
|
---|
4173 |
|
---|
4174 | QtDoublePropertyManager *m_doublePropertyManager;
|
---|
4175 |
|
---|
4176 | QMap<const QtProperty *, QtProperty *> m_propertyToX;
|
---|
4177 | QMap<const QtProperty *, QtProperty *> m_propertyToY;
|
---|
4178 | QMap<const QtProperty *, QtProperty *> m_propertyToW;
|
---|
4179 | QMap<const QtProperty *, QtProperty *> m_propertyToH;
|
---|
4180 |
|
---|
4181 | QMap<const QtProperty *, QtProperty *> m_xToProperty;
|
---|
4182 | QMap<const QtProperty *, QtProperty *> m_yToProperty;
|
---|
4183 | QMap<const QtProperty *, QtProperty *> m_wToProperty;
|
---|
4184 | QMap<const QtProperty *, QtProperty *> m_hToProperty;
|
---|
4185 | };
|
---|
4186 |
|
---|
4187 | void QtRectFPropertyManagerPrivate::slotDoubleChanged(QtProperty *property, double value)
|
---|
4188 | {
|
---|
4189 | if (QtProperty *prop = m_xToProperty.value(property, 0)) {
|
---|
4190 | QRectF r = m_values[prop].val;
|
---|
4191 | r.moveLeft(value);
|
---|
4192 | q_ptr->setValue(prop, r);
|
---|
4193 | } else if (QtProperty *prop = m_yToProperty.value(property, 0)) {
|
---|
4194 | QRectF r = m_values[prop].val;
|
---|
4195 | r.moveTop(value);
|
---|
4196 | q_ptr->setValue(prop, r);
|
---|
4197 | } else if (QtProperty *prop = m_wToProperty.value(property, 0)) {
|
---|
4198 | Data data = m_values[prop];
|
---|
4199 | QRectF r = data.val;
|
---|
4200 | r.setWidth(value);
|
---|
4201 | if (!data.constraint.isNull() && data.constraint.x() + data.constraint.width() < r.x() + r.width()) {
|
---|
4202 | r.moveLeft(data.constraint.left() + data.constraint.width() - r.width());
|
---|
4203 | }
|
---|
4204 | q_ptr->setValue(prop, r);
|
---|
4205 | } else if (QtProperty *prop = m_hToProperty.value(property, 0)) {
|
---|
4206 | Data data = m_values[prop];
|
---|
4207 | QRectF r = data.val;
|
---|
4208 | r.setHeight(value);
|
---|
4209 | if (!data.constraint.isNull() && data.constraint.y() + data.constraint.height() < r.y() + r.height()) {
|
---|
4210 | r.moveTop(data.constraint.top() + data.constraint.height() - r.height());
|
---|
4211 | }
|
---|
4212 | q_ptr->setValue(prop, r);
|
---|
4213 | }
|
---|
4214 | }
|
---|
4215 |
|
---|
4216 | void QtRectFPropertyManagerPrivate::slotPropertyDestroyed(QtProperty *property)
|
---|
4217 | {
|
---|
4218 | if (QtProperty *pointProp = m_xToProperty.value(property, 0)) {
|
---|
4219 | m_propertyToX[pointProp] = 0;
|
---|
4220 | m_xToProperty.remove(property);
|
---|
4221 | } else if (QtProperty *pointProp = m_yToProperty.value(property, 0)) {
|
---|
4222 | m_propertyToY[pointProp] = 0;
|
---|
4223 | m_yToProperty.remove(property);
|
---|
4224 | } else if (QtProperty *pointProp = m_wToProperty.value(property, 0)) {
|
---|
4225 | m_propertyToW[pointProp] = 0;
|
---|
4226 | m_wToProperty.remove(property);
|
---|
4227 | } else if (QtProperty *pointProp = m_hToProperty.value(property, 0)) {
|
---|
4228 | m_propertyToH[pointProp] = 0;
|
---|
4229 | m_hToProperty.remove(property);
|
---|
4230 | }
|
---|
4231 | }
|
---|
4232 |
|
---|
4233 | void QtRectFPropertyManagerPrivate::setConstraint(QtProperty *property,
|
---|
4234 | const QRectF &constraint, const QRectF &val)
|
---|
4235 | {
|
---|
4236 | const bool isNull = constraint.isNull();
|
---|
4237 | const float left = isNull ? FLT_MIN : constraint.left();
|
---|
4238 | const float right = isNull ? FLT_MAX : constraint.left() + constraint.width();
|
---|
4239 | const float top = isNull ? FLT_MIN : constraint.top();
|
---|
4240 | const float bottom = isNull ? FLT_MAX : constraint.top() + constraint.height();
|
---|
4241 | const float width = isNull ? FLT_MAX : constraint.width();
|
---|
4242 | const float height = isNull ? FLT_MAX : constraint.height();
|
---|
4243 |
|
---|
4244 | m_doublePropertyManager->setRange(m_propertyToX[property], left, right);
|
---|
4245 | m_doublePropertyManager->setRange(m_propertyToY[property], top, bottom);
|
---|
4246 | m_doublePropertyManager->setRange(m_propertyToW[property], 0, width);
|
---|
4247 | m_doublePropertyManager->setRange(m_propertyToH[property], 0, height);
|
---|
4248 |
|
---|
4249 | m_doublePropertyManager->setValue(m_propertyToX[property], val.x());
|
---|
4250 | m_doublePropertyManager->setValue(m_propertyToY[property], val.y());
|
---|
4251 | m_doublePropertyManager->setValue(m_propertyToW[property], val.width());
|
---|
4252 | m_doublePropertyManager->setValue(m_propertyToH[property], val.height());
|
---|
4253 | }
|
---|
4254 |
|
---|
4255 | /*!
|
---|
4256 | \class QtRectFPropertyManager
|
---|
4257 | \internal
|
---|
4258 | \inmodule QtDesigner
|
---|
4259 | \since 4.4
|
---|
4260 |
|
---|
4261 | \brief The QtRectFPropertyManager provides and manages QRectF properties.
|
---|
4262 |
|
---|
4263 | A rectangle property has nested \e x, \e y, \e width and \e height
|
---|
4264 | subproperties. The top-level property's value can be retrieved
|
---|
4265 | using the value() function, and set using the setValue() slot.
|
---|
4266 |
|
---|
4267 | The subproperties are created by a QtDoublePropertyManager object. This
|
---|
4268 | manager can be retrieved using the subDoublePropertyManager() function. In
|
---|
4269 | order to provide editing widgets for the subproperties in a
|
---|
4270 | property browser widget, this manager must be associated with an
|
---|
4271 | editor factory.
|
---|
4272 |
|
---|
4273 | A rectangle property also has a constraint rectangle which can be
|
---|
4274 | retrieved using the constraint() function, and set using the
|
---|
4275 | setConstraint() slot.
|
---|
4276 |
|
---|
4277 | In addition, QtRectFPropertyManager provides the valueChanged() signal
|
---|
4278 | which is emitted whenever a property created by this manager
|
---|
4279 | changes, and the constraintChanged() signal which is emitted
|
---|
4280 | whenever such a property changes its constraint rectangle.
|
---|
4281 |
|
---|
4282 | \sa QtAbstractPropertyManager, QtDoublePropertyManager, QtRectPropertyManager
|
---|
4283 | */
|
---|
4284 |
|
---|
4285 | /*!
|
---|
4286 | \fn void QtRectFPropertyManager::valueChanged(QtProperty *property, const QRectF &value)
|
---|
4287 |
|
---|
4288 | This signal is emitted whenever a property created by this manager
|
---|
4289 | changes its value, passing a pointer to the \a property and the new
|
---|
4290 | \a value as parameters.
|
---|
4291 |
|
---|
4292 | \sa setValue()
|
---|
4293 | */
|
---|
4294 |
|
---|
4295 | /*!
|
---|
4296 | \fn void QtRectFPropertyManager::constraintChanged(QtProperty *property, const QRectF &constraint)
|
---|
4297 |
|
---|
4298 | This signal is emitted whenever property changes its constraint
|
---|
4299 | rectangle, passing a pointer to the \a property and the new \a
|
---|
4300 | constraint rectangle as parameters.
|
---|
4301 |
|
---|
4302 | \sa setConstraint()
|
---|
4303 | */
|
---|
4304 |
|
---|
4305 | /*!
|
---|
4306 | \fn void QtRectFPropertyManager::decimalsChanged(QtProperty *property, int prec)
|
---|
4307 |
|
---|
4308 | This signal is emitted whenever a property created by this manager
|
---|
4309 | changes its precision of value, passing a pointer to the
|
---|
4310 | \a property and the new \a prec value
|
---|
4311 |
|
---|
4312 | \sa setDecimals()
|
---|
4313 | */
|
---|
4314 |
|
---|
4315 | /*!
|
---|
4316 | Creates a manager with the given \a parent.
|
---|
4317 | */
|
---|
4318 | QtRectFPropertyManager::QtRectFPropertyManager(QObject *parent)
|
---|
4319 | : QtAbstractPropertyManager(parent), d_ptr(new QtRectFPropertyManagerPrivate)
|
---|
4320 | {
|
---|
4321 | d_ptr->q_ptr = this;
|
---|
4322 |
|
---|
4323 | d_ptr->m_doublePropertyManager = new QtDoublePropertyManager(this);
|
---|
4324 | connect(d_ptr->m_doublePropertyManager, SIGNAL(valueChanged(QtProperty*,double)),
|
---|
4325 | this, SLOT(slotDoubleChanged(QtProperty*,double)));
|
---|
4326 | connect(d_ptr->m_doublePropertyManager, SIGNAL(propertyDestroyed(QtProperty*)),
|
---|
4327 | this, SLOT(slotPropertyDestroyed(QtProperty*)));
|
---|
4328 | }
|
---|
4329 |
|
---|
4330 | /*!
|
---|
4331 | Destroys this manager, and all the properties it has created.
|
---|
4332 | */
|
---|
4333 | QtRectFPropertyManager::~QtRectFPropertyManager()
|
---|
4334 | {
|
---|
4335 | clear();
|
---|
4336 | }
|
---|
4337 |
|
---|
4338 | /*!
|
---|
4339 | Returns the manager that creates the nested \e x, \e y, \e width
|
---|
4340 | and \e height subproperties.
|
---|
4341 |
|
---|
4342 | In order to provide editing widgets for the mentioned
|
---|
4343 | subproperties in a property browser widget, this manager must be
|
---|
4344 | associated with an editor factory.
|
---|
4345 |
|
---|
4346 | \sa QtAbstractPropertyBrowser::setFactoryForManager()
|
---|
4347 | */
|
---|
4348 | QtDoublePropertyManager *QtRectFPropertyManager::subDoublePropertyManager() const
|
---|
4349 | {
|
---|
4350 | return d_ptr->m_doublePropertyManager;
|
---|
4351 | }
|
---|
4352 |
|
---|
4353 | /*!
|
---|
4354 | Returns the given \a property's value.
|
---|
4355 |
|
---|
4356 | If the given \a property is not managed by this manager, this
|
---|
4357 | function returns an invalid rectangle.
|
---|
4358 |
|
---|
4359 | \sa setValue(), constraint()
|
---|
4360 | */
|
---|
4361 | QRectF QtRectFPropertyManager::value(const QtProperty *property) const
|
---|
4362 | {
|
---|
4363 | return getValue<QRectF>(d_ptr->m_values, property);
|
---|
4364 | }
|
---|
4365 |
|
---|
4366 | /*!
|
---|
4367 | Returns the given \a property's precision, in decimals.
|
---|
4368 |
|
---|
4369 | \sa setDecimals()
|
---|
4370 | */
|
---|
4371 | int QtRectFPropertyManager::decimals(const QtProperty *property) const
|
---|
4372 | {
|
---|
4373 | return getData<int>(d_ptr->m_values, &QtRectFPropertyManagerPrivate::Data::decimals, property, 0);
|
---|
4374 | }
|
---|
4375 |
|
---|
4376 | /*!
|
---|
4377 | Returns the given \a property's constraining rectangle. If returned value is null QRectF it means there is no constraint applied.
|
---|
4378 |
|
---|
4379 | \sa value(), setConstraint()
|
---|
4380 | */
|
---|
4381 | QRectF QtRectFPropertyManager::constraint(const QtProperty *property) const
|
---|
4382 | {
|
---|
4383 | return getData<QRectF>(d_ptr->m_values, &QtRectFPropertyManagerPrivate::Data::constraint, property, QRect());
|
---|
4384 | }
|
---|
4385 |
|
---|
4386 | /*!
|
---|
4387 | \reimp
|
---|
4388 | */
|
---|
4389 | QString QtRectFPropertyManager::valueText(const QtProperty *property) const
|
---|
4390 | {
|
---|
4391 | const QtRectFPropertyManagerPrivate::PropertyValueMap::const_iterator it = d_ptr->m_values.constFind(property);
|
---|
4392 | if (it == d_ptr->m_values.constEnd())
|
---|
4393 | return QString();
|
---|
4394 | const QRectF v = it.value().val;
|
---|
4395 | const int dec = it.value().decimals;
|
---|
4396 | return QString(tr("[(%1, %2), %3 x %4]").arg(QString::number(v.x(), 'f', dec))
|
---|
4397 | .arg(QString::number(v.y(), 'f', dec))
|
---|
4398 | .arg(QString::number(v.width(), 'f', dec))
|
---|
4399 | .arg(QString::number(v.height(), 'f', dec)));
|
---|
4400 | }
|
---|
4401 |
|
---|
4402 | /*!
|
---|
4403 | \fn void QtRectFPropertyManager::setValue(QtProperty *property, const QRectF &value)
|
---|
4404 |
|
---|
4405 | Sets the value of the given \a property to \a value. Nested
|
---|
4406 | properties are updated automatically.
|
---|
4407 |
|
---|
4408 | If the specified \a value is not inside the given \a property's
|
---|
4409 | constraining rectangle, the value is adjusted accordingly to fit
|
---|
4410 | within the constraint.
|
---|
4411 |
|
---|
4412 | \sa value(), setConstraint(), valueChanged()
|
---|
4413 | */
|
---|
4414 | void QtRectFPropertyManager::setValue(QtProperty *property, const QRectF &val)
|
---|
4415 | {
|
---|
4416 | const QtRectFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
---|
4417 | if (it == d_ptr->m_values.end())
|
---|
4418 | return;
|
---|
4419 |
|
---|
4420 | QtRectFPropertyManagerPrivate::Data data = it.value();
|
---|
4421 |
|
---|
4422 | QRectF newRect = val.normalized();
|
---|
4423 | if (!data.constraint.isNull() && !data.constraint.contains(newRect)) {
|
---|
4424 | const QRectF r1 = data.constraint;
|
---|
4425 | const QRectF r2 = newRect;
|
---|
4426 | newRect.setLeft(qMax(r1.left(), r2.left()));
|
---|
4427 | newRect.setRight(qMin(r1.right(), r2.right()));
|
---|
4428 | newRect.setTop(qMax(r1.top(), r2.top()));
|
---|
4429 | newRect.setBottom(qMin(r1.bottom(), r2.bottom()));
|
---|
4430 | if (newRect.width() < 0 || newRect.height() < 0)
|
---|
4431 | return;
|
---|
4432 | }
|
---|
4433 |
|
---|
4434 | if (data.val == newRect)
|
---|
4435 | return;
|
---|
4436 |
|
---|
4437 | data.val = newRect;
|
---|
4438 |
|
---|
4439 | it.value() = data;
|
---|
4440 | d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToX[property], newRect.x());
|
---|
4441 | d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToY[property], newRect.y());
|
---|
4442 | d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToW[property], newRect.width());
|
---|
4443 | d_ptr->m_doublePropertyManager->setValue(d_ptr->m_propertyToH[property], newRect.height());
|
---|
4444 |
|
---|
4445 | emit propertyChanged(property);
|
---|
4446 | emit valueChanged(property, data.val);
|
---|
4447 | }
|
---|
4448 |
|
---|
4449 | /*!
|
---|
4450 | Sets the given \a property's constraining rectangle to \a
|
---|
4451 | constraint.
|
---|
4452 |
|
---|
4453 | When setting the constraint, the current value is adjusted if
|
---|
4454 | necessary (ensuring that the current rectangle value is inside the
|
---|
4455 | constraint). In order to reset the constraint pass a null QRectF value.
|
---|
4456 |
|
---|
4457 | \sa setValue(), constraint(), constraintChanged()
|
---|
4458 | */
|
---|
4459 | void QtRectFPropertyManager::setConstraint(QtProperty *property, const QRectF &constraint)
|
---|
4460 | {
|
---|
4461 | const QtRectFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
---|
4462 | if (it == d_ptr->m_values.end())
|
---|
4463 | return;
|
---|
4464 |
|
---|
4465 | QtRectFPropertyManagerPrivate::Data data = it.value();
|
---|
4466 |
|
---|
4467 | QRectF newConstraint = constraint.normalized();
|
---|
4468 | if (data.constraint == newConstraint)
|
---|
4469 | return;
|
---|
4470 |
|
---|
4471 | const QRectF oldVal = data.val;
|
---|
4472 |
|
---|
4473 | data.constraint = newConstraint;
|
---|
4474 |
|
---|
4475 | if (!data.constraint.isNull() && !data.constraint.contains(oldVal)) {
|
---|
4476 | QRectF r1 = data.constraint;
|
---|
4477 | QRectF r2 = data.val;
|
---|
4478 |
|
---|
4479 | if (r2.width() > r1.width())
|
---|
4480 | r2.setWidth(r1.width());
|
---|
4481 | if (r2.height() > r1.height())
|
---|
4482 | r2.setHeight(r1.height());
|
---|
4483 | if (r2.left() < r1.left())
|
---|
4484 | r2.moveLeft(r1.left());
|
---|
4485 | else if (r2.right() > r1.right())
|
---|
4486 | r2.moveRight(r1.right());
|
---|
4487 | if (r2.top() < r1.top())
|
---|
4488 | r2.moveTop(r1.top());
|
---|
4489 | else if (r2.bottom() > r1.bottom())
|
---|
4490 | r2.moveBottom(r1.bottom());
|
---|
4491 |
|
---|
4492 | data.val = r2;
|
---|
4493 | }
|
---|
4494 |
|
---|
4495 | it.value() = data;
|
---|
4496 |
|
---|
4497 | emit constraintChanged(property, data.constraint);
|
---|
4498 |
|
---|
4499 | d_ptr->setConstraint(property, data.constraint, data.val);
|
---|
4500 |
|
---|
4501 | if (data.val == oldVal)
|
---|
4502 | return;
|
---|
4503 |
|
---|
4504 | emit propertyChanged(property);
|
---|
4505 | emit valueChanged(property, data.val);
|
---|
4506 | }
|
---|
4507 |
|
---|
4508 | /*!
|
---|
4509 | \fn void QtRectFPropertyManager::setDecimals(QtProperty *property, int prec)
|
---|
4510 |
|
---|
4511 | Sets the precision of the given \a property to \a prec.
|
---|
4512 |
|
---|
4513 | The valid decimal range is 0-13. The default is 2.
|
---|
4514 |
|
---|
4515 | \sa decimals()
|
---|
4516 | */
|
---|
4517 | void QtRectFPropertyManager::setDecimals(QtProperty *property, int prec)
|
---|
4518 | {
|
---|
4519 | const QtRectFPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
|
---|
4520 | if (it == d_ptr->m_values.end())
|
---|
4521 | return;
|
---|
4522 |
|
---|
4523 | QtRectFPropertyManagerPrivate::Data data = it.value();
|
---|
4524 |
|
---|
4525 | if (prec > 13)
|
---|
4526 | prec = 13;
|
---|
4527 | else if (prec < 0)
|
---|
4528 | prec = 0;
|
---|
4529 |
|
---|
4530 | if (data.decimals == prec)
|
---|
4531 | return;
|
---|
4532 |
|
---|
4533 | data.decimals = prec;
|
---|
4534 | d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToX[property], prec);
|
---|
4535 | d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToY[property], prec);
|
---|
4536 | d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToW[property], prec);
|
---|
4537 | d_ptr->m_doublePropertyManager->setDecimals(d_ptr->m_propertyToH[property], prec);
|
---|
4538 |
|
---|
4539 | it.value() = data;
|
---|
4540 |
|
---|
4541 | emit decimalsChanged(property, data.decimals);
|
---|
4542 | }
|
---|
4543 |
|
---|
4544 | /*!
|
---|
4545 | \reimp
|
---|
4546 | */
|
---|
4547 | void QtRectFPropertyManager::initializeProperty(QtProperty *property)
|
---|
4548 | {
|
---|
4549 | d_ptr->m_values[property] = QtRectFPropertyManagerPrivate::Data();
|
---|
4550 |
|
---|
|
---|