ctkCheckableModelHelper.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0.txt
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. // Qt includes
  15. #include <QAbstractItemModel>
  16. #include <QApplication>
  17. #include <QDebug>
  18. #include <QStandardItemModel>
  19. #include <QWeakPointer>
  20. // CTK includes
  21. #include "ctkCheckableModelHelper.h"
  22. //-----------------------------------------------------------------------------
  23. class ctkCheckableModelHelperPrivate
  24. {
  25. Q_DECLARE_PUBLIC(ctkCheckableModelHelper);
  26. protected:
  27. ctkCheckableModelHelper* const q_ptr;
  28. public:
  29. ctkCheckableModelHelperPrivate(ctkCheckableModelHelper& object);
  30. ~ctkCheckableModelHelperPrivate();
  31. void init();
  32. /// Set index checkstate and call propagate
  33. void setIndexCheckState(const QModelIndex& index, Qt::CheckState checkState);
  34. /// Return the depth in the model tree of the index.
  35. /// -1 if the index is the root element a header or a header, 0 if the index
  36. /// is a toplevel index, 1 if its parent is toplevel, 2 if its grandparent is
  37. /// toplevel, etc.
  38. int indexDepth(const QModelIndex& modelIndex)const;
  39. /// Set the checkstate of the index based on its children and grand children
  40. void updateCheckState(const QModelIndex& modelIndex);
  41. /// Set the check state of the index to all its children and grand children
  42. void propagateCheckStateToChildren(const QModelIndex& modelIndex);
  43. Qt::CheckState checkState(const QModelIndex& index, bool *checkable)const;
  44. void setCheckState(const QModelIndex& index, Qt::CheckState newCheckState);
  45. void forceCheckability(const QModelIndex& index);
  46. QWeakPointer<QAbstractItemModel> Model;
  47. QModelIndex RootIndex;
  48. Qt::Orientation Orientation;
  49. bool HeaderIsUpdating;
  50. bool ItemsAreUpdating;
  51. bool ForceCheckability;
  52. /// 0 means no propagation
  53. /// -1 means unlimited propagation
  54. /// 1 means propagate to top-level indexes
  55. /// 2 means propagate to top-level and their children
  56. /// ...
  57. int PropagateDepth;
  58. Qt::CheckState DefaultCheckState;
  59. };
  60. //----------------------------------------------------------------------------
  61. ctkCheckableModelHelperPrivate::ctkCheckableModelHelperPrivate(ctkCheckableModelHelper& object)
  62. : q_ptr(&object)
  63. {
  64. this->HeaderIsUpdating = false;
  65. this->ItemsAreUpdating = false;
  66. this->ForceCheckability = false;
  67. this->PropagateDepth = -1;
  68. this->DefaultCheckState = Qt::Unchecked;
  69. }
  70. //-----------------------------------------------------------------------------
  71. ctkCheckableModelHelperPrivate::~ctkCheckableModelHelperPrivate()
  72. {
  73. }
  74. //----------------------------------------------------------------------------
  75. void ctkCheckableModelHelperPrivate::init()
  76. {
  77. }
  78. //----------------------------------------------------------------------------
  79. Qt::CheckState ctkCheckableModelHelperPrivate::checkState(
  80. const QModelIndex& index, bool *checkable)const
  81. {
  82. Q_Q(const ctkCheckableModelHelper);
  83. QVariant indexCheckState = index != q->rootIndex() ?
  84. q->model()->data(index, Qt::CheckStateRole):
  85. q->model()->headerData(0, q->orientation(), Qt::CheckStateRole);
  86. return static_cast<Qt::CheckState>(indexCheckState.toInt(checkable));
  87. }
  88. //----------------------------------------------------------------------------
  89. void ctkCheckableModelHelperPrivate::setCheckState(
  90. const QModelIndex& modelIndex, Qt::CheckState newCheckState)
  91. {
  92. Q_Q(ctkCheckableModelHelper);
  93. if (modelIndex != q->rootIndex())
  94. {
  95. q->model()->setData(modelIndex, newCheckState, Qt::CheckStateRole);
  96. }
  97. else
  98. {
  99. q->model()->setHeaderData(0, q->orientation(), newCheckState, Qt::CheckStateRole);
  100. }
  101. }
  102. //----------------------------------------------------------------------------
  103. void ctkCheckableModelHelperPrivate::setIndexCheckState(
  104. const QModelIndex& index, Qt::CheckState checkState)
  105. {
  106. bool checkable = false;
  107. this->checkState(index, &checkable);
  108. if (!checkable && !this->ForceCheckability)
  109. {
  110. // The index is not checkable and we don't want to force checkability
  111. return;
  112. }
  113. this->setCheckState(index, checkState);
  114. this->propagateCheckStateToChildren(index);
  115. }
  116. //-----------------------------------------------------------------------------
  117. int ctkCheckableModelHelperPrivate::indexDepth(const QModelIndex& modelIndex)const
  118. {
  119. int depth = -1;
  120. QModelIndex parentIndex = modelIndex;
  121. while (parentIndex.isValid())
  122. {
  123. ++depth;
  124. parentIndex = parentIndex.parent();
  125. }
  126. return depth;
  127. }
  128. //-----------------------------------------------------------------------------
  129. void ctkCheckableModelHelperPrivate
  130. ::updateCheckState(const QModelIndex& modelIndex)
  131. {
  132. Q_Q(ctkCheckableModelHelper);
  133. bool checkable = false;
  134. int oldCheckState = this->checkState(modelIndex, &checkable);
  135. if (!checkable)
  136. {
  137. return;
  138. }
  139. Qt::CheckState newCheckState = Qt::PartiallyChecked;
  140. bool firstCheckableChild = true;
  141. const int rowCount = q->orientation() == Qt::Horizontal ?
  142. q->model()->rowCount(modelIndex) : 1;
  143. const int columnCount = q->orientation() == Qt::Vertical ?
  144. q->model()->columnCount(modelIndex) : 1;
  145. for (int r = 0; r < rowCount; ++r)
  146. {
  147. for (int c = 0; c < columnCount; ++c)
  148. {
  149. QModelIndex child = q->model()->index(r, c, modelIndex);
  150. QVariant childCheckState = q->model()->data(child, Qt::CheckStateRole);
  151. int childState = childCheckState.toInt(&checkable);
  152. if (!checkable)
  153. {
  154. continue;
  155. }
  156. if (firstCheckableChild)
  157. {
  158. newCheckState = static_cast<Qt::CheckState>(childState);
  159. firstCheckableChild = false;
  160. }
  161. if (newCheckState != childState)
  162. {
  163. newCheckState = Qt::PartiallyChecked;
  164. }
  165. if (newCheckState == Qt::PartiallyChecked)
  166. {
  167. break;
  168. }
  169. }
  170. if (!firstCheckableChild && newCheckState == Qt::PartiallyChecked)
  171. {
  172. break;
  173. }
  174. }
  175. if (oldCheckState == newCheckState)
  176. {
  177. return;
  178. }
  179. this->setCheckState(modelIndex, newCheckState);
  180. if (modelIndex != q->rootIndex())
  181. {
  182. this->updateCheckState(modelIndex.parent());
  183. }
  184. }
  185. //-----------------------------------------------------------------------------
  186. void ctkCheckableModelHelperPrivate
  187. ::propagateCheckStateToChildren(const QModelIndex& modelIndex)
  188. {
  189. Q_Q(ctkCheckableModelHelper);
  190. int indexDepth = this->indexDepth(modelIndex);
  191. if (this->PropagateDepth == 0 ||
  192. !(indexDepth < this->PropagateDepth || this->PropagateDepth == -1))
  193. {
  194. return;
  195. }
  196. bool checkable = false;
  197. Qt::CheckState checkState = this->checkState(modelIndex, &checkable);
  198. if (!checkable || checkState == Qt::PartiallyChecked)
  199. {
  200. return;
  201. }
  202. while (this->ForceCheckability && q->model()->canFetchMore(modelIndex))
  203. {
  204. q->model()->fetchMore(modelIndex);
  205. }
  206. const int rowCount = q->orientation() == Qt::Horizontal ?
  207. q->model()->rowCount(modelIndex) : 1;
  208. const int columnCount = q->orientation() == Qt::Vertical ?
  209. q->model()->columnCount(modelIndex) : 1;
  210. for (int r = 0; r < rowCount; ++r)
  211. {
  212. for (int c = 0; c < columnCount; ++c)
  213. {
  214. QModelIndex child = q->model()->index(r, c, modelIndex);
  215. this->setIndexCheckState(child, checkState);
  216. }
  217. }
  218. }
  219. //-----------------------------------------------------------------------------
  220. void ctkCheckableModelHelperPrivate
  221. ::forceCheckability(const QModelIndex& modelIndex)
  222. {
  223. Q_Q(ctkCheckableModelHelper);
  224. if (!this->ForceCheckability)
  225. {
  226. return;
  227. }
  228. this->setCheckState(modelIndex, this->DefaultCheckState);
  229. // Apparently (not sure) some views require the User-checkable
  230. // flag to be set to be able to show the checkboxes
  231. if (qobject_cast<QStandardItemModel*>(q->model()))
  232. {
  233. QStandardItem* item = modelIndex != q->rootIndex() ?
  234. qobject_cast<QStandardItemModel*>(q->model())->itemFromIndex(modelIndex) :
  235. (q->orientation() == Qt::Horizontal ?
  236. qobject_cast<QStandardItemModel*>(q->model())->horizontalHeaderItem(0) :
  237. qobject_cast<QStandardItemModel*>(q->model())->verticalHeaderItem(0));
  238. item->setCheckable(true);
  239. }
  240. }
  241. //----------------------------------------------------------------------------
  242. ctkCheckableModelHelper::ctkCheckableModelHelper(
  243. Qt::Orientation orient, QObject* objectParent)
  244. : QObject(objectParent)
  245. , d_ptr(new ctkCheckableModelHelperPrivate(*this))
  246. {
  247. Q_D(ctkCheckableModelHelper);
  248. d->Orientation = orient;
  249. d->init();
  250. }
  251. //-----------------------------------------------------------------------------
  252. ctkCheckableModelHelper::~ctkCheckableModelHelper()
  253. {
  254. }
  255. //-----------------------------------------------------------------------------
  256. Qt::Orientation ctkCheckableModelHelper::orientation()const
  257. {
  258. Q_D(const ctkCheckableModelHelper);
  259. return d->Orientation;
  260. }
  261. //-----------------------------------------------------------------------------
  262. QAbstractItemModel* ctkCheckableModelHelper::model()const
  263. {
  264. Q_D(const ctkCheckableModelHelper);
  265. return d->Model.isNull() ? 0 : d->Model.data();
  266. }
  267. //-----------------------------------------------------------------------------
  268. void ctkCheckableModelHelper::setModel(QAbstractItemModel *newModel)
  269. {
  270. Q_D(ctkCheckableModelHelper);
  271. QAbstractItemModel *current = this->model();
  272. if (current == newModel)
  273. {
  274. return;
  275. }
  276. if(current)
  277. {
  278. this->disconnect(
  279. current, SIGNAL(headerDataChanged(Qt::Orientation,int,int)),
  280. this, SLOT(onHeaderDataChanged(Qt::Orientation,int,int)));
  281. this->disconnect(
  282. current, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
  283. this, SLOT(onDataChanged(QModelIndex,QModelIndex)));
  284. this->disconnect(
  285. current, SIGNAL(columnsInserted(QModelIndex,int,int)),
  286. this, SLOT(onColumnsInserted(QModelIndex,int,int)));
  287. this->disconnect(
  288. current, SIGNAL(rowsInserted(QModelIndex,int,int)),
  289. this, SLOT(onRowsInserted(QModelIndex,int,int)));
  290. }
  291. d->Model = newModel;
  292. if(newModel)
  293. {
  294. this->connect(
  295. newModel, SIGNAL(headerDataChanged(Qt::Orientation,int,int)),
  296. this, SLOT(onHeaderDataChanged(Qt::Orientation,int,int)));
  297. if (d->PropagateDepth != 0)
  298. {
  299. this->connect(
  300. newModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
  301. this, SLOT(onDataChanged(QModelIndex,QModelIndex)));
  302. }
  303. this->connect(
  304. newModel, SIGNAL(columnsInserted(QModelIndex,int,int)),
  305. this, SLOT(onColumnsInserted(QModelIndex,int,int)));
  306. this->connect(
  307. newModel, SIGNAL(rowsInserted(QModelIndex,int,int)),
  308. this, SLOT(onRowsInserted(QModelIndex,int,int)));
  309. if (d->ForceCheckability)
  310. {
  311. foreach(QModelIndex index, newModel->match(newModel->index(0,0), Qt::CheckStateRole, QVariant(), -1,Qt::MatchRecursive))
  312. {
  313. d->forceCheckability(index);
  314. }
  315. d->forceCheckability(this->rootIndex());
  316. }
  317. this->updateHeadersFromItems();
  318. }
  319. }
  320. //-----------------------------------------------------------------------------
  321. QModelIndex ctkCheckableModelHelper::rootIndex()const
  322. {
  323. Q_D(const ctkCheckableModelHelper);
  324. return d->RootIndex;
  325. }
  326. //-----------------------------------------------------------------------------
  327. void ctkCheckableModelHelper::setRootIndex(const QModelIndex &index)
  328. {
  329. Q_D(ctkCheckableModelHelper);
  330. d->RootIndex = index;
  331. if (d->PropagateDepth != 0)
  332. {
  333. this->updateHeadersFromItems();
  334. }
  335. }
  336. //-----------------------------------------------------------------------------
  337. void ctkCheckableModelHelper::setPropagateDepth(int depth)
  338. {
  339. Q_D(ctkCheckableModelHelper);
  340. if (d->PropagateDepth == depth)
  341. {
  342. return;
  343. }
  344. d->PropagateDepth = depth;
  345. if (!this->model())
  346. {
  347. return;
  348. }
  349. if (depth != 0)
  350. {
  351. this->connect(
  352. this->model(), SIGNAL(dataChanged(QModelIndex,QModelIndex)),
  353. this, SLOT(onDataChanged(QModelIndex,QModelIndex)), Qt::UniqueConnection);
  354. this->updateHeadersFromItems();
  355. }
  356. else
  357. {
  358. this->disconnect(
  359. this->model(), SIGNAL(dataChanged(QModelIndex,QModelIndex)),
  360. this, SLOT(onDataChanged(QModelIndex,QModelIndex)));
  361. }
  362. }
  363. //-----------------------------------------------------------------------------
  364. int ctkCheckableModelHelper::propagateDepth()const
  365. {
  366. Q_D(const ctkCheckableModelHelper);
  367. return d->PropagateDepth;
  368. }
  369. //-----------------------------------------------------------------------------
  370. void ctkCheckableModelHelper::setForceCheckability(bool force)
  371. {
  372. Q_D(ctkCheckableModelHelper);
  373. if (d->ForceCheckability == force)
  374. {
  375. return;
  376. }
  377. d->ForceCheckability = force;
  378. if (this->model())
  379. {
  380. d->propagateCheckStateToChildren(this->rootIndex());
  381. }
  382. }
  383. //-----------------------------------------------------------------------------
  384. bool ctkCheckableModelHelper::forceCheckability()const
  385. {
  386. Q_D(const ctkCheckableModelHelper);
  387. return d->ForceCheckability;
  388. }
  389. //-----------------------------------------------------------------------------
  390. void ctkCheckableModelHelper::setDefaultCheckState(Qt::CheckState defaultCheckState)
  391. {
  392. Q_D(ctkCheckableModelHelper);
  393. d->DefaultCheckState = defaultCheckState;
  394. }
  395. //-----------------------------------------------------------------------------
  396. Qt::CheckState ctkCheckableModelHelper::defaultCheckState()const
  397. {
  398. Q_D(const ctkCheckableModelHelper);
  399. return d->DefaultCheckState;
  400. }
  401. //-----------------------------------------------------------------------------
  402. void ctkCheckableModelHelper::setHeaderCheckState(int section, Qt::CheckState checkState)
  403. {
  404. QAbstractItemModel *current = this->model();
  405. if(current == 0)
  406. {
  407. return;
  408. }
  409. current->setHeaderData(section, this->orientation(),
  410. checkState, Qt::CheckStateRole);
  411. }
  412. //-----------------------------------------------------------------------------
  413. void ctkCheckableModelHelper::setCheckState(const QModelIndex& index, Qt::CheckState checkState)
  414. {
  415. QAbstractItemModel *current = this->model();
  416. if(current == 0)
  417. {
  418. return;
  419. }
  420. current->setData(index, checkState, Qt::CheckStateRole);
  421. }
  422. //-----------------------------------------------------------------------------
  423. void ctkCheckableModelHelper::toggleCheckState(const QModelIndex& modelIndex)
  424. {
  425. // If the section is checkable, toggle the check state.
  426. if(!this->isCheckable(modelIndex))
  427. {
  428. return;
  429. }
  430. // I've no strong feeling to turn the state checked or unchecked when the
  431. // state is PartiallyChecked.
  432. this->setCheckState(modelIndex,
  433. this->checkState(modelIndex) == Qt::Checked ? Qt::Unchecked : Qt::Checked);
  434. }
  435. //-----------------------------------------------------------------------------
  436. void ctkCheckableModelHelper::toggleHeaderCheckState(int section)
  437. {
  438. // If the section is checkable, toggle the check state.
  439. if(!this->isHeaderCheckable(section))
  440. {
  441. return;
  442. }
  443. // I've no strong feeling to turn the state checked or unchecked when the
  444. // state is PartiallyChecked.
  445. this->setHeaderCheckState(section,
  446. this->headerCheckState(section) == Qt::Checked ? Qt::Unchecked : Qt::Checked);
  447. }
  448. //-----------------------------------------------------------------------------
  449. void ctkCheckableModelHelper::onHeaderDataChanged(Qt::Orientation orient,
  450. int firstSection,
  451. int lastSection)
  452. {
  453. Q_D(ctkCheckableModelHelper);
  454. Q_UNUSED(firstSection);
  455. Q_UNUSED(lastSection);
  456. if(orient != this->orientation())
  457. {
  458. return;
  459. }
  460. bool oldItemsAreUpdating = d->ItemsAreUpdating;
  461. if (!d->ItemsAreUpdating)
  462. {
  463. d->ItemsAreUpdating = true;
  464. d->propagateCheckStateToChildren(this->rootIndex());
  465. }
  466. d->ItemsAreUpdating = oldItemsAreUpdating;
  467. }
  468. //-----------------------------------------------------------------------------
  469. void ctkCheckableModelHelper::updateHeadersFromItems()
  470. {
  471. Q_D(ctkCheckableModelHelper);
  472. QAbstractItemModel *currentModel = this->model();
  473. if (!currentModel)
  474. {
  475. return;
  476. }
  477. d->updateCheckState(QModelIndex());
  478. }
  479. //-----------------------------------------------------------------------------
  480. void ctkCheckableModelHelper::onDataChanged(const QModelIndex & topLeft,
  481. const QModelIndex & bottomRight)
  482. {
  483. Q_UNUSED(bottomRight);
  484. Q_D(ctkCheckableModelHelper);
  485. if(d->ItemsAreUpdating || d->PropagateDepth == 0)
  486. {
  487. return;
  488. }
  489. bool checkable = false;
  490. d->checkState(topLeft, &checkable);
  491. if (!checkable)
  492. {
  493. return;
  494. }
  495. d->ItemsAreUpdating = true;
  496. // TODO: handle topLeft "TO bottomRight"
  497. d->propagateCheckStateToChildren(topLeft);
  498. d->updateCheckState(topLeft.parent());
  499. d->ItemsAreUpdating = false;
  500. }
  501. //-----------------------------------------------------------------------------
  502. void ctkCheckableModelHelper::onColumnsInserted(const QModelIndex &parentIndex,
  503. int start, int end)
  504. {
  505. Q_D(ctkCheckableModelHelper);
  506. if (this->orientation() == Qt::Horizontal)
  507. {
  508. if (start == 0)
  509. {
  510. this->updateHeadersFromItems();
  511. }
  512. }
  513. else
  514. {
  515. if (d->ForceCheckability)
  516. {
  517. for (int i = start; i <= end; ++i)
  518. {
  519. QModelIndex index = this->model()->index(0, i, parentIndex);
  520. d->forceCheckability(index);
  521. }
  522. }
  523. this->onDataChanged(this->model()->index(0, start, parentIndex),
  524. this->model()->index(0, end, parentIndex));
  525. }
  526. }
  527. //-----------------------------------------------------------------------------
  528. void ctkCheckableModelHelper::onRowsInserted(const QModelIndex &parentIndex,
  529. int start, int end)
  530. {
  531. Q_D(ctkCheckableModelHelper);
  532. if (this->orientation() == Qt::Vertical)
  533. {
  534. if (start == 0)
  535. {
  536. this->updateHeadersFromItems();
  537. }
  538. }
  539. else
  540. {
  541. if (d->ForceCheckability)
  542. {
  543. for (int i = start; i <= end; ++i)
  544. {
  545. QModelIndex index = this->model()->index(i, 0, parentIndex);
  546. d->forceCheckability(index);
  547. }
  548. }
  549. this->onDataChanged(this->model()->index(start, 0, parentIndex),
  550. this->model()->index(end, 0, parentIndex));
  551. }
  552. }
  553. //-----------------------------------------------------------------------------
  554. bool ctkCheckableModelHelper::isHeaderCheckable(int section)const
  555. {
  556. return !this->model()->headerData(section, this->orientation(), Qt::CheckStateRole).isNull();
  557. }
  558. //-----------------------------------------------------------------------------
  559. bool ctkCheckableModelHelper::isCheckable(const QModelIndex& index)const
  560. {
  561. return !this->model()->data(index, Qt::CheckStateRole).isNull();
  562. }
  563. //-----------------------------------------------------------------------------
  564. Qt::CheckState ctkCheckableModelHelper::headerCheckState(int section)const
  565. {
  566. return static_cast<Qt::CheckState>(
  567. this->model()->headerData(section, this->orientation(), Qt::CheckStateRole).toInt());
  568. }
  569. //-----------------------------------------------------------------------------
  570. Qt::CheckState ctkCheckableModelHelper::checkState(const QModelIndex& index)const
  571. {
  572. return static_cast<Qt::CheckState>(
  573. this->model()->data(index, Qt::CheckStateRole).toInt());
  574. }
  575. //-----------------------------------------------------------------------------
  576. bool ctkCheckableModelHelper::headerCheckState(int section, Qt::CheckState& checkState)const
  577. {
  578. bool checkable = false;
  579. checkState = static_cast<Qt::CheckState>(
  580. this->model()->headerData(section, this->orientation(), Qt::CheckStateRole).toInt(&checkable));
  581. return checkable;
  582. }
  583. //-----------------------------------------------------------------------------
  584. bool ctkCheckableModelHelper::checkState(const QModelIndex& index, Qt::CheckState& checkState)const
  585. {
  586. bool checkable = false;
  587. checkState = static_cast<Qt::CheckState>(
  588. this->model()->data(index, Qt::CheckStateRole).toInt(&checkable));
  589. return checkable;
  590. }