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 {