QCMakeCacheView.cxx 19 KB

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