Update usage of deprecated qt model and regex API.

This commit is contained in:
Kārlis Seņko 2021-04-13 21:35:18 +03:00 committed by karliss
parent 820aa98b7b
commit fe92aaeb3d
22 changed files with 61 additions and 35 deletions

View File

@ -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 } // end namespace

View File

@ -23,6 +23,7 @@ class QAction;
class QMenu; class QMenu;
class QPaintDevice; class QPaintDevice;
class QComboBox; class QComboBox;
class QSortFilterProxyModel;
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
# define CUTTER_QT_SKIP_EMPTY_PARTS QString::SkipEmptyParts # 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 void emitColumnChanged(QAbstractItemModel *model, int column);
CUTTER_EXPORT bool filterStringContains(const QString &string, const QSortFilterProxyModel *model);
} // qhelpers } // qhelpers
#endif // HELPERS_H #endif // HELPERS_H

View File

@ -156,7 +156,7 @@ bool ProcessProxyModel::filterAcceptsRow(int row, const QModelIndex &parent) con
QModelIndex index = sourceModel()->index(row, 0, parent); QModelIndex index = sourceModel()->index(row, 0, parent);
ProcessDescription item = ProcessDescription item =
index.data(ProcessModel::ProcDescriptionRole).value<ProcessDescription>(); index.data(ProcessModel::ProcDescriptionRole).value<ProcessDescription>();
return item.path.contains(filterRegExp()); return qhelpers::filterStringContains(item.path, this);
} }
bool ProcessProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const bool ProcessProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const

View File

@ -525,7 +525,7 @@ ClassesSortFilterProxyModel::ClassesSortFilterProxyModel(QObject *parent)
bool ClassesSortFilterProxyModel::filterAcceptsRow(int row, const QModelIndex &parent) const bool ClassesSortFilterProxyModel::filterAcceptsRow(int row, const QModelIndex &parent) const
{ {
QModelIndex index = sourceModel()->index(row, 0, parent); 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 bool ClassesSortFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const

View File

@ -195,7 +195,7 @@ bool CommentsProxyModel::filterAcceptsRow(int row, const QModelIndex &parent) co
QModelIndex index = sourceModel()->index(row, 0, parent); QModelIndex index = sourceModel()->index(row, 0, parent);
auto comment = index.data(CommentsModel::CommentDescriptionRole).value<CommentDescription>(); auto comment = index.data(CommentsModel::CommentDescriptionRole).value<CommentDescription>();
return comment.name.contains(filterRegExp()); return qhelpers::filterStringContains(comment.name, this);
} }
bool CommentsProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const bool CommentsProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const

View File

@ -98,7 +98,7 @@ bool ExportsProxyModel::filterAcceptsRow(int row, const QModelIndex &parent) con
QModelIndex index = sourceModel()->index(row, 0, parent); QModelIndex index = sourceModel()->index(row, 0, parent);
auto exp = index.data(ExportsModel::ExportDescriptionRole).value<ExportDescription>(); auto exp = index.data(ExportsModel::ExportDescriptionRole).value<ExportDescription>();
return exp.name.contains(filterRegExp()); return qhelpers::filterStringContains(exp.name, this);
} }
bool ExportsProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const bool ExportsProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const

View File

@ -107,7 +107,7 @@ bool FlagsSortFilterProxyModel::filterAcceptsRow(int row, const QModelIndex &par
{ {
QModelIndex index = sourceModel()->index(row, 0, parent); QModelIndex index = sourceModel()->index(row, 0, parent);
FlagDescription flag = index.data(FlagsModel::FlagDescriptionRole).value<FlagDescription>(); FlagDescription flag = index.data(FlagsModel::FlagDescriptionRole).value<FlagDescription>();
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 bool FlagsSortFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const

View File

@ -368,7 +368,8 @@ bool FunctionSortFilterProxyModel::filterAcceptsRow(int row, const QModelIndex &
QModelIndex index = sourceModel()->index(row, 0, parent); QModelIndex index = sourceModel()->index(row, 0, parent);
FunctionDescription function = FunctionDescription function =
index.data(FunctionModel::FunctionDescriptionRole).value<FunctionDescription>(); index.data(FunctionModel::FunctionDescriptionRole).value<FunctionDescription>();
return function.name.contains(filterRegExp());
return qhelpers::filterStringContains(function.name, this);
} }
bool FunctionSortFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const bool FunctionSortFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const

View File

@ -89,7 +89,7 @@ bool HeadersProxyModel::filterAcceptsRow(int row, const QModelIndex &parent) con
QModelIndex index = sourceModel()->index(row, 0, parent); QModelIndex index = sourceModel()->index(row, 0, parent);
HeaderDescription item = HeaderDescription item =
index.data(HeadersModel::HeaderDescriptionRole).value<HeaderDescription>(); index.data(HeadersModel::HeaderDescriptionRole).value<HeaderDescription>();
return item.name.contains(filterRegExp()); return qhelpers::filterStringContains(item.name, this);
} }
bool HeadersProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const bool HeadersProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const

View File

@ -123,7 +123,7 @@ bool ImportsProxyModel::filterAcceptsRow(int row, const QModelIndex &parent) con
QModelIndex index = sourceModel()->index(row, 0, parent); QModelIndex index = sourceModel()->index(row, 0, parent);
auto import = index.data(ImportsModel::ImportDescriptionRole).value<ImportDescription>(); auto import = index.data(ImportsModel::ImportDescriptionRole).value<ImportDescription>();
return import.name.contains(filterRegExp()); return qhelpers::filterStringContains(import.name, this);
} }
bool ImportsProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const bool ImportsProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const

View File

@ -88,7 +88,7 @@ bool MemoryProxyModel::filterAcceptsRow(int row, const QModelIndex &parent) cons
QModelIndex index = sourceModel()->index(row, 0, parent); QModelIndex index = sourceModel()->index(row, 0, parent);
MemoryMapDescription item = MemoryMapDescription item =
index.data(MemoryMapModel::MemoryDescriptionRole).value<MemoryMapDescription>(); index.data(MemoryMapModel::MemoryDescriptionRole).value<MemoryMapDescription>();
return item.name.contains(filterRegExp()); return qhelpers::filterStringContains(item.name, this);
} }
bool MemoryProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const bool MemoryProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const

View File

@ -191,7 +191,7 @@ bool ProcessesFilterModel::filterAcceptsRow(int row, const QModelIndex &parent)
// All columns are checked for a match // All columns are checked for a match
for (int i = COLUMN_PID; i <= COLUMN_PATH; ++i) { for (int i = COLUMN_PID; i <= COLUMN_PATH; ++i) {
QModelIndex index = sourceModel()->index(row, i, parent); QModelIndex index = sourceModel()->index(row, i, parent);
if (sourceModel()->data(index).toString().contains(filterRegExp())) { if (qhelpers::filterStringContains(sourceModel()->data(index).toString(), this)) {
return true; return true;
} }
} }

View File

@ -90,7 +90,7 @@ bool RegisterRefProxyModel::filterAcceptsRow(int row, const QModelIndex &parent)
QModelIndex index = sourceModel()->index(row, 0, parent); QModelIndex index = sourceModel()->index(row, 0, parent);
RegisterRefDescription item = index.data(RegisterRefModel::RegisterRefDescriptionRole) RegisterRefDescription item = index.data(RegisterRefModel::RegisterRefDescriptionRole)
.value<RegisterRefDescription>(); .value<RegisterRefDescription>();
return item.reg.contains(filterRegExp()); return qhelpers::filterStringContains(item.reg, this);
} }
bool RegisterRefProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const bool RegisterRefProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const

View File

@ -93,7 +93,7 @@ bool RelocsProxyModel::filterAcceptsRow(int row, const QModelIndex &parent) cons
QModelIndex index = sourceModel()->index(row, 0, parent); QModelIndex index = sourceModel()->index(row, 0, parent);
auto reloc = index.data(RelocsModel::RelocDescriptionRole).value<RelocDescription>(); auto reloc = index.data(RelocsModel::RelocDescriptionRole).value<RelocDescription>();
return reloc.name.contains(filterRegExp()); return qhelpers::filterStringContains(reloc.name, this);
} }
bool RelocsProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const bool RelocsProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const

View File

@ -145,7 +145,7 @@ bool SearchSortFilterProxyModel::filterAcceptsRow(int row, const QModelIndex &pa
QModelIndex index = sourceModel()->index(row, 0, parent); QModelIndex index = sourceModel()->index(row, 0, parent);
SearchDescription search = SearchDescription search =
index.data(SearchModel::SearchDescriptionRole).value<SearchDescription>(); index.data(SearchModel::SearchDescriptionRole).value<SearchDescription>();
return search.code.contains(filterRegExp()); return qhelpers::filterStringContains(search.code, this);
} }
bool SearchSortFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const bool SearchSortFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const

View File

@ -103,15 +103,26 @@ StringsProxyModel::StringsProxyModel(StringsModel *sourceModel, QObject *parent)
setSortCaseSensitivity(Qt::CaseInsensitive); 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 bool StringsProxyModel::filterAcceptsRow(int row, const QModelIndex &parent) const
{ {
QModelIndex index = sourceModel()->index(row, 0, parent); QModelIndex index = sourceModel()->index(row, 0, parent);
StringDescription str = StringDescription str =
index.data(StringsModel::StringDescriptionRole).value<StringDescription>(); index.data(StringsModel::StringDescriptionRole).value<StringDescription>();
if (selectedSection.isEmpty()) if (selectedSection.isEmpty()) {
return str.string.contains(filterRegExp()); return qhelpers::filterStringContains(str.string, this);
else } else {
return selectedSection == str.section && str.string.contains(filterRegExp()); return selectedSection == str.section && qhelpers::filterStringContains(str.string, this);
}
} }
bool StringsProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const bool StringsProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
@ -198,8 +209,7 @@ StringsWidget::StringsWidget(MainWindow *main)
[this]() { qhelpers::emitColumnChanged(model, StringsModel::CommentColumn); }); [this]() { qhelpers::emitColumnChanged(model, StringsModel::CommentColumn); });
connect(ui->quickFilterView->comboBox(), &QComboBox::currentTextChanged, this, [this]() { connect(ui->quickFilterView->comboBox(), &QComboBox::currentTextChanged, this, [this]() {
proxyModel->selectedSection = ui->quickFilterView->comboBox()->currentData().toString(); proxyModel->setSelectedSection(ui->quickFilterView->comboBox()->currentData().toString());
proxyModel->setFilterRegExp(proxyModel->filterRegExp());
tree->showItemsNumber(proxyModel->rowCount()); tree->showItemsNumber(proxyModel->rowCount());
}); });
@ -237,7 +247,7 @@ void StringsWidget::refreshSectionCombo()
combo->addItem(section, section); combo->addItem(section, section);
} }
proxyModel->selectedSection.clear(); proxyModel->setSelectedSection(QString());
} }
void StringsWidget::stringSearchFinished(const QList<StringDescription> &strings) void StringsWidget::stringSearchFinished(const QList<StringDescription> &strings)

View File

@ -59,10 +59,9 @@ class StringsProxyModel : public AddressableFilterProxyModel
{ {
Q_OBJECT Q_OBJECT
friend StringsWidget;
public: public:
StringsProxyModel(StringsModel *sourceModel, QObject *parent = nullptr); StringsProxyModel(StringsModel *sourceModel, QObject *parent = nullptr);
void setSelectedSection(QString section);
protected: protected:
bool filterAcceptsRow(int row, const QModelIndex &parent) const override; bool filterAcceptsRow(int row, const QModelIndex &parent) const override;

View File

@ -94,7 +94,7 @@ bool SymbolsProxyModel::filterAcceptsRow(int row, const QModelIndex &parent) con
QModelIndex index = sourceModel()->index(row, 0, parent); QModelIndex index = sourceModel()->index(row, 0, parent);
auto symbol = index.data(SymbolsModel::SymbolDescriptionRole).value<SymbolDescription>(); auto symbol = index.data(SymbolsModel::SymbolDescriptionRole).value<SymbolDescription>();
return symbol.name.contains(filterRegExp()); return qhelpers::filterStringContains(symbol.name, this);
} }
bool SymbolsProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const bool SymbolsProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const

View File

@ -174,7 +174,7 @@ bool ThreadsFilterModel::filterAcceptsRow(int row, const QModelIndex &parent) co
// All columns are checked for a match // All columns are checked for a match
for (int i = COLUMN_PID; i <= COLUMN_PATH; ++i) { for (int i = COLUMN_PID; i <= COLUMN_PATH; ++i) {
QModelIndex index = sourceModel()->index(row, i, parent); QModelIndex index = sourceModel()->index(row, i, parent);
if (sourceModel()->data(index).toString().contains(filterRegExp())) { if (qhelpers::filterStringContains(sourceModel()->data(index).toString(), this)) {
return true; return true;
} }
} }

View File

@ -91,15 +91,24 @@ TypesSortFilterProxyModel::TypesSortFilterProxyModel(TypesModel *source_model, Q
setSourceModel(source_model); 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 bool TypesSortFilterProxyModel::filterAcceptsRow(int row, const QModelIndex &parent) const
{ {
QModelIndex index = sourceModel()->index(row, 0, parent); QModelIndex index = sourceModel()->index(row, 0, parent);
TypeDescription exp = index.data(TypesModel::TypeDescriptionRole).value<TypeDescription>(); TypeDescription exp = index.data(TypesModel::TypeDescriptionRole).value<TypeDescription>();
if (selectedCategory.isEmpty()) { if (!selectedCategory.isEmpty() && selectedCategory != exp.category) {
return exp.type.contains(filterRegExp()); return false;
} else {
return selectedCategory == exp.category && exp.type.contains(filterRegExp());
} }
return qhelpers::filterStringContains(exp.type, this);
} }
bool TypesSortFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const 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(Core(), &CutterCore::refreshAll, this, &TypesWidget::refreshTypes);
connect(ui->quickFilterView->comboBox(), &QComboBox::currentTextChanged, this, [this]() { connect(ui->quickFilterView->comboBox(), &QComboBox::currentTextChanged, this, [this]() {
types_proxy_model->selectedCategory = types_proxy_model->setCategory(ui->quickFilterView->comboBox()->currentData().toString());
ui->quickFilterView->comboBox()->currentData().toString();
types_proxy_model->setFilterRegExp(types_proxy_model->filterRegExp());
tree->showItemsNumber(types_proxy_model->rowCount()); tree->showItemsNumber(types_proxy_model->rowCount());
}); });
@ -213,7 +220,7 @@ void TypesWidget::refreshCategoryCombo(const QStringList &categories)
combo->addItem(category, category); combo->addItem(category, category);
} }
types_proxy_model->selectedCategory.clear(); types_proxy_model->setCategory(QString());
} }
void TypesWidget::setScrollMode() void TypesWidget::setScrollMode()

View File

@ -50,10 +50,9 @@ class TypesSortFilterProxyModel : public QSortFilterProxyModel
{ {
Q_OBJECT Q_OBJECT
friend TypesWidget;
public: public:
TypesSortFilterProxyModel(TypesModel *source_model, QObject *parent = nullptr); TypesSortFilterProxyModel(TypesModel *source_model, QObject *parent = nullptr);
void setCategory(QString category);
protected: protected:
bool filterAcceptsRow(int row, const QModelIndex &parent) const override; bool filterAcceptsRow(int row, const QModelIndex &parent) const override;

View File

@ -87,7 +87,7 @@ bool ZignaturesProxyModel::filterAcceptsRow(int row, const QModelIndex &parent)
QModelIndex index = sourceModel()->index(row, 0, parent); QModelIndex index = sourceModel()->index(row, 0, parent);
ZignatureDescription item = ZignatureDescription item =
index.data(ZignaturesModel::ZignatureDescriptionRole).value<ZignatureDescription>(); index.data(ZignaturesModel::ZignatureDescriptionRole).value<ZignatureDescription>();
return item.name.contains(filterRegExp()); return qhelpers::filterStringContains(item.name, this);
} }
bool ZignaturesProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const bool ZignaturesProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const