From 814504306df0b76da1654a74524bdc353527d06f Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Wed, 15 Jan 2014 16:17:22 +0100 Subject: [new compiler] Add support for type and enum resolution for custom parsers This is in preparation for listmodel support, share the code for resolving types and enums between the old and the new compiler, as all it needs is the imports. Change-Id: I4908d71eee50c769108e0e2b68b03496722fa49d Reviewed-by: Lars Knoll --- src/qml/qml/qqmlcustomparser.cpp | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'src/qml/qml/qqmlcustomparser.cpp') diff --git a/src/qml/qml/qqmlcustomparser.cpp b/src/qml/qml/qqmlcustomparser.cpp index 3f8fc967f4..ca23451774 100644 --- a/src/qml/qml/qqmlcustomparser.cpp +++ b/src/qml/qml/qqmlcustomparser.cpp @@ -346,7 +346,44 @@ const QMetaObject *QQmlCustomParser::resolveType(const QString& name) const */ QQmlBinding::Identifier QQmlCustomParser::bindingIdentifier(const QQmlScript::Variant &value, const QString& name) { - return compiler->bindingIdentifier(name, value, QQmlCompilerTypes::BindingContext(object)); + return compiler->bindingIdentifier(value, name, this); +} + +struct StaticQtMetaObject : public QObject +{ + static const QMetaObject *get() + { return &staticQtMetaObject; } +}; + +int QQmlCustomParserCompilerBackend::evaluateEnum(const QString &scope, const QByteArray &enumValue, bool *ok) const +{ + Q_ASSERT_X(ok, "QQmlCompiler::evaluateEnum", "ok must not be a null pointer"); + *ok = false; + + if (scope != QLatin1String("Qt")) { + QQmlType *type = 0; + imports().resolveType(scope, &type, 0, 0, 0); + return type ? type->enumValue(QHashedCStringRef(enumValue.constData(), enumValue.length()), ok) : -1; + } + + const QMetaObject *mo = StaticQtMetaObject::get(); + int i = mo->enumeratorCount(); + while (i--) { + int v = mo->enumerator(i).keyToValue(enumValue.constData(), ok); + if (*ok) + return v; + } + return -1; +} + +const QMetaObject *QQmlCustomParserCompilerBackend::resolveType(const QString &name) const +{ + QQmlType *qmltype = 0; + if (!imports().resolveType(name, &qmltype, 0, 0, 0)) + return 0; + if (!qmltype) + return 0; + return qmltype->metaObject(); } QT_END_NAMESPACE -- cgit v1.2.3