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.10 6.9 6.8 6.5 Change-Id: I363f2f34a06cc5de031fa87c6274322bf03bd77f Reviewed-by: David Faure <david.faure@kdab.com>
This commit is contained in:
parent
a9a68a87b9
commit
3f0261ebe3
@ -2110,6 +2110,13 @@ void QSortFilterProxyModel::setSourceModel(QAbstractItemModel *sourceModel)
|
|||||||
QObjectPrivate::connect(d->model, &QAbstractItemModel::modelReset, d,
|
QObjectPrivate::connect(d->model, &QAbstractItemModel::modelReset, d,
|
||||||
&QSortFilterProxyModelPrivate::_q_sourceReset)
|
&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();
|
endResetModel();
|
||||||
if (d->update_source_sort_column() && d->dynamic_sortfilter)
|
if (d->update_source_sort_column() && d->dynamic_sortfilter)
|
||||||
d->sort();
|
d->sort();
|
||||||
|
@ -3663,6 +3663,18 @@ void tst_QSortFilterProxyModel::resetInvalidate()
|
|||||||
QCOMPARE(ok, works);
|
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'
|
* A proxy which changes the background color for items ending in 'y' or 'r'
|
||||||
*/
|
*/
|
||||||
|
@ -104,6 +104,7 @@ private slots:
|
|||||||
void unnecessaryMapCreation();
|
void unnecessaryMapCreation();
|
||||||
void resetInvalidate_data();
|
void resetInvalidate_data();
|
||||||
void resetInvalidate();
|
void resetInvalidate();
|
||||||
|
void sourceModelInReset();
|
||||||
|
|
||||||
void testMultipleProxiesWithSelection();
|
void testMultipleProxiesWithSelection();
|
||||||
void mapSelectionFromSource();
|
void mapSelectionFromSource();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user