aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/types/qqmllistmodel_p.h
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2017-12-28 16:03:44 +0100
committerJ-P Nurmi <jpnurmi@qt.io>2017-12-29 15:51:56 +0000
commit3accc1dae76575120e71cadb547e961ecd50bcb0 (patch)
tree2013ad02edb525ad22dac157e5a931b5cf162be5 /src/qml/types/qqmllistmodel_p.h
parent1db9405128972d5ba77e33181bee40356f718cea (diff)
Fix failed assertions coming from the QML list model
QAbstractItemModel has become more strict in sanity checking the arguments of beginInsertRows and friends with change 00c09e752ff7e482e1308e0e34721dc979204595 in qtbase. Unfortunately, the QML list model was feeding it out of bound rows in some cases, leading to failed assertions. Fix this properly, by calculating the inserted/removed and changed rows on the fly when syncing the list model from the worker thread. Adjust the code in the XML list model as well, so it does call things in the proper order. Fix two tests, one for a minimal change in behavior (more correct now), the other to remove an assertion that is not valid anymore in debug builds (where assertions in QtCore will call rowCount()). Change-Id: Ied85269f78d41b64e06388590be3ed227ac88fdb Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
Diffstat (limited to 'src/qml/types/qqmllistmodel_p.h')
-rw-r--r--src/qml/types/qqmllistmodel_p.h17
1 files changed, 7 insertions, 10 deletions
diff --git a/src/qml/types/qqmllistmodel_p.h b/src/qml/types/qqmllistmodel_p.h
index 499a113504..18b7b8bb22 100644
--- a/src/qml/types/qqmllistmodel_p.h
+++ b/src/qml/types/qqmllistmodel_p.h
@@ -147,24 +147,21 @@ private:
struct ElementSync
{
- ElementSync() : src(0), target(0) {}
-
- DynamicRoleModelNode *src;
- DynamicRoleModelNode *target;
+ DynamicRoleModelNode *src = nullptr;
+ DynamicRoleModelNode *target = nullptr;
+ int srcIndex = -1;
+ int targetIndex = -1;
+ QVector<int> changedRoles;
};
int getUid() const { return m_uid; }
- static void sync(QQmlListModel *src, QQmlListModel *target, QHash<int, QQmlListModel *> *targetModelHash);
+ static bool sync(QQmlListModel *src, QQmlListModel *target);
static QQmlListModel *createWithOwner(QQmlListModel *newOwner);
void emitItemsChanged(int index, int count, const QVector<int> &roles);
- void emitItemsAboutToBeRemoved(int index, int count);
- void emitItemsRemoved(int index, int count);
void emitItemsAboutToBeInserted(int index, int count);
- void emitItemsInserted(int index, int count);
- void emitItemsAboutToBeMoved(int from, int to, int n);
- void emitItemsMoved(int from, int to, int n);
+ void emitItemsInserted();
void removeElements(int index, int removeCount);
};