summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBea Lam <bea.lam@nokia.com>2010-09-17 04:55:52 (GMT)
committerJason McDonald <jason.mcdonald@nokia.com>2010-09-22 04:55:39 (GMT)
commit755a82fea47402be5857edf2f882e0135e02267a (patch)
treee0a90e54228f83ebcefdc3344434490136785138
parent5ef8bc9393dcd06062bd38d6761e23837d7a86c5 (diff)
downloadQt-755a82fea47402be5857edf2f882e0135e02267a.zip
Qt-755a82fea47402be5857edf2f882e0135e02267a.tar.gz
Qt-755a82fea47402be5857edf2f882e0135e02267a.tar.bz2
Make it clear that private ListModel constructor is only for worker
agent. Also set up the worker list copy in the ListModel implementation instead of the agent. (cherry picked from commit c298ed31f8dfa917e5428820aecd39234b4c9097)
-rw-r--r--src/declarative/util/qdeclarativelistmodel.cpp37
-rw-r--r--src/declarative/util/qdeclarativelistmodel_p.h6
-rw-r--r--src/declarative/util/qdeclarativelistmodel_p_p.h2
-rw-r--r--src/declarative/util/qdeclarativelistmodelworkeragent.cpp8
4 files changed, 33 insertions, 20 deletions
diff --git a/src/declarative/util/qdeclarativelistmodel.cpp b/src/declarative/util/qdeclarativelistmodel.cpp
index 401e400..0be9122 100644
--- a/src/declarative/util/qdeclarativelistmodel.cpp
+++ b/src/declarative/util/qdeclarativelistmodel.cpp
@@ -217,17 +217,21 @@ QDeclarativeListModelParser::ListInstruction *QDeclarativeListModelParser::ListM
*/
QDeclarativeListModel::QDeclarativeListModel(QObject *parent)
-: QListModelInterface(parent), m_agent(0), m_nested(new NestedListModel(this)), m_flat(0), m_isWorkerCopy(false)
+: QListModelInterface(parent), m_agent(0), m_nested(new NestedListModel(this)), m_flat(0)
{
}
-QDeclarativeListModel::QDeclarativeListModel(bool workerCopy, QObject *parent)
-: QListModelInterface(parent), m_agent(0), m_nested(0), m_flat(0), m_isWorkerCopy(workerCopy)
+QDeclarativeListModel::QDeclarativeListModel(const QDeclarativeListModel *orig, QDeclarativeListModelWorkerAgent *parent)
+: QListModelInterface(parent), m_agent(0), m_nested(0), m_flat(0)
{
- if (workerCopy)
- m_flat = new FlatListModel(this);
- else
- m_nested = new NestedListModel(this);
+ m_flat = new FlatListModel(this);
+ m_flat->m_parentAgent = parent;
+
+ if (orig->m_flat) {
+ m_flat->m_roles = orig->m_flat->m_roles;
+ m_flat->m_strings = orig->m_flat->m_strings;
+ m_flat->m_values = orig->m_flat->m_values;
+ }
}
QDeclarativeListModel::~QDeclarativeListModel()
@@ -269,6 +273,11 @@ bool QDeclarativeListModel::flatten()
return true;
}
+bool QDeclarativeListModel::inWorkerThread() const
+{
+ return m_flat && m_flat->m_parentAgent;
+}
+
QDeclarativeListModelWorkerAgent *QDeclarativeListModel::agent()
{
if (m_agent)
@@ -333,7 +342,7 @@ void QDeclarativeListModel::clear()
else
m_nested->clear();
- if (!m_isWorkerCopy) {
+ if (!inWorkerThread()) {
emit itemsRemoved(0, cleared);
emit countChanged();
}
@@ -358,7 +367,7 @@ void QDeclarativeListModel::remove(int index)
else
m_nested->remove(index);
- if (!m_isWorkerCopy) {
+ if (!inWorkerThread()) {
emit itemsRemoved(index, 1);
emit countChanged();
}
@@ -392,7 +401,7 @@ void QDeclarativeListModel::insert(int index, const QScriptValue& valuemap)
}
bool ok = m_flat ? m_flat->insert(index, valuemap) : m_nested->insert(index, valuemap);
- if (ok && !m_isWorkerCopy) {
+ if (ok && !inWorkerThread()) {
emit itemsInserted(index, 1);
emit countChanged();
}
@@ -438,7 +447,7 @@ void QDeclarativeListModel::move(int from, int to, int n)
else
m_nested->move(from, to, n);
- if (!m_isWorkerCopy)
+ if (!inWorkerThread())
emit itemsMoved(origfrom, origto, orign);
}
@@ -529,7 +538,7 @@ void QDeclarativeListModel::set(int index, const QScriptValue& valuemap)
else
m_nested->set(index, valuemap, &roles);
- if (!m_isWorkerCopy)
+ if (!inWorkerThread())
emit itemsChanged(index, 1, roles);
}
}
@@ -560,7 +569,7 @@ void QDeclarativeListModel::setProperty(int index, const QString& property, cons
else
m_nested->setProperty(index, property, value, &roles);
- if (!m_isWorkerCopy)
+ if (!inWorkerThread())
emit itemsChanged(index, 1, roles);
}
@@ -848,7 +857,7 @@ bool QDeclarativeListModelParser::definesEmptyList(const QString &s)
*/
FlatListModel::FlatListModel(QDeclarativeListModel *base)
- : m_scriptEngine(0), m_listModel(base)
+ : m_scriptEngine(0), m_listModel(base), m_parentAgent(0)
{
}
diff --git a/src/declarative/util/qdeclarativelistmodel_p.h b/src/declarative/util/qdeclarativelistmodel_p.h
index 6aff9c6..0a5e3ff 100644
--- a/src/declarative/util/qdeclarativelistmodel_p.h
+++ b/src/declarative/util/qdeclarativelistmodel_p.h
@@ -98,14 +98,16 @@ private:
friend class QDeclarativeListModelWorkerAgent;
friend struct ModelNode;
+ // Constructs a flat list model for a worker agent
+ QDeclarativeListModel(const QDeclarativeListModel *orig, QDeclarativeListModelWorkerAgent *parent);
+
QDeclarativeListModel(bool workerCopy, QObject *parent=0);
bool flatten();
- bool modifyCheck();
+ bool inWorkerThread() const;
QDeclarativeListModelWorkerAgent *m_agent;
NestedListModel *m_nested;
FlatListModel *m_flat;
- bool m_isWorkerCopy;
};
// ### FIXME
diff --git a/src/declarative/util/qdeclarativelistmodel_p_p.h b/src/declarative/util/qdeclarativelistmodel_p_p.h
index 8231414..1e9513e 100644
--- a/src/declarative/util/qdeclarativelistmodel_p_p.h
+++ b/src/declarative/util/qdeclarativelistmodel_p_p.h
@@ -102,6 +102,8 @@ private:
QHash<QString, int> m_strings;
QList<QHash<int, QVariant> > m_values;
QDeclarativeListModel *m_listModel;
+
+ QDeclarativeListModelWorkerAgent *m_parentAgent;
};
class NestedListModel
diff --git a/src/declarative/util/qdeclarativelistmodelworkeragent.cpp b/src/declarative/util/qdeclarativelistmodelworkeragent.cpp
index 4392bed..658584e 100644
--- a/src/declarative/util/qdeclarativelistmodelworkeragent.cpp
+++ b/src/declarative/util/qdeclarativelistmodelworkeragent.cpp
@@ -83,11 +83,11 @@ void QDeclarativeListModelWorkerAgent::Data::changedChange(int index, int count)
}
QDeclarativeListModelWorkerAgent::QDeclarativeListModelWorkerAgent(QDeclarativeListModel *model)
-: m_engine(0), m_ref(1), m_orig(model), m_copy(new QDeclarativeListModel(true, this))
+ : m_engine(0),
+ m_ref(1),
+ m_orig(model),
+ m_copy(new QDeclarativeListModel(m_orig, this))
{
- m_copy->m_flat->m_roles = m_orig->m_flat->m_roles;
- m_copy->m_flat->m_strings = m_orig->m_flat->m_strings;
- m_copy->m_flat->m_values = m_orig->m_flat->m_values;
}
QDeclarativeListModelWorkerAgent::~QDeclarativeListModelWorkerAgent()