Skip to content

Commit

Permalink
qt: Use QRegularExpression in AddressBookSortFilterProxyModel class
Browse files Browse the repository at this point in the history
Co-authored-by: João Barbosa <joao.paulo.barbosa@gmail.com>
  • Loading branch information
hebasto and promag committed May 21, 2022
1 parent 5c5d8f2 commit e280087
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/qt/addressbookpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
#include <QMenu>
#include <QMessageBox>
#include <QSortFilterProxyModel>
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
#include <QRegularExpression>
#else
#include <QRegExp>
#endif

class AddressBookSortFilterProxyModel final : public QSortFilterProxyModel
{
Expand Down Expand Up @@ -46,12 +51,13 @@ class AddressBookSortFilterProxyModel final : public QSortFilterProxyModel

auto address = model->index(row, AddressTableModel::Address, parent);

if (filterRegExp().indexIn(model->data(address).toString()) < 0 &&
filterRegExp().indexIn(model->data(label).toString()) < 0) {
return false;
}

return true;
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
const auto pattern = filterRegularExpression();
#else
const auto pattern = filterRegExp();
#endif
return (model->data(address).toString().contains(pattern) ||
model->data(label).toString().contains(pattern));
}
};

Expand Down

0 comments on commit e280087

Please sign in to comment.