Deprecate QAbstractItemModel::reset().

It is broken in most uses because it emits modelAboutToBeReset()
after actually resetting the internal data instead of before.

That is, usually it is used like this:

myData.clear();
reset();

Which should be

beginResetModel();
myData.clear();
endResetModel();

Change-Id: I7b00a1e40c4915930944340764074efc29faaf5a
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
bb10
Stephen Kelly 2012-01-24 16:48:22 +01:00 committed by Qt by Nokia
parent 764840ec0e
commit 9af77d214a
2 changed files with 10 additions and 8 deletions

View File

@ -2927,19 +2927,14 @@ void QAbstractItemModel::endMoveColumns()
}
/*!
\obsolete
Resets the model to its original state in any attached views.
\note Use beginResetModel() and endResetModel() instead whenever possible.
Use this method only if there is no way to call beginResetModel() before invalidating the model.
Otherwise it could lead to unexpected behaviour, especially when used with proxy models.
*/
void QAbstractItemModel::reset()
{
Q_D(QAbstractItemModel);
emit modelAboutToBeReset();
d->invalidatePersistentIndexes();
emit modelReset();
}
/*!
Begins a model reset operation.

View File

@ -306,7 +306,14 @@ protected:
bool beginMoveColumns(const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationColumn);
void endMoveColumns();
void reset();
#if QT_DEPRECATED_SINCE(5,0)
QT_DEPRECATED void reset()
{
beginResetModel();
endResetModel();
}
#endif
void beginResetModel();
void endResetModel();