diff options
author | Maximilian Goldstein <max.goldstein@qt.io> | 2020-10-01 11:32:41 +0200 |
---|---|---|
committer | Maximilian Goldstein <max.goldstein@qt.io> | 2020-10-05 15:14:53 +0200 |
commit | ecd018b4833863e9f7b8cecc616f681c361957b3 (patch) | |
tree | 07cccaba3e439755c6965639ff20283e466cad2a /tools/qmlformat | |
parent | 47c5a3e43e054292de468d4306b039143b3df636 (diff) |
qmlformat: Fix inline components
Fixes: QTBUG-86979
Pick-to: 5.15
Change-Id: Ie8863bc2ecf75a9dd8e4af5e96e48c30e7acbacd
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tools/qmlformat')
-rw-r--r-- | tools/qmlformat/dumpastvisitor.cpp | 47 | ||||
-rw-r--r-- | tools/qmlformat/dumpastvisitor.h | 2 |
2 files changed, 11 insertions, 38 deletions
diff --git a/tools/qmlformat/dumpastvisitor.cpp b/tools/qmlformat/dumpastvisitor.cpp index ada713aa9d..008f10ae17 100644 --- a/tools/qmlformat/dumpastvisitor.cpp +++ b/tools/qmlformat/dumpastvisitor.cpp @@ -1071,45 +1071,10 @@ QHash<QString, UiObjectMember*> findBindings(UiObjectMemberList *list) { bool DumpAstVisitor::visit(UiInlineComponent *node) { - if (scope().m_firstObject) { - if (scope().m_firstOfAll) - scope().m_firstOfAll = false; - else - addNewLine(); - - scope().m_firstObject = false; - } - - addLine(getComment(node, Comment::Location::Front)); - addLine(getComment(node, Comment::Location::Front_Inline)); - addLine("component " + node->name + ": " - + parseUiQualifiedId(node->component->qualifiedTypeNameId) + " {"); - - m_indentLevel++; - - ScopeProperties props; - props.m_bindings = findBindings(node->component->initializer->members); - m_scope_properties.push(props); - - m_result += getOrphanedComments(node); - + m_component_name = node->name.toString(); return true; } -void DumpAstVisitor::endVisit(UiInlineComponent *node) -{ - m_indentLevel--; - - m_scope_properties.pop(); - - bool need_comma = scope().m_inArrayBinding && scope().m_lastInArrayBinding != node; - - addLine(need_comma ? "}," : "}"); - addLine(getComment(node, Comment::Location::Back)); - if (!scope().m_inArrayBinding) - addNewLine(); -} - bool DumpAstVisitor::visit(UiObjectDefinition *node) { if (scope().m_firstObject) { if (scope().m_firstOfAll) @@ -1122,7 +1087,15 @@ bool DumpAstVisitor::visit(UiObjectDefinition *node) { addLine(getComment(node, Comment::Location::Front)); addLine(getComment(node, Comment::Location::Front_Inline)); - addLine(parseUiQualifiedId(node->qualifiedTypeNameId) + " {"); + + QString component = ""; + + if (!m_component_name.isEmpty()) { + component = "component "+m_component_name+": "; + m_component_name = ""; + } + + addLine(component + parseUiQualifiedId(node->qualifiedTypeNameId) + " {"); m_indentLevel++; diff --git a/tools/qmlformat/dumpastvisitor.h b/tools/qmlformat/dumpastvisitor.h index fbbd6871eb..729e15702a 100644 --- a/tools/qmlformat/dumpastvisitor.h +++ b/tools/qmlformat/dumpastvisitor.h @@ -61,7 +61,6 @@ public: void endVisit(FunctionDeclaration *node) override; bool visit(UiInlineComponent *node) override; - void endVisit(UiInlineComponent *node) override; bool visit(UiObjectDefinition *node) override; void endVisit(UiObjectDefinition *node) override; @@ -148,6 +147,7 @@ private: QStack<ScopeProperties> m_scope_properties; QString m_result = ""; + QString m_component_name = ""; QQmlJS::Engine *m_engine; CommentAstVisitor *m_comment; }; |