From a363aa3df44da399d2aeb8785608501eae50e600 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Tue, 11 Feb 2020 14:44:28 +0100 Subject: QQmlCustomParser: Resolve import namespaces Also, don't use plain QObject for testing registrations with extensions and foreign types. This interacts with other tests. Change-Id: I43df8a4e5b22def5a87f508130f1c7b4833ecfb6 Fixes: QTBUG-81970 Reviewed-by: Simon Hausmann --- src/qml/qml/qqmlcustomparser.cpp | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'src/qml/qml/qqmlcustomparser.cpp') diff --git a/src/qml/qml/qqmlcustomparser.cpp b/src/qml/qml/qqmlcustomparser.cpp index a5f34dafdf..ecd5020482 100644 --- a/src/qml/qml/qqmlcustomparser.cpp +++ b/src/qml/qml/qqmlcustomparser.cpp @@ -131,8 +131,13 @@ int QQmlCustomParser::evaluateEnum(const QByteArray& script, bool *ok) const // * . // * .. - int dot = script.indexOf('.'); - if (dot == -1 || dot == script.length()-1) + auto nextDot = [&](int dot) { + const int nextDot = script.indexOf('.', dot + 1); + return (nextDot == script.length() - 1) ? -1 : nextDot; + }; + + int dot = nextDot(-1); + if (dot == -1) return -1; QString scope = QString::fromUtf8(script.left(dot)); @@ -143,18 +148,32 @@ int QQmlCustomParser::evaluateEnum(const QByteArray& script, bool *ok) const QQmlType type; if (imports.isT1()) { - imports.asT1()->resolveType(scope, &type, nullptr, nullptr, nullptr); + QQmlImportNamespace *ns = nullptr; + if (!imports.asT1()->resolveType(scope, &type, nullptr, nullptr, &ns)) + return -1; + if (!type.isValid() && ns != nullptr) { + dot = nextDot(dot); + if (dot == -1 || !imports.asT1()->resolveType(QString::fromUtf8(script.left(dot)), + &type, nullptr, nullptr, nullptr)) { + return -1; + } + } } else { QQmlTypeNameCache::Result result = imports.asT2()->query(scope); - if (result.isValid()) + if (result.isValid()) { type = result.type; + } else if (result.importNamespace) { + dot = nextDot(dot); + if (dot != -1) + type = imports.asT2()->query(QString::fromUtf8(script.left(dot))).type; + } } if (!type.isValid()) return -1; - int dot2 = script.indexOf('.', dot+1); - const bool dot2Valid = dot2 != -1 && dot2 != script.length()-1; + const int dot2 = nextDot(dot); + const bool dot2Valid = (dot2 != -1); QByteArray enumValue = script.mid(dot2Valid ? dot2 + 1 : dot + 1); QByteArray scopedEnumName = (dot2Valid ? script.mid(dot + 1, dot2 - dot - 1) : QByteArray()); if (!scopedEnumName.isEmpty()) -- cgit v1.2.3