diff options
author | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2018-03-11 18:01:32 +0100 |
---|---|---|
committer | André Hartmann <aha_1980@gmx.de> | 2018-04-22 12:46:45 +0000 |
commit | b3bbba7b871144c5d6f4b1a432f5c2cce02e321f (patch) | |
tree | 30199071e4392da28f9d5f5309066299ebf5932e /examples/widgets | |
parent | 999ba23946352a0ae4afd5e18f38a44851121b56 (diff) |
Examples: fix wrong QRegExp in Custom Sort/Filter Model Example
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 <aha_1980@gmx.de>
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
Reviewed-by: Samuel Gaist <samuel.gaist@edeltech.ch>
Reviewed-by: Topi Reiniö <topi.reinio@qt.io>
Diffstat (limited to 'examples/widgets')
-rw-r--r-- | examples/widgets/doc/src/customsortfiltermodel.qdoc | 16 | ||||
-rw-r--r-- | examples/widgets/itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp | 17 |
2 files changed, 19 insertions, 14 deletions
diff --git a/examples/widgets/doc/src/customsortfiltermodel.qdoc b/examples/widgets/doc/src/customsortfiltermodel.qdoc index 6eab846e89..9f0d13dd83 100644 --- a/examples/widgets/doc/src/customsortfiltermodel.qdoc +++ b/examples/widgets/doc/src/customsortfiltermodel.qdoc @@ -121,14 +121,14 @@ \snippet itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp 6 - We use QRegExp to define a pattern for the addresses we are looking - for. The QRegExp::indexIn() function attempts to find a match in - the given string and returns the position of the first match, or - -1 if there was no match. If the given string contains the - pattern, we use QRegExp's \l {QRegExp::cap()}{cap()} function to - retrieve the actual address. The \l {QRegExp::cap()}{cap()} - function returns the text captured by the \e nth - subexpression. The entire match has index 0 and the parenthesized + We use QRegularExpression to define a pattern for the addresses we + are looking for. The \l {QRegularExpression::match()}{match()} function + returns a QRegularExpressionMatch object which contains the result of + the matching. If there is a match, + \l {QRegularExpressionMatch::hasMatch()}{hasMatch()} returns true. The + result of the match can be retrieved with QRegularExpressionMatch's + \l {QRegularExpressionMatch::captured()}{captured()} function. + The entire match has index 0 and the parenthesized subexpressions have indexes starting from 1 (excluding non-capturing parentheses). 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; } |