QCMakeCacheView.cxx 19 KB

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