/tools/shared/qtpropertybrowser/qtpropertymanager.cpp

https://bitbucket.org/ultra_iter/qt-vtl · C++ · 6451 lines · 3446 code · 802 blank · 2203 comment · 475 complexity · 7b7a5d9ff479082a393da1752d944ee3 MD5 · raw file

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