aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmlmodels/qqmldelegatemodel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/qmlmodels/qqmldelegatemodel.cpp')
-rw-r--r--src/qmlmodels/qqmldelegatemodel.cpp19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/qmlmodels/qqmldelegatemodel.cpp b/src/qmlmodels/qqmldelegatemodel.cpp
index 2216e5fb50..6c80f4a3e5 100644
--- a/src/qmlmodels/qqmldelegatemodel.cpp
+++ b/src/qmlmodels/qqmldelegatemodel.cpp
@@ -1344,6 +1344,11 @@ void QQmlDelegateModel::_q_itemsInserted(int index, int count)
const QList<QQmlDelegateModelItem *> cache = d->m_cache;
for (int i = 0, c = cache.count(); i < c; ++i) {
QQmlDelegateModelItem *item = cache.at(i);
+ // layout change triggered by changing the modelIndex might have
+ // already invalidated this item in d->m_cache and deleted it.
+ if (!d->m_cache.isSharedWith(cache) && !d->m_cache.contains(item))
+ continue;
+
if (item->modelIndex() >= index) {
const int newIndex = item->modelIndex() + count;
const int row = newIndex;
@@ -1487,7 +1492,7 @@ void QQmlDelegateModel::_q_itemsRemoved(int index, int count)
QQmlDelegateModelItem *item = cache.at(i);
// layout change triggered by removal of a previous item might have
// already invalidated this item in d->m_cache and deleted it
- if (!d->m_cache.contains(item))
+ if (!d->m_cache.isSharedWith(cache) && !d->m_cache.contains(item))
continue;
if (item->modelIndex() >= index + count) {
@@ -1542,6 +1547,11 @@ void QQmlDelegateModel::_q_itemsMoved(int from, int to, int count)
const QList<QQmlDelegateModelItem *> cache = d->m_cache;
for (int i = 0, c = cache.count(); i < c; ++i) {
QQmlDelegateModelItem *item = cache.at(i);
+ // layout change triggered by changing the modelIndex might have
+ // already invalidated this item in d->m_cache and deleted it.
+ if (!d->m_cache.isSharedWith(cache) && !d->m_cache.contains(item))
+ continue;
+
if (item->modelIndex() >= from && item->modelIndex() < from + count) {
const int newIndex = item->modelIndex() - from + to;
const int row = newIndex;
@@ -1634,6 +1644,11 @@ void QQmlDelegateModel::_q_modelReset()
const QList<QQmlDelegateModelItem *> cache = d->m_cache;
for (int i = 0, c = cache.count(); i < c; ++i) {
QQmlDelegateModelItem *item = cache.at(i);
+ // layout change triggered by changing the modelIndex might have
+ // already invalidated this item in d->m_cache and deleted it.
+ if (!d->m_cache.isSharedWith(cache) && !d->m_cache.contains(item))
+ continue;
+
if (item->modelIndex() != -1)
item->setModelIndex(-1, -1, -1);
}
@@ -2639,10 +2654,10 @@ QJSValue QQmlDelegateModelGroup::get(int index)
model->m_cacheMetaType->initializePrototype();
QV4::ExecutionEngine *v4 = model->m_cacheMetaType->v4Engine;
QV4::Scope scope(v4);
+ ++cacheItem->scriptRef;
QV4::ScopedObject o(scope, v4->memoryManager->allocate<QQmlDelegateModelItemObject>(cacheItem));
QV4::ScopedObject p(scope, model->m_cacheMetaType->modelItemProto.value());
o->setPrototypeOf(p);
- ++cacheItem->scriptRef;
return QJSValue(v4, o->asReturnedValue());
}