diff options
-rw-r--r-- | src/qml/types/qqmllistmodel.cpp | 15 | ||||
-rw-r--r-- | src/qml/types/qqmllistmodel_p_p.h | 2 |
2 files changed, 11 insertions, 6 deletions
diff --git a/src/qml/types/qqmllistmodel.cpp b/src/qml/types/qqmllistmodel.cpp index 06caa77bb4..eebf0f74d8 100644 --- a/src/qml/types/qqmllistmodel.cpp +++ b/src/qml/types/qqmllistmodel.cpp @@ -359,7 +359,7 @@ int ListModel::appendElement() void ListModel::insertElement(int index) { newElement(index); - updateCacheIndices(); + updateCacheIndices(index); } void ListModel::move(int from, int to, int n) @@ -381,7 +381,7 @@ void ListModel::move(int from, int to, int n) for (int i=0 ; i < store.count() ; ++i) elements[from+i] = store[i]; - updateCacheIndices(); + updateCacheIndices(from, to + n); } void ListModel::newElement(int index) @@ -390,9 +390,14 @@ void ListModel::newElement(int index) elements.insert(index, e); } -void ListModel::updateCacheIndices() +void ListModel::updateCacheIndices(int start, int end) { - for (int i=0 ; i < elements.count() ; ++i) { + int count = elements.count(); + + if (end < 0 || end > count) + end = count; + + for (int i = start; i < end; ++i) { ListElement *e = elements.at(i); if (ModelNodeMetaObject *mo = e->objectCache()) mo->m_elementIndex = i; @@ -574,7 +579,7 @@ void ListModel::remove(int index, int count) delete elements[index+i]; } elements.remove(index, count); - updateCacheIndices(); + updateCacheIndices(index); } void ListModel::insert(int elementIndex, QV4::Object *object) diff --git a/src/qml/types/qqmllistmodel_p_p.h b/src/qml/types/qqmllistmodel_p_p.h index 44583df2a6..e2653c220d 100644 --- a/src/qml/types/qqmllistmodel_p_p.h +++ b/src/qml/types/qqmllistmodel_p_p.h @@ -397,7 +397,7 @@ private: void newElement(int index); - void updateCacheIndices(); + void updateCacheIndices(int start = 0, int end = -1); friend class ListElement; friend class QQmlListModelWorkerAgent; |