forked from qt-creator/qt-creator
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 "<UNSET>" 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 <cristian.adam@qt.io>
This commit is contained in:
@@ -12,6 +12,12 @@ CategorySortFilterModel::CategorySortFilterModel(QObject *parent)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CategorySortFilterModel::setNewItemRole(int role)
|
||||||
|
{
|
||||||
|
m_newItemRole = role;
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
bool CategorySortFilterModel::filterAcceptsRow(int source_row,
|
bool CategorySortFilterModel::filterAcceptsRow(int source_row,
|
||||||
const QModelIndex &source_parent) const
|
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);
|
const QModelIndex &categoryIndex = sourceModel()->index(source_row, 0, source_parent);
|
||||||
if (regexp.match(sourceModel()->data(categoryIndex, filterRole()).toString()).hasMatch())
|
if (regexp.match(sourceModel()->data(categoryIndex, filterRole()).toString()).hasMatch())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
if (m_newItemRole != -1 && categoryIndex.isValid()) {
|
||||||
|
if (categoryIndex.data(m_newItemRole).toBool())
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
const int rowCount = sourceModel()->rowCount(categoryIndex);
|
const int rowCount = sourceModel()->rowCount(categoryIndex);
|
||||||
for (int row = 0; row < rowCount; ++row) {
|
for (int row = 0; row < rowCount; ++row) {
|
||||||
if (filterAcceptsRow(row, categoryIndex))
|
if (filterAcceptsRow(row, categoryIndex))
|
||||||
@@ -28,6 +40,14 @@ bool CategorySortFilterModel::filterAcceptsRow(int source_row,
|
|||||||
}
|
}
|
||||||
return false;
|
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);
|
return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -14,8 +14,14 @@ class QTCREATOR_UTILS_EXPORT CategorySortFilterModel : public QSortFilterProxyMo
|
|||||||
public:
|
public:
|
||||||
CategorySortFilterModel(QObject *parent = nullptr);
|
CategorySortFilterModel(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
// "New" items will always be accepted, regardless of the filter.
|
||||||
|
void setNewItemRole(int role);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
|
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
int m_newItemRole = -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // Utils
|
} // Utils
|
||||||
|
@@ -236,6 +236,7 @@ CMakeBuildSettingsWidget::CMakeBuildSettingsWidget(CMakeBuildSystem *bs) :
|
|||||||
m_configTextFilterModel->setSourceModel(m_configFilterModel);
|
m_configTextFilterModel->setSourceModel(m_configFilterModel);
|
||||||
m_configTextFilterModel->setSortRole(Qt::DisplayRole);
|
m_configTextFilterModel->setSortRole(Qt::DisplayRole);
|
||||||
m_configTextFilterModel->setFilterKeyColumn(-1);
|
m_configTextFilterModel->setFilterKeyColumn(-1);
|
||||||
|
m_configTextFilterModel->setNewItemRole(ConfigModel::ItemIsUserNew);
|
||||||
|
|
||||||
connect(m_configTextFilterModel, &QAbstractItemModel::layoutChanged, this, [this]() {
|
connect(m_configTextFilterModel, &QAbstractItemModel::layoutChanged, this, [this]() {
|
||||||
QModelIndex selectedIdx = m_configView->currentIndex();
|
QModelIndex selectedIdx = m_configView->currentIndex();
|
||||||
|
@@ -546,6 +546,9 @@ QVariant ConfigModelTreeItem::data(int column, int role) const
|
|||||||
if (role == ConfigModel::ItemIsInitialRole) {
|
if (role == ConfigModel::ItemIsInitialRole) {
|
||||||
return dataItem->isInitial ? "1" : "0";
|
return dataItem->isInitial ? "1" : "0";
|
||||||
}
|
}
|
||||||
|
if (role == ConfigModel::ItemIsUserNew) {
|
||||||
|
return dataItem->isUserNew ? "1" : "0";
|
||||||
|
}
|
||||||
|
|
||||||
auto fontRole = [this]() -> QFont {
|
auto fontRole = [this]() -> QFont {
|
||||||
QFont font;
|
QFont font;
|
||||||
|
@@ -18,7 +18,8 @@ class ConfigModel : public Utils::TreeModel<>
|
|||||||
public:
|
public:
|
||||||
enum Roles {
|
enum Roles {
|
||||||
ItemIsAdvancedRole = Qt::UserRole,
|
ItemIsAdvancedRole = Qt::UserRole,
|
||||||
ItemIsInitialRole
|
ItemIsInitialRole,
|
||||||
|
ItemIsUserNew,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DataItem {
|
struct DataItem {
|
||||||
|
Reference in New Issue
Block a user