qtbuttonpropertybrowser.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
  4. ** Contact: http://www.qt-project.org/legal
  5. **
  6. ** This file is part of the Qt Solutions component.
  7. **
  8. ** $QT_BEGIN_LICENSE:BSD$
  9. ** You may use this file under the terms of the BSD license as follows:
  10. **
  11. ** "Redistribution and use in source and binary forms, with or without
  12. ** modification, are permitted provided that the following conditions are
  13. ** met:
  14. ** * Redistributions of source code must retain the above copyright
  15. ** notice, this list of conditions and the following disclaimer.
  16. ** * Redistributions in binary form must reproduce the above copyright
  17. ** notice, this list of conditions and the following disclaimer in
  18. ** the documentation and/or other materials provided with the
  19. ** distribution.
  20. ** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
  21. ** of its contributors may be used to endorse or promote products derived
  22. ** from this software without specific prior written permission.
  23. **
  24. **
  25. ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  26. ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  27. ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  28. ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  29. ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  30. ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  31. ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  32. ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  33. ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  34. ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  35. ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
  36. **
  37. ** $QT_END_LICENSE$
  38. **
  39. ****************************************************************************/
  40. #pragma execution_character_set("utf-8")
  41. #include "qtbuttonpropertybrowser.h"
  42. #include <QSet>
  43. #include <QGridLayout>
  44. #include <QLabel>
  45. #include <QTimer>
  46. #include <QMap>
  47. #include <QToolButton>
  48. #include <QStyle>
  49. #if QT_VERSION >= 0x040400
  50. QT_BEGIN_NAMESPACE
  51. #endif
  52. class QtButtonPropertyBrowserPrivate
  53. {
  54. QtButtonPropertyBrowser *q_ptr = nullptr;
  55. Q_DECLARE_PUBLIC(QtButtonPropertyBrowser)
  56. public:
  57. void init(QWidget *parent);
  58. void propertyInserted(QtBrowserItem *index, QtBrowserItem *afterIndex);
  59. void propertyRemoved(QtBrowserItem *index);
  60. void propertyChanged(QtBrowserItem *index);
  61. QWidget *createEditor(QtProperty *property, QWidget *parent) const
  62. { return q_ptr->createEditor(property, parent); }
  63. void slotEditorDestroyed();
  64. void slotUpdate();
  65. void slotToggled(bool checked);
  66. struct WidgetItem
  67. {
  68. WidgetItem() : widget(0), label(0), widgetLabel(0),
  69. button(0), container(0), layout(0), /*line(0), */parent(0), expanded(false) { }
  70. QWidget *widget; // can be null
  71. QLabel *label; // main label with property name
  72. QLabel *widgetLabel; // label substitute showing the current value if there is no widget
  73. QToolButton *button; // expandable button for items with children
  74. QWidget *container; // container which is expanded when the button is clicked
  75. QGridLayout *layout; // layout in container
  76. WidgetItem *parent;
  77. QList<WidgetItem *> children;
  78. bool expanded;
  79. };
  80. private:
  81. void updateLater();
  82. void updateItem(WidgetItem *item);
  83. void insertRow(QGridLayout *layout, int row) const;
  84. void removeRow(QGridLayout *layout, int row) const;
  85. int gridRow(WidgetItem *item) const;
  86. int gridSpan(WidgetItem *item) const;
  87. void setExpanded(WidgetItem *item, bool expanded);
  88. QToolButton *createButton(QWidget *panret = 0) const;
  89. QMap<QtBrowserItem *, WidgetItem *> m_indexToItem;
  90. QMap<WidgetItem *, QtBrowserItem *> m_itemToIndex;
  91. QMap<QWidget *, WidgetItem *> m_widgetToItem;
  92. QMap<QObject *, WidgetItem *> m_buttonToItem;
  93. QGridLayout *m_mainLayout = nullptr;
  94. QList<WidgetItem *> m_children;
  95. QList<WidgetItem *> m_recreateQueue;
  96. };
  97. QToolButton *QtButtonPropertyBrowserPrivate::createButton(QWidget *parent) const
  98. {
  99. QToolButton *button = new QToolButton(parent);
  100. button->setCheckable(true);
  101. button->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed));
  102. button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
  103. button->setArrowType(Qt::DownArrow);
  104. button->setIconSize(QSize(3, 16));
  105. /*
  106. QIcon icon;
  107. icon.addPixmap(q_ptr->style()->standardPixmap(QStyle::SP_ArrowDown), QIcon::Normal, QIcon::Off);
  108. icon.addPixmap(q_ptr->style()->standardPixmap(QStyle::SP_ArrowUp), QIcon::Normal, QIcon::On);
  109. button->setIcon(icon);
  110. */
  111. return button;
  112. }
  113. int QtButtonPropertyBrowserPrivate::gridRow(WidgetItem *item) const
  114. {
  115. QList<WidgetItem *> siblings;
  116. if (item->parent)
  117. siblings = item->parent->children;
  118. else
  119. siblings = m_children;
  120. int row = 0;
  121. QListIterator<WidgetItem *> it(siblings);
  122. while (it.hasNext()) {
  123. WidgetItem *sibling = it.next();
  124. if (sibling == item)
  125. return row;
  126. row += gridSpan(sibling);
  127. }
  128. return -1;
  129. }
  130. int QtButtonPropertyBrowserPrivate::gridSpan(WidgetItem *item) const
  131. {
  132. if (item->container && item->expanded)
  133. return 2;
  134. return 1;
  135. }
  136. void QtButtonPropertyBrowserPrivate::init(QWidget *parent)
  137. {
  138. m_mainLayout = new QGridLayout();
  139. parent->setLayout(m_mainLayout);
  140. QLayoutItem *item = new QSpacerItem(0, 0,
  141. QSizePolicy::Fixed, QSizePolicy::Expanding);
  142. m_mainLayout->addItem(item, 0, 0);
  143. }
  144. void QtButtonPropertyBrowserPrivate::slotEditorDestroyed()
  145. {
  146. QWidget *editor = qobject_cast<QWidget *>(q_ptr->sender());
  147. if (!editor)
  148. return;
  149. if (!m_widgetToItem.contains(editor))
  150. return;
  151. m_widgetToItem[editor]->widget = 0;
  152. m_widgetToItem.remove(editor);
  153. }
  154. void QtButtonPropertyBrowserPrivate::slotUpdate()
  155. {
  156. QListIterator<WidgetItem *> itItem(m_recreateQueue);
  157. while (itItem.hasNext()) {
  158. WidgetItem *item = itItem.next();
  159. WidgetItem *parent = item->parent;
  160. QWidget *w = 0;
  161. QGridLayout *l = 0;
  162. const int oldRow = gridRow(item);
  163. if (parent) {
  164. w = parent->container;
  165. l = parent->layout;
  166. } else {
  167. w = q_ptr;
  168. l = m_mainLayout;
  169. }
  170. int span = 1;
  171. if (!item->widget && !item->widgetLabel)
  172. span = 2;
  173. item->label = new QLabel(w);
  174. item->label->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
  175. l->addWidget(item->label, oldRow, 0, 1, span);
  176. updateItem(item);
  177. }
  178. m_recreateQueue.clear();
  179. }
  180. void QtButtonPropertyBrowserPrivate::setExpanded(WidgetItem *item, bool expanded)
  181. {
  182. if (item->expanded == expanded)
  183. return;
  184. if (!item->container)
  185. return;
  186. item->expanded = expanded;
  187. const int row = gridRow(item);
  188. WidgetItem *parent = item->parent;
  189. QGridLayout *l = 0;
  190. if (parent)
  191. l = parent->layout;
  192. else
  193. l = m_mainLayout;
  194. if (expanded) {
  195. insertRow(l, row + 1);
  196. l->addWidget(item->container, row + 1, 0, 1, 2);
  197. item->container->show();
  198. } else {
  199. l->removeWidget(item->container);
  200. item->container->hide();
  201. removeRow(l, row + 1);
  202. }
  203. item->button->setChecked(expanded);
  204. item->button->setArrowType(expanded ? Qt::UpArrow : Qt::DownArrow);
  205. }
  206. void QtButtonPropertyBrowserPrivate::slotToggled(bool checked)
  207. {
  208. WidgetItem *item = m_buttonToItem.value(q_ptr->sender());
  209. if (!item)
  210. return;
  211. setExpanded(item, checked);
  212. if (checked)
  213. emit q_ptr->expanded(m_itemToIndex.value(item));
  214. else
  215. emit q_ptr->collapsed(m_itemToIndex.value(item));
  216. }
  217. void QtButtonPropertyBrowserPrivate::updateLater()
  218. {
  219. QTimer::singleShot(0, q_ptr, SLOT(slotUpdate()));
  220. }
  221. void QtButtonPropertyBrowserPrivate::propertyInserted(QtBrowserItem *index, QtBrowserItem *afterIndex)
  222. {
  223. WidgetItem *afterItem = m_indexToItem.value(afterIndex);
  224. WidgetItem *parentItem = m_indexToItem.value(index->parent());
  225. WidgetItem *newItem = new WidgetItem();
  226. newItem->parent = parentItem;
  227. QGridLayout *layout = 0;
  228. QWidget *parentWidget = 0;
  229. int row = -1;
  230. if (!afterItem) {
  231. row = 0;
  232. if (parentItem)
  233. parentItem->children.insert(0, newItem);
  234. else
  235. m_children.insert(0, newItem);
  236. } else {
  237. row = gridRow(afterItem) + gridSpan(afterItem);
  238. if (parentItem)
  239. parentItem->children.insert(parentItem->children.indexOf(afterItem) + 1, newItem);
  240. else
  241. m_children.insert(m_children.indexOf(afterItem) + 1, newItem);
  242. }
  243. if (!parentItem) {
  244. layout = m_mainLayout;
  245. parentWidget = q_ptr;
  246. } else {
  247. if (!parentItem->container) {
  248. m_recreateQueue.removeAll(parentItem);
  249. WidgetItem *grandParent = parentItem->parent;
  250. QGridLayout *l = 0;
  251. const int oldRow = gridRow(parentItem);
  252. if (grandParent) {
  253. l = grandParent->layout;
  254. } else {
  255. l = m_mainLayout;
  256. }
  257. QFrame *container = new QFrame();
  258. container->setFrameShape(QFrame::Panel);
  259. container->setFrameShadow(QFrame::Raised);
  260. parentItem->container = container;
  261. parentItem->button = createButton();
  262. m_buttonToItem[parentItem->button] = parentItem;
  263. q_ptr->connect(parentItem->button, SIGNAL(toggled(bool)), q_ptr, SLOT(slotToggled(bool)));
  264. parentItem->layout = new QGridLayout();
  265. container->setLayout(parentItem->layout);
  266. if (parentItem->label) {
  267. l->removeWidget(parentItem->label);
  268. delete parentItem->label;
  269. parentItem->label = 0;
  270. }
  271. int span = 1;
  272. if (!parentItem->widget && !parentItem->widgetLabel)
  273. span = 2;
  274. l->addWidget(parentItem->button, oldRow, 0, 1, span);
  275. updateItem(parentItem);
  276. }
  277. layout = parentItem->layout;
  278. parentWidget = parentItem->container;
  279. }
  280. newItem->label = new QLabel(parentWidget);
  281. newItem->label->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
  282. newItem->widget = createEditor(index->property(), parentWidget);
  283. if (newItem->widget) {
  284. QObject::connect(newItem->widget, SIGNAL(destroyed()), q_ptr, SLOT(slotEditorDestroyed()));
  285. m_widgetToItem[newItem->widget] = newItem;
  286. } else if (index->property()->hasValue()) {
  287. newItem->widgetLabel = new QLabel(parentWidget);
  288. newItem->widgetLabel->setSizePolicy(QSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed));
  289. }
  290. insertRow(layout, row);
  291. int span = 1;
  292. if (newItem->widget)
  293. layout->addWidget(newItem->widget, row, 1);
  294. else if (newItem->widgetLabel)
  295. layout->addWidget(newItem->widgetLabel, row, 1);
  296. else
  297. span = 2;
  298. layout->addWidget(newItem->label, row, 0, span, 1);
  299. m_itemToIndex[newItem] = index;
  300. m_indexToItem[index] = newItem;
  301. updateItem(newItem);
  302. }
  303. void QtButtonPropertyBrowserPrivate::propertyRemoved(QtBrowserItem *index)
  304. {
  305. WidgetItem *item = m_indexToItem.value(index);
  306. m_indexToItem.remove(index);
  307. m_itemToIndex.remove(item);
  308. WidgetItem *parentItem = item->parent;
  309. const int row = gridRow(item);
  310. if (parentItem)
  311. parentItem->children.removeAt(parentItem->children.indexOf(item));
  312. else
  313. m_children.removeAt(m_children.indexOf(item));
  314. const int colSpan = gridSpan(item);
  315. m_buttonToItem.remove(item->button);
  316. if (item->widget)
  317. delete item->widget;
  318. if (item->label)
  319. delete item->label;
  320. if (item->widgetLabel)
  321. delete item->widgetLabel;
  322. if (item->button)
  323. delete item->button;
  324. if (item->container)
  325. delete item->container;
  326. if (!parentItem) {
  327. removeRow(m_mainLayout, row);
  328. if (colSpan > 1)
  329. removeRow(m_mainLayout, row);
  330. } else if (parentItem->children.count() != 0) {
  331. removeRow(parentItem->layout, row);
  332. if (colSpan > 1)
  333. removeRow(parentItem->layout, row);
  334. } else {
  335. const WidgetItem *grandParent = parentItem->parent;
  336. QGridLayout *l = 0;
  337. if (grandParent) {
  338. l = grandParent->layout;
  339. } else {
  340. l = m_mainLayout;
  341. }
  342. const int parentRow = gridRow(parentItem);
  343. const int parentSpan = gridSpan(parentItem);
  344. l->removeWidget(parentItem->button);
  345. l->removeWidget(parentItem->container);
  346. delete parentItem->button;
  347. delete parentItem->container;
  348. parentItem->button = 0;
  349. parentItem->container = 0;
  350. parentItem->layout = 0;
  351. if (!m_recreateQueue.contains(parentItem))
  352. m_recreateQueue.append(parentItem);
  353. if (parentSpan > 1)
  354. removeRow(l, parentRow + 1);
  355. updateLater();
  356. }
  357. m_recreateQueue.removeAll(item);
  358. delete item;
  359. }
  360. void QtButtonPropertyBrowserPrivate::insertRow(QGridLayout *layout, int row) const
  361. {
  362. QMap<QLayoutItem *, QRect> itemToPos;
  363. int idx = 0;
  364. while (idx < layout->count()) {
  365. int r, c, rs, cs;
  366. layout->getItemPosition(idx, &r, &c, &rs, &cs);
  367. if (r >= row) {
  368. itemToPos[layout->takeAt(idx)] = QRect(r + 1, c, rs, cs);
  369. } else {
  370. idx++;
  371. }
  372. }
  373. const QMap<QLayoutItem *, QRect>::ConstIterator icend = itemToPos.constEnd();
  374. for(QMap<QLayoutItem *, QRect>::ConstIterator it = itemToPos.constBegin(); it != icend; ++it) {
  375. const QRect r = it.value();
  376. layout->addItem(it.key(), r.x(), r.y(), r.width(), r.height());
  377. }
  378. }
  379. void QtButtonPropertyBrowserPrivate::removeRow(QGridLayout *layout, int row) const
  380. {
  381. QMap<QLayoutItem *, QRect> itemToPos;
  382. int idx = 0;
  383. while (idx < layout->count()) {
  384. int r, c, rs, cs;
  385. layout->getItemPosition(idx, &r, &c, &rs, &cs);
  386. if (r > row) {
  387. itemToPos[layout->takeAt(idx)] = QRect(r - 1, c, rs, cs);
  388. } else {
  389. idx++;
  390. }
  391. }
  392. const QMap<QLayoutItem *, QRect>::ConstIterator icend = itemToPos.constEnd();
  393. for(QMap<QLayoutItem *, QRect>::ConstIterator it = itemToPos.constBegin(); it != icend; ++it) {
  394. const QRect r = it.value();
  395. layout->addItem(it.key(), r.x(), r.y(), r.width(), r.height());
  396. }
  397. }
  398. void QtButtonPropertyBrowserPrivate::propertyChanged(QtBrowserItem *index)
  399. {
  400. WidgetItem *item = m_indexToItem.value(index);
  401. updateItem(item);
  402. }
  403. void QtButtonPropertyBrowserPrivate::updateItem(WidgetItem *item)
  404. {
  405. QtProperty *property = m_itemToIndex[item]->property();
  406. if (item->button) {
  407. QFont font = item->button->font();
  408. font.setUnderline(property->isModified());
  409. item->button->setFont(font);
  410. item->button->setText(property->propertyName());
  411. item->button->setToolTip(property->toolTip());
  412. item->button->setStatusTip(property->statusTip());
  413. item->button->setWhatsThis(property->whatsThis());
  414. item->button->setEnabled(property->isEnabled());
  415. }
  416. if (item->label) {
  417. QFont font = item->label->font();
  418. font.setUnderline(property->isModified());
  419. item->label->setFont(font);
  420. item->label->setText(property->propertyName());
  421. item->label->setToolTip(property->toolTip());
  422. item->label->setStatusTip(property->statusTip());
  423. item->label->setWhatsThis(property->whatsThis());
  424. item->label->setEnabled(property->isEnabled());
  425. }
  426. if (item->widgetLabel) {
  427. QFont font = item->widgetLabel->font();
  428. font.setUnderline(false);
  429. item->widgetLabel->setFont(font);
  430. item->widgetLabel->setText(property->valueText());
  431. item->widgetLabel->setToolTip(property->valueText());
  432. item->widgetLabel->setEnabled(property->isEnabled());
  433. }
  434. if (item->widget) {
  435. QFont font = item->widget->font();
  436. font.setUnderline(false);
  437. item->widget->setFont(font);
  438. item->widget->setEnabled(property->isEnabled());
  439. item->widget->setToolTip(property->valueText());
  440. }
  441. }
  442. /*!
  443. \class QtButtonPropertyBrowser
  444. \brief The QtButtonPropertyBrowser class provides a drop down QToolButton
  445. based property browser.
  446. A property browser is a widget that enables the user to edit a
  447. given set of properties. Each property is represented by a label
  448. specifying the property's name, and an editing widget (e.g. a line
  449. edit or a combobox) holding its value. A property can have zero or
  450. more subproperties.
  451. QtButtonPropertyBrowser provides drop down button for all nested
  452. properties, i.e. subproperties are enclosed by a container associated with
  453. the drop down button. The parent property's name is displayed as button text. For example:
  454. \image qtbuttonpropertybrowser.png
  455. Use the QtAbstractPropertyBrowser API to add, insert and remove
  456. properties from an instance of the QtButtonPropertyBrowser
  457. class. The properties themselves are created and managed by
  458. implementations of the QtAbstractPropertyManager class.
  459. \sa QtTreePropertyBrowser, QtAbstractPropertyBrowser
  460. */
  461. /*!
  462. \fn void QtButtonPropertyBrowser::collapsed(QtBrowserItem *item)
  463. This signal is emitted when the \a item is collapsed.
  464. \sa expanded(), setExpanded()
  465. */
  466. /*!
  467. \fn void QtButtonPropertyBrowser::expanded(QtBrowserItem *item)
  468. This signal is emitted when the \a item is expanded.
  469. \sa collapsed(), setExpanded()
  470. */
  471. /*!
  472. Creates a property browser with the given \a parent.
  473. */
  474. QtButtonPropertyBrowser::QtButtonPropertyBrowser(QWidget *parent)
  475. : QtAbstractPropertyBrowser(parent)
  476. {
  477. d_ptr = new QtButtonPropertyBrowserPrivate;
  478. d_ptr->q_ptr = this;
  479. d_ptr->init(this);
  480. }
  481. /*!
  482. Destroys this property browser.
  483. Note that the properties that were inserted into this browser are
  484. \e not destroyed since they may still be used in other
  485. browsers. The properties are owned by the manager that created
  486. them.
  487. \sa QtProperty, QtAbstractPropertyManager
  488. */
  489. QtButtonPropertyBrowser::~QtButtonPropertyBrowser()
  490. {
  491. const QMap<QtButtonPropertyBrowserPrivate::WidgetItem *, QtBrowserItem *>::ConstIterator icend = d_ptr->m_itemToIndex.constEnd();
  492. for (QMap<QtButtonPropertyBrowserPrivate::WidgetItem *, QtBrowserItem *>::ConstIterator it = d_ptr->m_itemToIndex.constBegin(); it != icend; ++it)
  493. delete it.key();
  494. delete d_ptr;
  495. }
  496. /*!
  497. \reimp
  498. */
  499. void QtButtonPropertyBrowser::itemInserted(QtBrowserItem *item, QtBrowserItem *afterItem)
  500. {
  501. d_ptr->propertyInserted(item, afterItem);
  502. }
  503. /*!
  504. \reimp
  505. */
  506. void QtButtonPropertyBrowser::itemRemoved(QtBrowserItem *item)
  507. {
  508. d_ptr->propertyRemoved(item);
  509. }
  510. /*!
  511. \reimp
  512. */
  513. void QtButtonPropertyBrowser::itemChanged(QtBrowserItem *item)
  514. {
  515. d_ptr->propertyChanged(item);
  516. }
  517. /*!
  518. Sets the \a item to either collapse or expanded, depending on the value of \a expanded.
  519. \sa isExpanded(), expanded(), collapsed()
  520. */
  521. void QtButtonPropertyBrowser::setExpanded(QtBrowserItem *item, bool expanded)
  522. {
  523. QtButtonPropertyBrowserPrivate::WidgetItem *itm = d_ptr->m_indexToItem.value(item);
  524. if (itm)
  525. d_ptr->setExpanded(itm, expanded);
  526. }
  527. /*!
  528. Returns true if the \a item is expanded; otherwise returns false.
  529. \sa setExpanded()
  530. */
  531. bool QtButtonPropertyBrowser::isExpanded(QtBrowserItem *item) const
  532. {
  533. QtButtonPropertyBrowserPrivate::WidgetItem *itm = d_ptr->m_indexToItem.value(item);
  534. if (itm)
  535. return itm->expanded;
  536. return false;
  537. }
  538. #if QT_VERSION >= 0x040400
  539. QT_END_NAMESPACE
  540. #endif
  541. #include "moc_qtbuttonpropertybrowser.cpp"