diff options
author | Maximilian Goldstein <max.goldstein@qt.io> | 2020-10-01 11:32:41 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2020-10-06 09:54:52 +0000 |
commit | 732ae8d88488aea6c7b1bf1828c500ae38c1749b (patch) | |
tree | 97ead22d7f7f1ea7bddd6870905076cef3433140 /tools | |
parent | 280f78a7fcfac2dd955237d7f602a03624b293bf (diff) |
qmlformat: Fix inline components
Fixes: QTBUG-86979
Change-Id: Ie8863bc2ecf75a9dd8e4af5e96e48c30e7acbacd
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit ecd018b4833863e9f7b8cecc616f681c361957b3)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tools')
-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 19bf3d6717..f45ddd5e46 100644 --- a/tools/qmlformat/dumpastvisitor.cpp +++ b/tools/qmlformat/dumpastvisitor.cpp @@ -1044,45 +1044,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) @@ -1095,7 +1060,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 f84c4859ae..e56e55615a 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; }; |