From b3beb6ded506f1701b68642d981c63295bc6c6a2 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Wed, 7 Apr 2010 13:27:23 +1000 Subject: Disallow nested elements in ListModel QTBUG-6082 --- src/declarative/qml/qdeclarativecustomparser.cpp | 3 +++ src/declarative/util/qdeclarativelistmodel.cpp | 7 ++++++- .../qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp | 8 +++++--- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/declarative/qml/qdeclarativecustomparser.cpp b/src/declarative/qml/qdeclarativecustomparser.cpp index 8b6ee7c..1a97315 100644 --- a/src/declarative/qml/qdeclarativecustomparser.cpp +++ b/src/declarative/qml/qdeclarativecustomparser.cpp @@ -108,6 +108,9 @@ QDeclarativeCustomParserNodePrivate::fromObject(QDeclarativeParser::Object *root rootNode.d->properties << fromProperty(p); } + if (root->defaultProperty) + rootNode.d->properties << fromProperty(root->defaultProperty); + return rootNode; } diff --git a/src/declarative/util/qdeclarativelistmodel.cpp b/src/declarative/util/qdeclarativelistmodel.cpp index ec23bb2..28bd852 100644 --- a/src/declarative/util/qdeclarativelistmodel.cpp +++ b/src/declarative/util/qdeclarativelistmodel.cpp @@ -622,6 +622,11 @@ bool QDeclarativeListModelParser::compileProperty(const QDeclarativeCustomParser QDeclarativeCustomParserNode node = qvariant_cast(value); + if (node.name() != "ListElement") { + error(node, QDeclarativeListModel::tr("ListElement: cannot contain nested elements")); + return false; + } + { ListInstruction li; li.type = ListInstruction::Push; @@ -633,7 +638,7 @@ bool QDeclarativeListModelParser::compileProperty(const QDeclarativeCustomParser for(int jj = 0; jj < props.count(); ++jj) { const QDeclarativeCustomParserProperty &nodeProp = props.at(jj); if (nodeProp.name() == "") { - error(nodeProp, QDeclarativeListModel::tr("ListElement: cannot use default property")); + error(nodeProp, QDeclarativeListModel::tr("ListElement: cannot contain nested elements")); return false; } if (nodeProp.name() == "id") { diff --git a/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp b/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp index d02f54f..8214723 100644 --- a/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp +++ b/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp @@ -528,7 +528,11 @@ void tst_QDeclarativeListModel::error_data() QTest::newRow("default properties not allowed in ListElement") << "import Qt 4.6\nListModel { ListElement { Item { } } }" - << "QTBUG-6082 ListElement should not allow child objects"; + << "ListElement: cannot contain nested elements"; + + QTest::newRow("QML elements not allowed in ListElement") + << "import Qt 4.6\nListModel { ListElement { a: Item { } } }" + << "ListElement: cannot contain nested elements"; } void tst_QDeclarativeListModel::error() @@ -543,8 +547,6 @@ void tst_QDeclarativeListModel::error() if (error.isEmpty()) { QVERIFY(!component.isError()); } else { - if (error.startsWith(QLatin1String("QTBUG-"))) - QEXPECT_FAIL("",error.toLatin1(),Abort); QVERIFY(component.isError()); QList errors = component.errors(); QCOMPARE(errors.count(),1); -- cgit v0.12