From f7a2132598e61ae2c4a547416ccf157ed6f6389d Mon Sep 17 00:00:00 2001 From: Marcus Tillmanns Date: Mon, 17 Oct 2022 13:28:59 +0200 Subject: [PATCH] CMake: Don't filter out new keys Previously, if you have a filter set in the CMake Settings variable list, adding a new one would immediately hide it, as the text filter hides the "" key. This made it look like the adding failed. With this change, new Variables are always shown so they stay editable to user. Change-Id: I9c2eb7f9983b23e1cd3aa50f589142551caaf56f Reviewed-by: Cristian Adam --- src/libs/utils/categorysortfiltermodel.cpp | 20 +++++++++++++++++++ src/libs/utils/categorysortfiltermodel.h | 6 ++++++ .../cmakebuildconfiguration.cpp | 1 + .../cmakeprojectmanager/configmodel.cpp | 3 +++ src/plugins/cmakeprojectmanager/configmodel.h | 3 ++- 5 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/libs/utils/categorysortfiltermodel.cpp b/src/libs/utils/categorysortfiltermodel.cpp index 8d3b1899ffb..f3b5e8e6e02 100644 --- a/src/libs/utils/categorysortfiltermodel.cpp +++ b/src/libs/utils/categorysortfiltermodel.cpp @@ -12,6 +12,12 @@ CategorySortFilterModel::CategorySortFilterModel(QObject *parent) { } +void CategorySortFilterModel::setNewItemRole(int role) +{ + m_newItemRole = role; + invalidate(); +} + bool CategorySortFilterModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const { @@ -21,6 +27,12 @@ bool CategorySortFilterModel::filterAcceptsRow(int source_row, const QModelIndex &categoryIndex = sourceModel()->index(source_row, 0, source_parent); if (regexp.match(sourceModel()->data(categoryIndex, filterRole()).toString()).hasMatch()) return true; + + if (m_newItemRole != -1 && categoryIndex.isValid()) { + if (categoryIndex.data(m_newItemRole).toBool()) + return true; + } + const int rowCount = sourceModel()->rowCount(categoryIndex); for (int row = 0; row < rowCount; ++row) { if (filterAcceptsRow(row, categoryIndex)) @@ -28,6 +40,14 @@ bool CategorySortFilterModel::filterAcceptsRow(int source_row, } return false; } + + if (m_newItemRole != -1) { + const QModelIndex &idx = sourceModel()->index(source_row, 0, source_parent); + if (idx.data(m_newItemRole).toBool()) + return true; + } + + return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent); } diff --git a/src/libs/utils/categorysortfiltermodel.h b/src/libs/utils/categorysortfiltermodel.h index 405419dedf3..f9f787b352f 100644 --- a/src/libs/utils/categorysortfiltermodel.h +++ b/src/libs/utils/categorysortfiltermodel.h @@ -14,8 +14,14 @@ class QTCREATOR_UTILS_EXPORT CategorySortFilterModel : public QSortFilterProxyMo public: CategorySortFilterModel(QObject *parent = nullptr); + // "New" items will always be accepted, regardless of the filter. + void setNewItemRole(int role); + protected: bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override; + +private: + int m_newItemRole = -1; }; } // Utils diff --git a/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp b/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp index 3dc13248b41..c48fdadea6c 100644 --- a/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp +++ b/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp @@ -236,6 +236,7 @@ CMakeBuildSettingsWidget::CMakeBuildSettingsWidget(CMakeBuildSystem *bs) : m_configTextFilterModel->setSourceModel(m_configFilterModel); m_configTextFilterModel->setSortRole(Qt::DisplayRole); m_configTextFilterModel->setFilterKeyColumn(-1); + m_configTextFilterModel->setNewItemRole(ConfigModel::ItemIsUserNew); connect(m_configTextFilterModel, &QAbstractItemModel::layoutChanged, this, [this]() { QModelIndex selectedIdx = m_configView->currentIndex(); diff --git a/src/plugins/cmakeprojectmanager/configmodel.cpp b/src/plugins/cmakeprojectmanager/configmodel.cpp index 084d917ffa8..43fb28d7d06 100644 --- a/src/plugins/cmakeprojectmanager/configmodel.cpp +++ b/src/plugins/cmakeprojectmanager/configmodel.cpp @@ -546,6 +546,9 @@ QVariant ConfigModelTreeItem::data(int column, int role) const if (role == ConfigModel::ItemIsInitialRole) { return dataItem->isInitial ? "1" : "0"; } + if (role == ConfigModel::ItemIsUserNew) { + return dataItem->isUserNew ? "1" : "0"; + } auto fontRole = [this]() -> QFont { QFont font; diff --git a/src/plugins/cmakeprojectmanager/configmodel.h b/src/plugins/cmakeprojectmanager/configmodel.h index 2d235a30aa9..71b4db5a347 100644 --- a/src/plugins/cmakeprojectmanager/configmodel.h +++ b/src/plugins/cmakeprojectmanager/configmodel.h @@ -18,7 +18,8 @@ class ConfigModel : public Utils::TreeModel<> public: enum Roles { ItemIsAdvancedRole = Qt::UserRole, - ItemIsInitialRole + ItemIsInitialRole, + ItemIsUserNew, }; struct DataItem {