summaryrefslogtreecommitdiffstats
path: root/src/declarative/util
diff options
context:
space:
mode:
authorQt Continuous Integration System <qt-info@nokia.com>2010-08-11 02:45:12 (GMT)
committerQt Continuous Integration System <qt-info@nokia.com>2010-08-11 02:45:12 (GMT)
commitcc2fe3a5e2a748a8284ee732befc6a25d193f0c0 (patch)
tree257e79d10969c04c2c460246ad68e2326be135e6 /src/declarative/util
parentc7a18308a2725e4d1763777cb549f1ae74848005 (diff)
parentc170e75cd3af746cfec80ff7d5feb44228a329c3 (diff)
downloadQt-cc2fe3a5e2a748a8284ee732befc6a25d193f0c0.zip
Qt-cc2fe3a5e2a748a8284ee732befc6a25d193f0c0.tar.gz
Qt-cc2fe3a5e2a748a8284ee732befc6a25d193f0c0.tar.bz2
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt-qml into 4.7-integration
* '4.7' of scm.dev.nokia.troll.no:qt/qt-qml: Don't destroy ListModel child list nodes.
Diffstat (limited to 'src/declarative/util')
-rw-r--r--src/declarative/util/qdeclarativelistmodel.cpp26
-rw-r--r--src/declarative/util/qdeclarativelistmodel_p_p.h13
2 files changed, 28 insertions, 11 deletions
diff --git a/src/declarative/util/qdeclarativelistmodel.cpp b/src/declarative/util/qdeclarativelistmodel.cpp
index 3ede335..b0d47a9 100644
--- a/src/declarative/util/qdeclarativelistmodel.cpp
+++ b/src/declarative/util/qdeclarativelistmodel.cpp
@@ -108,9 +108,9 @@ QDeclarativeListModelParser::ListInstruction *QDeclarativeListModelParser::ListM
\snippet doc/src/snippets/declarative/listmodel-modify.qml delegate
- When creating content dynamically, note that the set of available properties cannot be changed
- except by first clearing the model. Whatever properties are first added to the model are then the
- only permitted properties in the model until it is cleared.
+ Note that when creating content dynamically the set of available properties cannot be changed
+ once set. Whatever properties are first added to the model are the
+ only permitted properties in the model.
\section2 Using threaded list models with WorkerScript
@@ -283,8 +283,7 @@ int QDeclarativeListModel::count() const
/*!
\qmlmethod ListModel::clear()
- Deletes all content from the model. The properties are cleared such that
- different properties may be set on subsequent additions.
+ Deletes all content from the model.
\sa append() remove()
*/
@@ -945,13 +944,14 @@ bool FlatListModel::addValue(const QScriptValue &value, QHash<int, QVariant> *ro
}
NestedListModel::NestedListModel(QDeclarativeListModel *base)
- : _root(0), m_listModel(base), _rolesOk(false)
+ : _root(0), m_ownsRoot(false), m_listModel(base), _rolesOk(false)
{
}
NestedListModel::~NestedListModel()
{
- delete _root;
+ if (m_ownsRoot)
+ delete _root;
}
QVariant NestedListModel::valueForNode(ModelNode *node, bool *hasNested) const
@@ -1051,8 +1051,8 @@ void NestedListModel::clear()
_rolesOk = false;
roleStrings.clear();
- delete _root;
- _root = 0;
+ if (_root)
+ _root->clear();
}
void NestedListModel::remove(int index)
@@ -1067,8 +1067,10 @@ void NestedListModel::remove(int index)
bool NestedListModel::insert(int index, const QScriptValue& valuemap)
{
- if (!_root)
+ if (!_root) {
_root = new ModelNode;
+ m_ownsRoot = true;
+ }
ModelNode *mn = new ModelNode;
mn->setObjectValue(valuemap);
@@ -1099,8 +1101,10 @@ void NestedListModel::move(int from, int to, int n)
bool NestedListModel::append(const QScriptValue& valuemap)
{
- if (!_root)
+ if (!_root) {
_root = new ModelNode;
+ m_ownsRoot = true;
+ }
ModelNode *mn = new ModelNode;
mn->setObjectValue(valuemap);
_root->values << qVariantFromValue(mn);
diff --git a/src/declarative/util/qdeclarativelistmodel_p_p.h b/src/declarative/util/qdeclarativelistmodel_p_p.h
index 532eefa..c41f016 100644
--- a/src/declarative/util/qdeclarativelistmodel_p_p.h
+++ b/src/declarative/util/qdeclarativelistmodel_p_p.h
@@ -130,6 +130,7 @@ public:
void checkRoles() const;
ModelNode *_root;
+ bool m_ownsRoot;
QDeclarativeListModel *m_listModel;
private:
@@ -157,6 +158,18 @@ struct ModelNode
QList<QVariant> values;
QHash<QString, ModelNode *> properties;
+ void clear() {
+ ModelNode *node;
+ for (int ii = 0; ii < values.count(); ++ii) {
+ node = qvariant_cast<ModelNode *>(values.at(ii));
+ if (node) { delete node; node = 0; }
+ }
+ values.clear();
+
+ qDeleteAll(properties.values());
+ properties.clear();
+ }
+
QDeclarativeListModel *model(const NestedListModel *model) {
if (!modelCache) {
modelCache = new QDeclarativeListModel;