summaryrefslogtreecommitdiffstats
path: root/src/corelib/itemmodels/qabstractitemmodel.cpp
diff options
context:
space:
mode:
authorQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2019-10-17 01:01:01 +0200
committerQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2019-10-17 01:01:01 +0200
commit6f27bb135246b7fe9d11ba58e05d2b7661bc2080 (patch)
tree9704e1c4ffb775472a9984872c3bd292faa999a5 /src/corelib/itemmodels/qabstractitemmodel.cpp
parentdc4212b3a694e143595968419ae5ad695ab2aa03 (diff)
parentc222a9283d94ad1e29334bb2fba0beef7cc716c7 (diff)
Merge remote-tracking branch 'origin/5.15' into dev
Diffstat (limited to 'src/corelib/itemmodels/qabstractitemmodel.cpp')
-rw-r--r--src/corelib/itemmodels/qabstractitemmodel.cpp32
1 files changed, 28 insertions, 4 deletions
diff --git a/src/corelib/itemmodels/qabstractitemmodel.cpp b/src/corelib/itemmodels/qabstractitemmodel.cpp
index 47151a4aba..fc69e362c7 100644
--- a/src/corelib/itemmodels/qabstractitemmodel.cpp
+++ b/src/corelib/itemmodels/qabstractitemmodel.cpp
@@ -46,6 +46,7 @@
#include <qdebug.h>
#include <qvector.h>
#include <qregexp.h>
+#include <qregularexpression.h>
#include <qstack.h>
#include <qbitarray.h>
#include <qdatetime.h>
@@ -2358,6 +2359,7 @@ QModelIndexList QAbstractItemModel::match(const QModelIndex &start, int role,
bool wrap = flags & Qt::MatchWrap;
bool allHits = (hits == -1);
QString text; // only convert to a string if it is needed
+ QRegularExpression rx; // only create it if needed
const int column = start.column();
QModelIndex p = parent(start);
int from = start.row();
@@ -2374,17 +2376,39 @@ QModelIndexList QAbstractItemModel::match(const QModelIndex &start, int role,
if (matchType == Qt::MatchExactly) {
if (value == v)
result.append(idx);
- } else { // QString based matching
- if (text.isEmpty()) // lazy conversion
- text = value.toString();
+ } else { // QString or regular expression based matching
+ if (matchType == Qt::MatchRegularExpression) {
+ if (rx.pattern().isEmpty()) {
+ if (value.type() == QVariant::RegularExpression) {
+ rx = value.toRegularExpression();
+ } else {
+ rx.setPattern(value.toString());
+ if (cs == Qt::CaseInsensitive)
+ rx.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
+ }
+ }
+ } else if (matchType == Qt::MatchWildcard) {
+ if (rx.pattern().isEmpty())
+ rx.setPattern(QRegularExpression::wildcardToRegularExpression(value.toString()));
+ if (cs == Qt::CaseInsensitive)
+ rx.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
+ } else {
+ if (text.isEmpty()) // lazy conversion
+ text = value.toString();
+ }
+
QString t = v.toString();
switch (matchType) {
+#if QT_DEPRECATED_SINCE(5, 15)
case Qt::MatchRegExp:
if (QRegExp(text, cs).exactMatch(t))
result.append(idx);
break;
+#endif
+ case Qt::MatchRegularExpression:
+ Q_FALLTHROUGH();
case Qt::MatchWildcard:
- if (QRegExp(text, cs, QRegExp::Wildcard).exactMatch(t))
+ if (t.contains(rx))
result.append(idx);
break;
case Qt::MatchStartsWith: