qtpropertybrowser.cpp 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971
  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 "qtpropertybrowser.h"
  40. #include <QtCore/QSet>
  41. #include <QtCore/QMap>
  42. #include <QtGui/QIcon>
  43. #if defined(Q_CC_MSVC)
  44. # pragma warning(disable: 4786) /* MS VS 6: truncating debug info after 255 characters */
  45. #endif
  46. QT_BEGIN_NAMESPACE
  47. class QtPropertyPrivate
  48. {
  49. public:
  50. QtPropertyPrivate(QtAbstractPropertyManager *manager) : m_enabled(true), m_modified(false), m_manager(manager) {}
  51. QtProperty *q_ptr;
  52. QSet<QtProperty *> m_parentItems;
  53. QList<QtProperty *> m_subItems;
  54. QString m_valueToolTip;
  55. QString m_descriptionToolTip;
  56. QString m_statusTip;
  57. QString m_whatsThis;
  58. QString m_name;
  59. bool m_enabled;
  60. bool m_modified;
  61. QtAbstractPropertyManager * const m_manager;
  62. };
  63. class QtAbstractPropertyManagerPrivate
  64. {
  65. QtAbstractPropertyManager *q_ptr;
  66. Q_DECLARE_PUBLIC(QtAbstractPropertyManager)
  67. public:
  68. void propertyDestroyed(QtProperty *property);
  69. void propertyChanged(QtProperty *property) const;
  70. void propertyRemoved(QtProperty *property,
  71. QtProperty *parentProperty) const;
  72. void propertyInserted(QtProperty *property, QtProperty *parentProperty,
  73. QtProperty *afterProperty) const;
  74. QSet<QtProperty *> m_properties;
  75. };
  76. /*!
  77. \class QtProperty
  78. \internal
  79. \inmodule QtDesigner
  80. \since 4.4
  81. \brief The QtProperty class encapsulates an instance of a property.
  82. Properties are created by objects of QtAbstractPropertyManager
  83. subclasses; a manager can create properties of a given type, and
  84. is used in conjunction with the QtAbstractPropertyBrowser class. A
  85. property is always owned by the manager that created it, which can
  86. be retrieved using the propertyManager() function.
  87. QtProperty contains the most common property attributes, and
  88. provides functions for retrieving as well as setting their values:
  89. \table
  90. \header \li Getter \li Setter
  91. \row
  92. \li propertyName() \li setPropertyName()
  93. \row
  94. \li statusTip() \li setStatusTip()
  95. \row
  96. \li descriptionToolTip() \li setDescriptionToolTip()
  97. \row
  98. \li valueToolTip() \li setValueToolTip()
  99. \row
  100. \li toolTip() \deprecated in 5.6 \li setToolTip() \deprecated in 5.6
  101. \row
  102. \li whatsThis() \li setWhatsThis()
  103. \row
  104. \li isEnabled() \li setEnabled()
  105. \row
  106. \li isModified() \li setModified()
  107. \row
  108. \li valueText() \li Nop
  109. \row
  110. \li valueIcon() \li Nop
  111. \endtable
  112. It is also possible to nest properties: QtProperty provides the
  113. addSubProperty(), insertSubProperty() and removeSubProperty() functions to
  114. manipulate the set of subproperties. Use the subProperties()
  115. function to retrieve a property's current set of subproperties.
  116. Note that nested properties are not owned by the parent property,
  117. i.e. each subproperty is owned by the manager that created it.
  118. \sa QtAbstractPropertyManager, QtBrowserItem
  119. */
  120. /*!
  121. Creates a property with the given \a manager.
  122. This constructor is only useful when creating a custom QtProperty
  123. subclass (e.g. QtVariantProperty). To create a regular QtProperty
  124. object, use the QtAbstractPropertyManager::addProperty()
  125. function instead.
  126. \sa QtAbstractPropertyManager::addProperty()
  127. */
  128. QtProperty::QtProperty(QtAbstractPropertyManager *manager)
  129. : d_ptr(new QtPropertyPrivate(manager))
  130. {
  131. d_ptr->q_ptr = this;
  132. }
  133. /*!
  134. Destroys this property.
  135. Note that subproperties are detached but not destroyed, i.e. they
  136. can still be used in another context.
  137. \sa QtAbstractPropertyManager::clear()
  138. */
  139. QtProperty::~QtProperty()
  140. {
  141. for (QtProperty *property : qAsConst(d_ptr->m_parentItems))
  142. property->d_ptr->m_manager->d_ptr->propertyRemoved(this, property);
  143. d_ptr->m_manager->d_ptr->propertyDestroyed(this);
  144. for (QtProperty *property : qAsConst(d_ptr->m_subItems))
  145. property->d_ptr->m_parentItems.remove(this);
  146. for (QtProperty *property : qAsConst(d_ptr->m_parentItems))
  147. property->d_ptr->m_subItems.removeAll(this);
  148. }
  149. /*!
  150. Returns the set of subproperties.
  151. Note that subproperties are not owned by \e this property, but by
  152. the manager that created them.
  153. \sa insertSubProperty(), removeSubProperty()
  154. */
  155. QList<QtProperty *> QtProperty::subProperties() const
  156. {
  157. return d_ptr->m_subItems;
  158. }
  159. /*!
  160. Returns a pointer to the manager that owns this property.
  161. */
  162. QtAbstractPropertyManager *QtProperty::propertyManager() const
  163. {
  164. return d_ptr->m_manager;
  165. }
  166. /* Note: As of 17.7.2015 for Qt 5.6, the existing 'toolTip' of the Property
  167. * Browser solution was split into valueToolTip() and descriptionToolTip()
  168. * to be able to implement custom tool tip for QTBUG-45442. This could
  169. * be back-ported to the solution. */
  170. /*!
  171. Returns the property value's tool tip.
  172. This is suitable for tool tips over the value (item delegate).
  173. \since 5.6
  174. \sa setValueToolTip()
  175. */
  176. QString QtProperty::valueToolTip() const
  177. {
  178. return d_ptr->m_valueToolTip;
  179. }
  180. /*!
  181. Returns the property description's tool tip.
  182. This is suitable for tool tips over the description (label).
  183. \since 5.6
  184. \sa setDescriptionToolTip()
  185. */
  186. QString QtProperty::descriptionToolTip() const
  187. {
  188. return d_ptr->m_descriptionToolTip;
  189. }
  190. /*!
  191. Returns the property's status tip.
  192. \sa setStatusTip()
  193. */
  194. QString QtProperty::statusTip() const
  195. {
  196. return d_ptr->m_statusTip;
  197. }
  198. /*!
  199. Returns the property's "What's This" help text.
  200. \sa setWhatsThis()
  201. */
  202. QString QtProperty::whatsThis() const
  203. {
  204. return d_ptr->m_whatsThis;
  205. }
  206. /*!
  207. Returns the property's name.
  208. \sa setPropertyName()
  209. */
  210. QString QtProperty::propertyName() const
  211. {
  212. return d_ptr->m_name;
  213. }
  214. /*!
  215. Returns whether the property is enabled.
  216. \sa setEnabled()
  217. */
  218. bool QtProperty::isEnabled() const
  219. {
  220. return d_ptr->m_enabled;
  221. }
  222. /*!
  223. Returns whether the property is modified.
  224. \sa setModified()
  225. */
  226. bool QtProperty::isModified() const
  227. {
  228. return d_ptr->m_modified;
  229. }
  230. /*!
  231. Returns whether the property has a value.
  232. \sa QtAbstractPropertyManager::hasValue()
  233. */
  234. bool QtProperty::hasValue() const
  235. {
  236. return d_ptr->m_manager->hasValue(this);
  237. }
  238. /*!
  239. Returns an icon representing the current state of this property.
  240. If the given property type can not generate such an icon, this
  241. function returns an invalid icon.
  242. \sa QtAbstractPropertyManager::valueIcon()
  243. */
  244. QIcon QtProperty::valueIcon() const
  245. {
  246. return d_ptr->m_manager->valueIcon(this);
  247. }
  248. /*!
  249. Returns a string representing the current state of this property.
  250. If the given property type can not generate such a string, this
  251. function returns an empty string.
  252. \sa QtAbstractPropertyManager::valueText()
  253. */
  254. QString QtProperty::valueText() const
  255. {
  256. return d_ptr->m_manager->valueText(this);
  257. }
  258. /*!
  259. Sets the property value's tool tip to the given \a text.
  260. \since 5.6
  261. \sa valueToolTip()
  262. */
  263. void QtProperty::setValueToolTip(const QString &text)
  264. {
  265. if (d_ptr->m_valueToolTip == text)
  266. return;
  267. d_ptr->m_valueToolTip = text;
  268. propertyChanged();
  269. }
  270. /*!
  271. Sets the property description's tool tip to the given \a text.
  272. \since 5.6
  273. \sa descriptionToolTip()
  274. */
  275. void QtProperty::setDescriptionToolTip(const QString &text)
  276. {
  277. if (d_ptr->m_descriptionToolTip == text)
  278. return;
  279. d_ptr->m_descriptionToolTip = text;
  280. propertyChanged();
  281. }
  282. /*!
  283. Sets the property's status tip to the given \a text.
  284. \sa statusTip()
  285. */
  286. void QtProperty::setStatusTip(const QString &text)
  287. {
  288. if (d_ptr->m_statusTip == text)
  289. return;
  290. d_ptr->m_statusTip = text;
  291. propertyChanged();
  292. }
  293. /*!
  294. Sets the property's "What's This" help text to the given \a text.
  295. \sa whatsThis()
  296. */
  297. void QtProperty::setWhatsThis(const QString &text)
  298. {
  299. if (d_ptr->m_whatsThis == text)
  300. return;
  301. d_ptr->m_whatsThis = text;
  302. propertyChanged();
  303. }
  304. /*!
  305. \fn void QtProperty::setPropertyName(const QString &name)
  306. Sets the property's name to the given \a name.
  307. \sa propertyName()
  308. */
  309. void QtProperty::setPropertyName(const QString &text)
  310. {
  311. if (d_ptr->m_name == text)
  312. return;
  313. d_ptr->m_name = text;
  314. propertyChanged();
  315. }
  316. /*!
  317. Enables or disables the property according to the passed \a enable value.
  318. \sa isEnabled()
  319. */
  320. void QtProperty::setEnabled(bool enable)
  321. {
  322. if (d_ptr->m_enabled == enable)
  323. return;
  324. d_ptr->m_enabled = enable;
  325. propertyChanged();
  326. }
  327. /*!
  328. Sets the property's modified state according to the passed \a modified value.
  329. \sa isModified()
  330. */
  331. void QtProperty::setModified(bool modified)
  332. {
  333. if (d_ptr->m_modified == modified)
  334. return;
  335. d_ptr->m_modified = modified;
  336. propertyChanged();
  337. }
  338. /*!
  339. Appends the given \a property to this property's subproperties.
  340. If the given \a property already is added, this function does
  341. nothing.
  342. \sa insertSubProperty(), removeSubProperty()
  343. */
  344. void QtProperty::addSubProperty(QtProperty *property)
  345. {
  346. QtProperty *after = 0;
  347. if (d_ptr->m_subItems.count() > 0)
  348. after = d_ptr->m_subItems.last();
  349. insertSubProperty(property, after);
  350. }
  351. /*!
  352. \fn void QtProperty::insertSubProperty(QtProperty *property, QtProperty *precedingProperty)
  353. Inserts the given \a property after the specified \a
  354. precedingProperty into this property's list of subproperties. If
  355. \a precedingProperty is 0, the specified \a property is inserted
  356. at the beginning of the list.
  357. If the given \a property already is inserted, this function does
  358. nothing.
  359. \sa addSubProperty(), removeSubProperty()
  360. */
  361. void QtProperty::insertSubProperty(QtProperty *property,
  362. QtProperty *afterProperty)
  363. {
  364. if (!property)
  365. return;
  366. if (property == this)
  367. return;
  368. // traverse all children of item. if this item is a child of item then cannot add.
  369. QList<QtProperty *> pendingList = property->subProperties();
  370. QMap<QtProperty *, bool> visited;
  371. while (!pendingList.isEmpty()) {
  372. QtProperty *i = pendingList.first();
  373. if (i == this)
  374. return;
  375. pendingList.removeFirst();
  376. if (visited.contains(i))
  377. continue;
  378. visited[i] = true;
  379. pendingList += i->subProperties();
  380. }
  381. pendingList = subProperties();
  382. int pos = 0;
  383. int newPos = 0;
  384. QtProperty *properAfterProperty = 0;
  385. while (pos < pendingList.count()) {
  386. QtProperty *i = pendingList.at(pos);
  387. if (i == property)
  388. return; // if item is already inserted in this item then cannot add.
  389. if (i == afterProperty) {
  390. newPos = pos + 1;
  391. properAfterProperty = afterProperty;
  392. }
  393. pos++;
  394. }
  395. d_ptr->m_subItems.insert(newPos, property);
  396. property->d_ptr->m_parentItems.insert(this);
  397. d_ptr->m_manager->d_ptr->propertyInserted(property, this, properAfterProperty);
  398. }
  399. /*!
  400. Removes the given \a property from the list of subproperties
  401. without deleting it.
  402. \sa addSubProperty(), insertSubProperty()
  403. */
  404. void QtProperty::removeSubProperty(QtProperty *property)
  405. {
  406. if (!property)
  407. return;
  408. d_ptr->m_manager->d_ptr->propertyRemoved(property, this);
  409. QList<QtProperty *> pendingList = subProperties();
  410. int pos = 0;
  411. while (pos < pendingList.count()) {
  412. if (pendingList.at(pos) == property) {
  413. d_ptr->m_subItems.removeAt(pos);
  414. property->d_ptr->m_parentItems.remove(this);
  415. return;
  416. }
  417. pos++;
  418. }
  419. }
  420. /*!
  421. \internal
  422. */
  423. void QtProperty::propertyChanged()
  424. {
  425. d_ptr->m_manager->d_ptr->propertyChanged(this);
  426. }
  427. ////////////////////////////////
  428. void QtAbstractPropertyManagerPrivate::propertyDestroyed(QtProperty *property)
  429. {
  430. if (m_properties.contains(property)) {
  431. emit q_ptr->propertyDestroyed(property);
  432. q_ptr->uninitializeProperty(property);
  433. m_properties.remove(property);
  434. }
  435. }
  436. void QtAbstractPropertyManagerPrivate::propertyChanged(QtProperty *property) const
  437. {
  438. emit q_ptr->propertyChanged(property);
  439. }
  440. void QtAbstractPropertyManagerPrivate::propertyRemoved(QtProperty *property,
  441. QtProperty *parentProperty) const
  442. {
  443. emit q_ptr->propertyRemoved(property, parentProperty);
  444. }
  445. void QtAbstractPropertyManagerPrivate::propertyInserted(QtProperty *property,
  446. QtProperty *parentProperty, QtProperty *afterProperty) const
  447. {
  448. emit q_ptr->propertyInserted(property, parentProperty, afterProperty);
  449. }
  450. /*!
  451. \class QtAbstractPropertyManager
  452. \internal
  453. \inmodule QtDesigner
  454. \since 4.4
  455. \brief The QtAbstractPropertyManager provides an interface for
  456. property managers.
  457. A manager can create and manage properties of a given type, and is
  458. used in conjunction with the QtAbstractPropertyBrowser class.
  459. When using a property browser widget, the properties are created
  460. and managed by implementations of the QtAbstractPropertyManager
  461. class. To ensure that the properties' values will be displayed
  462. using suitable editing widgets, the managers are associated with
  463. objects of QtAbstractEditorFactory subclasses. The property browser
  464. will use these associations to determine which factories it should
  465. use to create the preferred editing widgets.
  466. The QtAbstractPropertyManager class provides common functionality
  467. like creating a property using the addProperty() function, and
  468. retrieving the properties created by the manager using the
  469. properties() function. The class also provides signals that are
  470. emitted when the manager's properties change: propertyInserted(),
  471. propertyRemoved(), propertyChanged() and propertyDestroyed().
  472. QtAbstractPropertyManager subclasses are supposed to provide their
  473. own type specific API. Note that several ready-made
  474. implementations are available:
  475. \list
  476. \li QtBoolPropertyManager
  477. \li QtColorPropertyManager
  478. \li QtDatePropertyManager
  479. \li QtDateTimePropertyManager
  480. \li QtDoublePropertyManager
  481. \li QtEnumPropertyManager
  482. \li QtFlagPropertyManager
  483. \li QtFontPropertyManager
  484. \li QtGroupPropertyManager
  485. \li QtIntPropertyManager
  486. \li QtPointPropertyManager
  487. \li QtRectPropertyManager
  488. \li QtSizePropertyManager
  489. \li QtSizePolicyPropertyManager
  490. \li QtStringPropertyManager
  491. \li QtTimePropertyManager
  492. \li QtVariantPropertyManager
  493. \endlist
  494. \sa QtAbstractEditorFactoryBase, QtAbstractPropertyBrowser, QtProperty
  495. */
  496. /*!
  497. \fn void QtAbstractPropertyManager::propertyInserted(QtProperty *newProperty,
  498. QtProperty *parentProperty, QtProperty *precedingProperty)
  499. This signal is emitted when a new subproperty is inserted into an
  500. existing property, passing pointers to the \a newProperty, \a
  501. parentProperty and \a precedingProperty as parameters.
  502. If \a precedingProperty is 0, the \a newProperty was inserted at
  503. the beginning of the \a parentProperty's subproperties list.
  504. Note that signal is emitted only if the \a parentProperty is created
  505. by this manager.
  506. \sa QtAbstractPropertyBrowser::itemInserted()
  507. */
  508. /*!
  509. \fn void QtAbstractPropertyManager::propertyChanged(QtProperty *property)
  510. This signal is emitted whenever a property's data changes, passing
  511. a pointer to the \a property as parameter.
  512. Note that signal is only emitted for properties that are created by
  513. this manager.
  514. \sa QtAbstractPropertyBrowser::itemChanged()
  515. */
  516. /*!
  517. \fn void QtAbstractPropertyManager::propertyRemoved(QtProperty *property, QtProperty *parent)
  518. This signal is emitted when a subproperty is removed, passing
  519. pointers to the removed \a property and the \a parent property as
  520. parameters.
  521. Note that signal is emitted only when the \a parent property is
  522. created by this manager.
  523. \sa QtAbstractPropertyBrowser::itemRemoved()
  524. */
  525. /*!
  526. \fn void QtAbstractPropertyManager::propertyDestroyed(QtProperty *property)
  527. This signal is emitted when the specified \a property is about to
  528. be destroyed.
  529. Note that signal is only emitted for properties that are created
  530. by this manager.
  531. \sa clear(), uninitializeProperty()
  532. */
  533. /*!
  534. \fn void QtAbstractPropertyBrowser::currentItemChanged(QtBrowserItem *current)
  535. This signal is emitted when the current item changes. The current item is specified by \a current.
  536. \sa QtAbstractPropertyBrowser::setCurrentItem()
  537. */
  538. /*!
  539. Creates an abstract property manager with the given \a parent.
  540. */
  541. QtAbstractPropertyManager::QtAbstractPropertyManager(QObject *parent)
  542. : QObject(parent), d_ptr(new QtAbstractPropertyManagerPrivate)
  543. {
  544. d_ptr->q_ptr = this;
  545. }
  546. /*!
  547. Destroys the manager. All properties created by the manager are
  548. destroyed.
  549. */
  550. QtAbstractPropertyManager::~QtAbstractPropertyManager()
  551. {
  552. clear();
  553. }
  554. /*!
  555. Destroys all the properties that this manager has created.
  556. \sa propertyDestroyed(), uninitializeProperty()
  557. */
  558. void QtAbstractPropertyManager::clear() const
  559. {
  560. while (!d_ptr->m_properties.isEmpty())
  561. delete *d_ptr->m_properties.cbegin();
  562. }
  563. /*!
  564. Returns the set of properties created by this manager.
  565. \sa addProperty()
  566. */
  567. QSet<QtProperty *> QtAbstractPropertyManager::properties() const
  568. {
  569. return d_ptr->m_properties;
  570. }
  571. /*!
  572. Returns whether the given \a property has a value.
  573. The default implementation of this function returns true.
  574. \sa QtProperty::hasValue()
  575. */
  576. bool QtAbstractPropertyManager::hasValue(const QtProperty *property) const
  577. {
  578. Q_UNUSED(property);
  579. return true;
  580. }
  581. /*!
  582. Returns an icon representing the current state of the given \a
  583. property.
  584. The default implementation of this function returns an invalid
  585. icon.
  586. \sa QtProperty::valueIcon()
  587. */
  588. QIcon QtAbstractPropertyManager::valueIcon(const QtProperty *property) const
  589. {
  590. Q_UNUSED(property);
  591. return QIcon();
  592. }
  593. /*!
  594. Returns a string representing the current state of the given \a
  595. property.
  596. The default implementation of this function returns an empty
  597. string.
  598. \sa QtProperty::valueText()
  599. */
  600. QString QtAbstractPropertyManager::valueText(const QtProperty *property) const
  601. {
  602. Q_UNUSED(property);
  603. return QString();
  604. }
  605. /*!
  606. Creates a property with the given \a name which then is owned by this manager.
  607. Internally, this function calls the createProperty() and
  608. initializeProperty() functions.
  609. \sa initializeProperty(), properties()
  610. */
  611. /// <summary>
  612. /// 添加属性到列表中
  613. /// </summary>
  614. /// <param name="name"></param>
  615. /// <returns></returns>
  616. QtProperty *QtAbstractPropertyManager::addProperty(const QString &name)
  617. {
  618. QtProperty *property = createProperty();
  619. // 创建属性
  620. if (property)
  621. {
  622. // 设置属性名称
  623. property->setPropertyName(name);
  624. // 数据结构中保存此属性
  625. d_ptr->m_properties.insert(property);
  626. // 初始化本属性
  627. initializeProperty(property);
  628. }
  629. // 创建完毕后,返回
  630. return property;
  631. }
  632. /*!
  633. Creates a property.
  634. The base implementation produce QtProperty instances; Reimplement
  635. this function to make this manager produce objects of a QtProperty
  636. subclass.
  637. \sa addProperty(), initializeProperty()
  638. */
  639. QtProperty *QtAbstractPropertyManager::createProperty()
  640. {
  641. return new QtProperty(this);
  642. }
  643. /*!
  644. \fn void QtAbstractPropertyManager::initializeProperty(QtProperty *property) = 0
  645. This function is called whenever a new valid property pointer has
  646. been created, passing the pointer as parameter.
  647. The purpose is to let the manager know that the \a property has
  648. been created so that it can provide additional attributes for the
  649. new property, e.g. QtIntPropertyManager adds \l
  650. {QtIntPropertyManager::value()}{value}, \l
  651. {QtIntPropertyManager::minimum()}{minimum} and \l
  652. {QtIntPropertyManager::maximum()}{maximum} attributes. Since each manager
  653. subclass adds type specific attributes, this function is pure
  654. virtual and must be reimplemented when deriving from the
  655. QtAbstractPropertyManager class.
  656. \sa addProperty(), createProperty()
  657. */
  658. /*!
  659. This function is called just before the specified \a property is destroyed.
  660. The purpose is to let the property manager know that the \a
  661. property is being destroyed so that it can remove the property's
  662. additional attributes.
  663. \sa clear(), propertyDestroyed()
  664. */
  665. void QtAbstractPropertyManager::uninitializeProperty(QtProperty *property)
  666. {
  667. Q_UNUSED(property);
  668. }
  669. ////////////////////////////////////
  670. /*!
  671. \class QtAbstractEditorFactoryBase
  672. \internal
  673. \inmodule QtDesigner
  674. \since 4.4
  675. \brief The QtAbstractEditorFactoryBase provides an interface for
  676. editor factories.
  677. An editor factory is a class that is able to create an editing
  678. widget of a specified type (e.g. line edits or comboboxes) for a
  679. given QtProperty object, and it is used in conjunction with the
  680. QtAbstractPropertyManager and QtAbstractPropertyBrowser classes.
  681. When using a property browser widget, the properties are created
  682. and managed by implementations of the QtAbstractPropertyManager
  683. class. To ensure that the properties' values will be displayed
  684. using suitable editing widgets, the managers are associated with
  685. objects of QtAbstractEditorFactory subclasses. The property browser
  686. will use these associations to determine which factories it should
  687. use to create the preferred editing widgets.
  688. Typically, an editor factory is created by subclassing the
  689. QtAbstractEditorFactory template class which inherits
  690. QtAbstractEditorFactoryBase. But note that several ready-made
  691. implementations are available:
  692. \list
  693. \li QtCheckBoxFactory
  694. \li QtDateEditFactory
  695. \li QtDateTimeEditFactory
  696. \li QtDoubleSpinBoxFactory
  697. \li QtEnumEditorFactory
  698. \li QtLineEditFactory
  699. \li QtScrollBarFactory
  700. \li QtSliderFactory
  701. \li QtSpinBoxFactory
  702. \li QtTimeEditFactory
  703. \li QtVariantEditorFactory
  704. \endlist
  705. \sa QtAbstractPropertyManager, QtAbstractPropertyBrowser
  706. */
  707. /*!
  708. \fn virtual QWidget *QtAbstractEditorFactoryBase::createEditor(QtProperty *property,
  709. QWidget *parent) = 0
  710. Creates an editing widget (with the given \a parent) for the given
  711. \a property.
  712. This function is reimplemented in QtAbstractEditorFactory template class
  713. which also provides a pure virtual convenience overload of this
  714. function enabling access to the property's manager.
  715. \sa QtAbstractEditorFactory::createEditor()
  716. */
  717. /*!
  718. \fn QtAbstractEditorFactoryBase::QtAbstractEditorFactoryBase(QObject *parent = 0)
  719. Creates an abstract editor factory with the given \a parent.
  720. */
  721. /*!
  722. \fn virtual void QtAbstractEditorFactoryBase::breakConnection(QtAbstractPropertyManager *manager) = 0
  723. \internal
  724. Detaches property manager from factory.
  725. This method is reimplemented in QtAbstractEditorFactory template subclass.
  726. You don't need to reimplement it in your subclasses. Instead implement more convenient
  727. QtAbstractEditorFactory::disconnectPropertyManager() which gives you access to particular manager subclass.
  728. */
  729. /*!
  730. \fn virtual void QtAbstractEditorFactoryBase::managerDestroyed(QObject *manager) = 0
  731. \internal
  732. This method is called when property manager is being destroyed.
  733. Basically it notifies factory not to produce editors for properties owned by \a manager.
  734. You don't need to reimplement it in your subclass. This method is implemented in
  735. QtAbstractEditorFactory template subclass.
  736. */
  737. /*!
  738. \class QtAbstractEditorFactory
  739. \internal
  740. \inmodule QtDesigner
  741. \since 4.4
  742. \brief The QtAbstractEditorFactory is the base template class for editor
  743. factories.
  744. An editor factory is a class that is able to create an editing
  745. widget of a specified type (e.g. line edits or comboboxes) for a
  746. given QtProperty object, and it is used in conjunction with the
  747. QtAbstractPropertyManager and QtAbstractPropertyBrowser classes.
  748. Note that the QtAbstractEditorFactory functions are using the
  749. PropertyManager template argument class which can be any
  750. QtAbstractPropertyManager subclass. For example:
  751. \snippet doc/src/snippets/code/tools_shared_qtpropertybrowser_qtpropertybrowser.cpp 0
  752. Note that QtSpinBoxFactory by definition creates editing widgets
  753. \e only for properties created by QtIntPropertyManager.
  754. When using a property browser widget, the properties are created
  755. and managed by implementations of the QtAbstractPropertyManager
  756. class. To ensure that the properties' values will be displayed
  757. using suitable editing widgets, the managers are associated with
  758. objects of QtAbstractEditorFactory subclasses. The property browser will
  759. use these associations to determine which factories it should use
  760. to create the preferred editing widgets.
  761. A QtAbstractEditorFactory object is capable of producing editors for
  762. several property managers at the same time. To create an
  763. association between this factory and a given manager, use the
  764. addPropertyManager() function. Use the removePropertyManager() function to make
  765. this factory stop producing editors for a given property
  766. manager. Use the propertyManagers() function to retrieve the set of
  767. managers currently associated with this factory.
  768. Several ready-made implementations of the QtAbstractEditorFactory class
  769. are available:
  770. \list
  771. \li QtCheckBoxFactory
  772. \li QtDateEditFactory
  773. \li QtDateTimeEditFactory
  774. \li QtDoubleSpinBoxFactory
  775. \li QtEnumEditorFactory
  776. \li QtLineEditFactory
  777. \li QtScrollBarFactory
  778. \li QtSliderFactory
  779. \li QtSpinBoxFactory
  780. \li QtTimeEditFactory
  781. \li QtVariantEditorFactory
  782. \endlist
  783. When deriving from the QtAbstractEditorFactory class, several pure virtual
  784. functions must be implemented: the connectPropertyManager() function is
  785. used by the factory to connect to the given manager's signals, the
  786. createEditor() function is supposed to create an editor for the
  787. given property controlled by the given manager, and finally the
  788. disconnectPropertyManager() function is used by the factory to disconnect
  789. from the specified manager's signals.
  790. \sa QtAbstractEditorFactoryBase, QtAbstractPropertyManager
  791. */
  792. /*!
  793. \fn QtAbstractEditorFactory::QtAbstractEditorFactory(QObject *parent = 0)
  794. Creates an editor factory with the given \a parent.
  795. \sa addPropertyManager()
  796. */
  797. /*!
  798. \fn QWidget *QtAbstractEditorFactory::createEditor(QtProperty *property, QWidget *parent)
  799. Creates an editing widget (with the given \a parent) for the given
  800. \a property.
  801. */
  802. /*!
  803. \fn void QtAbstractEditorFactory::addPropertyManager(PropertyManager *manager)
  804. Adds the given \a manager to this factory's set of managers,
  805. making this factory produce editing widgets for properties created
  806. by the given manager.
  807. The PropertyManager type is a template argument class, and represents the chosen
  808. QtAbstractPropertyManager subclass.
  809. \sa propertyManagers(), removePropertyManager()
  810. */
  811. /*!
  812. \fn void QtAbstractEditorFactory::removePropertyManager(PropertyManager *manager)
  813. Removes the given \a manager from this factory's set of
  814. managers. The PropertyManager type is a template argument class, and may be
  815. any QtAbstractPropertyManager subclass.
  816. \sa propertyManagers(), addPropertyManager()
  817. */
  818. /*!
  819. \fn virtual void QtAbstractEditorFactory::connectPropertyManager(PropertyManager *manager) = 0
  820. Connects this factory to the given \a manager's signals. The
  821. PropertyManager type is a template argument class, and represents
  822. the chosen QtAbstractPropertyManager subclass.
  823. This function is used internally by the addPropertyManager() function, and
  824. makes it possible to update an editing widget when the associated
  825. property's data changes. This is typically done in custom slots
  826. responding to the signals emitted by the property's manager,
  827. e.g. QtIntPropertyManager::valueChanged() and
  828. QtIntPropertyManager::rangeChanged().
  829. \sa propertyManagers(), disconnectPropertyManager()
  830. */
  831. /*!
  832. \fn virtual QWidget *QtAbstractEditorFactory::createEditor(PropertyManager *manager, QtProperty *property,
  833. QWidget *parent) = 0
  834. Creates an editing widget with the given \a parent for the
  835. specified \a property created by the given \a manager. The
  836. PropertyManager type is a template argument class, and represents
  837. the chosen QtAbstractPropertyManager subclass.
  838. This function must be implemented in derived classes: It is
  839. recommended to store a pointer to the widget and map it to the
  840. given \a property, since the widget must be updated whenever the
  841. associated property's data changes. This is typically done in
  842. custom slots responding to the signals emitted by the property's
  843. manager, e.g. QtIntPropertyManager::valueChanged() and
  844. QtIntPropertyManager::rangeChanged().
  845. \sa connectPropertyManager()
  846. */
  847. /*!
  848. \fn virtual void QtAbstractEditorFactory::disconnectPropertyManager(PropertyManager *manager) = 0
  849. Disconnects this factory from the given \a manager's signals. The
  850. PropertyManager type is a template argument class, and represents
  851. the chosen QtAbstractPropertyManager subclass.
  852. This function is used internally by the removePropertyManager() function.
  853. \sa propertyManagers(), connectPropertyManager()
  854. */
  855. /*!
  856. \fn QSet<PropertyManager *> QtAbstractEditorFactory::propertyManagers() const
  857. Returns the factory's set of associated managers. The
  858. PropertyManager type is a template argument class, and represents
  859. the chosen QtAbstractPropertyManager subclass.
  860. \sa addPropertyManager(), removePropertyManager()
  861. */
  862. /*!
  863. \fn PropertyManager *QtAbstractEditorFactory::propertyManager(QtProperty *property) const
  864. Returns the property manager for the given \a property, or 0 if
  865. the given \a property doesn't belong to any of this factory's
  866. registered managers.
  867. The PropertyManager type is a template argument class, and represents the chosen
  868. QtAbstractPropertyManager subclass.
  869. \sa propertyManagers()
  870. */
  871. /*!
  872. \fn virtual void QtAbstractEditorFactory::managerDestroyed(QObject *manager)
  873. \internal
  874. */
  875. ////////////////////////////////////
  876. class QtBrowserItemPrivate
  877. {
  878. public:
  879. QtBrowserItemPrivate(QtAbstractPropertyBrowser *browser, QtProperty *property, QtBrowserItem *parent)
  880. : m_browser(browser), m_property(property), m_parent(parent), q_ptr(0) {}
  881. void addChild(QtBrowserItem *index, QtBrowserItem *after);
  882. void removeChild(QtBrowserItem *index);
  883. QtAbstractPropertyBrowser * const m_browser;
  884. QtProperty *m_property;
  885. QtBrowserItem *m_parent;
  886. QtBrowserItem *q_ptr;
  887. QList<QtBrowserItem *> m_children;
  888. };
  889. void QtBrowserItemPrivate::addChild(QtBrowserItem *index, QtBrowserItem *after)
  890. {
  891. if (m_children.contains(index))
  892. return;
  893. int idx = m_children.indexOf(after) + 1; // we insert after returned idx, if it was -1 then we set idx to 0;
  894. m_children.insert(idx, index);
  895. }
  896. void QtBrowserItemPrivate::removeChild(QtBrowserItem *index)
  897. {
  898. m_children.removeAll(index);
  899. }
  900. /*!
  901. \class QtBrowserItem
  902. \internal
  903. \inmodule QtDesigner
  904. \since 4.4
  905. \brief The QtBrowserItem class represents a property in
  906. a property browser instance.
  907. Browser items are created whenever a QtProperty is inserted to the
  908. property browser. A QtBrowserItem uniquely identifies a
  909. browser's item. Thus, if the same QtProperty is inserted multiple
  910. times, each occurrence gets its own unique QtBrowserItem. The
  911. items are owned by QtAbstractPropertyBrowser and automatically
  912. deleted when they are removed from the browser.
  913. You can traverse a browser's properties by calling parent() and
  914. children(). The property and the browser associated with an item
  915. are available as property() and browser().
  916. \sa QtAbstractPropertyBrowser, QtProperty
  917. */
  918. /*!
  919. Returns the property which is accosiated with this item. Note that
  920. several items can be associated with the same property instance in
  921. the same property browser.
  922. \sa QtAbstractPropertyBrowser::items()
  923. */
  924. QtProperty *QtBrowserItem::property() const
  925. {
  926. return d_ptr->m_property;
  927. }
  928. /*!
  929. Returns the parent item of \e this item. Returns 0 if \e this item
  930. is associated with top-level property in item's property browser.
  931. \sa children()
  932. */
  933. QtBrowserItem *QtBrowserItem::parent() const
  934. {
  935. return d_ptr->m_parent;
  936. }
  937. /*!
  938. Returns the children items of \e this item. The properties
  939. reproduced from children items are always the same as
  940. reproduced from associated property' children, for example:
  941. \snippet doc/src/snippets/code/tools_shared_qtpropertybrowser_qtpropertybrowser.cpp 1
  942. The \e childrenItems list represents the same list as \e childrenProperties.
  943. */
  944. QList<QtBrowserItem *> QtBrowserItem::children() const
  945. {
  946. return d_ptr->m_children;
  947. }
  948. /*!
  949. Returns the property browser which owns \e this item.
  950. */
  951. QtAbstractPropertyBrowser *QtBrowserItem::browser() const
  952. {
  953. return d_ptr->m_browser;
  954. }
  955. QtBrowserItem::QtBrowserItem(QtAbstractPropertyBrowser *browser, QtProperty *property, QtBrowserItem *parent)
  956. : d_ptr(new QtBrowserItemPrivate(browser, property, parent))
  957. {
  958. d_ptr->q_ptr = this;
  959. }
  960. QtBrowserItem::~QtBrowserItem()
  961. {
  962. }
  963. ////////////////////////////////////
  964. typedef QMap<QtAbstractPropertyBrowser *, QMap<QtAbstractPropertyManager *,
  965. QtAbstractEditorFactoryBase *> > Map1;
  966. typedef QMap<QtAbstractPropertyManager *, QMap<QtAbstractEditorFactoryBase *,
  967. QList<QtAbstractPropertyBrowser *> > > Map2;
  968. Q_GLOBAL_STATIC(Map1, m_viewToManagerToFactory)
  969. Q_GLOBAL_STATIC(Map2, m_managerToFactoryToViews)
  970. class QtAbstractPropertyBrowserPrivate
  971. {
  972. QtAbstractPropertyBrowser *q_ptr;
  973. Q_DECLARE_PUBLIC(QtAbstractPropertyBrowser)
  974. public:
  975. QtAbstractPropertyBrowserPrivate();
  976. void insertSubTree(QtProperty *property,
  977. QtProperty *parentProperty);
  978. void removeSubTree(QtProperty *property,
  979. QtProperty *parentProperty);
  980. void createBrowserIndexes(QtProperty *property, QtProperty *parentProperty, QtProperty *afterProperty);
  981. void removeBrowserIndexes(QtProperty *property, QtProperty *parentProperty);
  982. QtBrowserItem *createBrowserIndex(QtProperty *property, QtBrowserItem *parentIndex, QtBrowserItem *afterIndex);
  983. void removeBrowserIndex(QtBrowserItem *index);
  984. void clearIndex(QtBrowserItem *index);
  985. void slotPropertyInserted(QtProperty *property,
  986. QtProperty *parentProperty, QtProperty *afterProperty);
  987. void slotPropertyRemoved(QtProperty *property, QtProperty *parentProperty);
  988. void slotPropertyDestroyed(QtProperty *property);
  989. void slotPropertyDataChanged(QtProperty *property);
  990. QList<QtProperty *> m_subItems;
  991. QMap<QtAbstractPropertyManager *, QList<QtProperty *> > m_managerToProperties;
  992. QMap<QtProperty *, QList<QtProperty *> > m_propertyToParents;
  993. QMap<QtProperty *, QtBrowserItem *> m_topLevelPropertyToIndex;
  994. QList<QtBrowserItem *> m_topLevelIndexes;
  995. QMap<QtProperty *, QList<QtBrowserItem *> > m_propertyToIndexes;
  996. QtBrowserItem *m_currentItem;
  997. };
  998. QtAbstractPropertyBrowserPrivate::QtAbstractPropertyBrowserPrivate() :
  999. m_currentItem(0)
  1000. {
  1001. }
  1002. void QtAbstractPropertyBrowserPrivate::insertSubTree(QtProperty *property,
  1003. QtProperty *parentProperty)
  1004. {
  1005. if (m_propertyToParents.contains(property)) {
  1006. // property was already inserted, so its manager is connected
  1007. // and all its children are inserted and theirs managers are connected
  1008. // we just register new parent (parent has to be new).
  1009. m_propertyToParents[property].append(parentProperty);
  1010. // don't need to update m_managerToProperties map since
  1011. // m_managerToProperties[manager] already contains property.
  1012. return;
  1013. }
  1014. QtAbstractPropertyManager *manager = property->propertyManager();
  1015. if (m_managerToProperties[manager].isEmpty()) {
  1016. // connect manager's signals
  1017. q_ptr->connect(manager, SIGNAL(propertyInserted(QtProperty *,
  1018. QtProperty *, QtProperty *)),
  1019. q_ptr, SLOT(slotPropertyInserted(QtProperty *,
  1020. QtProperty *, QtProperty *)));
  1021. q_ptr->connect(manager, SIGNAL(propertyRemoved(QtProperty *,
  1022. QtProperty *)),
  1023. q_ptr, SLOT(slotPropertyRemoved(QtProperty*,QtProperty*)));
  1024. q_ptr->connect(manager, SIGNAL(propertyDestroyed(QtProperty*)),
  1025. q_ptr, SLOT(slotPropertyDestroyed(QtProperty*)));
  1026. q_ptr->connect(manager, SIGNAL(propertyChanged(QtProperty*)),
  1027. q_ptr, SLOT(slotPropertyDataChanged(QtProperty*)));
  1028. }
  1029. m_managerToProperties[manager].append(property);
  1030. m_propertyToParents[property].append(parentProperty);
  1031. const QList<QtProperty *> subList = property->subProperties();
  1032. for (QtProperty *subProperty : subList)
  1033. insertSubTree(subProperty, property);
  1034. }
  1035. void QtAbstractPropertyBrowserPrivate::removeSubTree(QtProperty *property,
  1036. QtProperty *parentProperty)
  1037. {
  1038. if (!m_propertyToParents.contains(property)) {
  1039. // ASSERT
  1040. return;
  1041. }
  1042. m_propertyToParents[property].removeAll(parentProperty);
  1043. if (!m_propertyToParents[property].isEmpty())
  1044. return;
  1045. m_propertyToParents.remove(property);
  1046. QtAbstractPropertyManager *manager = property->propertyManager();
  1047. m_managerToProperties[manager].removeAll(property);
  1048. if (m_managerToProperties[manager].isEmpty()) {
  1049. // disconnect manager's signals
  1050. q_ptr->disconnect(manager, SIGNAL(propertyInserted(QtProperty *,
  1051. QtProperty *, QtProperty *)),
  1052. q_ptr, SLOT(slotPropertyInserted(QtProperty *,
  1053. QtProperty *, QtProperty *)));
  1054. q_ptr->disconnect(manager, SIGNAL(propertyRemoved(QtProperty *,
  1055. QtProperty *)),
  1056. q_ptr, SLOT(slotPropertyRemoved(QtProperty*,QtProperty*)));
  1057. q_ptr->disconnect(manager, SIGNAL(propertyDestroyed(QtProperty*)),
  1058. q_ptr, SLOT(slotPropertyDestroyed(QtProperty*)));
  1059. q_ptr->disconnect(manager, SIGNAL(propertyChanged(QtProperty*)),
  1060. q_ptr, SLOT(slotPropertyDataChanged(QtProperty*)));
  1061. m_managerToProperties.remove(manager);
  1062. }
  1063. const QList<QtProperty *> subList = property->subProperties();
  1064. for (QtProperty *subProperty : subList)
  1065. removeSubTree(subProperty, property);
  1066. }
  1067. void QtAbstractPropertyBrowserPrivate::createBrowserIndexes(QtProperty *property, QtProperty *parentProperty, QtProperty *afterProperty)
  1068. {
  1069. QMap<QtBrowserItem *, QtBrowserItem *> parentToAfter;
  1070. if (afterProperty) {
  1071. QMap<QtProperty *, QList<QtBrowserItem *> >::ConstIterator it =
  1072. m_propertyToIndexes.constFind(afterProperty);
  1073. if (it == m_propertyToIndexes.constEnd())
  1074. return;
  1075. for (QtBrowserItem *idx : it.value()) {
  1076. QtBrowserItem *parentIdx = idx->parent();
  1077. if ((parentProperty && parentIdx && parentIdx->property() == parentProperty) || (!parentProperty && !parentIdx))
  1078. parentToAfter[idx->parent()] = idx;
  1079. }
  1080. } else if (parentProperty) {
  1081. QMap<QtProperty *, QList<QtBrowserItem *> >::ConstIterator it =
  1082. m_propertyToIndexes.find(parentProperty);
  1083. if (it == m_propertyToIndexes.constEnd())
  1084. return;
  1085. for (QtBrowserItem *idx : it.value())
  1086. parentToAfter[idx] = 0;
  1087. } else {
  1088. parentToAfter[0] = 0;
  1089. }
  1090. const QMap<QtBrowserItem *, QtBrowserItem *>::ConstIterator pcend = parentToAfter.constEnd();
  1091. for (QMap<QtBrowserItem *, QtBrowserItem *>::ConstIterator it = parentToAfter.constBegin(); it != pcend; ++it)
  1092. createBrowserIndex(property, it.key(), it.value());
  1093. }
  1094. QtBrowserItem *QtAbstractPropertyBrowserPrivate::createBrowserIndex(QtProperty *property,
  1095. QtBrowserItem *parentIndex, QtBrowserItem *afterIndex)
  1096. {
  1097. QtBrowserItem *newIndex = new QtBrowserItem(q_ptr, property, parentIndex);
  1098. if (parentIndex) {
  1099. parentIndex->d_ptr->addChild(newIndex, afterIndex);
  1100. } else {
  1101. m_topLevelPropertyToIndex[property] = newIndex;
  1102. m_topLevelIndexes.insert(m_topLevelIndexes.indexOf(afterIndex) + 1, newIndex);
  1103. }
  1104. m_propertyToIndexes[property].append(newIndex);
  1105. q_ptr->itemInserted(newIndex, afterIndex);
  1106. const QList<QtProperty *> subItems = property->subProperties();
  1107. QtBrowserItem *afterChild = 0;
  1108. for (QtProperty *child : subItems)
  1109. afterChild = createBrowserIndex(child, newIndex, afterChild);
  1110. return newIndex;
  1111. }
  1112. void QtAbstractPropertyBrowserPrivate::removeBrowserIndexes(QtProperty *property, QtProperty *parentProperty)
  1113. {
  1114. QList<QtBrowserItem *> toRemove;
  1115. QMap<QtProperty *, QList<QtBrowserItem *> >::ConstIterator it =
  1116. m_propertyToIndexes.constFind(property);
  1117. if (it == m_propertyToIndexes.constEnd())
  1118. return;
  1119. for (QtBrowserItem *idx : it.value()) {
  1120. QtBrowserItem *parentIdx = idx->parent();
  1121. if ((parentProperty && parentIdx && parentIdx->property() == parentProperty) || (!parentProperty && !parentIdx))
  1122. toRemove.append(idx);
  1123. }
  1124. for (QtBrowserItem *index : qAsConst(toRemove))
  1125. removeBrowserIndex(index);
  1126. }
  1127. void QtAbstractPropertyBrowserPrivate::removeBrowserIndex(QtBrowserItem *index)
  1128. {
  1129. QList<QtBrowserItem *> children = index->children();
  1130. for (int i = children.count(); i > 0; i--) {
  1131. removeBrowserIndex(children.at(i - 1));
  1132. }
  1133. q_ptr->itemRemoved(index);
  1134. if (index->parent()) {
  1135. index->parent()->d_ptr->removeChild(index);
  1136. } else {
  1137. m_topLevelPropertyToIndex.remove(index->property());
  1138. m_topLevelIndexes.removeAll(index);
  1139. }
  1140. QtProperty *property = index->property();
  1141. m_propertyToIndexes[property].removeAll(index);
  1142. if (m_propertyToIndexes[property].isEmpty())
  1143. m_propertyToIndexes.remove(property);
  1144. delete index;
  1145. }
  1146. void QtAbstractPropertyBrowserPrivate::clearIndex(QtBrowserItem *index)
  1147. {
  1148. const QList<QtBrowserItem *> children = index->children();
  1149. for (QtBrowserItem *item : children)
  1150. clearIndex(item);
  1151. delete index;
  1152. }
  1153. void QtAbstractPropertyBrowserPrivate::slotPropertyInserted(QtProperty *property,
  1154. QtProperty *parentProperty, QtProperty *afterProperty)
  1155. {
  1156. if (!m_propertyToParents.contains(parentProperty))
  1157. return;
  1158. createBrowserIndexes(property, parentProperty, afterProperty);
  1159. insertSubTree(property, parentProperty);
  1160. //q_ptr->propertyInserted(property, parentProperty, afterProperty);
  1161. }
  1162. void QtAbstractPropertyBrowserPrivate::slotPropertyRemoved(QtProperty *property,
  1163. QtProperty *parentProperty)
  1164. {
  1165. if (!m_propertyToParents.contains(parentProperty))
  1166. return;
  1167. removeSubTree(property, parentProperty); // this line should be probably moved down after propertyRemoved call
  1168. //q_ptr->propertyRemoved(property, parentProperty);
  1169. removeBrowserIndexes(property, parentProperty);
  1170. }
  1171. void QtAbstractPropertyBrowserPrivate::slotPropertyDestroyed(QtProperty *property)
  1172. {
  1173. if (!m_subItems.contains(property))
  1174. return;
  1175. q_ptr->removeProperty(property);
  1176. }
  1177. void QtAbstractPropertyBrowserPrivate::slotPropertyDataChanged(QtProperty *property)
  1178. {
  1179. if (!m_propertyToParents.contains(property))
  1180. return;
  1181. QMap<QtProperty *, QList<QtBrowserItem *> >::ConstIterator it =
  1182. m_propertyToIndexes.find(property);
  1183. if (it == m_propertyToIndexes.constEnd())
  1184. return;
  1185. const QList<QtBrowserItem *> indexes = it.value();
  1186. for (QtBrowserItem *idx : indexes)
  1187. q_ptr->itemChanged(idx);
  1188. //q_ptr->propertyChanged(property);
  1189. }
  1190. /*!
  1191. \class QtAbstractPropertyBrowser
  1192. \internal
  1193. \inmodule QtDesigner
  1194. \since 4.4
  1195. \brief QtAbstractPropertyBrowser provides a base class for
  1196. implementing property browsers.
  1197. A property browser is a widget that enables the user to edit a
  1198. given set of properties. Each property is represented by a label
  1199. specifying the property's name, and an editing widget (e.g. a line
  1200. edit or a combobox) holding its value. A property can have zero or
  1201. more subproperties.
  1202. \image qtpropertybrowser.png
  1203. The top level properties can be retrieved using the
  1204. properties() function. To traverse each property's
  1205. subproperties, use the QtProperty::subProperties() function. In
  1206. addition, the set of top level properties can be manipulated using
  1207. the addProperty(), insertProperty() and removeProperty()
  1208. functions. Note that the QtProperty class provides a corresponding
  1209. set of functions making it possible to manipulate the set of
  1210. subproperties as well.
  1211. To remove all the properties from the property browser widget, use
  1212. the clear() function. This function will clear the editor, but it
  1213. will not delete the properties since they can still be used in
  1214. other editors.
  1215. The properties themselves are created and managed by
  1216. implementations of the QtAbstractPropertyManager class. A manager
  1217. can handle (i.e. create and manage) properties of a given type. In
  1218. the property browser the managers are associated with
  1219. implementations of the QtAbstractEditorFactory: A factory is a
  1220. class able to create an editing widget of a specified type.
  1221. When using a property browser widget, managers must be created for
  1222. each of the required property types before the properties
  1223. themselves can be created. To ensure that the properties' values
  1224. will be displayed using suitable editing widgets, the managers
  1225. must be associated with objects of the preferred factory
  1226. implementations using the setFactoryForManager() function. The
  1227. property browser will use these associations to determine which
  1228. factory it should use to create the preferred editing widget.
  1229. Note that a factory can be associated with many managers, but a
  1230. manager can only be associated with one single factory within the
  1231. context of a single property browser. The associations between
  1232. managers and factories can at any time be removed using the
  1233. unsetFactoryForManager() function.
  1234. Whenever the property data changes or a property is inserted or
  1235. removed, the itemChanged(), itemInserted() or
  1236. itemRemoved() functions are called, respectively. These
  1237. functions must be reimplemented in derived classes in order to
  1238. update the property browser widget. Be aware that some property
  1239. instances can appear several times in an abstract tree
  1240. structure. For example:
  1241. \table 100%
  1242. \row
  1243. \li
  1244. \snippet doc/src/snippets/code/tools_shared_qtpropertybrowser_qtpropertybrowser.cpp 2
  1245. \li \image qtpropertybrowser-duplicate.png
  1246. \endtable
  1247. The addProperty() function returns a QtBrowserItem that uniquely
  1248. identifies the created item.
  1249. To make a property editable in the property browser, the
  1250. createEditor() function must be called to provide the
  1251. property with a suitable editing widget.
  1252. Note that there are two ready-made property browser
  1253. implementations:
  1254. \list
  1255. \li QtGroupBoxPropertyBrowser
  1256. \li QtTreePropertyBrowser
  1257. \endlist
  1258. \sa QtAbstractPropertyManager, QtAbstractEditorFactoryBase
  1259. */
  1260. /*!
  1261. \fn void QtAbstractPropertyBrowser::setFactoryForManager(PropertyManager *manager,
  1262. QtAbstractEditorFactory<PropertyManager> *factory)
  1263. Connects the given \a manager to the given \a factory, ensuring
  1264. that properties of the \a manager's type will be displayed with an
  1265. editing widget suitable for their value.
  1266. For example:
  1267. \snippet doc/src/snippets/code/tools_shared_qtpropertybrowser_qtpropertybrowser.cpp 3
  1268. In this example the \c myInteger property's value is displayed
  1269. with a QSpinBox widget, while the \c myDouble property's value is
  1270. displayed with a QDoubleSpinBox widget.
  1271. Note that a factory can be associated with many managers, but a
  1272. manager can only be associated with one single factory. If the
  1273. given \a manager already is associated with another factory, the
  1274. old association is broken before the new one established.
  1275. This function ensures that the given \a manager and the given \a
  1276. factory are compatible, and it automatically calls the
  1277. QtAbstractEditorFactory::addPropertyManager() function if necessary.
  1278. \sa unsetFactoryForManager()
  1279. */
  1280. /*!
  1281. \fn virtual void QtAbstractPropertyBrowser::itemInserted(QtBrowserItem *insertedItem,
  1282. QtBrowserItem *precedingItem) = 0
  1283. This function is called to update the widget whenever a property
  1284. is inserted or added to the property browser, passing pointers to
  1285. the \a insertedItem of property and the specified
  1286. \a precedingItem as parameters.
  1287. If \a precedingItem is 0, the \a insertedItem was put at
  1288. the beginning of its parent item's list of subproperties. If
  1289. the parent of \a insertedItem is 0, the \a insertedItem was added as a top
  1290. level property of \e this property browser.
  1291. This function must be reimplemented in derived classes. Note that
  1292. if the \a insertedItem's property has subproperties, this
  1293. method will be called for those properties as soon as the current call is finished.
  1294. \sa insertProperty(), addProperty()
  1295. */
  1296. /*!
  1297. \fn virtual void QtAbstractPropertyBrowser::itemRemoved(QtBrowserItem *item) = 0
  1298. This function is called to update the widget whenever a property
  1299. is removed from the property browser, passing the pointer to the
  1300. \a item of the property as parameters. The passed \a item is
  1301. deleted just after this call is finished.
  1302. If the the parent of \a item is 0, the removed \a item was a
  1303. top level property in this editor.
  1304. This function must be reimplemented in derived classes. Note that
  1305. if the removed \a item's property has subproperties, this
  1306. method will be called for those properties just before the current call is started.
  1307. \sa removeProperty()
  1308. */
  1309. /*!
  1310. \fn virtual void QtAbstractPropertyBrowser::itemChanged(QtBrowserItem *item) = 0
  1311. This function is called whenever a property's data changes,
  1312. passing a pointer to the \a item of property as parameter.
  1313. This function must be reimplemented in derived classes in order to
  1314. update the property browser widget whenever a property's name,
  1315. tool tip, status tip, "what's this" text, value text or value icon
  1316. changes.
  1317. Note that if the property browser contains several occurrences of
  1318. the same property, this method will be called once for each
  1319. occurrence (with a different item each time).
  1320. \sa QtProperty, items()
  1321. */
  1322. /*!
  1323. Creates an abstract property browser with the given \a parent.
  1324. */
  1325. QtAbstractPropertyBrowser::QtAbstractPropertyBrowser(QWidget *parent)
  1326. : QWidget(parent), d_ptr(new QtAbstractPropertyBrowserPrivate)
  1327. {
  1328. d_ptr->q_ptr = this;
  1329. }
  1330. /*!
  1331. Destroys the property browser, and destroys all the items that were
  1332. created by this property browser.
  1333. Note that the properties that were displayed in the editor are not
  1334. deleted since they still can be used in other editors. Neither
  1335. does the destructor delete the property managers and editor
  1336. factories that were used by this property browser widget unless
  1337. this widget was their parent.
  1338. \sa QtAbstractPropertyManager::~QtAbstractPropertyManager()
  1339. */
  1340. QtAbstractPropertyBrowser::~QtAbstractPropertyBrowser()
  1341. {
  1342. const QList<QtBrowserItem *> indexes = topLevelItems();
  1343. for (QtBrowserItem *item : indexes)
  1344. d_ptr->clearIndex(item);
  1345. }
  1346. /*!
  1347. Returns the property browser's list of top level properties.
  1348. To traverse the subproperties, use the QtProperty::subProperties()
  1349. function.
  1350. \sa addProperty(), insertProperty(), removeProperty()
  1351. */
  1352. QList<QtProperty *> QtAbstractPropertyBrowser::properties() const
  1353. {
  1354. return d_ptr->m_subItems;
  1355. }
  1356. /*!
  1357. Returns the property browser's list of all items associated
  1358. with the given \a property.
  1359. There is one item per instance of the property in the browser.
  1360. \sa topLevelItem()
  1361. */
  1362. QList<QtBrowserItem *> QtAbstractPropertyBrowser::items(QtProperty *property) const
  1363. {
  1364. return d_ptr->m_propertyToIndexes.value(property);
  1365. }
  1366. /*!
  1367. Returns the top-level items associated with the given \a property.
  1368. Returns 0 if \a property wasn't inserted into this property
  1369. browser or isn't a top-level one.
  1370. \sa topLevelItems(), items()
  1371. */
  1372. QtBrowserItem *QtAbstractPropertyBrowser::topLevelItem(QtProperty *property) const
  1373. {
  1374. return d_ptr->m_topLevelPropertyToIndex.value(property);
  1375. }
  1376. /*!
  1377. Returns the list of top-level items.
  1378. \sa topLevelItem()
  1379. */
  1380. QList<QtBrowserItem *> QtAbstractPropertyBrowser::topLevelItems() const
  1381. {
  1382. return d_ptr->m_topLevelIndexes;
  1383. }
  1384. /*!
  1385. Removes all the properties from the editor, but does not delete
  1386. them since they can still be used in other editors.
  1387. \sa removeProperty(), QtAbstractPropertyManager::clear()
  1388. */
  1389. void QtAbstractPropertyBrowser::clear()
  1390. {
  1391. const QList<QtProperty *> subList = properties();
  1392. for (auto rit = subList.crbegin(), rend = subList.crend(); rit != rend; ++rit)
  1393. removeProperty(*rit);
  1394. }
  1395. /*!
  1396. Appends the given \a property (and its subproperties) to the
  1397. property browser's list of top level properties. Returns the item
  1398. created by property browser which is associated with the \a property.
  1399. In order to get all children items created by the property
  1400. browser in this call, the returned item should be traversed.
  1401. If the specified \a property is already added, this function does
  1402. nothing and returns 0.
  1403. \sa insertProperty(), QtProperty::addSubProperty(), properties()
  1404. */
  1405. QtBrowserItem *QtAbstractPropertyBrowser::addProperty(QtProperty *property)
  1406. {
  1407. QtProperty *afterProperty = 0;
  1408. if (d_ptr->m_subItems.count() > 0)
  1409. afterProperty = d_ptr->m_subItems.last();
  1410. return insertProperty(property, afterProperty);
  1411. }
  1412. /*!
  1413. \fn QtBrowserItem *QtAbstractPropertyBrowser::insertProperty(QtProperty *property,
  1414. QtProperty *afterProperty)
  1415. Inserts the given \a property (and its subproperties) after
  1416. the specified \a afterProperty in the browser's list of top
  1417. level properties. Returns item created by property browser which
  1418. is associated with the \a property. In order to get all children items
  1419. created by the property browser in this call returned item should be traversed.
  1420. If the specified \a afterProperty is 0, the given \a property is
  1421. inserted at the beginning of the list. If \a property is
  1422. already inserted, this function does nothing and returns 0.
  1423. \sa addProperty(), QtProperty::insertSubProperty(), properties()
  1424. */
  1425. QtBrowserItem *QtAbstractPropertyBrowser::insertProperty(QtProperty *property,
  1426. QtProperty *afterProperty)
  1427. {
  1428. if (!property)
  1429. return 0;
  1430. // if item is already inserted in this item then cannot add.
  1431. QList<QtProperty *> pendingList = properties();
  1432. int pos = 0;
  1433. int newPos = 0;
  1434. while (pos < pendingList.count()) {
  1435. QtProperty *prop = pendingList.at(pos);
  1436. if (prop == property)
  1437. return 0;
  1438. if (prop == afterProperty) {
  1439. newPos = pos + 1;
  1440. }
  1441. pos++;
  1442. }
  1443. d_ptr->createBrowserIndexes(property, 0, afterProperty);
  1444. // traverse inserted subtree and connect to manager's signals
  1445. d_ptr->insertSubTree(property, 0);
  1446. d_ptr->m_subItems.insert(newPos, property);
  1447. //propertyInserted(property, 0, properAfterProperty);
  1448. return topLevelItem(property);
  1449. }
  1450. /*!
  1451. Removes the specified \a property (and its subproperties) from the
  1452. property browser's list of top level properties. All items
  1453. that were associated with the given \a property and its children
  1454. are deleted.
  1455. Note that the properties are \e not deleted since they can still
  1456. be used in other editors.
  1457. \sa clear(), QtProperty::removeSubProperty(), properties()
  1458. */
  1459. void QtAbstractPropertyBrowser::removeProperty(QtProperty *property)
  1460. {
  1461. if (!property)
  1462. return;
  1463. QList<QtProperty *> pendingList = properties();
  1464. int pos = 0;
  1465. while (pos < pendingList.count()) {
  1466. if (pendingList.at(pos) == property) {
  1467. d_ptr->m_subItems.removeAt(pos); //perhaps this two lines
  1468. d_ptr->removeSubTree(property, 0); //should be moved down after propertyRemoved call.
  1469. //propertyRemoved(property, 0);
  1470. d_ptr->removeBrowserIndexes(property, 0);
  1471. // when item is deleted, item will call removeItem for top level items,
  1472. // and itemRemoved for nested items.
  1473. return;
  1474. }
  1475. pos++;
  1476. }
  1477. }
  1478. /*!
  1479. Creates an editing widget (with the given \a parent) for the given
  1480. \a property according to the previously established associations
  1481. between property managers and editor factories.
  1482. If the property is created by a property manager which was not
  1483. associated with any of the existing factories in \e this property
  1484. editor, the function returns 0.
  1485. To make a property editable in the property browser, the
  1486. createEditor() function must be called to provide the
  1487. property with a suitable editing widget.
  1488. Reimplement this function to provide additional decoration for the
  1489. editing widgets created by the installed factories.
  1490. \sa setFactoryForManager()
  1491. */
  1492. QWidget *QtAbstractPropertyBrowser::createEditor(QtProperty *property,
  1493. QWidget *parent)
  1494. {
  1495. QtAbstractEditorFactoryBase *factory = 0;
  1496. QtAbstractPropertyManager *manager = property->propertyManager();
  1497. if (m_viewToManagerToFactory()->contains(this) &&
  1498. (*m_viewToManagerToFactory())[this].contains(manager)) {
  1499. factory = (*m_viewToManagerToFactory())[this][manager];
  1500. }
  1501. if (!factory)
  1502. return 0;
  1503. QWidget *w = factory->createEditor(property, parent);
  1504. // Since some editors can be QComboBoxes, and we changed their focus policy in Qt 5
  1505. // to make them feel more native on Mac, we need to relax the focus policy to something
  1506. // more permissive to keep the combo box from losing focus, allowing it to stay alive,
  1507. // when the user clicks on it to show the popup.
  1508. if (w)
  1509. w->setFocusPolicy(Qt::WheelFocus);
  1510. return w;
  1511. }
  1512. bool QtAbstractPropertyBrowser::addFactory(QtAbstractPropertyManager *abstractManager,
  1513. QtAbstractEditorFactoryBase *abstractFactory)
  1514. {
  1515. bool connectNeeded = false;
  1516. if (!m_managerToFactoryToViews()->contains(abstractManager) ||
  1517. !(*m_managerToFactoryToViews())[abstractManager].contains(abstractFactory)) {
  1518. connectNeeded = true;
  1519. } else if ((*m_managerToFactoryToViews())[abstractManager][abstractFactory]
  1520. .contains(this)) {
  1521. return connectNeeded;
  1522. }
  1523. if (m_viewToManagerToFactory()->contains(this) &&
  1524. (*m_viewToManagerToFactory())[this].contains(abstractManager)) {
  1525. unsetFactoryForManager(abstractManager);
  1526. }
  1527. (*m_managerToFactoryToViews())[abstractManager][abstractFactory].append(this);
  1528. (*m_viewToManagerToFactory())[this][abstractManager] = abstractFactory;
  1529. return connectNeeded;
  1530. }
  1531. /*!
  1532. Removes the association between the given \a manager and the
  1533. factory bound to it, automatically calling the
  1534. QtAbstractEditorFactory::removePropertyManager() function if necessary.
  1535. \sa setFactoryForManager()
  1536. */
  1537. void QtAbstractPropertyBrowser::unsetFactoryForManager(QtAbstractPropertyManager *manager)
  1538. {
  1539. if (!m_viewToManagerToFactory()->contains(this) ||
  1540. !(*m_viewToManagerToFactory())[this].contains(manager)) {
  1541. return;
  1542. }
  1543. QtAbstractEditorFactoryBase *abstractFactory =
  1544. (*m_viewToManagerToFactory())[this][manager];
  1545. (*m_viewToManagerToFactory())[this].remove(manager);
  1546. if ((*m_viewToManagerToFactory())[this].isEmpty()) {
  1547. (*m_viewToManagerToFactory()).remove(this);
  1548. }
  1549. (*m_managerToFactoryToViews())[manager][abstractFactory].removeAll(this);
  1550. if ((*m_managerToFactoryToViews())[manager][abstractFactory].isEmpty()) {
  1551. (*m_managerToFactoryToViews())[manager].remove(abstractFactory);
  1552. abstractFactory->breakConnection(manager);
  1553. if ((*m_managerToFactoryToViews())[manager].isEmpty()) {
  1554. (*m_managerToFactoryToViews()).remove(manager);
  1555. }
  1556. }
  1557. }
  1558. /*!
  1559. Returns the current item in the property browser.
  1560. \sa setCurrentItem()
  1561. */
  1562. QtBrowserItem *QtAbstractPropertyBrowser::currentItem() const
  1563. {
  1564. return d_ptr->m_currentItem;
  1565. }
  1566. /*!
  1567. Sets the current item in the property browser to \a item.
  1568. \sa currentItem(), currentItemChanged()
  1569. */
  1570. void QtAbstractPropertyBrowser::setCurrentItem(QtBrowserItem *item)
  1571. {
  1572. QtBrowserItem *oldItem = d_ptr->m_currentItem;
  1573. d_ptr->m_currentItem = item;
  1574. if (oldItem != item)
  1575. emit currentItemChanged(item);
  1576. }
  1577. QT_END_NAMESPACE
  1578. #include "moc_qtpropertybrowser.cpp"