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>
This commit is contained in:
parent
24961cb18c
commit
3ffcfc357d
@ -1408,7 +1408,7 @@ void QSortFilterProxyModelPrivate::_q_sourceReset()
|
||||
// All internal structures are deleted in clear()
|
||||
q->endResetModel();
|
||||
update_source_sort_column();
|
||||
if (dynamic_sortfilter)
|
||||
if (dynamic_sortfilter && update_source_sort_column())
|
||||
sort();
|
||||
}
|
||||
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user