summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWarwick Allison <warwick.allison@nokia.com>2010-06-25 06:37:28 (GMT)
committerWarwick Allison <warwick.allison@nokia.com>2010-06-25 06:37:28 (GMT)
commit03df7f73de6a1fd482876caaf377a61593df8a38 (patch)
treec9e70014c4646d3b1b2a02369862a6557c87e15e
parentc91030e308f8cd9ad66e7de127a1f9dbbedd11d3 (diff)
downloadQt-03df7f73de6a1fd482876caaf377a61593df8a38.zip
Qt-03df7f73de6a1fd482876caaf377a61593df8a38.tar.gz
Qt-03df7f73de6a1fd482876caaf377a61593df8a38.tar.bz2
Test ListElement type via type system, not string comparison.
Task-number: QTBUG-11222 Reviewed-by: Aaron Kennedy
-rw-r--r--src/declarative/qml/qdeclarativecompiler.cpp12
-rw-r--r--src/declarative/qml/qdeclarativecompiler_p.h1
-rw-r--r--src/declarative/qml/qdeclarativecustomparser.cpp10
-rw-r--r--src/declarative/qml/qdeclarativecustomparser_p.h2
-rw-r--r--src/declarative/util/qdeclarativelistmodel.cpp11
-rw-r--r--src/declarative/util/qdeclarativelistmodel_p.h2
6 files changed, 35 insertions, 3 deletions
diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp
index 80a1093..a7cfa62 100644
--- a/src/declarative/qml/qdeclarativecompiler.cpp
+++ b/src/declarative/qml/qdeclarativecompiler.cpp
@@ -2176,6 +2176,18 @@ int QDeclarativeCompiler::evaluateEnum(const QByteArray& script) const
return -1;
}
+const QMetaObject *QDeclarativeCompiler::resolveType(const QByteArray& name) const
+{
+ QDeclarativeType *qmltype = 0;
+ if (!enginePrivate->importDatabase.resolveType(unit->imports, name, &qmltype,
+ 0, 0, 0, 0))
+ return 0;
+ if (!qmltype)
+ return 0;
+ return qmltype->metaObject();
+}
+
+
// Ensures that the dynamic meta specification on obj is valid
bool QDeclarativeCompiler::checkDynamicMeta(QDeclarativeParser::Object *obj)
{
diff --git a/src/declarative/qml/qdeclarativecompiler_p.h b/src/declarative/qml/qdeclarativecompiler_p.h
index 908c703..caad376 100644
--- a/src/declarative/qml/qdeclarativecompiler_p.h
+++ b/src/declarative/qml/qdeclarativecompiler_p.h
@@ -161,6 +161,7 @@ public:
static bool isSignalPropertyName(const QByteArray &);
int evaluateEnum(const QByteArray& script) const; // for QDeclarativeCustomParser::evaluateEnum
+ const QMetaObject *resolveType(const QByteArray& name) const; // for QDeclarativeCustomParser::resolveType
private:
static void reset(QDeclarativeCompiledData *);
diff --git a/src/declarative/qml/qdeclarativecustomparser.cpp b/src/declarative/qml/qdeclarativecustomparser.cpp
index 472a883..97a6a00 100644
--- a/src/declarative/qml/qdeclarativecustomparser.cpp
+++ b/src/declarative/qml/qdeclarativecustomparser.cpp
@@ -295,4 +295,14 @@ int QDeclarativeCustomParser::evaluateEnum(const QByteArray& script) const
return compiler->evaluateEnum(script);
}
+/*!
+ Resolves \a name to a type, or 0 if it is not a type. This can be used
+ to type-check object nodes.
+*/
+const QMetaObject *QDeclarativeCustomParser::resolveType(const QByteArray& name) const
+{
+ return compiler->resolveType(name);
+}
+
+
QT_END_NAMESPACE
diff --git a/src/declarative/qml/qdeclarativecustomparser_p.h b/src/declarative/qml/qdeclarativecustomparser_p.h
index 0e397c5..8eb86e8 100644
--- a/src/declarative/qml/qdeclarativecustomparser_p.h
+++ b/src/declarative/qml/qdeclarativecustomparser_p.h
@@ -130,6 +130,8 @@ protected:
int evaluateEnum(const QByteArray&) const;
+ const QMetaObject *resolveType(const QByteArray&) const;
+
private:
QList<QDeclarativeError> exceptions;
QDeclarativeCompiler *compiler;
diff --git a/src/declarative/util/qdeclarativelistmodel.cpp b/src/declarative/util/qdeclarativelistmodel.cpp
index 9ed21a6..deb835d 100644
--- a/src/declarative/util/qdeclarativelistmodel.cpp
+++ b/src/declarative/util/qdeclarativelistmodel.cpp
@@ -551,9 +551,13 @@ bool QDeclarativeListModelParser::compileProperty(const QDeclarativeCustomParser
QDeclarativeCustomParserNode node =
qvariant_cast<QDeclarativeCustomParserNode>(value);
- if (node.name() != "ListElement") {
- error(node, QDeclarativeListModel::tr("ListElement: cannot contain nested elements"));
- return false;
+ if (node.name() != listElementTypeName) {
+ const QMetaObject *mo = resolveType(node.name());
+ if (mo != &QDeclarativeListElement::staticMetaObject) {
+ error(node, QDeclarativeListModel::tr("ListElement: cannot contain nested elements"));
+ return false;
+ }
+ listElementTypeName = node.name(); // cache right name for next time
}
{
@@ -650,6 +654,7 @@ QByteArray QDeclarativeListModelParser::compile(const QList<QDeclarativeCustomPa
{
QList<ListInstruction> instr;
QByteArray data;
+ listElementTypeName = QByteArray(); // unknown
for(int ii = 0; ii < customProps.count(); ++ii) {
const QDeclarativeCustomParserProperty &prop = customProps.at(ii);
diff --git a/src/declarative/util/qdeclarativelistmodel_p.h b/src/declarative/util/qdeclarativelistmodel_p.h
index d09062e..6aff9c6 100644
--- a/src/declarative/util/qdeclarativelistmodel_p.h
+++ b/src/declarative/util/qdeclarativelistmodel_p.h
@@ -135,6 +135,8 @@ private:
bool compileProperty(const QDeclarativeCustomParserProperty &prop, QList<ListInstruction> &instr, QByteArray &data);
bool definesEmptyList(const QString &);
+
+ QByteArray listElementTypeName;
};