QCMakeCacheView.cxx 18 KB

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