summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2023-03-07 13:19:50 +0100
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2023-03-09 18:26:59 +0100
commit7261a2298734d4d4844d7ff34592378410293664 (patch)
treee1ebb2bf09c21bbb00c089a225a97b1ae1f1cada /tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp
parent057a3ddc174d7d99c8aa6f43003fd98542a79386 (diff)
QAbstractItemModel: fix match() with Qt::MatchWildcard
QAIM::match() supports different matching modes. The wildcard match mode was never meant to be specifically a filepath globbing wildcard, but rather a generic one -- something like "*" should match into a string like "a/b/c". This is a regression from Qt 5, where QRegExp::Wildcard was ported to only allow for path globbing rather than generic matching. [ChangeLog][QtCore][QAbstractItemModel] QAbstractItemModel::match() now uses more generic wildcard matches rather than file path globbing. Please refer to the documentation of QRegularExpression::wildcardToRegularExpression() for more information about the differences. Change-Id: I28b8a76b01fdd9c5dd8f99528fac1c7b704564bc Fixes: QTBUG-104585 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp')
-rw-r--r--tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp17
1 files changed, 9 insertions, 8 deletions
diff --git a/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp b/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp
index ddeb9da649..4c69575ecc 100644
--- a/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp
+++ b/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp
@@ -414,7 +414,7 @@ void tst_QAbstractItemModel::itemFlags()
void tst_QAbstractItemModel::match()
{
- QtTestModel model(4, 1);
+ QtTestModel model(5, 1);
QModelIndex start = model.index(0, 0, QModelIndex());
QVERIFY(start.isValid());
QModelIndexList res = model.match(start, Qt::DisplayRole, QVariant("1"), 3);
@@ -427,19 +427,20 @@ void tst_QAbstractItemModel::match()
model.setData(model.index(1, 0, QModelIndex()), "cat", Qt::DisplayRole);
model.setData(model.index(2, 0, QModelIndex()), "dog", Qt::DisplayRole);
model.setData(model.index(3, 0, QModelIndex()), "boar", Qt::DisplayRole);
+ model.setData(model.index(4, 0, QModelIndex()), "bo/a/r", Qt::DisplayRole); // QTBUG-104585
res = model.match(start, Qt::DisplayRole, QVariant("dog"), -1, Qt::MatchExactly);
QCOMPARE(res.size(), 1);
res = model.match(start, Qt::DisplayRole, QVariant("a"), -1, Qt::MatchContains);
- QCOMPARE(res.size(), 3);
+ QCOMPARE(res.size(), 4);
res = model.match(start, Qt::DisplayRole, QVariant("b"), -1, Qt::MatchStartsWith);
- QCOMPARE(res.size(), 2);
+ QCOMPARE(res.size(), 3);
res = model.match(start, Qt::DisplayRole, QVariant("t"), -1, Qt::MatchEndsWith);
QCOMPARE(res.size(), 2);
res = model.match(start, Qt::DisplayRole, QVariant("*a*"), -1, Qt::MatchWildcard);
- QCOMPARE(res.size(), 3);
+ QCOMPARE(res.size(), 4);
res = model.match(start, Qt::DisplayRole, QVariant(".*O.*"), -1, Qt::MatchRegularExpression);
- QCOMPARE(res.size(), 2);
+ QCOMPARE(res.size(), 3);
res = model.match(start, Qt::DisplayRole, QVariant(".*O.*"), -1, Qt::MatchRegularExpression | Qt::MatchCaseSensitive);
QCOMPARE(res.size(), 0);
res = model.match(start, Qt::DisplayRole, QVariant("BOAR"), -1, Qt::MatchFixedString);
@@ -450,7 +451,7 @@ void tst_QAbstractItemModel::match()
res = model.match(start, Qt::DisplayRole, QVariant(".*O.*"), -1,
Qt::MatchRegularExpression);
- QCOMPARE(res.size(), 2);
+ QCOMPARE(res.size(), 3);
res = model.match(start, Qt::DisplayRole, QVariant(".*O.*"), -1,
Qt::MatchRegularExpression | Qt::MatchCaseSensitive);
QCOMPARE(res.size(), 0);
@@ -464,7 +465,7 @@ void tst_QAbstractItemModel::match()
QRegularExpression::CaseInsensitiveOption)),
-1,
Qt::MatchRegularExpression);
- QCOMPARE(res.size(), 2);
+ QCOMPARE(res.size(), 3);
// Ensure that the case sensitivity is properly ignored when passing a
// QRegularExpression object.
@@ -474,7 +475,7 @@ void tst_QAbstractItemModel::match()
QRegularExpression::CaseInsensitiveOption)),
-1,
Qt::MatchRegularExpression | Qt::MatchCaseSensitive);
- QCOMPARE(res.size(), 2);
+ QCOMPARE(res.size(), 3);
}
typedef QPair<int, int> Position;