OSDN Git Service

effectively revert 3b2f36749730a11d1f058e0e6889a8280b2209f1 and cd5217cdbcf47683f1b63...
authorIvailo Monev <xakepa10@gmail.com>
Sun, 6 Nov 2022 12:12:40 +0000 (14:12 +0200)
committerIvailo Monev <xakepa10@gmail.com>
Sun, 6 Nov 2022 12:26:26 +0000 (14:26 +0200)
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
src/core/global/qnamespace.h
src/core/kernel/qabstractitemmodel.cpp

index 0fdc7cd..82e217e 100644 (file)
@@ -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)
 
index 3afdff3..17c6caa 100644 (file)
@@ -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