/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

Large files are truncated click here to view the full 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 QtDatePropertyMa