mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-18 10:56:11 +00:00
Update usage of deprecated qt model and regex API.
This commit is contained in:
parent
820aa98b7b
commit
fe92aaeb3d
@ -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
|
||||
|
@ -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
|
||||
|
@ -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<ProcessDescription>();
|
||||
return item.path.contains(filterRegExp());
|
||||
return qhelpers::filterStringContains(item.path, this);
|
||||
}
|
||||
|
||||
bool ProcessProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
|
||||
|
@ -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
|
||||
|
@ -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<CommentDescription>();
|
||||
|
||||
return comment.name.contains(filterRegExp());
|
||||
return qhelpers::filterStringContains(comment.name, this);
|
||||
}
|
||||
|
||||
bool CommentsProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
|
||||
|
@ -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<ExportDescription>();
|
||||
|
||||
return exp.name.contains(filterRegExp());
|
||||
return qhelpers::filterStringContains(exp.name, this);
|
||||
}
|
||||
|
||||
bool ExportsProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
|
||||
|
@ -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<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
|
||||
|
@ -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<FunctionDescription>();
|
||||
return function.name.contains(filterRegExp());
|
||||
|
||||
return qhelpers::filterStringContains(function.name, this);
|
||||
}
|
||||
|
||||
bool FunctionSortFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
|
||||
|
@ -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<HeaderDescription>();
|
||||
return item.name.contains(filterRegExp());
|
||||
return qhelpers::filterStringContains(item.name, this);
|
||||
}
|
||||
|
||||
bool HeadersProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
|
||||
|
@ -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<ImportDescription>();
|
||||
|
||||
return import.name.contains(filterRegExp());
|
||||
return qhelpers::filterStringContains(import.name, this);
|
||||
}
|
||||
|
||||
bool ImportsProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
|
||||
|
@ -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<MemoryMapDescription>();
|
||||
return item.name.contains(filterRegExp());
|
||||
return qhelpers::filterStringContains(item.name, this);
|
||||
}
|
||||
|
||||
bool MemoryProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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<RegisterRefDescription>();
|
||||
return item.reg.contains(filterRegExp());
|
||||
return qhelpers::filterStringContains(item.reg, this);
|
||||
}
|
||||
|
||||
bool RegisterRefProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
|
||||
|
@ -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<RelocDescription>();
|
||||
|
||||
return reloc.name.contains(filterRegExp());
|
||||
return qhelpers::filterStringContains(reloc.name, this);
|
||||
}
|
||||
|
||||
bool RelocsProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
|
||||
|
@ -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<SearchDescription>();
|
||||
return search.code.contains(filterRegExp());
|
||||
return qhelpers::filterStringContains(search.code, this);
|
||||
}
|
||||
|
||||
bool SearchSortFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
|
||||
|
@ -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<StringDescription>();
|
||||
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<StringDescription> &strings)
|
||||
|
@ -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;
|
||||
|
@ -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<SymbolDescription>();
|
||||
|
||||
return symbol.name.contains(filterRegExp());
|
||||
return qhelpers::filterStringContains(symbol.name, this);
|
||||
}
|
||||
|
||||
bool SymbolsProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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<TypeDescription>();
|
||||
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()
|
||||
|
@ -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;
|
||||
|
@ -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<ZignatureDescription>();
|
||||
return item.name.contains(filterRegExp());
|
||||
return qhelpers::filterStringContains(item.name, this);
|
||||
}
|
||||
|
||||
bool ZignaturesProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
|
||||
|
Loading…
Reference in New Issue
Block a user