aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrei Golubev <andrei.golubev@qt.io>2022-07-25 11:49:31 +0200
committerAndrei Golubev <andrei.golubev@qt.io>2022-07-29 09:20:31 +0200
commit5ffd81567f816523ce09896e2f2608238fb43bb1 (patch)
treeb1ec43743346a0b5704f1bc6a7fe8c3d37e337bd
parent34e7142ed40a4fd2a745c5ffe6f374f3a4a32842 (diff)
qmltc: Fix import namespace code generation
Fix subtle issue where an import namespace would become part of the generated C++ class name without modifications (so with '.'). Preserve the namespace for the time being just to make the generated code more verbose (e.g. consider mixing QQ.Text and ZZ.Text in the same file) Change-Id: I3d409988ae136c272aac6a4eab287a7221f88450 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit 38d9bf60ba270cd02d28497252eb64fa60b1f4c9)
-rw-r--r--tests/auto/qml/qmltc/QmltcTests/importNamespace.qml2
-rw-r--r--tools/qmltc/qmltcvisitor.cpp17
2 files changed, 14 insertions, 5 deletions
diff --git a/tests/auto/qml/qmltc/QmltcTests/importNamespace.qml b/tests/auto/qml/qmltc/QmltcTests/importNamespace.qml
index 2786356843..5484b9f8a6 100644
--- a/tests/auto/qml/qmltc/QmltcTests/importNamespace.qml
+++ b/tests/auto/qml/qmltc/QmltcTests/importNamespace.qml
@@ -1,4 +1,6 @@
import QtQuick as QQ
QQ.Text {
text: "hello, world"
+
+ QQ.Text {}
}
diff --git a/tools/qmltc/qmltcvisitor.cpp b/tools/qmltc/qmltcvisitor.cpp
index 176410ef6d..1099dfaae5 100644
--- a/tools/qmltc/qmltcvisitor.cpp
+++ b/tools/qmltc/qmltcvisitor.cpp
@@ -147,6 +147,16 @@ void QmltcVisitor::findCppIncludes()
m_cppIncludes.remove(m_exportedRootScope->filePath());
}
+static void addCleanQmlTypeName(QStringList *names, const QQmlJSScope::ConstPtr &scope)
+{
+ Q_ASSERT(scope->scopeType() == QQmlJSScope::QMLScope);
+ Q_ASSERT(!scope->isArrayScope());
+ Q_ASSERT(!scope->baseTypeName().isEmpty());
+ // the scope is guaranteed to be a new QML type, so any prefixes (separated
+ // by dots) should be import namespaces
+ names->append(scope->baseTypeName().replace(u'.', u'_'));
+}
+
bool QmltcVisitor::visit(QQmlJS::AST::UiObjectDefinition *object)
{
const bool processingRoot = !rootScopeIsValid();
@@ -163,9 +173,8 @@ bool QmltcVisitor::visit(QQmlJS::AST::UiObjectDefinition *object)
if (m_currentScope->scopeType() != QQmlJSScope::QMLScope)
return true;
- Q_ASSERT(!m_currentScope->baseTypeName().isEmpty());
if (m_currentScope != m_exportedRootScope) // not document root
- m_qmlTypeNames.append(m_currentScope->baseTypeName());
+ addCleanQmlTypeName(&m_qmlTypeNames, m_currentScope);
// give C++-relevant internal names to QMLScopes, we can use them later in compiler
m_currentScope->setInternalName(uniqueNameFromPieces(m_qmlTypeNames, m_qmlTypeNameCounts));
@@ -189,10 +198,8 @@ bool QmltcVisitor::visit(QQmlJS::AST::UiObjectBinding *uiob)
if (!QQmlJSImportVisitor::visit(uiob))
return false;
- Q_ASSERT(m_currentScope->scopeType() == QQmlJSScope::QMLScope);
- Q_ASSERT(!m_currentScope->baseTypeName().isEmpty());
if (m_currentScope != m_exportedRootScope) // not document root
- m_qmlTypeNames.append(m_currentScope->baseTypeName());
+ addCleanQmlTypeName(&m_qmlTypeNames, m_currentScope);
// give C++-relevant internal names to QMLScopes, we can use them later in compiler
m_currentScope->setInternalName(uniqueNameFromPieces(m_qmlTypeNames, m_qmlTypeNameCounts));