diff --git a/src/common/Helpers.cpp b/src/common/Helpers.cpp index 5cceaaca..b62b093c 100644 --- a/src/common/Helpers.cpp +++ b/src/common/Helpers.cpp @@ -278,4 +278,12 @@ void emitColumnChanged(QAbstractItemModel *model, int column) } } +bool filterStringContains(const QString &string, const QSortFilterProxyModel *model) +{ +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + return string.contains(model->filterRegExp()); +#else + return string.contains(model->filterRegularExpression()); +#endif +} } // end namespace diff --git a/src/common/Helpers.h b/src/common/Helpers.h index 2a2da821..38462d55 100644 --- a/src/common/Helpers.h +++ b/src/common/Helpers.h @@ -23,6 +23,7 @@ class QAction; class QMenu; class QPaintDevice; class QComboBox; +class QSortFilterProxyModel; #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) # define CUTTER_QT_SKIP_EMPTY_PARTS QString::SkipEmptyParts @@ -83,6 +84,7 @@ CUTTER_EXPORT void selectIndexByData(QComboBox *comboBox, QVariant data, int def */ CUTTER_EXPORT void emitColumnChanged(QAbstractItemModel *model, int column); +CUTTER_EXPORT bool filterStringContains(const QString &string, const QSortFilterProxyModel *model); } // qhelpers #endif // HELPERS_H diff --git a/src/dialogs/AttachProcDialog.cpp b/src/dialogs/AttachProcDialog.cpp index d2e8f42e..5c0abed3 100644 --- a/src/dialogs/AttachProcDialog.cpp +++ b/src/dialogs/AttachProcDialog.cpp @@ -156,7 +156,7 @@ bool ProcessProxyModel::filterAcceptsRow(int row, const QModelIndex &parent) con QModelIndex index = sourceModel()->index(row, 0, parent); ProcessDescription item = index.data(ProcessModel::ProcDescriptionRole).value(); - return item.path.contains(filterRegExp()); + return qhelpers::filterStringContains(item.path, this); } bool ProcessProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const diff --git a/src/widgets/ClassesWidget.cpp b/src/widgets/ClassesWidget.cpp index b20f1935..ade8af4d 100644 --- a/src/widgets/ClassesWidget.cpp +++ b/src/widgets/ClassesWidget.cpp @@ -525,7 +525,7 @@ ClassesSortFilterProxyModel::ClassesSortFilterProxyModel(QObject *parent) bool ClassesSortFilterProxyModel::filterAcceptsRow(int row, const QModelIndex &parent) const { QModelIndex index = sourceModel()->index(row, 0, parent); - return index.data(ClassesModel::NameRole).toString().contains(filterRegExp()); + return qhelpers::filterStringContains(index.data(ClassesModel::NameRole).toString(), this); } bool ClassesSortFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const diff --git a/src/widgets/CommentsWidget.cpp b/src/widgets/CommentsWidget.cpp index 29f98025..6fc98b3c 100644 --- a/src/widgets/CommentsWidget.cpp +++ b/src/widgets/CommentsWidget.cpp @@ -195,7 +195,7 @@ bool CommentsProxyModel::filterAcceptsRow(int row, const QModelIndex &parent) co QModelIndex index = sourceModel()->index(row, 0, parent); auto comment = index.data(CommentsModel::CommentDescriptionRole).value(); - return comment.name.contains(filterRegExp()); + return qhelpers::filterStringContains(comment.name, this); } bool CommentsProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const diff --git a/src/widgets/ExportsWidget.cpp b/src/widgets/ExportsWidget.cpp index 8eee5207..2f7884a8 100644 --- a/src/widgets/ExportsWidget.cpp +++ b/src/widgets/ExportsWidget.cpp @@ -98,7 +98,7 @@ bool ExportsProxyModel::filterAcceptsRow(int row, const QModelIndex &parent) con QModelIndex index = sourceModel()->index(row, 0, parent); auto exp = index.data(ExportsModel::ExportDescriptionRole).value(); - return exp.name.contains(filterRegExp()); + return qhelpers::filterStringContains(exp.name, this); } bool ExportsProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const diff --git a/src/widgets/FlagsWidget.cpp b/src/widgets/FlagsWidget.cpp index 792ab435..12c775c3 100644 --- a/src/widgets/FlagsWidget.cpp +++ b/src/widgets/FlagsWidget.cpp @@ -107,7 +107,7 @@ bool FlagsSortFilterProxyModel::filterAcceptsRow(int row, const QModelIndex &par { QModelIndex index = sourceModel()->index(row, 0, parent); FlagDescription flag = index.data(FlagsModel::FlagDescriptionRole).value(); - return flag.name.contains(filterRegExp()) || flag.realname.contains(filterRegExp()); + return qhelpers::filterStringContains(flag.name, this); } bool FlagsSortFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const diff --git a/src/widgets/FunctionsWidget.cpp b/src/widgets/FunctionsWidget.cpp index f5875ee3..b04f6169 100644 --- a/src/widgets/FunctionsWidget.cpp +++ b/src/widgets/FunctionsWidget.cpp @@ -368,7 +368,8 @@ bool FunctionSortFilterProxyModel::filterAcceptsRow(int row, const QModelIndex & QModelIndex index = sourceModel()->index(row, 0, parent); FunctionDescription function = index.data(FunctionModel::FunctionDescriptionRole).value(); - return function.name.contains(filterRegExp()); + + return qhelpers::filterStringContains(function.name, this); } bool FunctionSortFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const diff --git a/src/widgets/HeadersWidget.cpp b/src/widgets/HeadersWidget.cpp index d5740734..80056b4e 100644 --- a/src/widgets/HeadersWidget.cpp +++ b/src/widgets/HeadersWidget.cpp @@ -89,7 +89,7 @@ bool HeadersProxyModel::filterAcceptsRow(int row, const QModelIndex &parent) con QModelIndex index = sourceModel()->index(row, 0, parent); HeaderDescription item = index.data(HeadersModel::HeaderDescriptionRole).value(); - return item.name.contains(filterRegExp()); + return qhelpers::filterStringContains(item.name, this); } bool HeadersProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const diff --git a/src/widgets/ImportsWidget.cpp b/src/widgets/ImportsWidget.cpp index 261a11b3..49174c8d 100644 --- a/src/widgets/ImportsWidget.cpp +++ b/src/widgets/ImportsWidget.cpp @@ -123,7 +123,7 @@ bool ImportsProxyModel::filterAcceptsRow(int row, const QModelIndex &parent) con QModelIndex index = sourceModel()->index(row, 0, parent); auto import = index.data(ImportsModel::ImportDescriptionRole).value(); - return import.name.contains(filterRegExp()); + return qhelpers::filterStringContains(import.name, this); } bool ImportsProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const diff --git a/src/widgets/MemoryMapWidget.cpp b/src/widgets/MemoryMapWidget.cpp index bcf189c7..7912a0de 100644 --- a/src/widgets/MemoryMapWidget.cpp +++ b/src/widgets/MemoryMapWidget.cpp @@ -88,7 +88,7 @@ bool MemoryProxyModel::filterAcceptsRow(int row, const QModelIndex &parent) cons QModelIndex index = sourceModel()->index(row, 0, parent); MemoryMapDescription item = index.data(MemoryMapModel::MemoryDescriptionRole).value(); - return item.name.contains(filterRegExp()); + return qhelpers::filterStringContains(item.name, this); } bool MemoryProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const diff --git a/src/widgets/ProcessesWidget.cpp b/src/widgets/ProcessesWidget.cpp index 34896a4c..29049da7 100644 --- a/src/widgets/ProcessesWidget.cpp +++ b/src/widgets/ProcessesWidget.cpp @@ -191,7 +191,7 @@ bool ProcessesFilterModel::filterAcceptsRow(int row, const QModelIndex &parent) // All columns are checked for a match for (int i = COLUMN_PID; i <= COLUMN_PATH; ++i) { QModelIndex index = sourceModel()->index(row, i, parent); - if (sourceModel()->data(index).toString().contains(filterRegExp())) { + if (qhelpers::filterStringContains(sourceModel()->data(index).toString(), this)) { return true; } } diff --git a/src/widgets/RegisterRefsWidget.cpp b/src/widgets/RegisterRefsWidget.cpp index 232db549..3718bec1 100644 --- a/src/widgets/RegisterRefsWidget.cpp +++ b/src/widgets/RegisterRefsWidget.cpp @@ -90,7 +90,7 @@ bool RegisterRefProxyModel::filterAcceptsRow(int row, const QModelIndex &parent) QModelIndex index = sourceModel()->index(row, 0, parent); RegisterRefDescription item = index.data(RegisterRefModel::RegisterRefDescriptionRole) .value(); - return item.reg.contains(filterRegExp()); + return qhelpers::filterStringContains(item.reg, this); } bool RegisterRefProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const diff --git a/src/widgets/RelocsWidget.cpp b/src/widgets/RelocsWidget.cpp index bb3e7587..f23d971e 100644 --- a/src/widgets/RelocsWidget.cpp +++ b/src/widgets/RelocsWidget.cpp @@ -93,7 +93,7 @@ bool RelocsProxyModel::filterAcceptsRow(int row, const QModelIndex &parent) cons QModelIndex index = sourceModel()->index(row, 0, parent); auto reloc = index.data(RelocsModel::RelocDescriptionRole).value(); - return reloc.name.contains(filterRegExp()); + return qhelpers::filterStringContains(reloc.name, this); } bool RelocsProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const diff --git a/src/widgets/SearchWidget.cpp b/src/widgets/SearchWidget.cpp index dca8f970..b4d38589 100644 --- a/src/widgets/SearchWidget.cpp +++ b/src/widgets/SearchWidget.cpp @@ -145,7 +145,7 @@ bool SearchSortFilterProxyModel::filterAcceptsRow(int row, const QModelIndex &pa QModelIndex index = sourceModel()->index(row, 0, parent); SearchDescription search = index.data(SearchModel::SearchDescriptionRole).value(); - return search.code.contains(filterRegExp()); + return qhelpers::filterStringContains(search.code, this); } bool SearchSortFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const diff --git a/src/widgets/StringsWidget.cpp b/src/widgets/StringsWidget.cpp index 7c3dec30..290c3af7 100644 --- a/src/widgets/StringsWidget.cpp +++ b/src/widgets/StringsWidget.cpp @@ -103,15 +103,26 @@ StringsProxyModel::StringsProxyModel(StringsModel *sourceModel, QObject *parent) setSortCaseSensitivity(Qt::CaseInsensitive); } +void StringsProxyModel::setSelectedSection(QString section) +{ + selectedSection = section; +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + invalidateFilter(); +#else + invalidateRowsFilter(); +#endif +} + bool StringsProxyModel::filterAcceptsRow(int row, const QModelIndex &parent) const { QModelIndex index = sourceModel()->index(row, 0, parent); StringDescription str = index.data(StringsModel::StringDescriptionRole).value(); - if (selectedSection.isEmpty()) - return str.string.contains(filterRegExp()); - else - return selectedSection == str.section && str.string.contains(filterRegExp()); + if (selectedSection.isEmpty()) { + return qhelpers::filterStringContains(str.string, this); + } else { + return selectedSection == str.section && qhelpers::filterStringContains(str.string, this); + } } bool StringsProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const @@ -198,8 +209,7 @@ StringsWidget::StringsWidget(MainWindow *main) [this]() { qhelpers::emitColumnChanged(model, StringsModel::CommentColumn); }); connect(ui->quickFilterView->comboBox(), &QComboBox::currentTextChanged, this, [this]() { - proxyModel->selectedSection = ui->quickFilterView->comboBox()->currentData().toString(); - proxyModel->setFilterRegExp(proxyModel->filterRegExp()); + proxyModel->setSelectedSection(ui->quickFilterView->comboBox()->currentData().toString()); tree->showItemsNumber(proxyModel->rowCount()); }); @@ -237,7 +247,7 @@ void StringsWidget::refreshSectionCombo() combo->addItem(section, section); } - proxyModel->selectedSection.clear(); + proxyModel->setSelectedSection(QString()); } void StringsWidget::stringSearchFinished(const QList &strings) diff --git a/src/widgets/StringsWidget.h b/src/widgets/StringsWidget.h index 15a5ce0f..e566cb0c 100644 --- a/src/widgets/StringsWidget.h +++ b/src/widgets/StringsWidget.h @@ -59,10 +59,9 @@ class StringsProxyModel : public AddressableFilterProxyModel { Q_OBJECT - friend StringsWidget; - public: StringsProxyModel(StringsModel *sourceModel, QObject *parent = nullptr); + void setSelectedSection(QString section); protected: bool filterAcceptsRow(int row, const QModelIndex &parent) const override; diff --git a/src/widgets/SymbolsWidget.cpp b/src/widgets/SymbolsWidget.cpp index ff9625ec..0a19a473 100644 --- a/src/widgets/SymbolsWidget.cpp +++ b/src/widgets/SymbolsWidget.cpp @@ -94,7 +94,7 @@ bool SymbolsProxyModel::filterAcceptsRow(int row, const QModelIndex &parent) con QModelIndex index = sourceModel()->index(row, 0, parent); auto symbol = index.data(SymbolsModel::SymbolDescriptionRole).value(); - return symbol.name.contains(filterRegExp()); + return qhelpers::filterStringContains(symbol.name, this); } bool SymbolsProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const diff --git a/src/widgets/ThreadsWidget.cpp b/src/widgets/ThreadsWidget.cpp index ddb9f8f0..b650e7a6 100644 --- a/src/widgets/ThreadsWidget.cpp +++ b/src/widgets/ThreadsWidget.cpp @@ -174,7 +174,7 @@ bool ThreadsFilterModel::filterAcceptsRow(int row, const QModelIndex &parent) co // All columns are checked for a match for (int i = COLUMN_PID; i <= COLUMN_PATH; ++i) { QModelIndex index = sourceModel()->index(row, i, parent); - if (sourceModel()->data(index).toString().contains(filterRegExp())) { + if (qhelpers::filterStringContains(sourceModel()->data(index).toString(), this)) { return true; } } diff --git a/src/widgets/TypesWidget.cpp b/src/widgets/TypesWidget.cpp index 925252d6..91cf9551 100644 --- a/src/widgets/TypesWidget.cpp +++ b/src/widgets/TypesWidget.cpp @@ -91,15 +91,24 @@ TypesSortFilterProxyModel::TypesSortFilterProxyModel(TypesModel *source_model, Q setSourceModel(source_model); } +void TypesSortFilterProxyModel::setCategory(QString category) +{ + selectedCategory = category; +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + invalidateFilter(); +#else + invalidateRowsFilter(); +#endif +} + bool TypesSortFilterProxyModel::filterAcceptsRow(int row, const QModelIndex &parent) const { QModelIndex index = sourceModel()->index(row, 0, parent); TypeDescription exp = index.data(TypesModel::TypeDescriptionRole).value(); - if (selectedCategory.isEmpty()) { - return exp.type.contains(filterRegExp()); - } else { - return selectedCategory == exp.category && exp.type.contains(filterRegExp()); + if (!selectedCategory.isEmpty() && selectedCategory != exp.category) { + return false; } + return qhelpers::filterStringContains(exp.type, this); } bool TypesSortFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const @@ -169,9 +178,7 @@ TypesWidget::TypesWidget(MainWindow *main) connect(Core(), &CutterCore::refreshAll, this, &TypesWidget::refreshTypes); connect(ui->quickFilterView->comboBox(), &QComboBox::currentTextChanged, this, [this]() { - types_proxy_model->selectedCategory = - ui->quickFilterView->comboBox()->currentData().toString(); - types_proxy_model->setFilterRegExp(types_proxy_model->filterRegExp()); + types_proxy_model->setCategory(ui->quickFilterView->comboBox()->currentData().toString()); tree->showItemsNumber(types_proxy_model->rowCount()); }); @@ -213,7 +220,7 @@ void TypesWidget::refreshCategoryCombo(const QStringList &categories) combo->addItem(category, category); } - types_proxy_model->selectedCategory.clear(); + types_proxy_model->setCategory(QString()); } void TypesWidget::setScrollMode() diff --git a/src/widgets/TypesWidget.h b/src/widgets/TypesWidget.h index 9372dd27..ddddeb09 100644 --- a/src/widgets/TypesWidget.h +++ b/src/widgets/TypesWidget.h @@ -50,10 +50,9 @@ class TypesSortFilterProxyModel : public QSortFilterProxyModel { Q_OBJECT - friend TypesWidget; - public: TypesSortFilterProxyModel(TypesModel *source_model, QObject *parent = nullptr); + void setCategory(QString category); protected: bool filterAcceptsRow(int row, const QModelIndex &parent) const override; diff --git a/src/widgets/ZignaturesWidget.cpp b/src/widgets/ZignaturesWidget.cpp index d9c61760..a1b2167a 100644 --- a/src/widgets/ZignaturesWidget.cpp +++ b/src/widgets/ZignaturesWidget.cpp @@ -87,7 +87,7 @@ bool ZignaturesProxyModel::filterAcceptsRow(int row, const QModelIndex &parent) QModelIndex index = sourceModel()->index(row, 0, parent); ZignatureDescription item = index.data(ZignaturesModel::ZignatureDescriptionRole).value(); - return item.name.contains(filterRegExp()); + return qhelpers::filterStringContains(item.name, this); } bool ZignaturesProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const