From cc9c8f9fc38eb5f039a85956e8a0d06f53cd67ab Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Sun, 6 Nov 2022 14:12:40 +0200 Subject: [PATCH] effectively revert 3b2f36749730a11d1f058e0e6889a8280b2209f1 and cd5217cdbcf47683f1b63fd42b63d354ea014bda Signed-off-by: Ivailo Monev --- src/core/global/qnamespace.h | 14 +++++++------- src/core/kernel/qabstractitemmodel.cpp | 24 ++++++++++++++++-------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/core/global/qnamespace.h b/src/core/global/qnamespace.h index 0fdc7cdab..82e217e71 100644 --- a/src/core/global/qnamespace.h +++ b/src/core/global/qnamespace.h @@ -1007,13 +1007,13 @@ public: MatchExactly = 0, MatchContains = 1, MatchStartsWith = 2, - MatchEndsWith = 4, - MatchRegExp = 8, - MatchWildcard = 16, - MatchFixedString = 32, - MatchCaseSensitive = 64, - MatchWrap = 128, - MatchRecursive = 256 + MatchEndsWith = 3, + MatchRegExp = 4, + MatchWildcard = 5, + MatchFixedString = 8, + MatchCaseSensitive = 16, + MatchWrap = 32, + MatchRecursive = 64 }; Q_DECLARE_FLAGS(MatchFlags, MatchFlag) diff --git a/src/core/kernel/qabstractitemmodel.cpp b/src/core/kernel/qabstractitemmodel.cpp index 3afdff380..17c6caa02 100644 --- a/src/core/kernel/qabstractitemmodel.cpp +++ b/src/core/kernel/qabstractitemmodel.cpp @@ -2039,6 +2039,7 @@ QModelIndexList QAbstractItemModel::match(const QModelIndex &start, int role, Qt::MatchFlags flags) const { QModelIndexList result; + uint matchType = flags & 0x0F; Qt::CaseSensitivity cs = flags & Qt::MatchCaseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive; bool recurse = flags & Qt::MatchRecursive; bool wrap = flags & Qt::MatchWrap; @@ -2056,32 +2057,39 @@ QModelIndexList QAbstractItemModel::match(const QModelIndex &start, int role, continue; QVariant v = data(idx, role); // QVariant based matching - if (flags & Qt::MatchExactly) { + if (matchType == Qt::MatchExactly) { if (value == v) result.append(idx); } else { // QString based matching if (text.isEmpty()) // lazy conversion text = value.toString(); QString t = v.toString(); - if (flags & Qt::MatchRegExp) { + switch (matchType) { + case Qt::MatchRegExp: if (QRegExp(text, cs).exactMatch(t)) result.append(idx); - } else if (flags & Qt::MatchWildcard) { + break; + case Qt::MatchWildcard: if (QRegExp(text, cs, QRegExp::Wildcard).exactMatch(t)) result.append(idx); - } else if (flags & Qt::MatchStartsWith) { + break; + case Qt::MatchStartsWith: if (t.startsWith(text, cs)) result.append(idx); - } else if (flags & Qt::MatchEndsWith) { + break; + case Qt::MatchEndsWith: if (t.endsWith(text, cs)) result.append(idx); - } else if (flags & Qt::MatchFixedString) { + break; + case Qt::MatchFixedString: if (t.compare(text, cs) == 0) result.append(idx); - } else { - // Qt::MatchContains: + break; + case Qt::MatchContains: + default: if (t.contains(text, cs)) result.append(idx); + break; } } if (recurse && hasChildren(idx)) { // search the hierarchy -- 2.11.0