QSFPM: Support source model undergoing reset during setSourceModel
Since 9d8663c18e88cb0b5a65f86cfd7726f3d31e04d6, we print a warning when endResetModel is called without beginResetModel. This however triggers false positives with a QSFPM if we set a source model which is resetting at this point in time: The QSFPM reacts to the endResetModel signal in _q_sourceReset by calling its own endResetModel, but it does not have the resetting flag set. Fix this by deferring the endResetModel work that we are doing in setSourceModel if the source is undergoing reset. Task-number: QTBUG-132775 Pick-to: 6.9 6.8 6.5 Change-Id: I363f2f34a06cc5de031fa87c6274322bf03bd77f Reviewed-by: David Faure <david.faure@kdab.com> (cherry picked from commit 3f0261ebe3010f12a887869ff5adf7ad30f5e4c7) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
4d644342ad
commit
64407cc9ce
@ -2110,6 +2110,13 @@ void QSortFilterProxyModel::setSourceModel(QAbstractItemModel *sourceModel)
|
||||
QObjectPrivate::connect(d->model, &QAbstractItemModel::modelReset, d,
|
||||
&QSortFilterProxyModelPrivate::_q_sourceReset)
|
||||
};
|
||||
/* check whether we are connecting to a model that is undergoing a reset currently.
|
||||
If it is, _q_sourceReset will take care of calling endResetModel, and of
|
||||
calling sort if necessary.
|
||||
*/
|
||||
auto modelPrivate = d->model ? QAbstractItemModelPrivate::get(d->model) : nullptr;
|
||||
if (modelPrivate && modelPrivate->resetting)
|
||||
return;
|
||||
endResetModel();
|
||||
if (d->update_source_sort_column() && d->dynamic_sortfilter)
|
||||
d->sort();
|
||||
|
@ -3663,6 +3663,18 @@ void tst_QSortFilterProxyModel::resetInvalidate()
|
||||
QCOMPARE(ok, works);
|
||||
}
|
||||
|
||||
void tst_QSortFilterProxyModel::sourceModelInReset()
|
||||
{
|
||||
QTest::failOnWarning();
|
||||
QStandardItemModel m1;
|
||||
QSortFilterProxyModel sfpm;
|
||||
connect(&m1, &QAbstractItemModel::modelAboutToBeReset, &sfpm, [&]() {
|
||||
sfpm.setSourceModel(&m1);
|
||||
});
|
||||
m1.clear();
|
||||
QCOMPARE_EQ(sfpm.sourceModel(), &m1);
|
||||
}
|
||||
|
||||
/**
|
||||
* A proxy which changes the background color for items ending in 'y' or 'r'
|
||||
*/
|
||||
|
@ -104,6 +104,7 @@ private slots:
|
||||
void unnecessaryMapCreation();
|
||||
void resetInvalidate_data();
|
||||
void resetInvalidate();
|
||||
void sourceModelInReset();
|
||||
|
||||
void testMultipleProxiesWithSelection();
|
||||
void mapSelectionFromSource();
|
||||
|
Loading…
x
Reference in New Issue
Block a user