QSFPM: fix filterCaseSensitivityChanged signal emission logic

This patch amends bcbbbdb2d640c059c19e9337c7418b83b1b7e4ea.
It fixes the logic of filterCaseSensitivityChanged signal emission.
The call to QRegularExpression overload of setFilterRegularExpression
could change the filterCaseSensitivity, but the signal was never
emitted.

[ChangeLog][QtCore][QSortFilterProxyModel] A call to QRegularExpression
overload of setFilterRegularExpression now emits a
filterCaseSensitivityChanged signal, if required.

Pick-to: 6.0
Pick-to: 6.1
Change-Id: Id4ef04227c1f8ed98153fa5107ec3fbe4c0c77fb
Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
Ivan Solovev 2021-04-23 10:24:13 +02:00
parent 5ae7527411
commit 0d76a5cd2c
2 changed files with 23 additions and 0 deletions

View File

@ -2523,9 +2523,13 @@ QRegularExpression QSortFilterProxyModel::filterRegularExpression() const
void QSortFilterProxyModel::setFilterRegularExpression(const QRegularExpression &regularExpression)
{
Q_D(QSortFilterProxyModel);
const Qt::CaseSensitivity cs = filterCaseSensitivity();
d->filter_about_to_be_changed();
d->filter_regularexpression = regularExpression;
d->filter_changed(QSortFilterProxyModelPrivate::Direction::Rows);
const Qt::CaseSensitivity updatedCs = filterCaseSensitivity();
if (cs != updatedCs)
emit filterCaseSensitivityChanged(updatedCs);
}
/*!

View File

@ -27,6 +27,7 @@
****************************************************************************/
#include <QTest>
#include <QSignalSpy>
#include <QStringListModel>
#include "tst_qsortfilterproxymodel.h"
@ -41,6 +42,7 @@ private slots:
void tst_caseSensitivity();
void tst_keepCaseSensitivity_QTBUG_92260();
void tst_keepPatternOptions_QTBUG_92260();
void tst_regexCaseSensitivityNotification();
};
tst_QSortFilterProxyModelRegularExpression::tst_QSortFilterProxyModelRegularExpression() :
@ -140,5 +142,22 @@ void tst_QSortFilterProxyModelRegularExpression::tst_keepPatternOptions_QTBUG_92
QRegularExpression::MultilineOption);
}
/*!
This test ensures that if the case sensitivity is changed during a call to
setFilterRegularExpression, the notification signal will be emitted
*/
void tst_QSortFilterProxyModelRegularExpression::tst_regexCaseSensitivityNotification()
{
QSortFilterProxyModel proxy;
QSignalSpy spy(&proxy, &QSortFilterProxyModel::filterCaseSensitivityChanged);
proxy.setFilterCaseSensitivity(Qt::CaseInsensitive);
QCOMPARE(spy.count(), 1);
QRegularExpression re("regex");
QVERIFY(!re.patternOptions().testFlag(QRegularExpression::CaseInsensitiveOption));
proxy.setFilterRegularExpression(re);
QCOMPARE(proxy.filterCaseSensitivity(), Qt::CaseSensitive);
QCOMPARE(spy.count(), 2);
}
QTEST_MAIN(tst_QSortFilterProxyModelRegularExpression)
#include "tst_qsortfilterproxymodel_regularexpression.moc"