diff options
author | Simon Hausmann <simon.hausmann@digia.com> | 2014-01-15 16:17:22 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-01-17 08:10:07 +0100 |
commit | 814504306df0b76da1654a74524bdc353527d06f (patch) | |
tree | d20bd388b6992e2e36c66f809070428235e7522b /src/qml/qml/qqmlcustomparser.cpp | |
parent | 8fc545de4166eb3c73833e9d9136dfbebf43539a (diff) |
[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 <lars.knoll@digia.com>
Diffstat (limited to 'src/qml/qml/qqmlcustomparser.cpp')
-rw-r--r-- | src/qml/qml/qqmlcustomparser.cpp | 39 |
1 files changed, 38 insertions, 1 deletions
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 |