aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndrew den Exter <andrew.den-exter@nokia.com>2011-07-27 17:54:04 +1000
committerQt by Nokia <qt-info@nokia.com>2011-07-28 04:34:22 +0200
commit44e201c04e699f3bee49f63894477f5105092cb0 (patch)
treea205f0222e167338ef68087b20f0585639fc5ebc /src
parent945aba32800d5a22fa01694a81d4dfe2c23e853a (diff)
Update ListModel's internal indexes when items are inserted/removed.
The changed signals of cached items were being emitted with incorrect indexes if a previous item in the list was inserted or removed, resulting in changes not being reflected in views. Task-number: QTBUG-20286 Change-Id: Id2fb8e2875c6cbd4f2e4d14ef859b7a7a4bac8d9 Reviewed-on: http://codereview.qt.nokia.com/2252 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Bea Lam <bea.lam@nokia.com>
Diffstat (limited to 'src')
-rw-r--r--src/declarative/util/qdeclarativelistmodel.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/declarative/util/qdeclarativelistmodel.cpp b/src/declarative/util/qdeclarativelistmodel.cpp
index 8659c5b7aa..e35d64b179 100644
--- a/src/declarative/util/qdeclarativelistmodel.cpp
+++ b/src/declarative/util/qdeclarativelistmodel.cpp
@@ -1373,6 +1373,11 @@ void NestedListModel::remove(int index)
return;
ModelNode *node = qvariant_cast<ModelNode *>(_root->values.at(index));
_root->values.removeAt(index);
+ for (int i = 0; i < _root->values.count(); ++i) {
+ ModelNode *node = qvariant_cast<ModelNode *>(_root->values.at(i));
+ if (node)
+ node->listIndex = i;
+ }
if (node)
delete node;
}
@@ -1388,6 +1393,11 @@ bool NestedListModel::insert(int index, v8::Handle<v8::Value> valuemap)
mn->listIndex = index;
mn->setObjectValue(valuemap);
_root->values.insert(index,QVariant::fromValue(mn));
+ for (int i = index + 1; i < _root->values.count(); ++i) {
+ ModelNode *node = qvariant_cast<ModelNode *>(_root->values.at(i));
+ if (node)
+ node->listIndex = i;
+ }
return true;
}
@@ -1396,6 +1406,11 @@ void NestedListModel::move(int from, int to, int n)
if (!_root)
return;
qdeclarativelistmodel_move<QVariantList>(from, to, n, &_root->values);
+ for (int i = qMin(from, to), end = qMin(_root->values.count(), qMax(from, to) + n); i < end; ++i) {
+ ModelNode *node = qvariant_cast<ModelNode *>(_root->values.at(i));
+ if (node)
+ node->listIndex = i;
+ }
}
v8::Handle<v8::Value> NestedListModel::get(int index) const