aboutsummaryrefslogtreecommitdiff
blob: fc60e30b62c15635547edaee1107b897ebbe37c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
https://bugreports.qt.io/browse/QTBUG-125053
https://bugreports.qt.io/browse/QTBUG-127340
https://codereview.qt-project.org/c/qt/qtbase/+/593123
--- a/src/corelib/itemmodels/qabstractitemmodel.cpp
+++ b/src/corelib/itemmodels/qabstractitemmodel.cpp
@@ -3396,4 +3396,11 @@
 void QAbstractItemModel::beginResetModel()
 {
+    Q_D(QAbstractItemModel);
+    if (d->resetting) {
+        qWarning() << "beginResetModel called on" << this << "without calling endResetModel first";
+        // Warn, but don't return early in case user code relies on the incorrect behavior.
+    }
+
+    d->resetting = true;
     emit modelAboutToBeReset(QPrivateSignal());
 }
@@ -3413,6 +3420,12 @@
 {
     Q_D(QAbstractItemModel);
+    if (!d->resetting) {
+        qWarning() << "endResetModel called on" << this << "without calling beginResetModel first";
+        // Warn, but don't return early in case user code relies on the incorrect behavior.
+    }
+
     d->invalidatePersistentIndexes();
     resetInternalData();
+    d->resetting = false;
     emit modelReset(QPrivateSignal());
 }
--- a/src/corelib/itemmodels/qabstractitemmodel_p.h
+++ b/src/corelib/itemmodels/qabstractitemmodel_p.h
@@ -46,4 +46,6 @@
     ~QAbstractItemModelPrivate();
 
+    static const QAbstractItemModelPrivate *get(const QAbstractItemModel *model) { return model->d_func(); }
+
     void removePersistentIndexData(QPersistentModelIndexData *data);
     void movePersistentIndexes(const QList<QPersistentModelIndexData *> &indexes, int change, const QModelIndex &parent,
@@ -116,4 +118,6 @@
     } persistent;
 
+    bool resetting = false;
+
     static const QHash<int,QByteArray> &defaultRoleNames();
     static bool isVariantLessThan(const QVariant &left, const QVariant &right,