1
0

QCMakeCacheView.cxx 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "QCMakeCacheView.h"
  14. #include <QHBoxLayout>
  15. #include <QHeaderView>
  16. #include <QEvent>
  17. #include <QStyle>
  18. #include <QKeyEvent>
  19. #include <QSortFilterProxyModel>
  20. #include <QMetaProperty>
  21. #include <QApplication>
  22. #include "QCMakeWidgets.h"
  23. // filter for searches
  24. class QCMakeSearchFilter : public QSortFilterProxyModel
  25. {
  26. public:
  27. QCMakeSearchFilter(QObject* o) : QSortFilterProxyModel(o) {}
  28. protected:
  29. bool filterAcceptsRow(int row, const QModelIndex& p) const
  30. {
  31. QStringList strs;
  32. const QAbstractItemModel* m = this->sourceModel();
  33. QModelIndex idx = m->index(row, 0, p);
  34. // if there are no children, get strings for column 0 and 1
  35. if(!m->hasChildren(idx))
  36. {
  37. strs.append(m->data(idx).toString());
  38. idx = m->index(row, 1, p);
  39. strs.append(m->data(idx).toString());
  40. }
  41. else
  42. {
  43. // get strings for children entries to compare with
  44. // instead of comparing with the parent
  45. int num = m->rowCount(idx);
  46. for(int i=0; i<num; i++)
  47. {
  48. QModelIndex tmpidx = m->index(i, 0, idx);
  49. strs.append(m->data(tmpidx).toString());
  50. tmpidx = m->index(i, 1, idx);
  51. strs.append(m->data(tmpidx).toString());
  52. }
  53. }
  54. // check all strings for a match
  55. foreach(QString str, strs)
  56. {
  57. if(str.contains(this->filterRegExp()))
  58. {
  59. return true;
  60. }
  61. }
  62. return false;
  63. }
  64. };
  65. // filter for searches
  66. class QCMakeAdvancedFilter : public QSortFilterProxyModel
  67. {
  68. public:
  69. QCMakeAdvancedFilter(QObject* o)
  70. : QSortFilterProxyModel(o), ShowAdvanced(false) {}
  71. void setShowAdvanced(bool f)
  72. {
  73. this->ShowAdvanced = f;
  74. this->invalidate();
  75. }
  76. bool showAdvanced() const { return this->ShowAdvanced; }
  77. protected:
  78. bool ShowAdvanced;
  79. bool filterAcceptsRow(int row, const QModelIndex& p) const
  80. {
  81. const QAbstractItemModel* m = this->sourceModel();
  82. QModelIndex idx = m->index(row, 0, p);
  83. // if there are no children
  84. if(!m->hasChildren(idx))
  85. {
  86. bool adv = m->data(idx, QCMakeCacheModel::AdvancedRole).toBool();
  87. if(!adv || (adv && this->ShowAdvanced))
  88. {
  89. return true;
  90. }
  91. return false;
  92. }
  93. // check children
  94. int num = m->rowCount(idx);
  95. for(int i=0; i<num; i++)
  96. {
  97. bool accept = this->filterAcceptsRow(i, idx);
  98. if(accept)
  99. {
  100. return true;
  101. }
  102. }
  103. return false;
  104. }
  105. };
  106. QCMakeCacheView::QCMakeCacheView(QWidget* p)
  107. : QTreeView(p)
  108. {
  109. // hook up our model and search/filter proxies
  110. this->CacheModel = new QCMakeCacheModel(this);
  111. this->AdvancedFilter = new QCMakeAdvancedFilter(this);
  112. this->AdvancedFilter->setSourceModel(this->CacheModel);
  113. this->AdvancedFilter->setDynamicSortFilter(true);
  114. this->SearchFilter = new QCMakeSearchFilter(this);
  115. this->SearchFilter->setSourceModel(this->AdvancedFilter);
  116. this->SearchFilter->setFilterCaseSensitivity(Qt::CaseInsensitive);
  117. this->SearchFilter->setDynamicSortFilter(true);
  118. this->setModel(this->SearchFilter);
  119. // our delegate for creating our editors
  120. QCMakeCacheModelDelegate* delegate = new QCMakeCacheModelDelegate(this);
  121. this->setItemDelegate(delegate);
  122. this->setUniformRowHeights(true);
  123. this->setEditTriggers(QAbstractItemView::AllEditTriggers);
  124. // tab, backtab doesn't step through items
  125. this->setTabKeyNavigation(false);
  126. this->setRootIsDecorated(false);
  127. }
  128. bool QCMakeCacheView::event(QEvent* e)
  129. {
  130. if(e->type() == QEvent::Show)
  131. {
  132. this->header()->setDefaultSectionSize(this->viewport()->width()/2);
  133. }
  134. return QTreeView::event(e);
  135. }
  136. QCMakeCacheModel* QCMakeCacheView::cacheModel() const
  137. {
  138. return this->CacheModel;
  139. }
  140. QModelIndex QCMakeCacheView::moveCursor(CursorAction act,
  141. Qt::KeyboardModifiers mod)
  142. {
  143. // want home/end to go to begin/end of rows, not columns
  144. if(act == MoveHome)
  145. {
  146. return this->model()->index(0, 1);
  147. }
  148. else if(act == MoveEnd)
  149. {
  150. return this->model()->index(this->model()->rowCount()-1, 1);
  151. }
  152. return QTreeView::moveCursor(act, mod);
  153. }
  154. void QCMakeCacheView::setShowAdvanced(bool s)
  155. {
  156. #if QT_VERSION >= 040300
  157. // new 4.3 api that needs to be called. what about an older Qt?
  158. this->SearchFilter->invalidate();
  159. #endif
  160. this->AdvancedFilter->setShowAdvanced(s);
  161. }
  162. bool QCMakeCacheView::showAdvanced() const
  163. {
  164. return this->AdvancedFilter->showAdvanced();
  165. }
  166. void QCMakeCacheView::setSearchFilter(const QString& s)
  167. {
  168. this->SearchFilter->setFilterFixedString(s);
  169. }
  170. QCMakeCacheModel::QCMakeCacheModel(QObject* p)
  171. : QStandardItemModel(p),
  172. EditEnabled(true),
  173. NewPropertyCount(0),
  174. View(FlatView)
  175. {
  176. QStringList labels;
  177. labels << tr("Name") << tr("Value");
  178. this->setHorizontalHeaderLabels(labels);
  179. }
  180. QCMakeCacheModel::~QCMakeCacheModel()
  181. {
  182. }
  183. static uint qHash(const QCMakeProperty& p)
  184. {
  185. return qHash(p.Key);
  186. }
  187. void QCMakeCacheModel::clear()
  188. {
  189. this->QStandardItemModel::clear();
  190. this->NewPropertyCount = 0;
  191. QStringList labels;
  192. labels << tr("Name") << tr("Value");
  193. this->setHorizontalHeaderLabels(labels);
  194. }
  195. void QCMakeCacheModel::setProperties(const QCMakePropertyList& props)
  196. {
  197. QSet<QCMakeProperty> newProps = props.toSet();
  198. QSet<QCMakeProperty> newProps2 = newProps;
  199. QSet<QCMakeProperty> oldProps = this->properties().toSet();
  200. oldProps.intersect(newProps);
  201. newProps.subtract(oldProps);
  202. newProps2.subtract(newProps);
  203. bool b = this->blockSignals(true);
  204. this->clear();
  205. this->NewPropertyCount = newProps.size();
  206. if(View == FlatView)
  207. {
  208. QCMakePropertyList newP = newProps.toList();
  209. QCMakePropertyList newP2 = newProps2.toList();
  210. qSort(newP);
  211. qSort(newP2);
  212. int row_count = 0;
  213. foreach(QCMakeProperty p, newP)
  214. {
  215. this->insertRow(row_count);
  216. this->setPropertyData(this->index(row_count, 0), p, true);
  217. row_count++;
  218. }
  219. foreach(QCMakeProperty p, newP2)
  220. {
  221. this->insertRow(row_count);
  222. this->setPropertyData(this->index(row_count, 0), p, false);
  223. row_count++;
  224. }
  225. }
  226. else if(this->View == GroupView)
  227. {
  228. QMap<QString, QCMakePropertyList> newPropsTree;
  229. this->breakProperties(newProps, newPropsTree);
  230. QMap<QString, QCMakePropertyList> newPropsTree2;
  231. this->breakProperties(newProps2, newPropsTree2);
  232. QStandardItem* root = this->invisibleRootItem();
  233. foreach(QString key, newPropsTree.keys())
  234. {
  235. QCMakePropertyList props2 = newPropsTree[key];
  236. QList<QStandardItem*> parentItems;
  237. parentItems.append(
  238. new QStandardItem(key.isEmpty() ? tr("Ungrouped Entries") : key)
  239. );
  240. parentItems.append(new QStandardItem());
  241. parentItems[0]->setData(QBrush(QColor(255,100,100)), Qt::BackgroundColorRole);
  242. parentItems[1]->setData(QBrush(QColor(255,100,100)), Qt::BackgroundColorRole);
  243. root->appendRow(parentItems);
  244. int num = props2.size();
  245. for(int i=0; i<num; i++)
  246. {
  247. QCMakeProperty prop = props2[i];
  248. QList<QStandardItem*> items;
  249. items.append(new QStandardItem());
  250. items.append(new QStandardItem());
  251. parentItems[0]->appendRow(items);
  252. this->setPropertyData(this->indexFromItem(items[0]), prop, true);
  253. }
  254. }
  255. foreach(QString key, newPropsTree2.keys())
  256. {
  257. QCMakePropertyList props2 = newPropsTree2[key];
  258. QStandardItem* parentItem =
  259. new QStandardItem(key.isEmpty() ? tr("Ungrouped Entries") : key);
  260. root->appendRow(parentItem);
  261. int num = props2.size();
  262. for(int i=0; i<num; i++)
  263. {
  264. QCMakeProperty prop = props2[i];
  265. QList<QStandardItem*> items;
  266. items.append(new QStandardItem());
  267. items.append(new QStandardItem());
  268. parentItem->appendRow(items);
  269. this->setPropertyData(this->indexFromItem(items[0]), prop, false);
  270. }
  271. }
  272. }
  273. this->blockSignals(b);
  274. this->reset();
  275. }
  276. QCMakeCacheModel::ViewType QCMakeCacheModel::viewType() const
  277. {
  278. return this->View;
  279. }
  280. void QCMakeCacheModel::setViewType(QCMakeCacheModel::ViewType t)
  281. {
  282. this->View = t;
  283. QCMakePropertyList props = this->properties();
  284. QCMakePropertyList oldProps;
  285. int numNew = this->NewPropertyCount;
  286. int numTotal = props.count();
  287. for(int i=numNew; i<numTotal; i++)
  288. {
  289. oldProps.append(props[i]);
  290. }
  291. bool b = this->blockSignals(true);
  292. this->clear();
  293. this->setProperties(oldProps);
  294. this->setProperties(props);
  295. this->blockSignals(b);
  296. this->reset();
  297. }
  298. void QCMakeCacheModel::setPropertyData(const QModelIndex& idx1,
  299. const QCMakeProperty& prop, bool isNew)
  300. {
  301. QModelIndex idx2 = idx1.sibling(idx1.row(), 1);
  302. this->setData(idx1, prop.Key, Qt::DisplayRole);
  303. this->setData(idx1, prop.Help, QCMakeCacheModel::HelpRole);
  304. this->setData(idx1, prop.Type, QCMakeCacheModel::TypeRole);
  305. this->setData(idx1, prop.Advanced, QCMakeCacheModel::AdvancedRole);
  306. if(prop.Type == QCMakeProperty::BOOL)
  307. {
  308. int check = prop.Value.toBool() ? Qt::Checked : Qt::Unchecked;
  309. this->setData(idx2, check, Qt::CheckStateRole);
  310. }
  311. else
  312. {
  313. this->setData(idx2, prop.Value, Qt::DisplayRole);
  314. }
  315. this->setData(idx2, prop.Help, QCMakeCacheModel::HelpRole);
  316. if (!prop.Strings.isEmpty())
  317. {
  318. this->setData(idx1, prop.Strings, QCMakeCacheModel::StringsRole);
  319. }
  320. if(isNew)
  321. {
  322. this->setData(idx1, QBrush(QColor(255,100,100)), Qt::BackgroundColorRole);
  323. this->setData(idx2, QBrush(QColor(255,100,100)), Qt::BackgroundColorRole);
  324. }
  325. }
  326. void QCMakeCacheModel::getPropertyData(const QModelIndex& idx1,
  327. QCMakeProperty& prop) const
  328. {
  329. QModelIndex idx2 = idx1.sibling(idx1.row(), 1);
  330. prop.Key = this->data(idx1, Qt::DisplayRole).toString();
  331. prop.Help = this->data(idx1, HelpRole).toString();
  332. prop.Type = static_cast<QCMakeProperty::PropertyType>(this->data(idx1, TypeRole).toInt());
  333. prop.Advanced = this->data(idx1, AdvancedRole).toBool();
  334. prop.Strings = this->data(idx1, QCMakeCacheModel::StringsRole).toStringList();
  335. if(prop.Type == QCMakeProperty::BOOL)
  336. {
  337. int check = this->data(idx2, Qt::CheckStateRole).toInt();
  338. prop.Value = check == Qt::Checked;
  339. }
  340. else
  341. {
  342. prop.Value = this->data(idx2, Qt::DisplayRole).toString();
  343. }
  344. }
  345. QString QCMakeCacheModel::prefix(const QString& s)
  346. {
  347. QString prefix = s.section('_', 0, 0);
  348. if(prefix == s)
  349. {
  350. prefix = QString();
  351. }
  352. return prefix;
  353. }
  354. void QCMakeCacheModel::breakProperties(const QSet<QCMakeProperty>& props,
  355. QMap<QString, QCMakePropertyList>& result)
  356. {
  357. QMap<QString, QCMakePropertyList> tmp;
  358. // return a map of properties grouped by prefixes, and sorted
  359. foreach(QCMakeProperty p, props)
  360. {
  361. QString prefix = QCMakeCacheModel::prefix(p.Key);
  362. tmp[prefix].append(p);
  363. }
  364. // sort it and re-org any properties with only one sub item
  365. QCMakePropertyList reorgProps;
  366. QMap<QString, QCMakePropertyList>::iterator iter;
  367. for(iter = tmp.begin(); iter != tmp.end();)
  368. {
  369. if(iter->count() == 1)
  370. {
  371. reorgProps.append((*iter)[0]);
  372. iter = tmp.erase(iter);
  373. }
  374. else
  375. {
  376. qSort(*iter);
  377. ++iter;
  378. }
  379. }
  380. if(reorgProps.count())
  381. {
  382. tmp[QString()] += reorgProps;
  383. }
  384. result = tmp;
  385. }
  386. QCMakePropertyList QCMakeCacheModel::properties() const
  387. {
  388. QCMakePropertyList props;
  389. if(!this->rowCount())
  390. {
  391. return props;
  392. }
  393. QList<QModelIndex> idxs;
  394. idxs.append(this->index(0,0));
  395. // walk the entire model for property entries
  396. // this works regardless of a flat view or a tree view
  397. while(!idxs.isEmpty())
  398. {
  399. QModelIndex idx = idxs.last();
  400. if(this->hasChildren(idx) && this->rowCount(idx))
  401. {
  402. idxs.append(this->index(0,0, idx));
  403. }
  404. else
  405. {
  406. // get data
  407. QCMakeProperty prop;
  408. this->getPropertyData(idx, prop);
  409. props.append(prop);
  410. // go to the next in the tree
  411. while(!idxs.isEmpty() && !idxs.last().sibling(idxs.last().row()+1, 0).isValid())
  412. {
  413. idxs.removeLast();
  414. }
  415. if(!idxs.isEmpty())
  416. {
  417. idxs.last() = idxs.last().sibling(idxs.last().row()+1, 0);
  418. }
  419. }
  420. }
  421. return props;
  422. }
  423. bool QCMakeCacheModel::insertProperty(QCMakeProperty::PropertyType t,
  424. const QString& name, const QString& description,
  425. const QVariant& value, bool advanced)
  426. {
  427. QCMakeProperty prop;
  428. prop.Key = name;
  429. prop.Value = value;
  430. prop.Help = description;
  431. prop.Type = t;
  432. prop.Advanced = advanced;
  433. //insert at beginning
  434. this->insertRow(0);
  435. this->setPropertyData(this->index(0,0), prop, true);
  436. this->NewPropertyCount++;
  437. return true;
  438. }
  439. void QCMakeCacheModel::setEditEnabled(bool e)
  440. {
  441. this->EditEnabled = e;
  442. }
  443. bool QCMakeCacheModel::editEnabled() const
  444. {
  445. return this->EditEnabled;
  446. }
  447. int QCMakeCacheModel::newPropertyCount() const
  448. {
  449. return this->NewPropertyCount;
  450. }
  451. Qt::ItemFlags QCMakeCacheModel::flags (const QModelIndex& idx) const
  452. {
  453. Qt::ItemFlags f = QStandardItemModel::flags(idx);
  454. if(!this->EditEnabled)
  455. {
  456. f &= ~Qt::ItemIsEditable;
  457. return f;
  458. }
  459. if(QCMakeProperty::BOOL == this->data(idx, TypeRole).toInt())
  460. {
  461. f |= Qt::ItemIsUserCheckable;
  462. }
  463. return f;
  464. }
  465. QModelIndex QCMakeCacheModel::buddy(const QModelIndex& idx) const
  466. {
  467. if(!this->hasChildren(idx) &&
  468. this->data(idx, TypeRole).toInt() != QCMakeProperty::BOOL)
  469. {
  470. return this->index(idx.row(), 1, idx.parent());
  471. }
  472. return idx;
  473. }
  474. QCMakeCacheModelDelegate::QCMakeCacheModelDelegate(QObject* p)
  475. : QItemDelegate(p), FileDialogFlag(false)
  476. {
  477. }
  478. void QCMakeCacheModelDelegate::setFileDialogFlag(bool f)
  479. {
  480. this->FileDialogFlag = f;
  481. }
  482. QWidget* QCMakeCacheModelDelegate::createEditor(QWidget* p,
  483. const QStyleOptionViewItem&, const QModelIndex& idx) const
  484. {
  485. QModelIndex var = idx.sibling(idx.row(), 0);
  486. int type = var.data(QCMakeCacheModel::TypeRole).toInt();
  487. if(type == QCMakeProperty::BOOL)
  488. {
  489. return NULL;
  490. }
  491. else if(type == QCMakeProperty::PATH)
  492. {
  493. QCMakePathEditor* editor =
  494. new QCMakePathEditor(p,
  495. var.data(Qt::DisplayRole).toString());
  496. QObject::connect(editor, SIGNAL(fileDialogExists(bool)), this,
  497. SLOT(setFileDialogFlag(bool)));
  498. return editor;
  499. }
  500. else if(type == QCMakeProperty::FILEPATH)
  501. {
  502. QCMakeFilePathEditor* editor =
  503. new QCMakeFilePathEditor(p,
  504. var.data(Qt::DisplayRole).toString());
  505. QObject::connect(editor, SIGNAL(fileDialogExists(bool)), this,
  506. SLOT(setFileDialogFlag(bool)));
  507. return editor;
  508. }
  509. else if(type == QCMakeProperty::STRING &&
  510. var.data(QCMakeCacheModel::StringsRole).isValid())
  511. {
  512. QCMakeComboBox* editor =
  513. new QCMakeComboBox(p, var.data(QCMakeCacheModel::StringsRole).toStringList());
  514. editor->setFrame(false);
  515. return editor;
  516. }
  517. QLineEdit* editor = new QLineEdit(p);
  518. editor->setFrame(false);
  519. return editor;
  520. }
  521. bool QCMakeCacheModelDelegate::editorEvent(QEvent* e, QAbstractItemModel* model,
  522. const QStyleOptionViewItem& option, const QModelIndex& index)
  523. {
  524. Qt::ItemFlags flags = model->flags(index);
  525. if (!(flags & Qt::ItemIsUserCheckable) || !(option.state & QStyle::State_Enabled)
  526. || !(flags & Qt::ItemIsEnabled))
  527. {
  528. return false;
  529. }
  530. QVariant value = index.data(Qt::CheckStateRole);
  531. if (!value.isValid())
  532. {
  533. return false;
  534. }
  535. if ((e->type() == QEvent::MouseButtonRelease)
  536. || (e->type() == QEvent::MouseButtonDblClick))
  537. {
  538. // eat the double click events inside the check rect
  539. if (e->type() == QEvent::MouseButtonDblClick)
  540. {
  541. return true;
  542. }
  543. }
  544. else if (e->type() == QEvent::KeyPress)
  545. {
  546. if(static_cast<QKeyEvent*>(e)->key() != Qt::Key_Space &&
  547. static_cast<QKeyEvent*>(e)->key() != Qt::Key_Select)
  548. {
  549. return false;
  550. }
  551. }
  552. else
  553. {
  554. return false;
  555. }
  556. Qt::CheckState state = (static_cast<Qt::CheckState>(value.toInt()) == Qt::Checked
  557. ? Qt::Unchecked : Qt::Checked);
  558. bool success = model->setData(index, state, Qt::CheckStateRole);
  559. if(success)
  560. {
  561. this->recordChange(model, index);
  562. }
  563. return success;
  564. }
  565. // Issue 205903 fixed in Qt 4.5.0.
  566. // Can remove this function and FileDialogFlag when minimum Qt version is 4.5
  567. bool QCMakeCacheModelDelegate::eventFilter(QObject* object, QEvent* evt)
  568. {
  569. // workaround for what looks like a bug in Qt on Mac OS X
  570. // where it doesn't create a QWidget wrapper for the native file dialog
  571. // so the Qt library ends up assuming the focus was lost to something else
  572. if(evt->type() == QEvent::FocusOut && this->FileDialogFlag)
  573. {
  574. return false;
  575. }
  576. return QItemDelegate::eventFilter(object, evt);
  577. }
  578. void QCMakeCacheModelDelegate::setModelData(QWidget* editor,
  579. QAbstractItemModel* model, const QModelIndex& index ) const
  580. {
  581. QItemDelegate::setModelData(editor, model, index);
  582. const_cast<QCMakeCacheModelDelegate*>(this)->recordChange(model, index);
  583. }
  584. QSize QCMakeCacheModelDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
  585. {
  586. QSize sz = QItemDelegate::sizeHint(option, index);
  587. QStyle *style = QApplication::style();
  588. // increase to checkbox size
  589. QStyleOptionButton opt;
  590. opt.QStyleOption::operator=(option);
  591. sz = sz.expandedTo(style->subElementRect(QStyle::SE_ViewItemCheckIndicator, &opt, NULL).size());
  592. return sz;
  593. }
  594. QSet<QCMakeProperty> QCMakeCacheModelDelegate::changes() const
  595. {
  596. return mChanges;
  597. }
  598. void QCMakeCacheModelDelegate::clearChanges()
  599. {
  600. mChanges.clear();
  601. }
  602. void QCMakeCacheModelDelegate::recordChange(QAbstractItemModel* model, const QModelIndex& index)
  603. {
  604. QModelIndex idx = index;
  605. QAbstractItemModel* mymodel = model;
  606. while(qobject_cast<QAbstractProxyModel*>(mymodel))
  607. {
  608. idx = static_cast<QAbstractProxyModel*>(mymodel)->mapToSource(idx);
  609. mymodel = static_cast<QAbstractProxyModel*>(mymodel)->sourceModel();
  610. }
  611. QCMakeCacheModel* cache_model = qobject_cast<QCMakeCacheModel*>(mymodel);
  612. if(cache_model && idx.isValid())
  613. {
  614. QCMakeProperty prop;
  615. idx = idx.sibling(idx.row(), 0);
  616. cache_model->getPropertyData(idx, prop);
  617. // clean out an old one
  618. QSet<QCMakeProperty>::iterator iter = mChanges.find(prop);
  619. if(iter != mChanges.end())
  620. {
  621. mChanges.erase(iter);
  622. }
  623. // now add the new item
  624. mChanges.insert(prop);
  625. }
  626. }