qtvariantproperty.cpp 95 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2016 The Qt Company Ltd.
  4. ** Contact: https://www.qt.io/licensing/
  5. **
  6. ** This file is part of the tools applications of the Qt Toolkit.
  7. **
  8. ** $QT_BEGIN_LICENSE:LGPL$
  9. ** Commercial License Usage
  10. ** Licensees holding valid commercial Qt licenses may use this file in
  11. ** accordance with the commercial license agreement provided with the
  12. ** Software or, alternatively, in accordance with the terms contained in
  13. ** a written agreement between you and The Qt Company. For licensing terms
  14. ** and conditions see https://www.qt.io/terms-conditions. For further
  15. ** information use the contact form at https://www.qt.io/contact-us.
  16. **
  17. ** GNU Lesser General Public License Usage
  18. ** Alternatively, this file may be used under the terms of the GNU Lesser
  19. ** General Public License version 3 as published by the Free Software
  20. ** Foundation and appearing in the file LICENSE.LGPL3 included in the
  21. ** packaging of this file. Please review the following information to
  22. ** ensure the GNU Lesser General Public License version 3 requirements
  23. ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
  24. **
  25. ** GNU General Public License Usage
  26. ** Alternatively, this file may be used under the terms of the GNU
  27. ** General Public License version 2.0 or (at your option) the GNU General
  28. ** Public license version 3 or any later version approved by the KDE Free
  29. ** Qt Foundation. The licenses are as published by the Free Software
  30. ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
  31. ** included in the packaging of this file. Please review the following
  32. ** information to ensure the GNU General Public License requirements will
  33. ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
  34. ** https://www.gnu.org/licenses/gpl-3.0.html.
  35. **
  36. ** $QT_END_LICENSE$
  37. **
  38. ****************************************************************************/
  39. #include "qtvariantproperty.h"
  40. #include "qtpropertymanager.h"
  41. #include "qteditorfactory.h"
  42. #include <QtCore/QVariant>
  43. #include <QtGui/QIcon>
  44. #include <QtCore/QDate>
  45. #include <QtCore/QLocale>
  46. #if defined(Q_CC_MSVC)
  47. # pragma warning(disable: 4786) /* MS VS 6: truncating debug info after 255 characters */
  48. #endif
  49. QT_BEGIN_NAMESPACE
  50. class QtEnumPropertyType
  51. {
  52. };
  53. class QtFlagPropertyType
  54. {
  55. };
  56. class QtGroupPropertyType
  57. {
  58. };
  59. QT_END_NAMESPACE
  60. Q_DECLARE_METATYPE(QtEnumPropertyType)
  61. Q_DECLARE_METATYPE(QtFlagPropertyType)
  62. Q_DECLARE_METATYPE(QtGroupPropertyType)
  63. QT_BEGIN_NAMESPACE
  64. /*!
  65. Returns the type id for an enum property.
  66. Note that the property's value type can be retrieved using the
  67. valueType() function (which is QVariant::Int for the enum property
  68. type).
  69. \sa propertyType(), valueType()
  70. */
  71. int QtVariantPropertyManager::enumTypeId()
  72. {
  73. return qMetaTypeId<QtEnumPropertyType>();
  74. }
  75. /*!
  76. Returns the type id for a flag property.
  77. Note that the property's value type can be retrieved using the
  78. valueType() function (which is QVariant::Int for the flag property
  79. type).
  80. \sa propertyType(), valueType()
  81. */
  82. int QtVariantPropertyManager::flagTypeId()
  83. {
  84. return qMetaTypeId<QtFlagPropertyType>();
  85. }
  86. /*!
  87. Returns the type id for a group property.
  88. Note that the property's value type can be retrieved using the
  89. valueType() function (which is QVariant::Invalid for the group
  90. property type, since it doesn't provide any value).
  91. \sa propertyType(), valueType()
  92. */
  93. int QtVariantPropertyManager::groupTypeId()
  94. {
  95. return qMetaTypeId<QtGroupPropertyType>();
  96. }
  97. /*!
  98. Returns the type id for a icon map attribute.
  99. Note that the property's attribute type can be retrieved using the
  100. attributeType() function.
  101. \sa attributeType(), QtEnumPropertyManager::enumIcons()
  102. */
  103. int QtVariantPropertyManager::iconMapTypeId()
  104. {
  105. return qMetaTypeId<QtIconMap>();
  106. }
  107. typedef QMap<const QtProperty *, QtProperty *> PropertyMap;
  108. Q_GLOBAL_STATIC(PropertyMap, propertyToWrappedProperty)
  109. static QtProperty *wrappedProperty(QtProperty *property)
  110. {
  111. return propertyToWrappedProperty()->value(property, 0);
  112. }
  113. class QtVariantPropertyPrivate
  114. {
  115. public:
  116. QtVariantPropertyPrivate(QtVariantPropertyManager *m) : manager(m) {}
  117. QtVariantPropertyManager *manager;
  118. };
  119. /*!
  120. \class QtVariantProperty
  121. \internal
  122. \inmodule QtDesigner
  123. \since 4.4
  124. \brief The QtVariantProperty class is a convenience class handling
  125. QVariant based properties.
  126. QtVariantProperty provides additional API: A property's type,
  127. value type, attribute values and current value can easily be
  128. retrieved using the propertyType(), valueType(), attributeValue()
  129. and value() functions respectively. In addition, the attribute
  130. values and the current value can be set using the corresponding
  131. setValue() and setAttribute() functions.
  132. For example, instead of writing:
  133. \snippet doc/src/snippets/code/tools_shared_qtpropertybrowser_qtvariantproperty.cpp 0
  134. you can write:
  135. \snippet doc/src/snippets/code/tools_shared_qtpropertybrowser_qtvariantproperty.cpp 1
  136. QtVariantProperty instances can only be created by the
  137. QtVariantPropertyManager class.
  138. \sa QtProperty, QtVariantPropertyManager, QtVariantEditorFactory
  139. */
  140. /*!
  141. Creates a variant property using the given \a manager.
  142. Do not use this constructor to create variant property instances;
  143. use the QtVariantPropertyManager::addProperty() function
  144. instead. This constructor is used internally by the
  145. QtVariantPropertyManager::createProperty() function.
  146. \sa QtVariantPropertyManager
  147. */
  148. QtVariantProperty::QtVariantProperty(QtVariantPropertyManager *manager)
  149. : QtProperty(manager), d_ptr(new QtVariantPropertyPrivate(manager))
  150. {
  151. }
  152. /*!
  153. Destroys this property.
  154. \sa QtProperty::~QtProperty()
  155. */
  156. QtVariantProperty::~QtVariantProperty()
  157. {
  158. }
  159. /*!
  160. Returns the property's current value.
  161. \sa valueType(), setValue()
  162. */
  163. QVariant QtVariantProperty::value() const
  164. {
  165. return d_ptr->manager->value(this);
  166. }
  167. /*!
  168. Returns this property's value for the specified \a attribute.
  169. QtVariantPropertyManager provides a couple of related functions:
  170. \l{QtVariantPropertyManager::attributes()}{attributes()} and
  171. \l{QtVariantPropertyManager::attributeType()}{attributeType()}.
  172. \sa setAttribute()
  173. */
  174. QVariant QtVariantProperty::attributeValue(const QString &attribute) const
  175. {
  176. return d_ptr->manager->attributeValue(this, attribute);
  177. }
  178. /*!
  179. Returns the type of this property's value.
  180. \sa propertyType()
  181. */
  182. int QtVariantProperty::valueType() const
  183. {
  184. return d_ptr->manager->valueType(this);
  185. }
  186. /*!
  187. Returns this property's type.
  188. QtVariantPropertyManager provides several related functions:
  189. \l{QtVariantPropertyManager::enumTypeId()}{enumTypeId()},
  190. \l{QtVariantPropertyManager::flagTypeId()}{flagTypeId()} and
  191. \l{QtVariantPropertyManager::groupTypeId()}{groupTypeId()}.
  192. \sa valueType()
  193. */
  194. int QtVariantProperty::propertyType() const
  195. {
  196. return d_ptr->manager->propertyType(this);
  197. }
  198. /*!
  199. Sets the value of this property to \a value.
  200. The specified \a value must be of the type returned by
  201. valueType(), or of a type that can be converted to valueType()
  202. using the QVariant::canConvert() function; otherwise this function
  203. does nothing.
  204. \sa value()
  205. */
  206. void QtVariantProperty::setValue(const QVariant &value)
  207. {
  208. d_ptr->manager->setValue(this, value);
  209. }
  210. /*!
  211. Sets the \a attribute of property to \a value.
  212. QtVariantPropertyManager provides the related
  213. \l{QtVariantPropertyManager::setAttribute()}{setAttribute()}
  214. function.
  215. \sa attributeValue()
  216. */
  217. void QtVariantProperty::setAttribute(const QString &attribute, const QVariant &value)
  218. {
  219. d_ptr->manager->setAttribute(this, attribute, value);
  220. }
  221. class QtVariantPropertyManagerPrivate
  222. {
  223. QtVariantPropertyManager *q_ptr;
  224. Q_DECLARE_PUBLIC(QtVariantPropertyManager)
  225. public:
  226. QtVariantPropertyManagerPrivate();
  227. bool m_creatingProperty;
  228. bool m_creatingSubProperties;
  229. bool m_destroyingSubProperties;
  230. int m_propertyType;
  231. void slotValueChanged(QtProperty *property, int val);
  232. void slotRangeChanged(QtProperty *property, int min, int max);
  233. void slotSingleStepChanged(QtProperty *property, int step);
  234. void slotValueChanged(QtProperty *property, double val);
  235. void slotRangeChanged(QtProperty *property, double min, double max);
  236. void slotSingleStepChanged(QtProperty *property, double step);
  237. void slotDecimalsChanged(QtProperty *property, int prec);
  238. void slotValueChanged(QtProperty *property, bool val);
  239. void slotValueChanged(QtProperty *property, const QString &val);
  240. void slotRegExpChanged(QtProperty *property, const QRegExp &regExp);
  241. void slotValueChanged(QtProperty *property, const QDate &val);
  242. void slotRangeChanged(QtProperty *property, const QDate &min, const QDate &max);
  243. void slotValueChanged(QtProperty *property, const QTime &val);
  244. void slotValueChanged(QtProperty *property, const QDateTime &val);
  245. void slotValueChanged(QtProperty *property, const QKeySequence &val);
  246. void slotValueChanged(QtProperty *property, const QChar &val);
  247. void slotValueChanged(QtProperty *property, const QLocale &val);
  248. void slotValueChanged(QtProperty *property, const QPoint &val);
  249. void slotValueChanged(QtProperty *property, const QPointF &val);
  250. void slotValueChanged(QtProperty *property, const QSize &val);
  251. void slotRangeChanged(QtProperty *property, const QSize &min, const QSize &max);
  252. void slotValueChanged(QtProperty *property, const QSizeF &val);
  253. void slotRangeChanged(QtProperty *property, const QSizeF &min, const QSizeF &max);
  254. void slotValueChanged(QtProperty *property, const QRect &val);
  255. void slotConstraintChanged(QtProperty *property, const QRect &val);
  256. void slotValueChanged(QtProperty *property, const QRectF &val);
  257. void slotConstraintChanged(QtProperty *property, const QRectF &val);
  258. void slotValueChanged(QtProperty *property, const QColor &val);
  259. void slotEnumChanged(QtProperty *property, int val);
  260. void slotEnumNamesChanged(QtProperty *property, const QStringList &enumNames);
  261. void slotEnumIconsChanged(QtProperty *property, const QMap<int, QIcon> &enumIcons);
  262. void slotValueChanged(QtProperty *property, const QSizePolicy &val);
  263. void slotValueChanged(QtProperty *property, const QFont &val);
  264. void slotValueChanged(QtProperty *property, const QCursor &val);
  265. void slotFlagChanged(QtProperty *property, int val);
  266. void slotFlagNamesChanged(QtProperty *property, const QStringList &flagNames);
  267. void slotPropertyInserted(QtProperty *property, QtProperty *parent, QtProperty *after);
  268. void slotPropertyRemoved(QtProperty *property, QtProperty *parent);
  269. void valueChanged(QtProperty *property, const QVariant &val);
  270. int internalPropertyToType(QtProperty *property) const;
  271. QtVariantProperty *createSubProperty(QtVariantProperty *parent, QtVariantProperty *after,
  272. QtProperty *internal);
  273. void removeSubProperty(QtVariantProperty *property);
  274. QMap<int, QtAbstractPropertyManager *> m_typeToPropertyManager;
  275. QMap<int, QMap<QString, int> > m_typeToAttributeToAttributeType;
  276. QMap<const QtProperty *, QPair<QtVariantProperty *, int> > m_propertyToType;
  277. QMap<int, int> m_typeToValueType;
  278. QMap<QtProperty *, QtVariantProperty *> m_internalToProperty;
  279. const QString m_constraintAttribute;
  280. const QString m_singleStepAttribute;
  281. const QString m_decimalsAttribute;
  282. const QString m_enumIconsAttribute;
  283. const QString m_enumNamesAttribute;
  284. const QString m_flagNamesAttribute;
  285. const QString m_maximumAttribute;
  286. const QString m_minimumAttribute;
  287. const QString m_regExpAttribute;
  288. };
  289. QtVariantPropertyManagerPrivate::QtVariantPropertyManagerPrivate() :
  290. m_constraintAttribute(QLatin1String("constraint")),
  291. m_singleStepAttribute(QLatin1String("singleStep")),
  292. m_decimalsAttribute(QLatin1String("decimals")),
  293. m_enumIconsAttribute(QLatin1String("enumIcons")),
  294. m_enumNamesAttribute(QLatin1String("enumNames")),
  295. m_flagNamesAttribute(QLatin1String("flagNames")),
  296. m_maximumAttribute(QLatin1String("maximum")),
  297. m_minimumAttribute(QLatin1String("minimum")),
  298. m_regExpAttribute(QLatin1String("regExp"))
  299. {
  300. }
  301. int QtVariantPropertyManagerPrivate::internalPropertyToType(QtProperty *property) const
  302. {
  303. int type = 0;
  304. QtAbstractPropertyManager *internPropertyManager = property->propertyManager();
  305. if (qobject_cast<QtIntPropertyManager *>(internPropertyManager))
  306. type = QVariant::Int;
  307. else if (qobject_cast<QtEnumPropertyManager *>(internPropertyManager))
  308. type = QtVariantPropertyManager::enumTypeId();
  309. else if (qobject_cast<QtBoolPropertyManager *>(internPropertyManager))
  310. type = QVariant::Bool;
  311. else if (qobject_cast<QtDoublePropertyManager *>(internPropertyManager))
  312. type = QVariant::Double;
  313. return type;
  314. }
  315. QtVariantProperty *QtVariantPropertyManagerPrivate::createSubProperty(QtVariantProperty *parent,
  316. QtVariantProperty *after, QtProperty *internal)
  317. {
  318. int type = internalPropertyToType(internal);
  319. if (!type)
  320. return 0;
  321. bool wasCreatingSubProperties = m_creatingSubProperties;
  322. m_creatingSubProperties = true;
  323. QtVariantProperty *varChild = q_ptr->addProperty(type, internal->propertyName());
  324. m_creatingSubProperties = wasCreatingSubProperties;
  325. varChild->setPropertyName(internal->propertyName());
  326. varChild->setToolTip(internal->toolTip());
  327. varChild->setStatusTip(internal->statusTip());
  328. varChild->setWhatsThis(internal->whatsThis());
  329. parent->insertSubProperty(varChild, after);
  330. m_internalToProperty[internal] = varChild;
  331. propertyToWrappedProperty()->insert(varChild, internal);
  332. return varChild;
  333. }
  334. void QtVariantPropertyManagerPrivate::removeSubProperty(QtVariantProperty *property)
  335. {
  336. QtProperty *internChild = wrappedProperty(property);
  337. bool wasDestroyingSubProperties = m_destroyingSubProperties;
  338. m_destroyingSubProperties = true;
  339. delete property;
  340. m_destroyingSubProperties = wasDestroyingSubProperties;
  341. m_internalToProperty.remove(internChild);
  342. propertyToWrappedProperty()->remove(property);
  343. }
  344. void QtVariantPropertyManagerPrivate::slotPropertyInserted(QtProperty *property,
  345. QtProperty *parent, QtProperty *after)
  346. {
  347. if (m_creatingProperty)
  348. return;
  349. QtVariantProperty *varParent = m_internalToProperty.value(parent, 0);
  350. if (!varParent)
  351. return;
  352. QtVariantProperty *varAfter = 0;
  353. if (after) {
  354. varAfter = m_internalToProperty.value(after, 0);
  355. if (!varAfter)
  356. return;
  357. }
  358. createSubProperty(varParent, varAfter, property);
  359. }
  360. void QtVariantPropertyManagerPrivate::slotPropertyRemoved(QtProperty *property, QtProperty *parent)
  361. {
  362. Q_UNUSED(parent);
  363. QtVariantProperty *varProperty = m_internalToProperty.value(property, 0);
  364. if (!varProperty)
  365. return;
  366. removeSubProperty(varProperty);
  367. }
  368. void QtVariantPropertyManagerPrivate::valueChanged(QtProperty *property, const QVariant &val)
  369. {
  370. QtVariantProperty *varProp = m_internalToProperty.value(property, 0);
  371. if (!varProp)
  372. return;
  373. emit q_ptr->valueChanged(varProp, val);
  374. emit q_ptr->propertyChanged(varProp);
  375. }
  376. void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, int val)
  377. {
  378. valueChanged(property, QVariant(val));
  379. }
  380. void QtVariantPropertyManagerPrivate::slotRangeChanged(QtProperty *property, int min, int max)
  381. {
  382. if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0)) {
  383. emit q_ptr->attributeChanged(varProp, m_minimumAttribute, QVariant(min));
  384. emit q_ptr->attributeChanged(varProp, m_maximumAttribute, QVariant(max));
  385. }
  386. }
  387. void QtVariantPropertyManagerPrivate::slotSingleStepChanged(QtProperty *property, int step)
  388. {
  389. if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0))
  390. emit q_ptr->attributeChanged(varProp, m_singleStepAttribute, QVariant(step));
  391. }
  392. void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, double val)
  393. {
  394. valueChanged(property, QVariant(val));
  395. }
  396. void QtVariantPropertyManagerPrivate::slotRangeChanged(QtProperty *property, double min, double max)
  397. {
  398. if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0)) {
  399. emit q_ptr->attributeChanged(varProp, m_minimumAttribute, QVariant(min));
  400. emit q_ptr->attributeChanged(varProp, m_maximumAttribute, QVariant(max));
  401. }
  402. }
  403. void QtVariantPropertyManagerPrivate::slotSingleStepChanged(QtProperty *property, double step)
  404. {
  405. if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0))
  406. emit q_ptr->attributeChanged(varProp, m_singleStepAttribute, QVariant(step));
  407. }
  408. void QtVariantPropertyManagerPrivate::slotDecimalsChanged(QtProperty *property, int prec)
  409. {
  410. if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0))
  411. emit q_ptr->attributeChanged(varProp, m_decimalsAttribute, QVariant(prec));
  412. }
  413. void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, bool val)
  414. {
  415. valueChanged(property, QVariant(val));
  416. }
  417. void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QString &val)
  418. {
  419. valueChanged(property, QVariant(val));
  420. }
  421. void QtVariantPropertyManagerPrivate::slotRegExpChanged(QtProperty *property, const QRegExp &regExp)
  422. {
  423. if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0))
  424. emit q_ptr->attributeChanged(varProp, m_regExpAttribute, QVariant(regExp));
  425. }
  426. void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QDate &val)
  427. {
  428. valueChanged(property, QVariant(val));
  429. }
  430. void QtVariantPropertyManagerPrivate::slotRangeChanged(QtProperty *property, const QDate &min, const QDate &max)
  431. {
  432. if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0)) {
  433. emit q_ptr->attributeChanged(varProp, m_minimumAttribute, QVariant(min));
  434. emit q_ptr->attributeChanged(varProp, m_maximumAttribute, QVariant(max));
  435. }
  436. }
  437. void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QTime &val)
  438. {
  439. valueChanged(property, QVariant(val));
  440. }
  441. void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QDateTime &val)
  442. {
  443. valueChanged(property, QVariant(val));
  444. }
  445. void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QKeySequence &val)
  446. {
  447. QVariant v;
  448. v.setValue(val);
  449. valueChanged(property, v);
  450. }
  451. void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QChar &val)
  452. {
  453. valueChanged(property, QVariant(val));
  454. }
  455. void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QLocale &val)
  456. {
  457. valueChanged(property, QVariant(val));
  458. }
  459. void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QPoint &val)
  460. {
  461. valueChanged(property, QVariant(val));
  462. }
  463. void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QPointF &val)
  464. {
  465. valueChanged(property, QVariant(val));
  466. }
  467. void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QSize &val)
  468. {
  469. valueChanged(property, QVariant(val));
  470. }
  471. void QtVariantPropertyManagerPrivate::slotRangeChanged(QtProperty *property, const QSize &min, const QSize &max)
  472. {
  473. if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0)) {
  474. emit q_ptr->attributeChanged(varProp, m_minimumAttribute, QVariant(min));
  475. emit q_ptr->attributeChanged(varProp, m_maximumAttribute, QVariant(max));
  476. }
  477. }
  478. void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QSizeF &val)
  479. {
  480. valueChanged(property, QVariant(val));
  481. }
  482. void QtVariantPropertyManagerPrivate::slotRangeChanged(QtProperty *property, const QSizeF &min, const QSizeF &max)
  483. {
  484. if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0)) {
  485. emit q_ptr->attributeChanged(varProp, m_minimumAttribute, QVariant(min));
  486. emit q_ptr->attributeChanged(varProp, m_maximumAttribute, QVariant(max));
  487. }
  488. }
  489. void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QRect &val)
  490. {
  491. valueChanged(property, QVariant(val));
  492. }
  493. void QtVariantPropertyManagerPrivate::slotConstraintChanged(QtProperty *property, const QRect &constraint)
  494. {
  495. if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0))
  496. emit q_ptr->attributeChanged(varProp, m_constraintAttribute, QVariant(constraint));
  497. }
  498. void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QRectF &val)
  499. {
  500. valueChanged(property, QVariant(val));
  501. }
  502. void QtVariantPropertyManagerPrivate::slotConstraintChanged(QtProperty *property, const QRectF &constraint)
  503. {
  504. if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0))
  505. emit q_ptr->attributeChanged(varProp, m_constraintAttribute, QVariant(constraint));
  506. }
  507. void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QColor &val)
  508. {
  509. valueChanged(property, QVariant(val));
  510. }
  511. void QtVariantPropertyManagerPrivate::slotEnumNamesChanged(QtProperty *property, const QStringList &enumNames)
  512. {
  513. if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0))
  514. emit q_ptr->attributeChanged(varProp, m_enumNamesAttribute, QVariant(enumNames));
  515. }
  516. void QtVariantPropertyManagerPrivate::slotEnumIconsChanged(QtProperty *property, const QMap<int, QIcon> &enumIcons)
  517. {
  518. if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0)) {
  519. QVariant v;
  520. v.setValue(enumIcons);
  521. emit q_ptr->attributeChanged(varProp, m_enumIconsAttribute, v);
  522. }
  523. }
  524. void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QSizePolicy &val)
  525. {
  526. valueChanged(property, QVariant(val));
  527. }
  528. void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QFont &val)
  529. {
  530. valueChanged(property, QVariant(val));
  531. }
  532. void QtVariantPropertyManagerPrivate::slotValueChanged(QtProperty *property, const QCursor &val)
  533. {
  534. #ifndef QT_NO_CURSOR
  535. valueChanged(property, QVariant(val));
  536. #endif
  537. }
  538. void QtVariantPropertyManagerPrivate::slotFlagNamesChanged(QtProperty *property, const QStringList &flagNames)
  539. {
  540. if (QtVariantProperty *varProp = m_internalToProperty.value(property, 0))
  541. emit q_ptr->attributeChanged(varProp, m_flagNamesAttribute, QVariant(flagNames));
  542. }
  543. /*!
  544. \class QtVariantPropertyManager
  545. \internal
  546. \inmodule QtDesigner
  547. \since 4.4
  548. \brief The QtVariantPropertyManager class provides and manages QVariant based properties.
  549. QtVariantPropertyManager provides the addProperty() function which
  550. creates QtVariantProperty objects. The QtVariantProperty class is
  551. a convenience class handling QVariant based properties inheriting
  552. QtProperty. A QtProperty object created by a
  553. QtVariantPropertyManager instance can be converted into a
  554. QtVariantProperty object using the variantProperty() function.
  555. The property's value can be retrieved using the value(), and set
  556. using the setValue() slot. In addition the property's type, and
  557. the type of its value, can be retrieved using the propertyType()
  558. and valueType() functions respectively.
  559. A property's type is a QVariant::Type enumerator value, and
  560. usually a property's type is the same as its value type. But for
  561. some properties the types differ, for example for enums, flags and
  562. group types in which case QtVariantPropertyManager provides the
  563. enumTypeId(), flagTypeId() and groupTypeId() functions,
  564. respectively, to identify their property type (the value types are
  565. QVariant::Int for the enum and flag types, and QVariant::Invalid
  566. for the group type).
  567. Use the isPropertyTypeSupported() function to check if a particular
  568. property type is supported. The currently supported property types
  569. are:
  570. \table
  571. \header
  572. \li Property Type
  573. \li Property Type Id
  574. \row
  575. \li int
  576. \li QVariant::Int
  577. \row
  578. \li double
  579. \li QVariant::Double
  580. \row
  581. \li bool
  582. \li QVariant::Bool
  583. \row
  584. \li QString
  585. \li QVariant::String
  586. \row
  587. \li QDate
  588. \li QVariant::Date
  589. \row
  590. \li QTime
  591. \li QVariant::Time
  592. \row
  593. \li QDateTime
  594. \li QVariant::DateTime
  595. \row
  596. \li QKeySequence
  597. \li QVariant::KeySequence
  598. \row
  599. \li QChar
  600. \li QVariant::Char
  601. \row
  602. \li QLocale
  603. \li QVariant::Locale
  604. \row
  605. \li QPoint
  606. \li QVariant::Point
  607. \row
  608. \li QPointF
  609. \li QVariant::PointF
  610. \row
  611. \li QSize
  612. \li QVariant::Size
  613. \row
  614. \li QSizeF
  615. \li QVariant::SizeF
  616. \row
  617. \li QRect
  618. \li QVariant::Rect
  619. \row
  620. \li QRectF
  621. \li QVariant::RectF
  622. \row
  623. \li QColor
  624. \li QVariant::Color
  625. \row
  626. \li QSizePolicy
  627. \li QVariant::SizePolicy
  628. \row
  629. \li QFont
  630. \li QVariant::Font
  631. \row
  632. \li QCursor
  633. \li QVariant::Cursor
  634. \row
  635. \li enum
  636. \li enumTypeId()
  637. \row
  638. \li flag
  639. \li flagTypeId()
  640. \row
  641. \li group
  642. \li groupTypeId()
  643. \endtable
  644. Each property type can provide additional attributes,
  645. e.g. QVariant::Int and QVariant::Double provides minimum and
  646. maximum values. The currently supported attributes are:
  647. \table
  648. \header
  649. \li Property Type
  650. \li Attribute Name
  651. \li Attribute Type
  652. \row
  653. \li \c int
  654. \li minimum
  655. \li QVariant::Int
  656. \row
  657. \li
  658. \li maximum
  659. \li QVariant::Int
  660. \row
  661. \li
  662. \li singleStep
  663. \li QVariant::Int
  664. \row
  665. \li \c double
  666. \li minimum
  667. \li QVariant::Double
  668. \row
  669. \li
  670. \li maximum
  671. \li QVariant::Double
  672. \row
  673. \li
  674. \li singleStep
  675. \li QVariant::Double
  676. \row
  677. \li
  678. \li decimals
  679. \li QVariant::Int
  680. \row
  681. \li QString
  682. \li regExp
  683. \li QVariant::RegExp
  684. \row
  685. \li QDate
  686. \li minimum
  687. \li QVariant::Date
  688. \row
  689. \li
  690. \li maximum
  691. \li QVariant::Date
  692. \row
  693. \li QPointF
  694. \li decimals
  695. \li QVariant::Int
  696. \row
  697. \li QSize
  698. \li minimum
  699. \li QVariant::Size
  700. \row
  701. \li
  702. \li maximum
  703. \li QVariant::Size
  704. \row
  705. \li QSizeF
  706. \li minimum
  707. \li QVariant::SizeF
  708. \row
  709. \li
  710. \li maximum
  711. \li QVariant::SizeF
  712. \row
  713. \li
  714. \li decimals
  715. \li QVariant::Int
  716. \row
  717. \li QRect
  718. \li constraint
  719. \li QVariant::Rect
  720. \row
  721. \li QRectF
  722. \li constraint
  723. \li QVariant::RectF
  724. \row
  725. \li
  726. \li decimals
  727. \li QVariant::Int
  728. \row
  729. \li \c enum
  730. \li enumNames
  731. \li QVariant::StringList
  732. \row
  733. \li
  734. \li enumIcons
  735. \li iconMapTypeId()
  736. \row
  737. \li \c flag
  738. \li flagNames
  739. \li QVariant::StringList
  740. \endtable
  741. The attributes for a given property type can be retrieved using
  742. the attributes() function. Each attribute has a value type which
  743. can be retrieved using the attributeType() function, and a value
  744. accessible through the attributeValue() function. In addition, the
  745. value can be set using the setAttribute() slot.
  746. QtVariantManager also provides the valueChanged() signal which is
  747. emitted whenever a property created by this manager change, and
  748. the attributeChanged() signal which is emitted whenever an
  749. attribute of such a property changes.
  750. \sa QtVariantProperty, QtVariantEditorFactory
  751. */
  752. /*!
  753. \fn void QtVariantPropertyManager::valueChanged(QtProperty *property, const QVariant &value)
  754. This signal is emitted whenever a property created by this manager
  755. changes its value, passing a pointer to the \a property and the
  756. new \a value as parameters.
  757. \sa setValue()
  758. */
  759. /*!
  760. \fn void QtVariantPropertyManager::attributeChanged(QtProperty *property,
  761. const QString &attribute, const QVariant &value)
  762. This signal is emitted whenever an attribute of a property created
  763. by this manager changes its value, passing a pointer to the \a
  764. property, the \a attribute and the new \a value as parameters.
  765. \sa setAttribute()
  766. */
  767. /*!
  768. Creates a manager with the given \a parent.
  769. */
  770. QtVariantPropertyManager::QtVariantPropertyManager(QObject *parent)
  771. : QtAbstractPropertyManager(parent), d_ptr(new QtVariantPropertyManagerPrivate)
  772. {
  773. d_ptr->q_ptr = this;
  774. d_ptr->m_creatingProperty = false;
  775. d_ptr->m_creatingSubProperties = false;
  776. d_ptr->m_destroyingSubProperties = false;
  777. d_ptr->m_propertyType = 0;
  778. // IntPropertyManager
  779. QtIntPropertyManager *intPropertyManager = new QtIntPropertyManager(this);
  780. d_ptr->m_typeToPropertyManager[QVariant::Int] = intPropertyManager;
  781. d_ptr->m_typeToAttributeToAttributeType[QVariant::Int][d_ptr->m_minimumAttribute] = QVariant::Int;
  782. d_ptr->m_typeToAttributeToAttributeType[QVariant::Int][d_ptr->m_maximumAttribute] = QVariant::Int;
  783. d_ptr->m_typeToAttributeToAttributeType[QVariant::Int][d_ptr->m_singleStepAttribute] = QVariant::Int;
  784. d_ptr->m_typeToValueType[QVariant::Int] = QVariant::Int;
  785. connect(intPropertyManager, SIGNAL(valueChanged(QtProperty*,int)),
  786. this, SLOT(slotValueChanged(QtProperty*,int)));
  787. connect(intPropertyManager, SIGNAL(rangeChanged(QtProperty*,int,int)),
  788. this, SLOT(slotRangeChanged(QtProperty*,int,int)));
  789. connect(intPropertyManager, SIGNAL(singleStepChanged(QtProperty*,int)),
  790. this, SLOT(slotSingleStepChanged(QtProperty*,int)));
  791. // DoublePropertyManager
  792. QtDoublePropertyManager *doublePropertyManager = new QtDoublePropertyManager(this);
  793. d_ptr->m_typeToPropertyManager[QVariant::Double] = doublePropertyManager;
  794. d_ptr->m_typeToAttributeToAttributeType[QVariant::Double][d_ptr->m_minimumAttribute] =
  795. QVariant::Double;
  796. d_ptr->m_typeToAttributeToAttributeType[QVariant::Double][d_ptr->m_maximumAttribute] =
  797. QVariant::Double;
  798. d_ptr->m_typeToAttributeToAttributeType[QVariant::Double][d_ptr->m_singleStepAttribute] =
  799. QVariant::Double;
  800. d_ptr->m_typeToAttributeToAttributeType[QVariant::Double][d_ptr->m_decimalsAttribute] =
  801. QVariant::Int;
  802. d_ptr->m_typeToValueType[QVariant::Double] = QVariant::Double;
  803. connect(doublePropertyManager, SIGNAL(valueChanged(QtProperty*,double)),
  804. this, SLOT(slotValueChanged(QtProperty*,double)));
  805. connect(doublePropertyManager, SIGNAL(rangeChanged(QtProperty*,double,double)),
  806. this, SLOT(slotRangeChanged(QtProperty*,double,double)));
  807. connect(doublePropertyManager, SIGNAL(singleStepChanged(QtProperty*,double)),
  808. this, SLOT(slotSingleStepChanged(QtProperty*,double)));
  809. connect(doublePropertyManager, SIGNAL(decimalsChanged(QtProperty*,int)),
  810. this, SLOT(slotDecimalsChanged(QtProperty*,int)));
  811. // BoolPropertyManager
  812. QtBoolPropertyManager *boolPropertyManager = new QtBoolPropertyManager(this);
  813. d_ptr->m_typeToPropertyManager[QVariant::Bool] = boolPropertyManager;
  814. d_ptr->m_typeToValueType[QVariant::Bool] = QVariant::Bool;
  815. connect(boolPropertyManager, SIGNAL(valueChanged(QtProperty*,bool)),
  816. this, SLOT(slotValueChanged(QtProperty*,bool)));
  817. // StringPropertyManager
  818. QtStringPropertyManager *stringPropertyManager = new QtStringPropertyManager(this);
  819. d_ptr->m_typeToPropertyManager[QVariant::String] = stringPropertyManager;
  820. d_ptr->m_typeToValueType[QVariant::String] = QVariant::String;
  821. d_ptr->m_typeToAttributeToAttributeType[QVariant::String][d_ptr->m_regExpAttribute] =
  822. QVariant::RegExp;
  823. connect(stringPropertyManager, SIGNAL(valueChanged(QtProperty*,QString)),
  824. this, SLOT(slotValueChanged(QtProperty*,QString)));
  825. connect(stringPropertyManager, SIGNAL(regExpChanged(QtProperty*,QRegExp)),
  826. this, SLOT(slotRegExpChanged(QtProperty*,QRegExp)));
  827. // DatePropertyManager
  828. QtDatePropertyManager *datePropertyManager = new QtDatePropertyManager(this);
  829. d_ptr->m_typeToPropertyManager[QVariant::Date] = datePropertyManager;
  830. d_ptr->m_typeToValueType[QVariant::Date] = QVariant::Date;
  831. d_ptr->m_typeToAttributeToAttributeType[QVariant::Date][d_ptr->m_minimumAttribute] =
  832. QVariant::Date;
  833. d_ptr->m_typeToAttributeToAttributeType[QVariant::Date][d_ptr->m_maximumAttribute] =
  834. QVariant::Date;
  835. connect(datePropertyManager, SIGNAL(valueChanged(QtProperty*,QDate)),
  836. this, SLOT(slotValueChanged(QtProperty*,QDate)));
  837. connect(datePropertyManager, SIGNAL(rangeChanged(QtProperty*,QDate,QDate)),
  838. this, SLOT(slotRangeChanged(QtProperty*,QDate,QDate)));
  839. // TimePropertyManager
  840. QtTimePropertyManager *timePropertyManager = new QtTimePropertyManager(this);
  841. d_ptr->m_typeToPropertyManager[QVariant::Time] = timePropertyManager;
  842. d_ptr->m_typeToValueType[QVariant::Time] = QVariant::Time;
  843. connect(timePropertyManager, SIGNAL(valueChanged(QtProperty*,QTime)),
  844. this, SLOT(slotValueChanged(QtProperty*,QTime)));
  845. // DateTimePropertyManager
  846. QtDateTimePropertyManager *dateTimePropertyManager = new QtDateTimePropertyManager(this);
  847. d_ptr->m_typeToPropertyManager[QVariant::DateTime] = dateTimePropertyManager;
  848. d_ptr->m_typeToValueType[QVariant::DateTime] = QVariant::DateTime;
  849. connect(dateTimePropertyManager, SIGNAL(valueChanged(QtProperty*,QDateTime)),
  850. this, SLOT(slotValueChanged(QtProperty*,QDateTime)));
  851. // KeySequencePropertyManager
  852. QtKeySequencePropertyManager *keySequencePropertyManager = new QtKeySequencePropertyManager(this);
  853. d_ptr->m_typeToPropertyManager[QVariant::KeySequence] = keySequencePropertyManager;
  854. d_ptr->m_typeToValueType[QVariant::KeySequence] = QVariant::KeySequence;
  855. connect(keySequencePropertyManager, SIGNAL(valueChanged(QtProperty*,QKeySequence)),
  856. this, SLOT(slotValueChanged(QtProperty*,QKeySequence)));
  857. // CharPropertyManager
  858. QtCharPropertyManager *charPropertyManager = new QtCharPropertyManager(this);
  859. d_ptr->m_typeToPropertyManager[QVariant::Char] = charPropertyManager;
  860. d_ptr->m_typeToValueType[QVariant::Char] = QVariant::Char;
  861. connect(charPropertyManager, SIGNAL(valueChanged(QtProperty*,QChar)),
  862. this, SLOT(slotValueChanged(QtProperty*,QChar)));
  863. // LocalePropertyManager
  864. QtLocalePropertyManager *localePropertyManager = new QtLocalePropertyManager(this);
  865. d_ptr->m_typeToPropertyManager[QVariant::Locale] = localePropertyManager;
  866. d_ptr->m_typeToValueType[QVariant::Locale] = QVariant::Locale;
  867. connect(localePropertyManager, SIGNAL(valueChanged(QtProperty*,QLocale)),
  868. this, SLOT(slotValueChanged(QtProperty*,QLocale)));
  869. connect(localePropertyManager->subEnumPropertyManager(), SIGNAL(valueChanged(QtProperty*,int)),
  870. this, SLOT(slotValueChanged(QtProperty*,int)));
  871. connect(localePropertyManager, SIGNAL(propertyInserted(QtProperty*,QtProperty*,QtProperty*)),
  872. this, SLOT(slotPropertyInserted(QtProperty*,QtProperty*,QtProperty*)));
  873. connect(localePropertyManager, SIGNAL(propertyRemoved(QtProperty*,QtProperty*)),
  874. this, SLOT(slotPropertyRemoved(QtProperty*,QtProperty*)));
  875. // PointPropertyManager
  876. QtPointPropertyManager *pointPropertyManager = new QtPointPropertyManager(this);
  877. d_ptr->m_typeToPropertyManager[QVariant::Point] = pointPropertyManager;
  878. d_ptr->m_typeToValueType[QVariant::Point] = QVariant::Point;
  879. connect(pointPropertyManager, SIGNAL(valueChanged(QtProperty*,QPoint)),
  880. this, SLOT(slotValueChanged(QtProperty*,QPoint)));
  881. connect(pointPropertyManager->subIntPropertyManager(), SIGNAL(valueChanged(QtProperty*,int)),
  882. this, SLOT(slotValueChanged(QtProperty*,int)));
  883. connect(pointPropertyManager, SIGNAL(propertyInserted(QtProperty*,QtProperty*,QtProperty*)),
  884. this, SLOT(slotPropertyInserted(QtProperty*,QtProperty*,QtProperty*)));
  885. connect(pointPropertyManager, SIGNAL(propertyRemoved(QtProperty*,QtProperty*)),
  886. this, SLOT(slotPropertyRemoved(QtProperty*,QtProperty*)));
  887. // PointFPropertyManager
  888. QtPointFPropertyManager *pointFPropertyManager = new QtPointFPropertyManager(this);
  889. d_ptr->m_typeToPropertyManager[QVariant::PointF] = pointFPropertyManager;
  890. d_ptr->m_typeToValueType[QVariant::PointF] = QVariant::PointF;
  891. d_ptr->m_typeToAttributeToAttributeType[QVariant::PointF][d_ptr->m_decimalsAttribute] =
  892. QVariant::Int;
  893. connect(pointFPropertyManager, SIGNAL(valueChanged(QtProperty*,QPointF)),
  894. this, SLOT(slotValueChanged(QtProperty*,QPointF)));
  895. connect(pointFPropertyManager, SIGNAL(decimalsChanged(QtProperty*,int)),
  896. this, SLOT(slotDecimalsChanged(QtProperty*,int)));
  897. connect(pointFPropertyManager->subDoublePropertyManager(), SIGNAL(valueChanged(QtProperty*,double)),
  898. this, SLOT(slotValueChanged(QtProperty*,double)));
  899. connect(pointFPropertyManager, SIGNAL(propertyInserted(QtProperty*,QtProperty*,QtProperty*)),
  900. this, SLOT(slotPropertyInserted(QtProperty*,QtProperty*,QtProperty*)));
  901. connect(pointFPropertyManager, SIGNAL(propertyRemoved(QtProperty*,QtProperty*)),
  902. this, SLOT(slotPropertyRemoved(QtProperty*,QtProperty*)));
  903. // SizePropertyManager
  904. QtSizePropertyManager *sizePropertyManager = new QtSizePropertyManager(this);
  905. d_ptr->m_typeToPropertyManager[QVariant::Size] = sizePropertyManager;
  906. d_ptr->m_typeToValueType[QVariant::Size] = QVariant::Size;
  907. d_ptr->m_typeToAttributeToAttributeType[QVariant::Size][d_ptr->m_minimumAttribute] =
  908. QVariant::Size;
  909. d_ptr->m_typeToAttributeToAttributeType[QVariant::Size][d_ptr->m_maximumAttribute] =
  910. QVariant::Size;
  911. connect(sizePropertyManager, SIGNAL(valueChanged(QtProperty*,QSize)),
  912. this, SLOT(slotValueChanged(QtProperty*,QSize)));
  913. connect(sizePropertyManager, SIGNAL(rangeChanged(QtProperty*,QSize,QSize)),
  914. this, SLOT(slotRangeChanged(QtProperty*,QSize,QSize)));
  915. connect(sizePropertyManager->subIntPropertyManager(), SIGNAL(valueChanged(QtProperty*,int)),
  916. this, SLOT(slotValueChanged(QtProperty*,int)));
  917. connect(sizePropertyManager->subIntPropertyManager(), SIGNAL(rangeChanged(QtProperty*,int,int)),
  918. this, SLOT(slotRangeChanged(QtProperty*,int,int)));
  919. connect(sizePropertyManager, SIGNAL(propertyInserted(QtProperty*,QtProperty*,QtProperty*)),
  920. this, SLOT(slotPropertyInserted(QtProperty*,QtProperty*,QtProperty*)));
  921. connect(sizePropertyManager, SIGNAL(propertyRemoved(QtProperty*,QtProperty*)),
  922. this, SLOT(slotPropertyRemoved(QtProperty*,QtProperty*)));
  923. // SizeFPropertyManager
  924. QtSizeFPropertyManager *sizeFPropertyManager = new QtSizeFPropertyManager(this);
  925. d_ptr->m_typeToPropertyManager[QVariant::SizeF] = sizeFPropertyManager;
  926. d_ptr->m_typeToValueType[QVariant::SizeF] = QVariant::SizeF;
  927. d_ptr->m_typeToAttributeToAttributeType[QVariant::SizeF][d_ptr->m_minimumAttribute] =
  928. QVariant::SizeF;
  929. d_ptr->m_typeToAttributeToAttributeType[QVariant::SizeF][d_ptr->m_maximumAttribute] =
  930. QVariant::SizeF;
  931. d_ptr->m_typeToAttributeToAttributeType[QVariant::SizeF][d_ptr->m_decimalsAttribute] =
  932. QVariant::Int;
  933. connect(sizeFPropertyManager, SIGNAL(valueChanged(QtProperty*,QSizeF)),
  934. this, SLOT(slotValueChanged(QtProperty*,QSizeF)));
  935. connect(sizeFPropertyManager, SIGNAL(rangeChanged(QtProperty*,QSizeF,QSizeF)),
  936. this, SLOT(slotRangeChanged(QtProperty*,QSizeF,QSizeF)));
  937. connect(sizeFPropertyManager, SIGNAL(decimalsChanged(QtProperty*,int)),
  938. this, SLOT(slotDecimalsChanged(QtProperty*,int)));
  939. connect(sizeFPropertyManager->subDoublePropertyManager(), SIGNAL(valueChanged(QtProperty*,double)),
  940. this, SLOT(slotValueChanged(QtProperty*,double)));
  941. connect(sizeFPropertyManager->subDoublePropertyManager(), SIGNAL(rangeChanged(QtProperty*,double,double)),
  942. this, SLOT(slotRangeChanged(QtProperty*,double,double)));
  943. connect(sizeFPropertyManager, SIGNAL(propertyInserted(QtProperty*,QtProperty*,QtProperty*)),
  944. this, SLOT(slotPropertyInserted(QtProperty*,QtProperty*,QtProperty*)));
  945. connect(sizeFPropertyManager, SIGNAL(propertyRemoved(QtProperty*,QtProperty*)),
  946. this, SLOT(slotPropertyRemoved(QtProperty*,QtProperty*)));
  947. // RectPropertyManager
  948. QtRectPropertyManager *rectPropertyManager = new QtRectPropertyManager(this);
  949. d_ptr->m_typeToPropertyManager[QVariant::Rect] = rectPropertyManager;
  950. d_ptr->m_typeToValueType[QVariant::Rect] = QVariant::Rect;
  951. d_ptr->m_typeToAttributeToAttributeType[QVariant::Rect][d_ptr->m_constraintAttribute] =
  952. QVariant::Rect;
  953. connect(rectPropertyManager, SIGNAL(valueChanged(QtProperty*,QRect)),
  954. this, SLOT(slotValueChanged(QtProperty*,QRect)));
  955. connect(rectPropertyManager, SIGNAL(constraintChanged(QtProperty*,QRect)),
  956. this, SLOT(slotConstraintChanged(QtProperty*,QRect)));
  957. connect(rectPropertyManager->subIntPropertyManager(), SIGNAL(valueChanged(QtProperty*,int)),
  958. this, SLOT(slotValueChanged(QtProperty*,int)));
  959. connect(rectPropertyManager->subIntPropertyManager(), SIGNAL(rangeChanged(QtProperty*,int,int)),
  960. this, SLOT(slotRangeChanged(QtProperty*,int,int)));
  961. connect(rectPropertyManager, SIGNAL(propertyInserted(QtProperty*,QtProperty*,QtProperty*)),
  962. this, SLOT(slotPropertyInserted(QtProperty*,QtProperty*,QtProperty*)));
  963. connect(rectPropertyManager, SIGNAL(propertyRemoved(QtProperty*,QtProperty*)),
  964. this, SLOT(slotPropertyRemoved(QtProperty*,QtProperty*)));
  965. // RectFPropertyManager
  966. QtRectFPropertyManager *rectFPropertyManager = new QtRectFPropertyManager(this);
  967. d_ptr->m_typeToPropertyManager[QVariant::RectF] = rectFPropertyManager;
  968. d_ptr->m_typeToValueType[QVariant::RectF] = QVariant::RectF;
  969. d_ptr->m_typeToAttributeToAttributeType[QVariant::RectF][d_ptr->m_constraintAttribute] =
  970. QVariant::RectF;
  971. d_ptr->m_typeToAttributeToAttributeType[QVariant::RectF][d_ptr->m_decimalsAttribute] =
  972. QVariant::Int;
  973. connect(rectFPropertyManager, SIGNAL(valueChanged(QtProperty*,QRectF)),
  974. this, SLOT(slotValueChanged(QtProperty*,QRectF)));
  975. connect(rectFPropertyManager, SIGNAL(constraintChanged(QtProperty*,QRectF)),
  976. this, SLOT(slotConstraintChanged(QtProperty*,QRectF)));
  977. connect(rectFPropertyManager, SIGNAL(decimalsChanged(QtProperty*,int)),
  978. this, SLOT(slotDecimalsChanged(QtProperty*,int)));
  979. connect(rectFPropertyManager->subDoublePropertyManager(), SIGNAL(valueChanged(QtProperty*,double)),
  980. this, SLOT(slotValueChanged(QtProperty*,double)));
  981. connect(rectFPropertyManager->subDoublePropertyManager(), SIGNAL(rangeChanged(QtProperty*,double,double)),
  982. this, SLOT(slotRangeChanged(QtProperty*,double,double)));
  983. connect(rectFPropertyManager, SIGNAL(propertyInserted(QtProperty*,QtProperty*,QtProperty*)),
  984. this, SLOT(slotPropertyInserted(QtProperty*,QtProperty*,QtProperty*)));
  985. connect(rectFPropertyManager, SIGNAL(propertyRemoved(QtProperty*,QtProperty*)),
  986. this, SLOT(slotPropertyRemoved(QtProperty*,QtProperty*)));
  987. // ColorPropertyManager
  988. QtColorPropertyManager *colorPropertyManager = new QtColorPropertyManager(this);
  989. d_ptr->m_typeToPropertyManager[QVariant::Color] = colorPropertyManager;
  990. d_ptr->m_typeToValueType[QVariant::Color] = QVariant::Color;
  991. connect(colorPropertyManager, SIGNAL(valueChanged(QtProperty*,QColor)),
  992. this, SLOT(slotValueChanged(QtProperty*,QColor)));
  993. connect(colorPropertyManager->subIntPropertyManager(), SIGNAL(valueChanged(QtProperty*,int)),
  994. this, SLOT(slotValueChanged(QtProperty*,int)));
  995. connect(colorPropertyManager, SIGNAL(propertyInserted(QtProperty*,QtProperty*,QtProperty*)),
  996. this, SLOT(slotPropertyInserted(QtProperty*,QtProperty*,QtProperty*)));
  997. connect(colorPropertyManager, SIGNAL(propertyRemoved(QtProperty*,QtProperty*)),
  998. this, SLOT(slotPropertyRemoved(QtProperty*,QtProperty*)));
  999. // EnumPropertyManager
  1000. int enumId = enumTypeId();
  1001. QtEnumPropertyManager *enumPropertyManager = new QtEnumPropertyManager(this);
  1002. d_ptr->m_typeToPropertyManager[enumId] = enumPropertyManager;
  1003. d_ptr->m_typeToValueType[enumId] = QVariant::Int;
  1004. d_ptr->m_typeToAttributeToAttributeType[enumId][d_ptr->m_enumNamesAttribute] =
  1005. QVariant::StringList;
  1006. d_ptr->m_typeToAttributeToAttributeType[enumId][d_ptr->m_enumIconsAttribute] =
  1007. iconMapTypeId();
  1008. connect(enumPropertyManager, SIGNAL(valueChanged(QtProperty*,int)),
  1009. this, SLOT(slotValueChanged(QtProperty*,int)));
  1010. connect(enumPropertyManager, SIGNAL(enumNamesChanged(QtProperty*,QStringList)),
  1011. this, SLOT(slotEnumNamesChanged(QtProperty*,QStringList)));
  1012. connect(enumPropertyManager, SIGNAL(enumIconsChanged(QtProperty*,QMap<int,QIcon>)),
  1013. this, SLOT(slotEnumIconsChanged(QtProperty*,QMap<int,QIcon>)));
  1014. // SizePolicyPropertyManager
  1015. QtSizePolicyPropertyManager *sizePolicyPropertyManager = new QtSizePolicyPropertyManager(this);
  1016. d_ptr->m_typeToPropertyManager[QVariant::SizePolicy] = sizePolicyPropertyManager;
  1017. d_ptr->m_typeToValueType[QVariant::SizePolicy] = QVariant::SizePolicy;
  1018. connect(sizePolicyPropertyManager, SIGNAL(valueChanged(QtProperty*,QSizePolicy)),
  1019. this, SLOT(slotValueChanged(QtProperty*,QSizePolicy)));
  1020. connect(sizePolicyPropertyManager->subIntPropertyManager(), SIGNAL(valueChanged(QtProperty*,int)),
  1021. this, SLOT(slotValueChanged(QtProperty*,int)));
  1022. connect(sizePolicyPropertyManager->subIntPropertyManager(), SIGNAL(rangeChanged(QtProperty*,int,int)),
  1023. this, SLOT(slotRangeChanged(QtProperty*,int,int)));
  1024. connect(sizePolicyPropertyManager->subEnumPropertyManager(), SIGNAL(valueChanged(QtProperty*,int)),
  1025. this, SLOT(slotValueChanged(QtProperty*,int)));
  1026. connect(sizePolicyPropertyManager->subEnumPropertyManager(),
  1027. SIGNAL(enumNamesChanged(QtProperty*,QStringList)),
  1028. this, SLOT(slotEnumNamesChanged(QtProperty*,QStringList)));
  1029. connect(sizePolicyPropertyManager, SIGNAL(propertyInserted(QtProperty*,QtProperty*,QtProperty*)),
  1030. this, SLOT(slotPropertyInserted(QtProperty*,QtProperty*,QtProperty*)));
  1031. connect(sizePolicyPropertyManager, SIGNAL(propertyRemoved(QtProperty*,QtProperty*)),
  1032. this, SLOT(slotPropertyRemoved(QtProperty*,QtProperty*)));
  1033. // FontPropertyManager
  1034. QtFontPropertyManager *fontPropertyManager = new QtFontPropertyManager(this);
  1035. d_ptr->m_typeToPropertyManager[QVariant::Font] = fontPropertyManager;
  1036. d_ptr->m_typeToValueType[QVariant::Font] = QVariant::Font;
  1037. connect(fontPropertyManager, SIGNAL(valueChanged(QtProperty*,QFont)),
  1038. this, SLOT(slotValueChanged(QtProperty*,QFont)));
  1039. connect(fontPropertyManager->subIntPropertyManager(), SIGNAL(valueChanged(QtProperty*,int)),
  1040. this, SLOT(slotValueChanged(QtProperty*,int)));
  1041. connect(fontPropertyManager->subIntPropertyManager(), SIGNAL(rangeChanged(QtProperty*,int,int)),
  1042. this, SLOT(slotRangeChanged(QtProperty*,int,int)));
  1043. connect(fontPropertyManager->subEnumPropertyManager(), SIGNAL(valueChanged(QtProperty*,int)),
  1044. this, SLOT(slotValueChanged(QtProperty*,int)));
  1045. connect(fontPropertyManager->subEnumPropertyManager(),
  1046. SIGNAL(enumNamesChanged(QtProperty*,QStringList)),
  1047. this, SLOT(slotEnumNamesChanged(QtProperty*,QStringList)));
  1048. connect(fontPropertyManager->subBoolPropertyManager(), SIGNAL(valueChanged(QtProperty*,bool)),
  1049. this, SLOT(slotValueChanged(QtProperty*,bool)));
  1050. connect(fontPropertyManager, SIGNAL(propertyInserted(QtProperty*,QtProperty*,QtProperty*)),
  1051. this, SLOT(slotPropertyInserted(QtProperty*,QtProperty*,QtProperty*)));
  1052. connect(fontPropertyManager, SIGNAL(propertyRemoved(QtProperty*,QtProperty*)),
  1053. this, SLOT(slotPropertyRemoved(QtProperty*,QtProperty*)));
  1054. // CursorPropertyManager
  1055. QtCursorPropertyManager *cursorPropertyManager = new QtCursorPropertyManager(this);
  1056. d_ptr->m_typeToPropertyManager[QVariant::Cursor] = cursorPropertyManager;
  1057. d_ptr->m_typeToValueType[QVariant::Cursor] = QVariant::Cursor;
  1058. connect(cursorPropertyManager, SIGNAL(valueChanged(QtProperty*,QCursor)),
  1059. this, SLOT(slotValueChanged(QtProperty*,QCursor)));
  1060. // FlagPropertyManager
  1061. int flagId = flagTypeId();
  1062. QtFlagPropertyManager *flagPropertyManager = new QtFlagPropertyManager(this);
  1063. d_ptr->m_typeToPropertyManager[flagId] = flagPropertyManager;
  1064. d_ptr->m_typeToValueType[flagId] = QVariant::Int;
  1065. d_ptr->m_typeToAttributeToAttributeType[flagId][d_ptr->m_flagNamesAttribute] =
  1066. QVariant::StringList;
  1067. connect(flagPropertyManager, SIGNAL(valueChanged(QtProperty*,int)),
  1068. this, SLOT(slotValueChanged(QtProperty*,int)));
  1069. connect(flagPropertyManager, SIGNAL(flagNamesChanged(QtProperty*,QStringList)),
  1070. this, SLOT(slotFlagNamesChanged(QtProperty*,QStringList)));
  1071. connect(flagPropertyManager->subBoolPropertyManager(), SIGNAL(valueChanged(QtProperty*,bool)),
  1072. this, SLOT(slotValueChanged(QtProperty*,bool)));
  1073. connect(flagPropertyManager, SIGNAL(propertyInserted(QtProperty*,QtProperty*,QtProperty*)),
  1074. this, SLOT(slotPropertyInserted(QtProperty*,QtProperty*,QtProperty*)));
  1075. connect(flagPropertyManager, SIGNAL(propertyRemoved(QtProperty*,QtProperty*)),
  1076. this, SLOT(slotPropertyRemoved(QtProperty*,QtProperty*)));
  1077. // FlagPropertyManager
  1078. int groupId = groupTypeId();
  1079. QtGroupPropertyManager *groupPropertyManager = new QtGroupPropertyManager(this);
  1080. d_ptr->m_typeToPropertyManager[groupId] = groupPropertyManager;
  1081. d_ptr->m_typeToValueType[groupId] = QVariant::Invalid;
  1082. }
  1083. /*!
  1084. Destroys this manager, and all the properties it has created.
  1085. */
  1086. QtVariantPropertyManager::~QtVariantPropertyManager()
  1087. {
  1088. clear();
  1089. }
  1090. /*!
  1091. Returns the given \a property converted into a QtVariantProperty.
  1092. If the \a property was not created by this variant manager, the
  1093. function returns 0.
  1094. \sa createProperty()
  1095. */
  1096. QtVariantProperty *QtVariantPropertyManager::variantProperty(const QtProperty *property) const
  1097. {
  1098. // 通过 QtProperty 找到对应的 QtVariantProperty
  1099. const QMap<const QtProperty *, QPair<QtVariantProperty *, int> >::const_iterator it = d_ptr->m_propertyToType.constFind(property);
  1100. if (it == d_ptr->m_propertyToType.constEnd())
  1101. return 0;
  1102. return it.value().first;
  1103. }
  1104. /*!
  1105. Returns true if the given \a propertyType is supported by this
  1106. variant manager; otherwise false.
  1107. \sa propertyType()
  1108. */
  1109. bool QtVariantPropertyManager::isPropertyTypeSupported(int propertyType) const
  1110. {
  1111. if (d_ptr->m_typeToValueType.contains(propertyType))
  1112. return true;
  1113. return false;
  1114. }
  1115. /*!
  1116. Creates and returns a variant property of the given \a propertyType
  1117. with the given \a name.
  1118. If the specified \a propertyType is not supported by this variant
  1119. manager, this function returns 0.
  1120. Do not use the inherited
  1121. QtAbstractPropertyManager::addProperty() function to create a
  1122. variant property (that function will always return 0 since it will
  1123. not be clear what type the property should have).
  1124. \sa isPropertyTypeSupported()
  1125. */
  1126. /// <summary>
  1127. /// 根据属性类型创建属性相关数据结构
  1128. /// </summary>
  1129. /// <param name="propertyType"></param>
  1130. /// <param name="name"></param>
  1131. /// <returns></returns>
  1132. QtVariantProperty *QtVariantPropertyManager::addProperty(int propertyType, const QString &name)
  1133. {
  1134. // 如果是不支持的属性则不予建立
  1135. if (!isPropertyTypeSupported(propertyType))
  1136. return 0;
  1137. bool wasCreating = d_ptr->m_creatingProperty;
  1138. d_ptr->m_creatingProperty = true;
  1139. // 保存属性Type
  1140. d_ptr->m_propertyType = propertyType;
  1141. // 首先通过基类创建并且初始化本属性
  1142. QtProperty *property = QtAbstractPropertyManager::addProperty(name);
  1143. d_ptr->m_creatingProperty = wasCreating;
  1144. d_ptr->m_propertyType = 0;
  1145. if (!property)
  1146. return 0;
  1147. // 通过 QtProperty 转换为 QtVariantProperty 并返回
  1148. return variantProperty(property);
  1149. }
  1150. /*!
  1151. Returns the given \a property's value.
  1152. If the given \a property is not managed by this manager, this
  1153. function returns an invalid variant.
  1154. \sa setValue()
  1155. */
  1156. QVariant QtVariantPropertyManager::value(const QtProperty *property) const
  1157. {
  1158. QtProperty *internProp = propertyToWrappedProperty()->value(property, 0);
  1159. if (internProp == 0)
  1160. return QVariant();
  1161. QtAbstractPropertyManager *manager = internProp->propertyManager();
  1162. if (QtIntPropertyManager *intManager = qobject_cast<QtIntPropertyManager *>(manager)) {
  1163. return intManager->value(internProp);
  1164. } else if (QtDoublePropertyManager *doubleManager = qobject_cast<QtDoublePropertyManager *>(manager)) {
  1165. return doubleManager->value(internProp);
  1166. } else if (QtBoolPropertyManager *boolManager = qobject_cast<QtBoolPropertyManager *>(manager)) {
  1167. return boolManager->value(internProp);
  1168. } else if (QtStringPropertyManager *stringManager = qobject_cast<QtStringPropertyManager *>(manager)) {
  1169. return stringManager->value(internProp);
  1170. } else if (QtDatePropertyManager *dateManager = qobject_cast<QtDatePropertyManager *>(manager)) {
  1171. return dateManager->value(internProp);
  1172. } else if (QtTimePropertyManager *timeManager = qobject_cast<QtTimePropertyManager *>(manager)) {
  1173. return timeManager->value(internProp);
  1174. } else if (QtDateTimePropertyManager *dateTimeManager = qobject_cast<QtDateTimePropertyManager *>(manager)) {
  1175. return dateTimeManager->value(internProp);
  1176. } else if (QtKeySequencePropertyManager *keySequenceManager = qobject_cast<QtKeySequencePropertyManager *>(manager)) {
  1177. return QVariant::fromValue(keySequenceManager->value(internProp));
  1178. } else if (QtCharPropertyManager *charManager = qobject_cast<QtCharPropertyManager *>(manager)) {
  1179. return charManager->value(internProp);
  1180. } else if (QtLocalePropertyManager *localeManager = qobject_cast<QtLocalePropertyManager *>(manager)) {
  1181. return localeManager->value(internProp);
  1182. } else if (QtPointPropertyManager *pointManager = qobject_cast<QtPointPropertyManager *>(manager)) {
  1183. return pointManager->value(internProp);
  1184. } else if (QtPointFPropertyManager *pointFManager = qobject_cast<QtPointFPropertyManager *>(manager)) {
  1185. return pointFManager->value(internProp);
  1186. } else if (QtSizePropertyManager *sizeManager = qobject_cast<QtSizePropertyManager *>(manager)) {
  1187. return sizeManager->value(internProp);
  1188. } else if (QtSizeFPropertyManager *sizeFManager = qobject_cast<QtSizeFPropertyManager *>(manager)) {
  1189. return sizeFManager->value(internProp);
  1190. } else if (QtRectPropertyManager *rectManager = qobject_cast<QtRectPropertyManager *>(manager)) {
  1191. return rectManager->value(internProp);
  1192. } else if (QtRectFPropertyManager *rectFManager = qobject_cast<QtRectFPropertyManager *>(manager)) {
  1193. return rectFManager->value(internProp);
  1194. } else if (QtColorPropertyManager *colorManager = qobject_cast<QtColorPropertyManager *>(manager)) {
  1195. return colorManager->value(internProp);
  1196. } else if (QtEnumPropertyManager *enumManager = qobject_cast<QtEnumPropertyManager *>(manager)) {
  1197. return enumManager->value(internProp);
  1198. } else if (QtSizePolicyPropertyManager *sizePolicyManager =
  1199. qobject_cast<QtSizePolicyPropertyManager *>(manager)) {
  1200. return sizePolicyManager->value(internProp);
  1201. } else if (QtFontPropertyManager *fontManager = qobject_cast<QtFontPropertyManager *>(manager)) {
  1202. return fontManager->value(internProp);
  1203. #ifndef QT_NO_CURSOR
  1204. } else if (QtCursorPropertyManager *cursorManager = qobject_cast<QtCursorPropertyManager *>(manager)) {
  1205. return cursorManager->value(internProp);
  1206. #endif
  1207. } else if (QtFlagPropertyManager *flagManager = qobject_cast<QtFlagPropertyManager *>(manager)) {
  1208. return flagManager->value(internProp);
  1209. }
  1210. return QVariant();
  1211. }
  1212. /*!
  1213. Returns the given \a property's value type.
  1214. \sa propertyType()
  1215. */
  1216. int QtVariantPropertyManager::valueType(const QtProperty *property) const
  1217. {
  1218. int propType = propertyType(property);
  1219. return valueType(propType);
  1220. }
  1221. /*!
  1222. \overload
  1223. Returns the value type associated with the given \a propertyType.
  1224. */
  1225. int QtVariantPropertyManager::valueType(int propertyType) const
  1226. {
  1227. if (d_ptr->m_typeToValueType.contains(propertyType))
  1228. return d_ptr->m_typeToValueType[propertyType];
  1229. return 0;
  1230. }
  1231. /*!
  1232. Returns the given \a property's type.
  1233. \sa valueType()
  1234. */
  1235. int QtVariantPropertyManager::propertyType(const QtProperty *property) const
  1236. {
  1237. const QMap<const QtProperty *, QPair<QtVariantProperty *, int> >::const_iterator it = d_ptr->m_propertyToType.constFind(property);
  1238. if (it == d_ptr->m_propertyToType.constEnd())
  1239. return 0;
  1240. return it.value().second;
  1241. }
  1242. /*!
  1243. Returns the given \a property's value for the specified \a
  1244. attribute
  1245. If the given \a property was not created by \e this manager, or if
  1246. the specified \a attribute does not exist, this function returns
  1247. an invalid variant.
  1248. \sa attributes(), attributeType(), setAttribute()
  1249. */
  1250. QVariant QtVariantPropertyManager::attributeValue(const QtProperty *property, const QString &attribute) const
  1251. {
  1252. int propType = propertyType(property);
  1253. if (!propType)
  1254. return QVariant();
  1255. QMap<int, QMap<QString, int> >::ConstIterator it =
  1256. d_ptr->m_typeToAttributeToAttributeType.find(propType);
  1257. if (it == d_ptr->m_typeToAttributeToAttributeType.constEnd())
  1258. return QVariant();
  1259. QMap<QString, int> attributes = it.value();
  1260. QMap<QString, int>::ConstIterator itAttr = attributes.find(attribute);
  1261. if (itAttr == attributes.constEnd())
  1262. return QVariant();
  1263. QtProperty *internProp = propertyToWrappedProperty()->value(property, 0);
  1264. if (internProp == 0)
  1265. return QVariant();
  1266. QtAbstractPropertyManager *manager = internProp->propertyManager();
  1267. if (QtIntPropertyManager *intManager = qobject_cast<QtIntPropertyManager *>(manager)) {
  1268. if (attribute == d_ptr->m_maximumAttribute)
  1269. return intManager->maximum(internProp);
  1270. if (attribute == d_ptr->m_minimumAttribute)
  1271. return intManager->minimum(internProp);
  1272. if (attribute == d_ptr->m_singleStepAttribute)
  1273. return intManager->singleStep(internProp);
  1274. return QVariant();
  1275. } else if (QtDoublePropertyManager *doubleManager = qobject_cast<QtDoublePropertyManager *>(manager)) {
  1276. if (attribute == d_ptr->m_maximumAttribute)
  1277. return doubleManager->maximum(internProp);
  1278. if (attribute == d_ptr->m_minimumAttribute)
  1279. return doubleManager->minimum(internProp);
  1280. if (attribute == d_ptr->m_singleStepAttribute)
  1281. return doubleManager->singleStep(internProp);
  1282. if (attribute == d_ptr->m_decimalsAttribute)
  1283. return doubleManager->decimals(internProp);
  1284. return QVariant();
  1285. } else if (QtStringPropertyManager *stringManager = qobject_cast<QtStringPropertyManager *>(manager)) {
  1286. if (attribute == d_ptr->m_regExpAttribute)
  1287. return stringManager->regExp(internProp);
  1288. return QVariant();
  1289. } else if (QtDatePropertyManager *dateManager = qobject_cast<QtDatePropertyManager *>(manager)) {
  1290. if (attribute == d_ptr->m_maximumAttribute)
  1291. return dateManager->maximum(internProp);
  1292. if (attribute == d_ptr->m_minimumAttribute)
  1293. return dateManager->minimum(internProp);
  1294. return QVariant();
  1295. } else if (QtPointFPropertyManager *pointFManager = qobject_cast<QtPointFPropertyManager *>(manager)) {
  1296. if (attribute == d_ptr->m_decimalsAttribute)
  1297. return pointFManager->decimals(internProp);
  1298. return QVariant();
  1299. } else if (QtSizePropertyManager *sizeManager = qobject_cast<QtSizePropertyManager *>(manager)) {
  1300. if (attribute == d_ptr->m_maximumAttribute)
  1301. return sizeManager->maximum(internProp);
  1302. if (attribute == d_ptr->m_minimumAttribute)
  1303. return sizeManager->minimum(internProp);
  1304. return QVariant();
  1305. } else if (QtSizeFPropertyManager *sizeFManager = qobject_cast<QtSizeFPropertyManager *>(manager)) {
  1306. if (attribute == d_ptr->m_maximumAttribute)
  1307. return sizeFManager->maximum(internProp);
  1308. if (attribute == d_ptr->m_minimumAttribute)
  1309. return sizeFManager->minimum(internProp);
  1310. if (attribute == d_ptr->m_decimalsAttribute)
  1311. return sizeFManager->decimals(internProp);
  1312. return QVariant();
  1313. } else if (QtRectPropertyManager *rectManager = qobject_cast<QtRectPropertyManager *>(manager)) {
  1314. if (attribute == d_ptr->m_constraintAttribute)
  1315. return rectManager->constraint(internProp);
  1316. return QVariant();
  1317. } else if (QtRectFPropertyManager *rectFManager = qobject_cast<QtRectFPropertyManager *>(manager)) {
  1318. if (attribute == d_ptr->m_constraintAttribute)
  1319. return rectFManager->constraint(internProp);
  1320. if (attribute == d_ptr->m_decimalsAttribute)
  1321. return rectFManager->decimals(internProp);
  1322. return QVariant();
  1323. } else if (QtEnumPropertyManager *enumManager = qobject_cast<QtEnumPropertyManager *>(manager)) {
  1324. if (attribute == d_ptr->m_enumNamesAttribute)
  1325. return enumManager->enumNames(internProp);
  1326. if (attribute == d_ptr->m_enumIconsAttribute) {
  1327. QVariant v;
  1328. v.setValue(enumManager->enumIcons(internProp));
  1329. return v;
  1330. }
  1331. return QVariant();
  1332. } else if (QtFlagPropertyManager *flagManager = qobject_cast<QtFlagPropertyManager *>(manager)) {
  1333. if (attribute == d_ptr->m_flagNamesAttribute)
  1334. return flagManager->flagNames(internProp);
  1335. return QVariant();
  1336. }
  1337. return QVariant();
  1338. }
  1339. /*!
  1340. Returns a list of the given \a propertyType 's attributes.
  1341. \sa attributeValue(), attributeType()
  1342. */
  1343. QStringList QtVariantPropertyManager::attributes(int propertyType) const
  1344. {
  1345. QMap<int, QMap<QString, int> >::ConstIterator it =
  1346. d_ptr->m_typeToAttributeToAttributeType.find(propertyType);
  1347. if (it == d_ptr->m_typeToAttributeToAttributeType.constEnd())
  1348. return QStringList();
  1349. return it.value().keys();
  1350. }
  1351. /*!
  1352. Returns the type of the specified \a attribute of the given \a
  1353. propertyType.
  1354. If the given \a propertyType is not supported by \e this manager,
  1355. or if the given \a propertyType does not possess the specified \a
  1356. attribute, this function returns QVariant::Invalid.
  1357. \sa attributes(), valueType()
  1358. */
  1359. int QtVariantPropertyManager::attributeType(int propertyType, const QString &attribute) const
  1360. {
  1361. QMap<int, QMap<QString, int> >::ConstIterator it =
  1362. d_ptr->m_typeToAttributeToAttributeType.find(propertyType);
  1363. if (it == d_ptr->m_typeToAttributeToAttributeType.constEnd())
  1364. return 0;
  1365. QMap<QString, int> attributes = it.value();
  1366. QMap<QString, int>::ConstIterator itAttr = attributes.find(attribute);
  1367. if (itAttr == attributes.constEnd())
  1368. return 0;
  1369. return itAttr.value();
  1370. }
  1371. /*!
  1372. \fn void QtVariantPropertyManager::setValue(QtProperty *property, const QVariant &value)
  1373. Sets the value of the given \a property to \a value.
  1374. The specified \a value must be of a type returned by valueType(),
  1375. or of type that can be converted to valueType() using the
  1376. QVariant::canConvert() function, otherwise this function does
  1377. nothing.
  1378. \sa value(), QtVariantProperty::setValue(), valueChanged()
  1379. */
  1380. /// <summary>
  1381. /// 根据属性的数据类型,调用不同的属性管理器来设置值
  1382. /// </summary>
  1383. /// <param name="property"></param>
  1384. /// <param name="val"></param>
  1385. void QtVariantPropertyManager::setValue(QtProperty *property, const QVariant &val)
  1386. {
  1387. int propType = val.userType();
  1388. if (!propType)
  1389. return;
  1390. int valType = valueType(property);
  1391. if (propType != valType && !val.canConvert(static_cast<QVariant::Type>(valType)))
  1392. return;
  1393. QtProperty *internProp = propertyToWrappedProperty()->value(property, 0);
  1394. if (internProp == 0)
  1395. return;
  1396. QtAbstractPropertyManager *manager = internProp->propertyManager();
  1397. if (QtIntPropertyManager *intManager = qobject_cast<QtIntPropertyManager *>(manager)) {
  1398. intManager->setValue(internProp, qvariant_cast<int>(val));
  1399. return;
  1400. } else if (QtDoublePropertyManager *doubleManager = qobject_cast<QtDoublePropertyManager *>(manager)) {
  1401. doubleManager->setValue(internProp, qvariant_cast<double>(val));
  1402. return;
  1403. } else if (QtBoolPropertyManager *boolManager = qobject_cast<QtBoolPropertyManager *>(manager)) {
  1404. boolManager->setValue(internProp, qvariant_cast<bool>(val));
  1405. return;
  1406. } else if (QtStringPropertyManager *stringManager = qobject_cast<QtStringPropertyManager *>(manager)) {
  1407. stringManager->setValue(internProp, qvariant_cast<QString>(val));
  1408. return;
  1409. } else if (QtDatePropertyManager *dateManager = qobject_cast<QtDatePropertyManager *>(manager)) {
  1410. dateManager->setValue(internProp, qvariant_cast<QDate>(val));
  1411. return;
  1412. } else if (QtTimePropertyManager *timeManager = qobject_cast<QtTimePropertyManager *>(manager)) {
  1413. timeManager->setValue(internProp, qvariant_cast<QTime>(val));
  1414. return;
  1415. } else if (QtDateTimePropertyManager *dateTimeManager = qobject_cast<QtDateTimePropertyManager *>(manager)) {
  1416. dateTimeManager->setValue(internProp, qvariant_cast<QDateTime>(val));
  1417. return;
  1418. } else if (QtKeySequencePropertyManager *keySequenceManager = qobject_cast<QtKeySequencePropertyManager *>(manager)) {
  1419. keySequenceManager->setValue(internProp, qvariant_cast<QKeySequence>(val));
  1420. return;
  1421. } else if (QtCharPropertyManager *charManager = qobject_cast<QtCharPropertyManager *>(manager)) {
  1422. charManager->setValue(internProp, qvariant_cast<QChar>(val));
  1423. return;
  1424. } else if (QtLocalePropertyManager *localeManager = qobject_cast<QtLocalePropertyManager *>(manager)) {
  1425. localeManager->setValue(internProp, qvariant_cast<QLocale>(val));
  1426. return;
  1427. } else if (QtPointPropertyManager *pointManager = qobject_cast<QtPointPropertyManager *>(manager)) {
  1428. pointManager->setValue(internProp, qvariant_cast<QPoint>(val));
  1429. return;
  1430. } else if (QtPointFPropertyManager *pointFManager = qobject_cast<QtPointFPropertyManager *>(manager)) {
  1431. pointFManager->setValue(internProp, qvariant_cast<QPointF>(val));
  1432. return;
  1433. } else if (QtSizePropertyManager *sizeManager = qobject_cast<QtSizePropertyManager *>(manager)) {
  1434. sizeManager->setValue(internProp, qvariant_cast<QSize>(val));
  1435. return;
  1436. } else if (QtSizeFPropertyManager *sizeFManager = qobject_cast<QtSizeFPropertyManager *>(manager)) {
  1437. sizeFManager->setValue(internProp, qvariant_cast<QSizeF>(val));
  1438. return;
  1439. } else if (QtRectPropertyManager *rectManager = qobject_cast<QtRectPropertyManager *>(manager)) {
  1440. rectManager->setValue(internProp, qvariant_cast<QRect>(val));
  1441. return;
  1442. } else if (QtRectFPropertyManager *rectFManager = qobject_cast<QtRectFPropertyManager *>(manager)) {
  1443. rectFManager->setValue(internProp, qvariant_cast<QRectF>(val));
  1444. return;
  1445. } else if (QtColorPropertyManager *colorManager = qobject_cast<QtColorPropertyManager *>(manager)) {
  1446. colorManager->setValue(internProp, qvariant_cast<QColor>(val));
  1447. return;
  1448. } else if (QtEnumPropertyManager *enumManager = qobject_cast<QtEnumPropertyManager *>(manager)) {
  1449. enumManager->setValue(internProp, qvariant_cast<int>(val));
  1450. return;
  1451. } else if (QtSizePolicyPropertyManager *sizePolicyManager =
  1452. qobject_cast<QtSizePolicyPropertyManager *>(manager)) {
  1453. sizePolicyManager->setValue(internProp, qvariant_cast<QSizePolicy>(val));
  1454. return;
  1455. } else if (QtFontPropertyManager *fontManager = qobject_cast<QtFontPropertyManager *>(manager)) {
  1456. fontManager->setValue(internProp, qvariant_cast<QFont>(val));
  1457. return;
  1458. #ifndef QT_NO_CURSOR
  1459. } else if (QtCursorPropertyManager *cursorManager = qobject_cast<QtCursorPropertyManager *>(manager)) {
  1460. cursorManager->setValue(internProp, qvariant_cast<QCursor>(val));
  1461. return;
  1462. #endif
  1463. } else if (QtFlagPropertyManager *flagManager = qobject_cast<QtFlagPropertyManager *>(manager)) {
  1464. flagManager->setValue(internProp, qvariant_cast<int>(val));
  1465. return;
  1466. }
  1467. }
  1468. /*!
  1469. Sets the value of the specified \a attribute of the given \a
  1470. property, to \a value.
  1471. The new \a value's type must be of the type returned by
  1472. attributeType(), or of a type that can be converted to
  1473. attributeType() using the QVariant::canConvert() function,
  1474. otherwise this function does nothing.
  1475. \sa attributeValue(), QtVariantProperty::setAttribute(), attributeChanged()
  1476. */
  1477. void QtVariantPropertyManager::setAttribute(QtProperty *property,
  1478. const QString &attribute, const QVariant &value)
  1479. {
  1480. QVariant oldAttr = attributeValue(property, attribute);
  1481. if (!oldAttr.isValid())
  1482. return;
  1483. int attrType = value.userType();
  1484. if (!attrType)
  1485. return;
  1486. if (attrType != attributeType(propertyType(property), attribute) &&
  1487. !value.canConvert((QVariant::Type)attrType))
  1488. return;
  1489. QtProperty *internProp = propertyToWrappedProperty()->value(property, 0);
  1490. if (internProp == 0)
  1491. return;
  1492. QtAbstractPropertyManager *manager = internProp->propertyManager();
  1493. if (QtIntPropertyManager *intManager = qobject_cast<QtIntPropertyManager *>(manager)) {
  1494. if (attribute == d_ptr->m_maximumAttribute)
  1495. intManager->setMaximum(internProp, qvariant_cast<int>(value));
  1496. else if (attribute == d_ptr->m_minimumAttribute)
  1497. intManager->setMinimum(internProp, qvariant_cast<int>(value));
  1498. else if (attribute == d_ptr->m_singleStepAttribute)
  1499. intManager->setSingleStep(internProp, qvariant_cast<int>(value));
  1500. return;
  1501. } else if (QtDoublePropertyManager *doubleManager = qobject_cast<QtDoublePropertyManager *>(manager)) {
  1502. if (attribute == d_ptr->m_maximumAttribute)
  1503. doubleManager->setMaximum(internProp, qvariant_cast<double>(value));
  1504. if (attribute == d_ptr->m_minimumAttribute)
  1505. doubleManager->setMinimum(internProp, qvariant_cast<double>(value));
  1506. if (attribute == d_ptr->m_singleStepAttribute)
  1507. doubleManager->setSingleStep(internProp, qvariant_cast<double>(value));
  1508. if (attribute == d_ptr->m_decimalsAttribute)
  1509. doubleManager->setDecimals(internProp, qvariant_cast<int>(value));
  1510. return;
  1511. } else if (QtStringPropertyManager *stringManager = qobject_cast<QtStringPropertyManager *>(manager)) {
  1512. if (attribute == d_ptr->m_regExpAttribute)
  1513. stringManager->setRegExp(internProp, qvariant_cast<QRegExp>(value));
  1514. return;
  1515. } else if (QtDatePropertyManager *dateManager = qobject_cast<QtDatePropertyManager *>(manager)) {
  1516. if (attribute == d_ptr->m_maximumAttribute)
  1517. dateManager->setMaximum(internProp, qvariant_cast<QDate>(value));
  1518. if (attribute == d_ptr->m_minimumAttribute)
  1519. dateManager->setMinimum(internProp, qvariant_cast<QDate>(value));
  1520. return;
  1521. } else if (QtPointFPropertyManager *pointFManager = qobject_cast<QtPointFPropertyManager *>(manager)) {
  1522. if (attribute == d_ptr->m_decimalsAttribute)
  1523. pointFManager->setDecimals(internProp, qvariant_cast<int>(value));
  1524. return;
  1525. } else if (QtSizePropertyManager *sizeManager = qobject_cast<QtSizePropertyManager *>(manager)) {
  1526. if (attribute == d_ptr->m_maximumAttribute)
  1527. sizeManager->setMaximum(internProp, qvariant_cast<QSize>(value));
  1528. if (attribute == d_ptr->m_minimumAttribute)
  1529. sizeManager->setMinimum(internProp, qvariant_cast<QSize>(value));
  1530. return;
  1531. } else if (QtSizeFPropertyManager *sizeFManager = qobject_cast<QtSizeFPropertyManager *>(manager)) {
  1532. if (attribute == d_ptr->m_maximumAttribute)
  1533. sizeFManager->setMaximum(internProp, qvariant_cast<QSizeF>(value));
  1534. if (attribute == d_ptr->m_minimumAttribute)
  1535. sizeFManager->setMinimum(internProp, qvariant_cast<QSizeF>(value));
  1536. if (attribute == d_ptr->m_decimalsAttribute)
  1537. sizeFManager->setDecimals(internProp, qvariant_cast<int>(value));
  1538. return;
  1539. } else if (QtRectPropertyManager *rectManager = qobject_cast<QtRectPropertyManager *>(manager)) {
  1540. if (attribute == d_ptr->m_constraintAttribute)
  1541. rectManager->setConstraint(internProp, qvariant_cast<QRect>(value));
  1542. return;
  1543. } else if (QtRectFPropertyManager *rectFManager = qobject_cast<QtRectFPropertyManager *>(manager)) {
  1544. if (attribute == d_ptr->m_constraintAttribute)
  1545. rectFManager->setConstraint(internProp, qvariant_cast<QRectF>(value));
  1546. if (attribute == d_ptr->m_decimalsAttribute)
  1547. rectFManager->setDecimals(internProp, qvariant_cast<int>(value));
  1548. return;
  1549. } else if (QtEnumPropertyManager *enumManager = qobject_cast<QtEnumPropertyManager *>(manager)) {
  1550. if (attribute == d_ptr->m_enumNamesAttribute)
  1551. enumManager->setEnumNames(internProp, qvariant_cast<QStringList>(value));
  1552. if (attribute == d_ptr->m_enumIconsAttribute)
  1553. enumManager->setEnumIcons(internProp, qvariant_cast<QtIconMap>(value));
  1554. return;
  1555. } else if (QtFlagPropertyManager *flagManager = qobject_cast<QtFlagPropertyManager *>(manager)) {
  1556. if (attribute == d_ptr->m_flagNamesAttribute)
  1557. flagManager->setFlagNames(internProp, qvariant_cast<QStringList>(value));
  1558. return;
  1559. }
  1560. }
  1561. /*!
  1562. \internal
  1563. */
  1564. bool QtVariantPropertyManager::hasValue(const QtProperty *property) const
  1565. {
  1566. if (propertyType(property) == groupTypeId())
  1567. return false;
  1568. return true;
  1569. }
  1570. /*!
  1571. \internal
  1572. */
  1573. QString QtVariantPropertyManager::valueText(const QtProperty *property) const
  1574. {
  1575. const QtProperty *internProp = propertyToWrappedProperty()->value(property, 0);
  1576. return internProp ? internProp->valueText() : QString();
  1577. }
  1578. /*!
  1579. \internal
  1580. */
  1581. QIcon QtVariantPropertyManager::valueIcon(const QtProperty *property) const
  1582. {
  1583. const QtProperty *internProp = propertyToWrappedProperty()->value(property, 0);
  1584. return internProp ? internProp->valueIcon() : QIcon();
  1585. }
  1586. /*!
  1587. \internal
  1588. */
  1589. /// <summary>
  1590. /// 属性初始化
  1591. /// </summary>
  1592. /// <param name="property"></param>
  1593. void QtVariantPropertyManager::initializeProperty(QtProperty *property)
  1594. {
  1595. QtVariantProperty *varProp = variantProperty(property);
  1596. if (!varProp)
  1597. return;
  1598. QMap<int, QtAbstractPropertyManager *>::ConstIterator it =
  1599. d_ptr->m_typeToPropertyManager.find(d_ptr->m_propertyType);
  1600. if (it != d_ptr->m_typeToPropertyManager.constEnd()) {
  1601. QtProperty *internProp = 0;
  1602. if (!d_ptr->m_creatingSubProperties) {
  1603. QtAbstractPropertyManager *manager = it.value();
  1604. internProp = manager->addProperty();
  1605. d_ptr->m_internalToProperty[internProp] = varProp;
  1606. }
  1607. // 添加此属性
  1608. propertyToWrappedProperty()->insert(varProp, internProp);
  1609. // 属性是否带有内部属性值
  1610. if (internProp)
  1611. {
  1612. // 遍历所有的内部属性值
  1613. const QList<QtProperty *> children = internProp->subProperties();
  1614. QtVariantProperty *lastProperty = 0;
  1615. // 逐一将内部子属性值添加到列表中
  1616. for (QtProperty *child : children) {
  1617. QtVariantProperty *prop = d_ptr->createSubProperty(varProp, lastProperty, child);
  1618. lastProperty = prop ? prop : lastProperty;
  1619. }
  1620. }
  1621. }
  1622. }
  1623. /*!
  1624. \internal
  1625. */
  1626. void QtVariantPropertyManager::uninitializeProperty(QtProperty *property)
  1627. {
  1628. const QMap<const QtProperty *, QPair<QtVariantProperty *, int> >::iterator type_it = d_ptr->m_propertyToType.find(property);
  1629. if (type_it == d_ptr->m_propertyToType.end())
  1630. return;
  1631. PropertyMap::iterator it = propertyToWrappedProperty()->find(property);
  1632. if (it != propertyToWrappedProperty()->end()) {
  1633. QtProperty *internProp = it.value();
  1634. if (internProp) {
  1635. d_ptr->m_internalToProperty.remove(internProp);
  1636. if (!d_ptr->m_destroyingSubProperties) {
  1637. delete internProp;
  1638. }
  1639. }
  1640. propertyToWrappedProperty()->erase(it);
  1641. }
  1642. d_ptr->m_propertyToType.erase(type_it);
  1643. }
  1644. /*!
  1645. \internal
  1646. */
  1647. QtProperty *QtVariantPropertyManager::createProperty()
  1648. {
  1649. if (!d_ptr->m_creatingProperty)
  1650. return 0;
  1651. QtVariantProperty *property = new QtVariantProperty(this);
  1652. d_ptr->m_propertyToType.insert(property, qMakePair(property, d_ptr->m_propertyType));
  1653. return property;
  1654. }
  1655. /////////////////////////////
  1656. class QtVariantEditorFactoryPrivate
  1657. {
  1658. QtVariantEditorFactory *q_ptr;
  1659. Q_DECLARE_PUBLIC(QtVariantEditorFactory)
  1660. public:
  1661. QtSpinBoxFactory *m_spinBoxFactory;
  1662. QtDoubleSpinBoxFactory *m_doubleSpinBoxFactory;
  1663. QtCheckBoxFactory *m_checkBoxFactory;
  1664. QtLineEditFactory *m_lineEditFactory;
  1665. QtDateEditFactory *m_dateEditFactory;
  1666. QtTimeEditFactory *m_timeEditFactory;
  1667. QtDateTimeEditFactory *m_dateTimeEditFactory;
  1668. QtKeySequenceEditorFactory *m_keySequenceEditorFactory;
  1669. QtCharEditorFactory *m_charEditorFactory;
  1670. QtEnumEditorFactory *m_comboBoxFactory;
  1671. QtCursorEditorFactory *m_cursorEditorFactory;
  1672. QtColorEditorFactory *m_colorEditorFactory;
  1673. QtFontEditorFactory *m_fontEditorFactory;
  1674. QMap<QtAbstractEditorFactoryBase *, int> m_factoryToType;
  1675. QMap<int, QtAbstractEditorFactoryBase *> m_typeToFactory;
  1676. };
  1677. /*!
  1678. \class QtVariantEditorFactory
  1679. \internal
  1680. \inmodule QtDesigner
  1681. \since 4.4
  1682. \brief The QtVariantEditorFactory class provides widgets for properties
  1683. created by QtVariantPropertyManager objects.
  1684. The variant factory provides the following widgets for the
  1685. specified property types:
  1686. \table
  1687. \header
  1688. \li Property Type
  1689. \li Widget
  1690. \row
  1691. \li \c int
  1692. \li QSpinBox
  1693. \row
  1694. \li \c double
  1695. \li QDoubleSpinBox
  1696. \row
  1697. \li \c bool
  1698. \li QCheckBox
  1699. \row
  1700. \li QString
  1701. \li QLineEdit
  1702. \row
  1703. \li QDate
  1704. \li QDateEdit
  1705. \row
  1706. \li QTime
  1707. \li QTimeEdit
  1708. \row
  1709. \li QDateTime
  1710. \li QDateTimeEdit
  1711. \row
  1712. \li QKeySequence
  1713. \li customized editor
  1714. \row
  1715. \li QChar
  1716. \li customized editor
  1717. \row
  1718. \li \c enum
  1719. \li QComboBox
  1720. \row
  1721. \li QCursor
  1722. \li QComboBox
  1723. \endtable
  1724. Note that QtVariantPropertyManager supports several additional property
  1725. types for which the QtVariantEditorFactory class does not provide
  1726. editing widgets, e.g. QPoint and QSize. To provide widgets for other
  1727. types using the variant approach, derive from the QtVariantEditorFactory
  1728. class.
  1729. \sa QtAbstractEditorFactory, QtVariantPropertyManager
  1730. */
  1731. /*!
  1732. Creates a factory with the given \a parent.
  1733. */
  1734. QtVariantEditorFactory::QtVariantEditorFactory(QObject *parent)
  1735. : QtAbstractEditorFactory<QtVariantPropertyManager>(parent), d_ptr(new QtVariantEditorFactoryPrivate())
  1736. {
  1737. d_ptr->q_ptr = this;
  1738. d_ptr->m_spinBoxFactory = new QtSpinBoxFactory(this);
  1739. d_ptr->m_factoryToType[d_ptr->m_spinBoxFactory] = QVariant::Int;
  1740. d_ptr->m_typeToFactory[QVariant::Int] = d_ptr->m_spinBoxFactory;
  1741. d_ptr->m_doubleSpinBoxFactory = new QtDoubleSpinBoxFactory(this);
  1742. d_ptr->m_factoryToType[d_ptr->m_doubleSpinBoxFactory] = QVariant::Double;
  1743. d_ptr->m_typeToFactory[QVariant::Double] = d_ptr->m_doubleSpinBoxFactory;
  1744. d_ptr->m_checkBoxFactory = new QtCheckBoxFactory(this);
  1745. d_ptr->m_factoryToType[d_ptr->m_checkBoxFactory] = QVariant::Bool;
  1746. d_ptr->m_typeToFactory[QVariant::Bool] = d_ptr->m_checkBoxFactory;
  1747. d_ptr->m_lineEditFactory = new QtLineEditFactory(this);
  1748. d_ptr->m_factoryToType[d_ptr->m_lineEditFactory] = QVariant::String;
  1749. d_ptr->m_typeToFactory[QVariant::String] = d_ptr->m_lineEditFactory;
  1750. d_ptr->m_dateEditFactory = new QtDateEditFactory(this);
  1751. d_ptr->m_factoryToType[d_ptr->m_dateEditFactory] = QVariant::Date;
  1752. d_ptr->m_typeToFactory[QVariant::Date] = d_ptr->m_dateEditFactory;
  1753. d_ptr->m_timeEditFactory = new QtTimeEditFactory(this);
  1754. d_ptr->m_factoryToType[d_ptr->m_timeEditFactory] = QVariant::Time;
  1755. d_ptr->m_typeToFactory[QVariant::Time] = d_ptr->m_timeEditFactory;
  1756. d_ptr->m_dateTimeEditFactory = new QtDateTimeEditFactory(this);
  1757. d_ptr->m_factoryToType[d_ptr->m_dateTimeEditFactory] = QVariant::DateTime;
  1758. d_ptr->m_typeToFactory[QVariant::DateTime] = d_ptr->m_dateTimeEditFactory;
  1759. d_ptr->m_keySequenceEditorFactory = new QtKeySequenceEditorFactory(this);
  1760. d_ptr->m_factoryToType[d_ptr->m_keySequenceEditorFactory] = QVariant::KeySequence;
  1761. d_ptr->m_typeToFactory[QVariant::KeySequence] = d_ptr->m_keySequenceEditorFactory;
  1762. d_ptr->m_charEditorFactory = new QtCharEditorFactory(this);
  1763. d_ptr->m_factoryToType[d_ptr->m_charEditorFactory] = QVariant::Char;
  1764. d_ptr->m_typeToFactory[QVariant::Char] = d_ptr->m_charEditorFactory;
  1765. d_ptr->m_cursorEditorFactory = new QtCursorEditorFactory(this);
  1766. d_ptr->m_factoryToType[d_ptr->m_cursorEditorFactory] = QVariant::Cursor;
  1767. d_ptr->m_typeToFactory[QVariant::Cursor] = d_ptr->m_cursorEditorFactory;
  1768. d_ptr->m_colorEditorFactory = new QtColorEditorFactory(this);
  1769. d_ptr->m_factoryToType[d_ptr->m_colorEditorFactory] = QVariant::Color;
  1770. d_ptr->m_typeToFactory[QVariant::Color] = d_ptr->m_colorEditorFactory;
  1771. d_ptr->m_fontEditorFactory = new QtFontEditorFactory(this);
  1772. d_ptr->m_factoryToType[d_ptr->m_fontEditorFactory] = QVariant::Font;
  1773. d_ptr->m_typeToFactory[QVariant::Font] = d_ptr->m_fontEditorFactory;
  1774. d_ptr->m_comboBoxFactory = new QtEnumEditorFactory(this);
  1775. const int enumId = QtVariantPropertyManager::enumTypeId();
  1776. d_ptr->m_factoryToType[d_ptr->m_comboBoxFactory] = enumId;
  1777. d_ptr->m_typeToFactory[enumId] = d_ptr->m_comboBoxFactory;
  1778. }
  1779. /*!
  1780. Destroys this factory, and all the widgets it has created.
  1781. */
  1782. QtVariantEditorFactory::~QtVariantEditorFactory()
  1783. {
  1784. }
  1785. /*!
  1786. \internal
  1787. Reimplemented from the QtAbstractEditorFactory class.
  1788. */
  1789. void QtVariantEditorFactory::connectPropertyManager(QtVariantPropertyManager *manager)
  1790. {
  1791. const QList<QtIntPropertyManager *> intPropertyManagers = manager->findChildren<QtIntPropertyManager *>();
  1792. for (QtIntPropertyManager *manager : intPropertyManagers)
  1793. d_ptr->m_spinBoxFactory->addPropertyManager(manager);
  1794. const QList<QtDoublePropertyManager *> doublePropertyManagers = manager->findChildren<QtDoublePropertyManager *>();
  1795. for (QtDoublePropertyManager *manager : doublePropertyManagers)
  1796. d_ptr->m_doubleSpinBoxFactory->addPropertyManager(manager);
  1797. const QList<QtBoolPropertyManager *> boolPropertyManagers = manager->findChildren<QtBoolPropertyManager *>();
  1798. for (QtBoolPropertyManager *manager : boolPropertyManagers)
  1799. d_ptr->m_checkBoxFactory->addPropertyManager(manager);
  1800. const QList<QtStringPropertyManager *> stringPropertyManagers = manager->findChildren<QtStringPropertyManager *>();
  1801. for (QtStringPropertyManager *manager : stringPropertyManagers)
  1802. d_ptr->m_lineEditFactory->addPropertyManager(manager);
  1803. const QList<QtDatePropertyManager *> datePropertyManagers = manager->findChildren<QtDatePropertyManager *>();
  1804. for (QtDatePropertyManager *manager : datePropertyManagers)
  1805. d_ptr->m_dateEditFactory->addPropertyManager(manager);
  1806. const QList<QtTimePropertyManager *> timePropertyManagers = manager->findChildren<QtTimePropertyManager *>();
  1807. for (QtTimePropertyManager *manager : timePropertyManagers)
  1808. d_ptr->m_timeEditFactory->addPropertyManager(manager);
  1809. const QList<QtDateTimePropertyManager *> dateTimePropertyManagers = manager->findChildren<QtDateTimePropertyManager *>();
  1810. for (QtDateTimePropertyManager *manager : dateTimePropertyManagers)
  1811. d_ptr->m_dateTimeEditFactory->addPropertyManager(manager);
  1812. const QList<QtKeySequencePropertyManager *> keySequencePropertyManagers = manager->findChildren<QtKeySequencePropertyManager *>();
  1813. for (QtKeySequencePropertyManager *manager : keySequencePropertyManagers)
  1814. d_ptr->m_keySequenceEditorFactory->addPropertyManager(manager);
  1815. const QList<QtCharPropertyManager *> charPropertyManagers = manager->findChildren<QtCharPropertyManager *>();
  1816. for (QtCharPropertyManager *manager : charPropertyManagers)
  1817. d_ptr->m_charEditorFactory->addPropertyManager(manager);
  1818. const QList<QtLocalePropertyManager *> localePropertyManagers = manager->findChildren<QtLocalePropertyManager *>();
  1819. for (QtLocalePropertyManager *manager : localePropertyManagers)
  1820. d_ptr->m_comboBoxFactory->addPropertyManager(manager->subEnumPropertyManager());
  1821. const QList<QtPointPropertyManager *> pointPropertyManagers = manager->findChildren<QtPointPropertyManager *>();
  1822. for (QtPointPropertyManager *manager : pointPropertyManagers)
  1823. d_ptr->m_spinBoxFactory->addPropertyManager(manager->subIntPropertyManager());
  1824. const QList<QtPointFPropertyManager *> pointFPropertyManagers = manager->findChildren<QtPointFPropertyManager *>();
  1825. for (QtPointFPropertyManager *manager : pointFPropertyManagers)
  1826. d_ptr->m_doubleSpinBoxFactory->addPropertyManager(manager->subDoublePropertyManager());
  1827. const QList<QtSizePropertyManager *> sizePropertyManagers = manager->findChildren<QtSizePropertyManager *>();
  1828. for (QtSizePropertyManager *manager : sizePropertyManagers)
  1829. d_ptr->m_spinBoxFactory->addPropertyManager(manager->subIntPropertyManager());
  1830. const QList<QtSizeFPropertyManager *> sizeFPropertyManagers = manager->findChildren<QtSizeFPropertyManager *>();
  1831. for (QtSizeFPropertyManager *manager : sizeFPropertyManagers)
  1832. d_ptr->m_doubleSpinBoxFactory->addPropertyManager(manager->subDoublePropertyManager());
  1833. const QList<QtRectPropertyManager *> rectPropertyManagers = manager->findChildren<QtRectPropertyManager *>();
  1834. for (QtRectPropertyManager *manager : rectPropertyManagers)
  1835. d_ptr->m_spinBoxFactory->addPropertyManager(manager->subIntPropertyManager());
  1836. const QList<QtRectFPropertyManager *> rectFPropertyManagers = manager->findChildren<QtRectFPropertyManager *>();
  1837. for (QtRectFPropertyManager *manager : rectFPropertyManagers)
  1838. d_ptr->m_doubleSpinBoxFactory->addPropertyManager(manager->subDoublePropertyManager());
  1839. const QList<QtColorPropertyManager *> colorPropertyManagers = manager->findChildren<QtColorPropertyManager *>();
  1840. for (QtColorPropertyManager *manager : colorPropertyManagers) {
  1841. d_ptr->m_colorEditorFactory->addPropertyManager(manager);
  1842. d_ptr->m_spinBoxFactory->addPropertyManager(manager->subIntPropertyManager());
  1843. }
  1844. const QList<QtEnumPropertyManager *> enumPropertyManagers = manager->findChildren<QtEnumPropertyManager *>();
  1845. for (QtEnumPropertyManager *manager : enumPropertyManagers)
  1846. d_ptr->m_comboBoxFactory->addPropertyManager(manager);
  1847. const QList<QtSizePolicyPropertyManager *> sizePolicyPropertyManagers = manager->findChildren<QtSizePolicyPropertyManager *>();
  1848. for (QtSizePolicyPropertyManager *manager : sizePolicyPropertyManagers) {
  1849. d_ptr->m_spinBoxFactory->addPropertyManager(manager->subIntPropertyManager());
  1850. d_ptr->m_comboBoxFactory->addPropertyManager(manager->subEnumPropertyManager());
  1851. }
  1852. const QList<QtFontPropertyManager *> fontPropertyManagers = manager->findChildren<QtFontPropertyManager *>();
  1853. for (QtFontPropertyManager *manager : fontPropertyManagers) {
  1854. d_ptr->m_fontEditorFactory->addPropertyManager(manager);
  1855. d_ptr->m_spinBoxFactory->addPropertyManager(manager->subIntPropertyManager());
  1856. d_ptr->m_comboBoxFactory->addPropertyManager(manager->subEnumPropertyManager());
  1857. d_ptr->m_checkBoxFactory->addPropertyManager(manager->subBoolPropertyManager());
  1858. }
  1859. const QList<QtCursorPropertyManager *> cursorPropertyManagers = manager->findChildren<QtCursorPropertyManager *>();
  1860. for (QtCursorPropertyManager *manager : cursorPropertyManagers)
  1861. d_ptr->m_cursorEditorFactory->addPropertyManager(manager);
  1862. const QList<QtFlagPropertyManager *> flagPropertyManagers = manager->findChildren<QtFlagPropertyManager *>();
  1863. for (QtFlagPropertyManager *manager : flagPropertyManagers)
  1864. d_ptr->m_checkBoxFactory->addPropertyManager(manager->subBoolPropertyManager());
  1865. }
  1866. /*!
  1867. \internal
  1868. Reimplemented from the QtAbstractEditorFactory class.
  1869. */
  1870. QWidget *QtVariantEditorFactory::createEditor(QtVariantPropertyManager *manager, QtProperty *property,
  1871. QWidget *parent)
  1872. {
  1873. const int propType = manager->propertyType(property);
  1874. QtAbstractEditorFactoryBase *factory = d_ptr->m_typeToFactory.value(propType, 0);
  1875. if (!factory)
  1876. return 0;
  1877. return factory->createEditor(wrappedProperty(property), parent);
  1878. }
  1879. /*!
  1880. \internal
  1881. Reimplemented from the QtAbstractEditorFactory class.
  1882. */
  1883. void QtVariantEditorFactory::disconnectPropertyManager(QtVariantPropertyManager *manager)
  1884. {
  1885. const QList<QtIntPropertyManager *> intPropertyManagers = manager->findChildren<QtIntPropertyManager *>();
  1886. for (QtIntPropertyManager *manager : intPropertyManagers)
  1887. d_ptr->m_spinBoxFactory->removePropertyManager(manager);
  1888. const QList<QtDoublePropertyManager *> doublePropertyManagers = manager->findChildren<QtDoublePropertyManager *>();
  1889. for (QtDoublePropertyManager *manager : doublePropertyManagers)
  1890. d_ptr->m_doubleSpinBoxFactory->removePropertyManager(manager);
  1891. const QList<QtBoolPropertyManager *> boolPropertyManagers = manager->findChildren<QtBoolPropertyManager *>();
  1892. for (QtBoolPropertyManager *manager : boolPropertyManagers)
  1893. d_ptr->m_checkBoxFactory->removePropertyManager(manager);
  1894. const QList<QtStringPropertyManager *> stringPropertyManagers = manager->findChildren<QtStringPropertyManager *>();
  1895. for (QtStringPropertyManager *manager : stringPropertyManagers)
  1896. d_ptr->m_lineEditFactory->removePropertyManager(manager);
  1897. const QList<QtDatePropertyManager *> datePropertyManagers = manager->findChildren<QtDatePropertyManager *>();
  1898. for (QtDatePropertyManager *manager : datePropertyManagers)
  1899. d_ptr->m_dateEditFactory->removePropertyManager(manager);
  1900. const QList<QtTimePropertyManager *> timePropertyManagers = manager->findChildren<QtTimePropertyManager *>();
  1901. for (QtTimePropertyManager *manager : timePropertyManagers)
  1902. d_ptr->m_timeEditFactory->removePropertyManager(manager);
  1903. const QList<QtDateTimePropertyManager *> dateTimePropertyManagers = manager->findChildren<QtDateTimePropertyManager *>();
  1904. for (QtDateTimePropertyManager *manager : dateTimePropertyManagers)
  1905. d_ptr->m_dateTimeEditFactory->removePropertyManager(manager);
  1906. const QList<QtKeySequencePropertyManager *> keySequencePropertyManagers = manager->findChildren<QtKeySequencePropertyManager *>();
  1907. for (QtKeySequencePropertyManager *manager : keySequencePropertyManagers)
  1908. d_ptr->m_keySequenceEditorFactory->removePropertyManager(manager);
  1909. const QList<QtCharPropertyManager *> charPropertyManagers = manager->findChildren<QtCharPropertyManager *>();
  1910. for (QtCharPropertyManager *manager : charPropertyManagers)
  1911. d_ptr->m_charEditorFactory->removePropertyManager(manager);
  1912. const QList<QtLocalePropertyManager *> localePropertyManagers = manager->findChildren<QtLocalePropertyManager *>();
  1913. for (QtLocalePropertyManager *manager : localePropertyManagers)
  1914. d_ptr->m_comboBoxFactory->removePropertyManager(manager->subEnumPropertyManager());
  1915. const QList<QtPointPropertyManager *> pointPropertyManagers = manager->findChildren<QtPointPropertyManager *>();
  1916. for (QtPointPropertyManager *manager : pointPropertyManagers)
  1917. d_ptr->m_spinBoxFactory->removePropertyManager(manager->subIntPropertyManager());
  1918. const QList<QtPointFPropertyManager *> pointFPropertyManagers = manager->findChildren<QtPointFPropertyManager *>();
  1919. for (QtPointFPropertyManager *manager : pointFPropertyManagers)
  1920. d_ptr->m_doubleSpinBoxFactory->removePropertyManager(manager->subDoublePropertyManager());
  1921. const QList<QtSizePropertyManager *> sizePropertyManagers = manager->findChildren<QtSizePropertyManager *>();
  1922. for (QtSizePropertyManager *manager : sizePropertyManagers)
  1923. d_ptr->m_spinBoxFactory->removePropertyManager(manager->subIntPropertyManager());
  1924. const QList<QtSizeFPropertyManager *> sizeFPropertyManagers = manager->findChildren<QtSizeFPropertyManager *>();
  1925. for (QtSizeFPropertyManager *manager : sizeFPropertyManagers)
  1926. d_ptr->m_doubleSpinBoxFactory->removePropertyManager(manager->subDoublePropertyManager());
  1927. const QList<QtRectPropertyManager *> rectPropertyManagers = manager->findChildren<QtRectPropertyManager *>();
  1928. for (QtRectPropertyManager *manager : rectPropertyManagers)
  1929. d_ptr->m_spinBoxFactory->removePropertyManager(manager->subIntPropertyManager());
  1930. const QList<QtRectFPropertyManager *> rectFPropertyManagers = manager->findChildren<QtRectFPropertyManager *>();
  1931. for (QtRectFPropertyManager *manager : rectFPropertyManagers)
  1932. d_ptr->m_doubleSpinBoxFactory->removePropertyManager(manager->subDoublePropertyManager());
  1933. const QList<QtColorPropertyManager *> colorPropertyManagers = manager->findChildren<QtColorPropertyManager *>();
  1934. for (QtColorPropertyManager *manager : colorPropertyManagers) {
  1935. d_ptr->m_colorEditorFactory->removePropertyManager(manager);
  1936. d_ptr->m_spinBoxFactory->removePropertyManager(manager->subIntPropertyManager());
  1937. }
  1938. const QList<QtEnumPropertyManager *> enumPropertyManagers = manager->findChildren<QtEnumPropertyManager *>();
  1939. for (QtEnumPropertyManager *manager : enumPropertyManagers)
  1940. d_ptr->m_comboBoxFactory->removePropertyManager(manager);
  1941. const QList<QtSizePolicyPropertyManager *> sizePolicyPropertyManagers = manager->findChildren<QtSizePolicyPropertyManager *>();
  1942. for (QtSizePolicyPropertyManager *manager : sizePolicyPropertyManagers) {
  1943. d_ptr->m_spinBoxFactory->removePropertyManager(manager->subIntPropertyManager());
  1944. d_ptr->m_comboBoxFactory->removePropertyManager(manager->subEnumPropertyManager());
  1945. }
  1946. const QList<QtFontPropertyManager *> fontPropertyManagers = manager->findChildren<QtFontPropertyManager *>();
  1947. for (QtFontPropertyManager *manager : fontPropertyManagers) {
  1948. d_ptr->m_fontEditorFactory->removePropertyManager(manager);
  1949. d_ptr->m_spinBoxFactory->removePropertyManager(manager->subIntPropertyManager());
  1950. d_ptr->m_comboBoxFactory->removePropertyManager(manager->subEnumPropertyManager());
  1951. d_ptr->m_checkBoxFactory->removePropertyManager(manager->subBoolPropertyManager());
  1952. }
  1953. const QList<QtCursorPropertyManager *> cursorPropertyManagers = manager->findChildren<QtCursorPropertyManager *>();
  1954. for (QtCursorPropertyManager *manager : cursorPropertyManagers)
  1955. d_ptr->m_cursorEditorFactory->removePropertyManager(manager);
  1956. const QList<QtFlagPropertyManager *> flagPropertyManagers = manager->findChildren<QtFlagPropertyManager *>();
  1957. for (QtFlagPropertyManager *manager : flagPropertyManagers)
  1958. d_ptr->m_checkBoxFactory->removePropertyManager(manager->subBoolPropertyManager());
  1959. }
  1960. QT_END_NAMESPACE
  1961. #include "moc_qtvariantproperty.cpp"