aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaximilian Goldstein <max.goldstein@qt.io>2020-10-01 11:32:41 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2020-10-06 09:54:52 +0000
commit732ae8d88488aea6c7b1bf1828c500ae38c1749b (patch)
tree97ead22d7f7f1ea7bddd6870905076cef3433140
parent280f78a7fcfac2dd955237d7f602a03624b293bf (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>
-rw-r--r--tests/auto/qml/qmlformat/data/inlineComponents.formatted.qml7
-rw-r--r--tools/qmlformat/dumpastvisitor.cpp47
-rw-r--r--tools/qmlformat/dumpastvisitor.h2
3 files changed, 13 insertions, 43 deletions
diff --git a/tests/auto/qml/qmlformat/data/inlineComponents.formatted.qml b/tests/auto/qml/qmlformat/data/inlineComponents.formatted.qml
index 5349280f2b..fd5ab99197 100644
--- a/tests/auto/qml/qmlformat/data/inlineComponents.formatted.qml
+++ b/tests/auto/qml/qmlformat/data/inlineComponents.formatted.qml
@@ -1,10 +1,7 @@
Item {
component CustomText: Text {
- Text {
- color: "red"
- text: "Test Text"
- }
-
+ color: "red"
+ text: "Test Text"
}
}
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;
};