forked from qt-creator/qt-creator
Port QtCreator over to use filterRegularExpression
QSortFilterProxyModel::filterRegExp is going to go away in Qt6, so port over to use QRegularExpression instead. This required some changes where setFilterWildcard/FixedString() was being used, as those would instantiate QRegExp based filters in Qt 5, and will use QRegularExpression in Qt 6. Use the generic setFilterRegularExpression here, to keep things portable between 5 and 6. Change-Id: I6379be781aa3821b10ba783c088f82c1a0970911 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -262,19 +262,18 @@ bool CategoryFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sou
|
||||
if (QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent))
|
||||
return true;
|
||||
|
||||
const QString pattern = filterRegExp().pattern();
|
||||
const QRegularExpression regex = filterRegularExpression();
|
||||
const CategoryModel *cm = static_cast<CategoryModel*>(sourceModel());
|
||||
const Category *category = cm->categories().at(sourceRow);
|
||||
for (const IOptionsPage *page : category->pages) {
|
||||
if (page->displayCategory().contains(pattern, Qt::CaseInsensitive)
|
||||
|| page->displayName().contains(pattern, Qt::CaseInsensitive)
|
||||
|| page->matches(pattern))
|
||||
if (page->displayCategory().contains(regex) || page->displayName().contains(regex)
|
||||
|| page->matches(regex))
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!category->providerPagesCreated) {
|
||||
for (const IOptionsPageProvider *provider : category->providers) {
|
||||
if (provider->matches(pattern))
|
||||
if (provider->matches(regex))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -469,8 +468,14 @@ SettingsDialog::SettingsDialog(QWidget *parent) :
|
||||
|
||||
// The order of the slot connection matters here, the filter slot
|
||||
// opens the matching page after the model has filtered.
|
||||
connect(m_filterLineEdit, &Utils::FancyLineEdit::filterChanged,
|
||||
&m_proxyModel, &QSortFilterProxyModel::setFilterFixedString);
|
||||
connect(m_filterLineEdit,
|
||||
&Utils::FancyLineEdit::filterChanged,
|
||||
&m_proxyModel,
|
||||
[this](const QString &filter) {
|
||||
m_proxyModel.setFilterRegularExpression(
|
||||
QRegularExpression(QRegularExpression::escape(filter),
|
||||
QRegularExpression::CaseInsensitiveOption));
|
||||
});
|
||||
connect(m_filterLineEdit, &Utils::FancyLineEdit::filterChanged,
|
||||
this, &SettingsDialog::filter);
|
||||
m_categoryList->setFocus();
|
||||
@@ -631,12 +636,12 @@ void SettingsDialog::disconnectTabWidgets()
|
||||
void SettingsDialog::updateEnabledTabs(Category *category, const QString &searchText)
|
||||
{
|
||||
int firstEnabledTab = -1;
|
||||
const QRegularExpression regex(QRegularExpression::escape(searchText),
|
||||
QRegularExpression::CaseInsensitiveOption);
|
||||
for (int i = 0; i < category->pages.size(); ++i) {
|
||||
const IOptionsPage *page = category->pages.at(i);
|
||||
const bool enabled = searchText.isEmpty()
|
||||
|| page->category().toString().contains(searchText, Qt::CaseInsensitive)
|
||||
|| page->displayName().contains(searchText, Qt::CaseInsensitive)
|
||||
|| page->matches(searchText);
|
||||
const bool enabled = searchText.isEmpty() || page->category().toString().contains(regex)
|
||||
|| page->displayName().contains(regex) || page->matches(regex);
|
||||
category->tabWidget->setTabEnabled(i, enabled);
|
||||
if (enabled && firstEnabledTab < 0)
|
||||
firstEnabledTab = i;
|
||||
|
||||
Reference in New Issue
Block a user