summaryrefslogtreecommitdiffstats
path: root/src/declarative/util/qdeclarativelistmodel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/declarative/util/qdeclarativelistmodel.cpp')
-rw-r--r--src/declarative/util/qdeclarativelistmodel.cpp42
1 files changed, 27 insertions, 15 deletions
diff --git a/src/declarative/util/qdeclarativelistmodel.cpp b/src/declarative/util/qdeclarativelistmodel.cpp
index 3ede335..1f66f0f 100644
--- a/src/declarative/util/qdeclarativelistmodel.cpp
+++ b/src/declarative/util/qdeclarativelistmodel.cpp
@@ -68,6 +68,7 @@ QDeclarativeListModelParser::ListInstruction *QDeclarativeListModelParser::ListM
/*!
\qmlclass ListModel QDeclarativeListModel
+ \ingroup qml-working-with-data
\since 4.7
\brief The ListModel element defines a free-form list data source.
@@ -108,9 +109,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
@@ -129,7 +130,7 @@ QDeclarativeListModelParser::ListInstruction *QDeclarativeListModelParser::ListM
\snippet examples/declarative/threading/threadedlistmodel/dataloader.js 0
- The application's \tt Timer object periodically sends a message to the
+working-with-data
worker script by calling \l WorkerScript::sendMessage(). When this message
is received, \l {WorkerScript::onMessage}{WorkerScript.onMessage()} is invoked in
\tt dataloader.js, which appends the current time to the list model.
@@ -283,8 +284,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()
*/
@@ -770,6 +770,7 @@ bool QDeclarativeListModelParser::definesEmptyList(const QString &s)
/*!
\qmlclass ListElement
+ \ingroup qml-working-with-data
\since 4.7
\brief The ListElement element defines a data item in a ListModel.
@@ -945,13 +946,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 +1053,8 @@ void NestedListModel::clear()
_rolesOk = false;
roleStrings.clear();
- delete _root;
- _root = 0;
+ if (_root)
+ _root->clear();
}
void NestedListModel::remove(int index)
@@ -1067,8 +1069,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 +1103,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);
@@ -1205,16 +1211,22 @@ ModelNode::ModelNode()
ModelNode::~ModelNode()
{
- qDeleteAll(properties.values());
+ clear();
+ if (modelCache) { modelCache->m_nested->_root = 0/* ==this */; delete modelCache; modelCache = 0; }
+ if (objectCache) { delete objectCache; objectCache = 0; }
+}
+void ModelNode::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();
- if (modelCache) { modelCache->m_nested->_root = 0/* ==this */; delete modelCache; modelCache = 0; }
- if (objectCache) { delete objectCache; objectCache = 0; }
+ qDeleteAll(properties.values());
+ properties.clear();
}
void ModelNode::setObjectValue(const QScriptValue& valuemap) {