summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2021-02-22 09:31:30 +0100
committerUlf Hermann <ulf.hermann@qt.io>2021-02-24 08:33:28 +0100
commite3ac1db9abe0cef47648072dbe2327be7299c7d4 (patch)
tree5a75b1277af3d7ea42ce7ba58cc24b0a1758a350
parent120eb155ef1f0da51c473b080880169a85e5ceb2 (diff)
qmllint: Support enum types from other scopes
In qmltypes, enum types can be scoped, just like in C++. Resolve those scopes. Also, resolve the enum scopes only once, in order not to duplicate the types. Change-Id: I095ec11f0ffec8e0e5f1034023c8956d2d39f660 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit 75b99a10b3229c7ed14ded8622f3334c3cd02af5)
-rw-r--r--src/qmlcompiler/qqmljsscope.cpp15
-rw-r--r--tests/auto/qml/qmllint/data/Things/plugins.qmltypes1
-rw-r--r--tests/auto/qml/qmllint/data/externalEnumProperty.qml5
-rw-r--r--tests/auto/qml/qmllint/tst_qmllint.cpp1
4 files changed, 21 insertions, 1 deletions
diff --git a/src/qmlcompiler/qqmljsscope.cpp b/src/qmlcompiler/qqmljsscope.cpp
index 5c3ce8d139..ce4897d20e 100644
--- a/src/qmlcompiler/qqmljsscope.cpp
+++ b/src/qmlcompiler/qqmljsscope.cpp
@@ -193,11 +193,22 @@ QQmlJSScope::findJSIdentifier(const QString &id) const
void QQmlJSScope::resolveTypes(const QQmlJSScope::Ptr &self,
const QHash<QString, QQmlJSScope::ConstPtr> &contextualTypes)
{
- auto findType = [&](const QString &name) {
+ auto findType = [&](const QString &name) -> QQmlJSScope::ConstPtr {
auto type = contextualTypes.constFind(name);
if (type != contextualTypes.constEnd())
return *type;
+ const auto colonColon = name.indexOf(QStringLiteral("::"));
+ if (colonColon > 0) {
+ const auto outerType = contextualTypes.constFind(name.left(colonColon));
+ if (outerType != contextualTypes.constEnd()) {
+ for (const auto &innerType : qAsConst((*outerType)->m_childScopes)) {
+ if (innerType->m_internalName == name)
+ return innerType;
+ }
+ }
+ }
+
return QQmlJSScope::ConstPtr();
};
@@ -217,6 +228,8 @@ void QQmlJSScope::resolveTypes(const QQmlJSScope::Ptr &self,
Q_ASSERT(intType); // There always has to be a builtin "int" type
for (auto it = self->m_enumerations.begin(), end = self->m_enumerations.end();
it != end; ++it) {
+ if (it->type())
+ continue;
auto enumScope = QQmlJSScope::create(EnumScope, self);
enumScope->m_baseTypeName = QStringLiteral("int");
enumScope->m_baseType = intType;
diff --git a/tests/auto/qml/qmllint/data/Things/plugins.qmltypes b/tests/auto/qml/qmllint/data/Things/plugins.qmltypes
index 99e1fdc466..9ad8c71468 100644
--- a/tests/auto/qml/qmllint/data/Things/plugins.qmltypes
+++ b/tests/auto/qml/qmllint/data/Things/plugins.qmltypes
@@ -62,5 +62,6 @@ Module {
exports: [
"Things/ItemDerived 1.0"
]
+ Property { name: "alignment"; type: "Qt::Alignment" }
}
}
diff --git a/tests/auto/qml/qmllint/data/externalEnumProperty.qml b/tests/auto/qml/qmllint/data/externalEnumProperty.qml
new file mode 100644
index 0000000000..2ba56a03a4
--- /dev/null
+++ b/tests/auto/qml/qmllint/data/externalEnumProperty.qml
@@ -0,0 +1,5 @@
+import Things
+
+ItemDerived {
+ alignment: Qt.AlignCenter
+}
diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp
index db44193871..9c0077582e 100644
--- a/tests/auto/qml/qmllint/tst_qmllint.cpp
+++ b/tests/auto/qml/qmllint/tst_qmllint.cpp
@@ -382,6 +382,7 @@ void TestQmllint::cleanQmlCode_data()
QTest::newRow("layouts depends quick") << QStringLiteral("layouts.qml");
QTest::newRow("attached") << QStringLiteral("attached.qml");
QTest::newRow("enumProperty") << QStringLiteral("enumProperty.qml");
+ QTest::newRow("externalEnumProperty") << QStringLiteral("externalEnumProperty.qml");
}
void TestQmllint::cleanQmlCode()