From b3bbba7b871144c5d6f4b1a432f5c2cce02e321f Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sun, 11 Mar 2018 18:01:32 +0100 Subject: Examples: fix wrong QRegExp in Custom Sort/Filter Model Example MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix wrong QRegExp in Custom Sort/Filter Model Example and replace it with QRegularExpression. Task-number: QTBUG-61129 Change-Id: I515474ee6985d36195d90dcd93876ba28a83bccc Reviewed-by: André Hartmann Reviewed-by: Paul Wicking Reviewed-by: Samuel Gaist Reviewed-by: Topi Reiniö --- .../customsortfiltermodel/mysortfilterproxymodel.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'examples/widgets/itemviews/customsortfiltermodel') diff --git a/examples/widgets/itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp b/examples/widgets/itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp index c93368b390..35426657d9 100644 --- a/examples/widgets/itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp +++ b/examples/widgets/itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp @@ -101,15 +101,20 @@ bool MySortFilterProxyModel::lessThan(const QModelIndex &left, if (leftData.type() == QVariant::DateTime) { return leftData.toDateTime() < rightData.toDateTime(); } else { - static QRegExp emailPattern("[\\w\\.]*@[\\w\\.]*)"); + static const QRegularExpression emailPattern("[\\w\\.]*@[\\w\\.]*"); QString leftString = leftData.toString(); - if(left.column() == 1 && emailPattern.indexIn(leftString) != -1) - leftString = emailPattern.cap(1); - + if (left.column() == 1) { + const QRegularExpressionMatch match = emailPattern.match(leftString); + if (match.hasMatch()) + leftString = match.captured(0); + } QString rightString = rightData.toString(); - if(right.column() == 1 && emailPattern.indexIn(rightString) != -1) - rightString = emailPattern.cap(1); + if (right.column() == 1) { + const QRegularExpressionMatch match = emailPattern.match(rightString); + if (match.hasMatch()) + rightString = match.captured(0); + } return QString::localeAwareCompare(leftString, rightString) < 0; } -- cgit v1.2.3