summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2010-08-11 00:04:53 (GMT)
committerMartin Jones <martin.jones@nokia.com>2010-08-11 00:04:53 (GMT)
commit4026b2c7bc91f8f25f73b182687d5d2bed823217 (patch)
tree974de988773e05fdceb4318a362eed35a691f658 /src
parent27b5da4ff5a762df0ab3e98ecde9dac4aa589178 (diff)
downloadQt-4026b2c7bc91f8f25f73b182687d5d2bed823217.zip
Qt-4026b2c7bc91f8f25f73b182687d5d2bed823217.tar.gz
Qt-4026b2c7bc91f8f25f73b182687d5d2bed823217.tar.bz2
Don't destroy ListModel child list nodes.
These are owned by the root and must not be destroyed by child lists. Task-number: QTBUG-12771 Reviewed-by: Bea Lam
Diffstat (limited to 'src')
-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;