aboutsummaryrefslogtreecommitdiffstats
path: root/src/declarative/qml/qdeclarativelistmodelworkeragent.cpp
diff options
context:
space:
mode:
authorGlenn Watson <glenn.watson@nokia.com>2011-12-01 10:40:44 +1000
committerQt by Nokia <qt-info@nokia.com>2011-12-02 10:13:40 +0100
commit542a7d164ad81973f911a54bc53aa385d09b5c1f (patch)
treef0b46f04f2c026f493d093e3ab787ea3ed2a116b /src/declarative/qml/qdeclarativelistmodelworkeragent.cpp
parent63662f7f0e92c080cb45c99149b36f179f9b1360 (diff)
Add dynamicRoles mode to ListModel for extra flexibility.
ListModel contains a new property called dynamicRoles. By default this property is disabled, meaning that the type of a given role cannot be changed dynamically. However, when this property is set, the type of a role can change between elements. This allows more flexibility but comes at a significant performance cost over the default static role mode. Change-Id: I478d48c882f51ba2dde37f88e2aac744e919b68b Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'src/declarative/qml/qdeclarativelistmodelworkeragent.cpp')
-rw-r--r--src/declarative/qml/qdeclarativelistmodelworkeragent.cpp49
1 files changed, 30 insertions, 19 deletions
diff --git a/src/declarative/qml/qdeclarativelistmodelworkeragent.cpp b/src/declarative/qml/qdeclarativelistmodelworkeragent.cpp
index c01025cd45..3904d35a92 100644
--- a/src/declarative/qml/qdeclarativelistmodelworkeragent.cpp
+++ b/src/declarative/qml/qdeclarativelistmodelworkeragent.cpp
@@ -53,10 +53,8 @@
QT_BEGIN_NAMESPACE
-void QDeclarativeListModelWorkerAgent::Data::clearChange(QDeclarativeListModel *model)
+void QDeclarativeListModelWorkerAgent::Data::clearChange(int uid)
{
- int uid = model->m_listModel->getUid();
-
for (int i=0 ; i < changes.count() ; ++i) {
if (changes[i].modelUid == uid) {
changes.removeAt(i);
@@ -65,27 +63,27 @@ void QDeclarativeListModelWorkerAgent::Data::clearChange(QDeclarativeListModel *
}
}
-void QDeclarativeListModelWorkerAgent::Data::insertChange(QDeclarativeListModel *model, int index, int count)
+void QDeclarativeListModelWorkerAgent::Data::insertChange(int uid, int index, int count)
{
- Change c = { model->m_listModel->getUid(), Change::Inserted, index, count, 0, QList<int>() };
+ Change c = { uid, Change::Inserted, index, count, 0, QList<int>() };
changes << c;
}
-void QDeclarativeListModelWorkerAgent::Data::removeChange(QDeclarativeListModel *model, int index, int count)
+void QDeclarativeListModelWorkerAgent::Data::removeChange(int uid, int index, int count)
{
- Change c = { model->m_listModel->getUid(), Change::Removed, index, count, 0, QList<int>() };
+ Change c = { uid, Change::Removed, index, count, 0, QList<int>() };
changes << c;
}
-void QDeclarativeListModelWorkerAgent::Data::moveChange(QDeclarativeListModel *model, int index, int count, int to)
+void QDeclarativeListModelWorkerAgent::Data::moveChange(int uid, int index, int count, int to)
{
- Change c = { model->m_listModel->getUid(), Change::Moved, index, count, to, QList<int>() };
+ Change c = { uid, Change::Moved, index, count, to, QList<int>() };
changes << c;
}
-void QDeclarativeListModelWorkerAgent::Data::changedChange(QDeclarativeListModel *model, int index, int count, const QList<int> &roles)
+void QDeclarativeListModelWorkerAgent::Data::changedChange(int uid, int index, int count, const QList<int> &roles)
{
- Change c = { model->m_listModel->getUid(), Change::Changed, index, count, 0, roles };
+ Change c = { uid, Change::Changed, index, count, 0, roles };
changes << c;
}
@@ -181,27 +179,40 @@ bool QDeclarativeListModelWorkerAgent::event(QEvent *e)
bool cc = m_orig->count() != s->list->count();
- QHash<int, ListModel *> targetModelHash;
- ListModel::sync(s->list->m_listModel, m_orig->m_listModel, &targetModelHash);
+ QHash<int, QDeclarativeListModel *> targetModelDynamicHash;
+ QHash<int, ListModel *> targetModelStaticHash;
+
+ Q_ASSERT(m_orig->m_dynamicRoles == s->list->m_dynamicRoles);
+ if (m_orig->m_dynamicRoles)
+ QDeclarativeListModel::sync(s->list, m_orig, &targetModelDynamicHash);
+ else
+ ListModel::sync(s->list->m_listModel, m_orig->m_listModel, &targetModelStaticHash);
for (int ii = 0; ii < changes.count(); ++ii) {
const Change &change = changes.at(ii);
- ListModel *model = targetModelHash.value(change.modelUid);
+ QDeclarativeListModel *model = 0;
+ if (m_orig->m_dynamicRoles) {
+ model = targetModelDynamicHash.value(change.modelUid);
+ } else {
+ ListModel *lm = targetModelStaticHash.value(change.modelUid);
+ if (lm)
+ model = lm->m_modelCache;
+ }
- if (model && model->m_modelCache) {
+ if (model) {
switch (change.type) {
case Change::Inserted:
- emit model->m_modelCache->itemsInserted(change.index, change.count);
+ emit model->itemsInserted(change.index, change.count);
break;
case Change::Removed:
- emit model->m_modelCache->itemsRemoved(change.index, change.count);
+ emit model->itemsRemoved(change.index, change.count);
break;
case Change::Moved:
- emit model->m_modelCache->itemsMoved(change.index, change.to, change.count);
+ emit model->itemsMoved(change.index, change.to, change.count);
break;
case Change::Changed:
- emit model->m_modelCache->itemsChanged(change.index, change.count, change.roles);
+ emit model->itemsChanged(change.index, change.count, change.roles);
break;
}
}