QCMakeCacheView.cxx 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  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 rowCount = 0;
  213. foreach(QCMakeProperty p, newP)
  214. {
  215. this->insertRow(rowCount);
  216. this->setPropertyData(this->index(rowCount, 0), p, true);
  217. rowCount++;
  218. }
  219. foreach(QCMakeProperty p, newP2)
  220. {
  221. this->insertRow(rowCount);
  222. this->setPropertyData(this->index(rowCount, 0), p, false);
  223. rowCount++;
  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 props = 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. foreach(QCMakeProperty prop, props)
  245. {
  246. QList<QStandardItem*> items;
  247. items.append(new QStandardItem());
  248. items.append(new QStandardItem());
  249. parentItems[0]->appendRow(items);
  250. this->setPropertyData(this->indexFromItem(items[0]), prop, true);
  251. }
  252. }
  253. foreach(QString key, newPropsTree2.keys())
  254. {
  255. QCMakePropertyList props = newPropsTree2[key];
  256. QStandardItem* parentItem =
  257. new QStandardItem(key.isEmpty() ? tr("Ungrouped Entries") : key);
  258. root->appendRow(parentItem);
  259. foreach(QCMakeProperty prop, props)
  260. {
  261. QList<QStandardItem*> items;
  262. items.append(new QStandardItem());
  263. items.append(new QStandardItem());
  264. parentItem->appendRow(items);
  265. this->setPropertyData(this->indexFromItem(items[0]), prop, false);
  266. }
  267. }
  268. }
  269. this->blockSignals(b);
  270. this->reset();
  271. }
  272. QCMakeCacheModel::ViewType QCMakeCacheModel::viewType() const
  273. {
  274. return this->View;
  275. }
  276. void QCMakeCacheModel::setViewType(QCMakeCacheModel::ViewType t)
  277. {
  278. this->View = t;
  279. QCMakePropertyList props = this->properties();
  280. QCMakePropertyList oldProps;
  281. int numNew = this->NewPropertyCount;
  282. int numTotal = props.count();
  283. for(int i=numNew; i<numTotal; i++)
  284. {
  285. oldProps.append(props[i]);
  286. }
  287. bool b = this->blockSignals(true);
  288. this->clear();
  289. this->setProperties(oldProps);
  290. this->setProperties(props);
  291. this->blockSignals(b);
  292. this->reset();
  293. }
  294. void QCMakeCacheModel::setPropertyData(const QModelIndex& idx1,
  295. const QCMakeProperty& prop, bool isNew)
  296. {
  297. QModelIndex idx2 = idx1.sibling(idx1.row(), 1);
  298. this->setData(idx1, prop.Key, Qt::DisplayRole);
  299. this->setData(idx1, prop.Help, QCMakeCacheModel::HelpRole);
  300. this->setData(idx1, prop.Type, QCMakeCacheModel::TypeRole);
  301. this->setData(idx1, prop.Advanced, QCMakeCacheModel::AdvancedRole);
  302. if(prop.Type == QCMakeProperty::BOOL)
  303. {
  304. int check = prop.Value.toBool() ? Qt::Checked : Qt::Unchecked;
  305. this->setData(idx2, check, Qt::CheckStateRole);
  306. }
  307. else
  308. {
  309. this->setData(idx2, prop.Value, Qt::DisplayRole);
  310. }
  311. this->setData(idx2, prop.Help, QCMakeCacheModel::HelpRole);
  312. if (!prop.Strings.isEmpty())
  313. {
  314. this->setData(idx1, prop.Strings, QCMakeCacheModel::StringsRole);
  315. }
  316. if(isNew)
  317. {
  318. this->setData(idx1, QBrush(QColor(255,100,100)), Qt::BackgroundColorRole);
  319. this->setData(idx2, QBrush(QColor(255,100,100)), Qt::BackgroundColorRole);
  320. }
  321. }
  322. void QCMakeCacheModel::getPropertyData(const QModelIndex& idx1,
  323. QCMakeProperty& prop) const
  324. {
  325. QModelIndex idx2 = idx1.sibling(idx1.row(), 1);
  326. prop.Key = this->data(idx1, Qt::DisplayRole).toString();
  327. prop.Help = this->data(idx1, HelpRole).toString();
  328. prop.Type = static_cast<QCMakeProperty::PropertyType>(this->data(idx1, TypeRole).toInt());
  329. prop.Advanced = this->data(idx1, AdvancedRole).toBool();
  330. prop.Strings = this->data(idx1, QCMakeCacheModel::StringsRole).toStringList();
  331. if(prop.Type == QCMakeProperty::BOOL)
  332. {
  333. int check = this->data(idx2, Qt::CheckStateRole).toInt();
  334. prop.Value = check == Qt::Checked;
  335. }
  336. else
  337. {
  338. prop.Value = this->data(idx2, Qt::DisplayRole).toString();
  339. }
  340. }
  341. QString QCMakeCacheModel::prefix(const QString& s)
  342. {
  343. QString prefix = s.section('_', 0, 0);
  344. if(prefix == s)
  345. {
  346. prefix = QString();
  347. }
  348. return prefix;
  349. }
  350. void QCMakeCacheModel::breakProperties(const QSet<QCMakeProperty>& props,
  351. QMap<QString, QCMakePropertyList>& result)
  352. {
  353. QMap<QString, QCMakePropertyList> tmp;
  354. // return a map of properties grouped by prefixes, and sorted
  355. foreach(QCMakeProperty p, props)
  356. {
  357. QString prefix = QCMakeCacheModel::prefix(p.Key);
  358. tmp[prefix].append(p);
  359. }
  360. // sort it and re-org any properties with only one sub item
  361. QCMakePropertyList reorgProps;
  362. QMap<QString, QCMakePropertyList>::iterator iter;
  363. for(iter = tmp.begin(); iter != tmp.end();)
  364. {
  365. if(iter->count() == 1)
  366. {
  367. reorgProps.append((*iter)[0]);
  368. iter = tmp.erase(iter);
  369. }
  370. else
  371. {
  372. qSort(*iter);
  373. ++iter;
  374. }
  375. }
  376. if(reorgProps.count())
  377. {
  378. tmp[QString()] += reorgProps;
  379. }
  380. result = tmp;
  381. }
  382. QCMakePropertyList QCMakeCacheModel::properties() const
  383. {
  384. QCMakePropertyList props;
  385. if(!this->rowCount())
  386. {
  387. return props;
  388. }
  389. QList<QModelIndex> idxs;
  390. idxs.append(this->index(0,0));
  391. // walk the entire model for property entries
  392. // this works regardless of a flat view or a tree view
  393. while(!idxs.isEmpty())
  394. {
  395. QModelIndex idx = idxs.last();
  396. if(this->hasChildren(idx) && this->rowCount(idx))
  397. {
  398. idxs.append(this->index(0,0, idx));
  399. }
  400. else
  401. {
  402. // get data
  403. QCMakeProperty prop;
  404. this->getPropertyData(idx, prop);
  405. props.append(prop);
  406. // go to the next in the tree
  407. while(!idxs.isEmpty() && !idxs.last().sibling(idxs.last().row()+1, 0).isValid())
  408. {
  409. idxs.removeLast();
  410. }
  411. if(!idxs.isEmpty())
  412. {
  413. idxs.last() = idxs.last().sibling(idxs.last().row()+1, 0);
  414. }
  415. }
  416. }
  417. return props;
  418. }
  419. bool QCMakeCacheModel::insertProperty(QCMakeProperty::PropertyType t,
  420. const QString& name, const QString& description,
  421. const QVariant& value, bool advanced)
  422. {
  423. QCMakeProperty prop;
  424. prop.Key = name;
  425. prop.Value = value;
  426. prop.Help = description;
  427. prop.Type = t;
  428. prop.Advanced = advanced;
  429. //insert at beginning
  430. this->insertRow(0);
  431. this->setPropertyData(this->index(0,0), prop, true);
  432. this->NewPropertyCount++;
  433. return true;
  434. }
  435. void QCMakeCacheModel::setEditEnabled(bool e)
  436. {
  437. this->EditEnabled = e;
  438. }
  439. bool QCMakeCacheModel::editEnabled() const
  440. {
  441. return this->EditEnabled;
  442. }
  443. int QCMakeCacheModel::newPropertyCount() const
  444. {
  445. return this->NewPropertyCount;
  446. }
  447. Qt::ItemFlags QCMakeCacheModel::flags (const QModelIndex& idx) const
  448. {
  449. Qt::ItemFlags f = QStandardItemModel::flags(idx);
  450. if(!this->EditEnabled)
  451. {
  452. f &= ~Qt::ItemIsEditable;
  453. return f;
  454. }
  455. if(QCMakeProperty::BOOL == this->data(idx, TypeRole).toInt())
  456. {
  457. f |= Qt::ItemIsUserCheckable;
  458. }
  459. return f;
  460. }
  461. QModelIndex QCMakeCacheModel::buddy(const QModelIndex& idx) const
  462. {
  463. if(!this->hasChildren(idx) &&
  464. this->data(idx, TypeRole).toInt() != QCMakeProperty::BOOL)
  465. {
  466. return this->index(idx.row(), 1, idx.parent());
  467. }
  468. return idx;
  469. }
  470. QCMakeCacheModelDelegate::QCMakeCacheModelDelegate(QObject* p)
  471. : QItemDelegate(p), FileDialogFlag(false)
  472. {
  473. }
  474. void QCMakeCacheModelDelegate::setFileDialogFlag(bool f)
  475. {
  476. this->FileDialogFlag = f;
  477. }
  478. QWidget* QCMakeCacheModelDelegate::createEditor(QWidget* p,
  479. const QStyleOptionViewItem&, const QModelIndex& idx) const
  480. {
  481. QModelIndex var = idx.sibling(idx.row(), 0);
  482. int type = var.data(QCMakeCacheModel::TypeRole).toInt();
  483. if(type == QCMakeProperty::BOOL)
  484. {
  485. return NULL;
  486. }
  487. else if(type == QCMakeProperty::PATH)
  488. {
  489. QCMakePathEditor* editor =
  490. new QCMakePathEditor(p,
  491. var.data(Qt::DisplayRole).toString());
  492. QObject::connect(editor, SIGNAL(fileDialogExists(bool)), this,
  493. SLOT(setFileDialogFlag(bool)));
  494. return editor;
  495. }
  496. else if(type == QCMakeProperty::FILEPATH)
  497. {
  498. QCMakeFilePathEditor* editor =
  499. new QCMakeFilePathEditor(p,
  500. var.data(Qt::DisplayRole).toString());
  501. QObject::connect(editor, SIGNAL(fileDialogExists(bool)), this,
  502. SLOT(setFileDialogFlag(bool)));
  503. return editor;
  504. }
  505. else if(type == QCMakeProperty::STRING &&
  506. var.data(QCMakeCacheModel::StringsRole).isValid())
  507. {
  508. QCMakeComboBox* editor =
  509. new QCMakeComboBox(p, var.data(QCMakeCacheModel::StringsRole).toStringList());
  510. editor->setFrame(false);
  511. return editor;
  512. }
  513. QLineEdit* editor = new QLineEdit(p);
  514. editor->setFrame(false);
  515. return editor;
  516. }
  517. bool QCMakeCacheModelDelegate::editorEvent(QEvent* e, QAbstractItemModel* model,
  518. const QStyleOptionViewItem& option, const QModelIndex& index)
  519. {
  520. Qt::ItemFlags flags = model->flags(index);
  521. if (!(flags & Qt::ItemIsUserCheckable) || !(option.state & QStyle::State_Enabled)
  522. || !(flags & Qt::ItemIsEnabled))
  523. {
  524. return false;
  525. }
  526. QVariant value = index.data(Qt::CheckStateRole);
  527. if (!value.isValid())
  528. {
  529. return false;
  530. }
  531. if ((e->type() == QEvent::MouseButtonRelease)
  532. || (e->type() == QEvent::MouseButtonDblClick))
  533. {
  534. // eat the double click events inside the check rect
  535. if (e->type() == QEvent::MouseButtonDblClick)
  536. {
  537. return true;
  538. }
  539. }
  540. else if (e->type() == QEvent::KeyPress)
  541. {
  542. if(static_cast<QKeyEvent*>(e)->key() != Qt::Key_Space &&
  543. static_cast<QKeyEvent*>(e)->key() != Qt::Key_Select)
  544. {
  545. return false;
  546. }
  547. }
  548. else
  549. {
  550. return false;
  551. }
  552. Qt::CheckState state = (static_cast<Qt::CheckState>(value.toInt()) == Qt::Checked
  553. ? Qt::Unchecked : Qt::Checked);
  554. bool success = model->setData(index, state, Qt::CheckStateRole);
  555. if(success)
  556. {
  557. this->recordChange(model, index);
  558. }
  559. return success;
  560. }
  561. // Issue 205903 fixed in Qt 4.5.0.
  562. // Can remove this function and FileDialogFlag when minimum Qt version is 4.5
  563. bool QCMakeCacheModelDelegate::eventFilter(QObject* object, QEvent* event)
  564. {
  565. // workaround for what looks like a bug in Qt on Mac OS X
  566. // where it doesn't create a QWidget wrapper for the native file dialog
  567. // so the Qt library ends up assuming the focus was lost to something else
  568. if(event->type() == QEvent::FocusOut && this->FileDialogFlag)
  569. {
  570. return false;
  571. }
  572. return QItemDelegate::eventFilter(object, event);
  573. }
  574. void QCMakeCacheModelDelegate::setModelData(QWidget* editor,
  575. QAbstractItemModel* model, const QModelIndex& index ) const
  576. {
  577. QItemDelegate::setModelData(editor, model, index);
  578. const_cast<QCMakeCacheModelDelegate*>(this)->recordChange(model, index);
  579. }
  580. QSize QCMakeCacheModelDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
  581. {
  582. QSize sz = QItemDelegate::sizeHint(option, index);
  583. QStyle *style = QApplication::style();
  584. // increase to checkbox size
  585. QStyleOptionButton opt;
  586. opt.QStyleOption::operator=(option);
  587. sz = sz.expandedTo(style->subElementRect(QStyle::SE_ViewItemCheckIndicator, &opt, NULL).size());
  588. return sz;
  589. }
  590. QSet<QCMakeProperty> QCMakeCacheModelDelegate::changes() const
  591. {
  592. return mChanges;
  593. }
  594. void QCMakeCacheModelDelegate::clearChanges()
  595. {
  596. mChanges.clear();
  597. }
  598. void QCMakeCacheModelDelegate::recordChange(QAbstractItemModel* model, const QModelIndex& index)
  599. {
  600. QModelIndex idx = index;
  601. QAbstractItemModel* mymodel = model;
  602. while(qobject_cast<QAbstractProxyModel*>(mymodel))
  603. {
  604. idx = static_cast<QAbstractProxyModel*>(mymodel)->mapToSource(idx);
  605. mymodel = static_cast<QAbstractProxyModel*>(mymodel)->sourceModel();
  606. }
  607. QCMakeCacheModel* cache_model = qobject_cast<QCMakeCacheModel*>(mymodel);
  608. if(cache_model && idx.isValid())
  609. {
  610. QCMakeProperty property;
  611. idx = idx.sibling(idx.row(), 0);
  612. cache_model->getPropertyData(idx, property);
  613. // clean out an old one
  614. QSet<QCMakeProperty>::iterator iter = mChanges.find(property);
  615. if(iter != mChanges.end())
  616. {
  617. mChanges.erase(iter);
  618. }
  619. // now add the new item
  620. mChanges.insert(property);
  621. }
  622. }