summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSamuel Gaist <samuel.gaist@idiap.ch>2021-04-01 09:59:21 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-04-22 08:45:24 +0000
commitdc9b55d6b232868a86471a6c0fcc17a82b0c7609 (patch)
tree91d44b192d1c53fd7d473e7b13876d2094105722 /tests
parente066c4d4bf1a0008a1993802c4e5b97f8df974dc (diff)
Fix case sensitivity handling QSFPM
This patch fixes the breaking of case sensitivity handling. The removal of QRegExp killed the wrong code paths which leads to inconsistencies when changing the regular expression throuh methods like setFilterWildCard or setFilterFixedString. Changing the case sensitivity also nukes the original options that were set on the regular expression if it was set through setFilterRegularExpression. [ChangeLog][QtCore][QSortFilterProxyModel] Case sensitivity as well as regular expression options handling have been fixed. The original value is properly kept when using setFilterWildCard and setFilterFixedString. The regular expression options are now also properly kept when changing the case senstitivity through setFilterCaseSensitivity. Fixes: QTBUG-92260 Change-Id: Ifb4732306f0c7d79ad0b18d3f5437c4523bb40e5 Reviewed-by: Igor Kushnir <igorkuo@gmail.com> Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> (cherry picked from commit bcbbbdb2d640c059c19e9337c7418b83b1b7e4ea) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/itemmodels/qsortfilterproxymodel_regularexpression/tst_qsortfilterproxymodel_regularexpression.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/auto/corelib/itemmodels/qsortfilterproxymodel_regularexpression/tst_qsortfilterproxymodel_regularexpression.cpp b/tests/auto/corelib/itemmodels/qsortfilterproxymodel_regularexpression/tst_qsortfilterproxymodel_regularexpression.cpp
index 7f2a4b64ae..aead57d9fc 100644
--- a/tests/auto/corelib/itemmodels/qsortfilterproxymodel_regularexpression/tst_qsortfilterproxymodel_regularexpression.cpp
+++ b/tests/auto/corelib/itemmodels/qsortfilterproxymodel_regularexpression/tst_qsortfilterproxymodel_regularexpression.cpp
@@ -38,6 +38,8 @@ public:
private slots:
void tst_invalid();
void tst_caseSensitivity();
+ void tst_keepCaseSensitivity_QTBUG_92260();
+ void tst_keepPatternOptions_QTBUG_92260();
};
tst_QSortFilterProxyModelRegularExpression::tst_QSortFilterProxyModelRegularExpression() :
@@ -73,5 +75,69 @@ void tst_QSortFilterProxyModelRegularExpression::tst_caseSensitivity()
QCOMPARE(proxyModel.rowCount(), 2);
}
+/*!
+ This test ensures that when a string pattern is passed to setRegularEpxression,
+ the options are properly reseted but that the case sensitivity is kept as is.
+
+ */
+void tst_QSortFilterProxyModelRegularExpression::tst_keepCaseSensitivity_QTBUG_92260()
+{
+ const QLatin1String pattern("test");
+ QStringListModel model({ "test", "TesT" });
+ QSortFilterProxyModel proxyModel;
+ proxyModel.setSourceModel(&model);
+
+ QRegularExpression patternWithOptions("Dummy",
+ QRegularExpression::MultilineOption
+ | QRegularExpression::CaseInsensitiveOption);
+
+ proxyModel.setFilterRegularExpression(patternWithOptions);
+ QCOMPARE(proxyModel.filterRegularExpression(), patternWithOptions);
+ QCOMPARE(proxyModel.filterCaseSensitivity(), Qt::CaseInsensitive);
+
+ proxyModel.setFilterRegularExpression(pattern);
+ QCOMPARE(proxyModel.filterCaseSensitivity(), Qt::CaseInsensitive);
+ QCOMPARE(proxyModel.filterRegularExpression().patternOptions(),
+ QRegularExpression::CaseInsensitiveOption);
+
+ patternWithOptions.setPatternOptions(QRegularExpression::MultilineOption);
+ proxyModel.setFilterRegularExpression(patternWithOptions);
+ QCOMPARE(proxyModel.filterCaseSensitivity(), Qt::CaseSensitive);
+ QCOMPARE(proxyModel.filterRegularExpression(), patternWithOptions);
+
+ proxyModel.setFilterRegularExpression(pattern);
+ QCOMPARE(proxyModel.filterCaseSensitivity(), Qt::CaseSensitive);
+ QCOMPARE(proxyModel.filterRegularExpression().patternOptions(),
+ QRegularExpression::NoPatternOption);
+}
+
+/*!
+ This test ensures that when the case sensitivity is changed, it does not nuke
+ the pattern options that were set before.
+ */
+void tst_QSortFilterProxyModelRegularExpression::tst_keepPatternOptions_QTBUG_92260()
+{
+ QStringListModel model({ "test", "TesT" });
+ QSortFilterProxyModel proxyModel;
+ proxyModel.setSourceModel(&model);
+
+ QRegularExpression patternWithOptions("Dummy",
+ QRegularExpression::MultilineOption
+ | QRegularExpression::CaseInsensitiveOption);
+
+ proxyModel.setFilterRegularExpression(patternWithOptions);
+ QCOMPARE(proxyModel.filterRegularExpression(), patternWithOptions);
+
+ proxyModel.setFilterCaseSensitivity(Qt::CaseInsensitive);
+ QCOMPARE(proxyModel.filterCaseSensitivity(), Qt::CaseInsensitive);
+ QCOMPARE(proxyModel.filterRegularExpression().patternOptions(),
+ patternWithOptions.patternOptions());
+
+ proxyModel.setFilterCaseSensitivity(Qt::CaseSensitive);
+ QCOMPARE(proxyModel.filterCaseSensitivity(), Qt::CaseSensitive);
+ QCOMPARE(proxyModel.filterRegularExpression().patternOptions(),
+ QRegularExpression::MultilineOption);
+}
+
QTEST_MAIN(tst_QSortFilterProxyModelRegularExpression)
#include "tst_qsortfilterproxymodel_regularexpression.moc"