qt: Use QRegularExpression in AddressBookSortFilterProxyModel class

Co-authored-by: João Barbosa <joao.paulo.barbosa@gmail.com>
This commit is contained in:
Hennadii Stepanov 2022-05-21 16:07:23 +02:00
parent 5c5d8f2465
commit e280087946
No known key found for this signature in database
GPG Key ID: 410108112E7EA81F

View File

@ -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
{
@ -46,12 +51,13 @@ protected:
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));
}
};