diff options
author | Stephen Kelly <ske@ableton.com> | 2016-06-03 14:18:41 +0200 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2017-06-28 07:00:20 +0000 |
commit | 3ffcfc357dbc51bf62ffb77eca9c99c6bf04e0f2 (patch) | |
tree | 09749040c1ae50e2f00965686ed963b46d9b46b1 /tests/auto/corelib/itemmodels | |
parent | 24961cb18c50efab4b62b91968f660d8b6736ec4 (diff) |
QSFPM: Avoid following a reset with unnecessary layoutChanged
Follow the pattern used to guard Private::sort() calls elsewhere in the
class.
Because QAbstractItemModel::sort() is not called in the unit test, the
content is not sorted after resetting.
[ChangeLog][QtCore][QSortFilterProxyModel] QSortFilterProxyModel
now does not emit an unnecessary layoutChanged() following a model
reset.
Change-Id: I0a36c7fbb172bdd06ecddb489c5595debbef6cb9
Reviewed-by: Milian Wolff <milian.wolff@kdab.com>
Diffstat (limited to 'tests/auto/corelib/itemmodels')
-rw-r--r-- | tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp b/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp index 54582ee4c3..383bbbd3f8 100644 --- a/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp +++ b/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp @@ -94,6 +94,7 @@ private slots: void changeSourceDataKeepsStableSorting_qtbug1548(); void changeSourceDataForwardsRoles_qtbug35440(); void resortingDoesNotBreakTreeModels(); + void dynamicFilterWithoutSort(); void sortFilterRole(); void selectionFilteredOut(); void match_data(); @@ -4485,6 +4486,29 @@ void tst_QSortFilterProxyModel::emitLayoutChangedOnlyIfSortingChanged() QCOMPARE(proxyLayoutChangedSpy.size(), expectedLayoutChanged); } +void tst_QSortFilterProxyModel::dynamicFilterWithoutSort() +{ + QStringListModel model; + const QStringList initial = QString("bravo charlie delta echo").split(QLatin1Char(' ')); + model.setStringList(initial); + QSortFilterProxyModel proxy; + proxy.setDynamicSortFilter(true); + proxy.setSourceModel(&model); + + QSignalSpy layoutChangeSpy(&proxy, &QAbstractItemModel::layoutChanged); + QSignalSpy resetSpy(&proxy, &QAbstractItemModel::modelReset); + + QVERIFY(layoutChangeSpy.isValid()); + QVERIFY(resetSpy.isValid()); + + model.setStringList(QStringList() << "Monday" << "Tuesday" << "Wednesday" << "Thursday" << "Friday"); + + QVERIFY(layoutChangeSpy.isEmpty()); + + QCOMPARE(model.stringList(), QStringList() << "Monday" << "Tuesday" << "Wednesday" << "Thursday" << "Friday"); + + QCOMPARE(resetSpy.count(), 1); +} QTEST_MAIN(tst_QSortFilterProxyModel) #include "tst_qsortfilterproxymodel.moc" |