From c222a9283d94ad1e29334bb2fba0beef7cc716c7 Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Tue, 18 Jun 2019 00:07:54 +0200 Subject: QAbstractItemModel: implement QRegularExpression support for match This is part of the migration of qtbase from QRexExp to QRegularExpression. [ChangeLog][QtCore][QAbstractItemModel] The match() method now supports the new Qt::RegularExpression match flag value. This will allow users to use either a string or a fully configured QRegularExpression when doing searches. In the second case, the case sensitivity flag will be ignored if passed. Task-number: QTBUG-72587 Change-Id: I07c8d72a661c48b7f4fcf13ef8e95980bcdcb998 Reviewed-by: Giuseppe D'Angelo --- .../qabstractitemmodel/tst_qabstractitemmodel.cpp | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp b/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp index f305edb2c5..9fab36deaa 100644 --- a/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp +++ b/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp @@ -458,6 +458,34 @@ void tst_QAbstractItemModel::match() res = model.match(start, Qt::DisplayRole, QVariant("bat"), -1, Qt::MatchFixedString | Qt::MatchCaseSensitive); QCOMPARE(res.count(), 1); + + res = model.match(start, Qt::DisplayRole, QVariant(".*O.*"), -1, + Qt::MatchRegularExpression); + QCOMPARE(res.count(), 2); + res = model.match(start, Qt::DisplayRole, QVariant(".*O.*"), -1, + Qt::MatchRegularExpression | Qt::MatchCaseSensitive); + QCOMPARE(res.count(), 0); + + res = model.match(start, Qt::DisplayRole, QVariant(QRegularExpression(".*O.*")), + -1, Qt::MatchRegularExpression); + QCOMPARE(res.count(), 0); + res = model.match(start, + Qt::DisplayRole, + QVariant(QRegularExpression(".*O.*", + QRegularExpression::CaseInsensitiveOption)), + -1, + Qt::MatchRegularExpression); + QCOMPARE(res.count(), 2); + + // Ensure that the case sensitivity is properly ignored when passing a + // QRegularExpression object. + res = model.match(start, + Qt::DisplayRole, + QVariant(QRegularExpression(".*O.*", + QRegularExpression::CaseInsensitiveOption)), + -1, + Qt::MatchRegularExpression | Qt::MatchCaseSensitive); + QCOMPARE(res.count(), 2); } typedef QPair Position; -- cgit v1.2.3