summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/declarative/cppextensions/referenceexamples/adding/main.cpp4
-rw-r--r--examples/declarative/cppextensions/referenceexamples/attached/main.cpp4
-rw-r--r--examples/declarative/cppextensions/referenceexamples/binding/main.cpp4
-rw-r--r--examples/declarative/cppextensions/referenceexamples/coercion/main.cpp4
-rw-r--r--examples/declarative/cppextensions/referenceexamples/default/main.cpp4
-rw-r--r--examples/declarative/cppextensions/referenceexamples/extended/main.cpp4
-rw-r--r--examples/declarative/cppextensions/referenceexamples/grouped/main.cpp4
-rw-r--r--examples/declarative/cppextensions/referenceexamples/properties/main.cpp4
-rw-r--r--examples/declarative/cppextensions/referenceexamples/signal/main.cpp4
-rw-r--r--examples/declarative/cppextensions/referenceexamples/valuesource/main.cpp4
-rw-r--r--src/declarative/util/qdeclarativelistmodel.cpp38
-rw-r--r--src/declarative/util/qdeclarativelistmodel_p_p.h3
-rw-r--r--tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp7
13 files changed, 51 insertions, 37 deletions
diff --git a/examples/declarative/cppextensions/referenceexamples/adding/main.cpp b/examples/declarative/cppextensions/referenceexamples/adding/main.cpp
index 391113c..19cf034 100644
--- a/examples/declarative/cppextensions/referenceexamples/adding/main.cpp
+++ b/examples/declarative/cppextensions/referenceexamples/adding/main.cpp
@@ -51,13 +51,13 @@ int main(int argc, char ** argv)
//![0]
QDeclarativeEngine engine;
- QDeclarativeComponent component(&engine, ":example.qml");
+ QDeclarativeComponent component(&engine, QUrl("qrc:example.qml"));
Person *person = qobject_cast<Person *>(component.create());
if (person) {
qWarning() << "The person's name is" << person->name();
qWarning() << "They wear a" << person->shoeSize() << "sized shoe";
} else {
- qWarning() << "An error occurred";
+ qWarning() << component.errors();
}
return 0;
diff --git a/examples/declarative/cppextensions/referenceexamples/attached/main.cpp b/examples/declarative/cppextensions/referenceexamples/attached/main.cpp
index 5a39a98..65cbc93 100644
--- a/examples/declarative/cppextensions/referenceexamples/attached/main.cpp
+++ b/examples/declarative/cppextensions/referenceexamples/attached/main.cpp
@@ -56,7 +56,7 @@ int main(int argc, char ** argv)
qmlRegisterType<Girl>("People", 1,0, "Girl");
QDeclarativeEngine engine;
- QDeclarativeComponent component(&engine, ":example.qml");
+ QDeclarativeComponent component(&engine, QUrl("qrc:example.qml"));
BirthdayParty *party = qobject_cast<BirthdayParty *>(component.create());
if (party && party->host()) {
@@ -83,7 +83,7 @@ int main(int argc, char ** argv)
}
} else {
- qWarning() << "An error occurred";
+ qWarning() << component.errors();
}
return 0;
diff --git a/examples/declarative/cppextensions/referenceexamples/binding/main.cpp b/examples/declarative/cppextensions/referenceexamples/binding/main.cpp
index fe1bbc8..150f961 100644
--- a/examples/declarative/cppextensions/referenceexamples/binding/main.cpp
+++ b/examples/declarative/cppextensions/referenceexamples/binding/main.cpp
@@ -57,7 +57,7 @@ int main(int argc, char ** argv)
qmlRegisterType<Girl>("People", 1,0, "Girl");
QDeclarativeEngine engine;
- QDeclarativeComponent component(&engine, ":example.qml");
+ QDeclarativeComponent component(&engine, QUrl("qrc:example.qml"));
BirthdayParty *party = qobject_cast<BirthdayParty *>(component.create());
if (party && party->host()) {
@@ -85,7 +85,7 @@ int main(int argc, char ** argv)
party->startParty();
} else {
- qWarning() << "An error occurred";
+ qWarning() << component.errors();
}
return app.exec();
diff --git a/examples/declarative/cppextensions/referenceexamples/coercion/main.cpp b/examples/declarative/cppextensions/referenceexamples/coercion/main.cpp
index 5c53368..5b16f99 100644
--- a/examples/declarative/cppextensions/referenceexamples/coercion/main.cpp
+++ b/examples/declarative/cppextensions/referenceexamples/coercion/main.cpp
@@ -56,7 +56,7 @@ int main(int argc, char ** argv)
qmlRegisterType<Girl>("People", 1,0, "Girl");
QDeclarativeEngine engine;
- QDeclarativeComponent component(&engine, ":example.qml");
+ QDeclarativeComponent component(&engine, QUrl("qrc:example.qml"));
BirthdayParty *party = qobject_cast<BirthdayParty *>(component.create());
if (party && party->host()) {
@@ -70,7 +70,7 @@ int main(int argc, char ** argv)
for (int ii = 0; ii < party->guestCount(); ++ii)
qWarning() << " " << party->guest(ii)->name();
} else {
- qWarning() << "An error occurred";
+ qWarning() << component.errors();
}
return 0;
diff --git a/examples/declarative/cppextensions/referenceexamples/default/main.cpp b/examples/declarative/cppextensions/referenceexamples/default/main.cpp
index f611bc4..bfba642 100644
--- a/examples/declarative/cppextensions/referenceexamples/default/main.cpp
+++ b/examples/declarative/cppextensions/referenceexamples/default/main.cpp
@@ -54,7 +54,7 @@ int main(int argc, char ** argv)
qmlRegisterType<Girl>("People", 1,0, "Girl");
QDeclarativeEngine engine;
- QDeclarativeComponent component(&engine, ":example.qml");
+ QDeclarativeComponent component(&engine, QUrl("qrc:example.qml"));
BirthdayParty *party = qobject_cast<BirthdayParty *>(component.create());
if (party && party->host()) {
@@ -68,7 +68,7 @@ int main(int argc, char ** argv)
for (int ii = 0; ii < party->guestCount(); ++ii)
qWarning() << " " << party->guest(ii)->name();
} else {
- qWarning() << "An error occurred";
+ qWarning() << component.errors();
}
return 0;
diff --git a/examples/declarative/cppextensions/referenceexamples/extended/main.cpp b/examples/declarative/cppextensions/referenceexamples/extended/main.cpp
index 65527c3..08c8440 100644
--- a/examples/declarative/cppextensions/referenceexamples/extended/main.cpp
+++ b/examples/declarative/cppextensions/referenceexamples/extended/main.cpp
@@ -51,14 +51,14 @@ int main(int argc, char ** argv)
qmlRegisterExtendedType<QLineEdit, LineEditExtension>("People", 1,0, "QLineEdit");
QDeclarativeEngine engine;
- QDeclarativeComponent component(&engine, ":example.qml");
+ QDeclarativeComponent component(&engine, QUrl("qrc:example.qml"));
QLineEdit *edit = qobject_cast<QLineEdit *>(component.create());
if (edit) {
edit->show();
return app.exec();
} else {
- qWarning() << "An error occurred";
+ qWarning() << component.errors();
return 0;
}
}
diff --git a/examples/declarative/cppextensions/referenceexamples/grouped/main.cpp b/examples/declarative/cppextensions/referenceexamples/grouped/main.cpp
index e56a14d..6f7f13f 100644
--- a/examples/declarative/cppextensions/referenceexamples/grouped/main.cpp
+++ b/examples/declarative/cppextensions/referenceexamples/grouped/main.cpp
@@ -55,7 +55,7 @@ int main(int argc, char ** argv)
qmlRegisterType<Girl>("People", 1,0, "Girl");
QDeclarativeEngine engine;
- QDeclarativeComponent component(&engine, ":example.qml");
+ QDeclarativeComponent component(&engine, QUrl("qrc:example.qml"));
BirthdayParty *party = qobject_cast<BirthdayParty *>(component.create());
if (party && party->host()) {
@@ -78,7 +78,7 @@ int main(int argc, char ** argv)
qWarning() << bestShoe->name() << "is wearing the best shoes!";
} else {
- qWarning() << "An error occurred";
+ qWarning() << component.errors();
}
return 0;
diff --git a/examples/declarative/cppextensions/referenceexamples/properties/main.cpp b/examples/declarative/cppextensions/referenceexamples/properties/main.cpp
index 80237ef..d974647 100644
--- a/examples/declarative/cppextensions/referenceexamples/properties/main.cpp
+++ b/examples/declarative/cppextensions/referenceexamples/properties/main.cpp
@@ -52,7 +52,7 @@ int main(int argc, char ** argv)
qmlRegisterType<Person>("People", 1,0, "Person");
QDeclarativeEngine engine;
- QDeclarativeComponent component(&engine, ":example.qml");
+ QDeclarativeComponent component(&engine, QUrl("qrc:example.qml"));
BirthdayParty *party = qobject_cast<BirthdayParty *>(component.create());
if (party && party->host()) {
@@ -61,7 +61,7 @@ int main(int argc, char ** argv)
for (int ii = 0; ii < party->guestCount(); ++ii)
qWarning() << " " << party->guest(ii)->name();
} else {
- qWarning() << "An error occurred";
+ qWarning() << component.errors();
}
return 0;
diff --git a/examples/declarative/cppextensions/referenceexamples/signal/main.cpp b/examples/declarative/cppextensions/referenceexamples/signal/main.cpp
index 56c0809..ad87bee 100644
--- a/examples/declarative/cppextensions/referenceexamples/signal/main.cpp
+++ b/examples/declarative/cppextensions/referenceexamples/signal/main.cpp
@@ -56,7 +56,7 @@ int main(int argc, char ** argv)
qmlRegisterType<Girl>("People", 1,0, "Girl");
QDeclarativeEngine engine;
- QDeclarativeComponent component(&engine, ":example.qml");
+ QDeclarativeComponent component(&engine, QUrl("qrc:example.qml"));
BirthdayParty *party = qobject_cast<BirthdayParty *>(component.create());
if (party && party->host()) {
@@ -84,7 +84,7 @@ int main(int argc, char ** argv)
party->startParty();
} else {
- qWarning() << "An error occurred";
+ qWarning() << component.errors();
}
return 0;
diff --git a/examples/declarative/cppextensions/referenceexamples/valuesource/main.cpp b/examples/declarative/cppextensions/referenceexamples/valuesource/main.cpp
index 40dc3cb..aa77665 100644
--- a/examples/declarative/cppextensions/referenceexamples/valuesource/main.cpp
+++ b/examples/declarative/cppextensions/referenceexamples/valuesource/main.cpp
@@ -58,7 +58,7 @@ int main(int argc, char ** argv)
qmlRegisterType<Girl>("People", 1,0, "Girl");
QDeclarativeEngine engine;
- QDeclarativeComponent component(&engine, ":example.qml");
+ QDeclarativeComponent component(&engine, QUrl("qrc:example.qml"));
BirthdayParty *party = qobject_cast<BirthdayParty *>(component.create());
if (party && party->host()) {
@@ -86,7 +86,7 @@ int main(int argc, char ** argv)
party->startParty();
} else {
- qWarning() << "An error occurred";
+ qWarning() << component.errors();
}
return app.exec();
diff --git a/src/declarative/util/qdeclarativelistmodel.cpp b/src/declarative/util/qdeclarativelistmodel.cpp
index 3ede335..20fe3a9 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);
@@ -1205,16 +1209,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) {
diff --git a/src/declarative/util/qdeclarativelistmodel_p_p.h b/src/declarative/util/qdeclarativelistmodel_p_p.h
index 532eefa..8231414 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,8 @@ struct ModelNode
QList<QVariant> values;
QHash<QString, ModelNode *> properties;
+ void clear();
+
QDeclarativeListModel *model(const NestedListModel *model) {
if (!modelCache) {
modelCache = new QDeclarativeListModel;
diff --git a/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp b/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp
index 858c26d..10805b4 100644
--- a/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp
+++ b/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp
@@ -271,6 +271,9 @@ void tst_qdeclarativelistmodel::dynamic_data()
QTest::newRow("nested-insert") << "{append({'foo':123});insert(0,{'bars':[{'a':1},{'b':2},{'c':3}]});get(0).bars.get(0).a}" << 1 << "";
QTest::newRow("nested-set") << "{append({'foo':123});set(0,{'foo':[{'x':123}]});get(0).foo.get(0).x}" << 123 << "";
+ QTest::newRow("nested-count") << "{append({'foo':123,'bars':[{'a':1},{'a':2},{'a':3}]}); get(0).bars.count}" << 3 << "";
+ QTest::newRow("nested-clear") << "{append({'foo':123,'bars':[{'a':1},{'a':2},{'a':3}]}); get(0).bars.clear(); get(0).bars.count}" << 0 << "";
+
// XXX
//QTest::newRow("nested-setprop") << "{append({'foo':123});setProperty(0,'foo',[{'x':123}]);get(0).foo.get(0).x}" << 123 << "";
}
@@ -344,9 +347,7 @@ void tst_qdeclarativelistmodel::dynamic_worker()
waitForWorker(item);
QDeclarativeExpression e(eng.rootContext(), &model, operations.last().toString());
- if (QByteArray(QTest::currentDataTag()).startsWith("nested"))
- QVERIFY(e.evaluate().toInt() != result);
- else
+ if (!QByteArray(QTest::currentDataTag()).startsWith("nested"))
QCOMPARE(e.evaluate().toInt(), result);
}