diff options
-rw-r--r-- | tests/auto/qml/qmlformat/data/largeBindings.formatted.qml | 5 | ||||
-rw-r--r-- | tests/auto/qml/qmlformat/data/largeBindings.qml | 1 | ||||
-rw-r--r-- | tools/qmlformat/dumpastvisitor.cpp | 12 |
3 files changed, 18 insertions, 0 deletions
diff --git a/tests/auto/qml/qmlformat/data/largeBindings.formatted.qml b/tests/auto/qml/qmlformat/data/largeBindings.formatted.qml index d8e4ffb087..8bd502ccab 100644 --- a/tests/auto/qml/qmlformat/data/largeBindings.formatted.qml +++ b/tests/auto/qml/qmlformat/data/largeBindings.formatted.qml @@ -1,6 +1,11 @@ QtObject { small1: 3 small2: foo + smallButNeedsBraces: { + if (foo) { + bar(); + } + } // THIS NEEDS TO BE LAST largeBinding: { var x = 300; diff --git a/tests/auto/qml/qmlformat/data/largeBindings.qml b/tests/auto/qml/qmlformat/data/largeBindings.qml index a2249f6815..9f69e9ad50 100644 --- a/tests/auto/qml/qmlformat/data/largeBindings.qml +++ b/tests/auto/qml/qmlformat/data/largeBindings.qml @@ -8,4 +8,5 @@ QtObject small1: 3 small2: foo + smallButNeedsBraces: if (foo) { bar(); } } diff --git a/tools/qmlformat/dumpastvisitor.cpp b/tools/qmlformat/dumpastvisitor.cpp index 859d399805..24d4dd454d 100644 --- a/tools/qmlformat/dumpastvisitor.cpp +++ b/tools/qmlformat/dumpastvisitor.cpp @@ -1162,8 +1162,20 @@ bool DumpAstVisitor::visit(UiScriptBinding *node) { addLine(getComment(node, Comment::Location::Front)); + bool multiline = !needsSemicolon(node->statement->kind); + + if (multiline) { + m_indentLevel++; + } + QString statement = parseStatement(node->statement); + if (multiline) { + statement = "{\n" + formatLine(statement); + m_indentLevel--; + statement += formatLine("}", false); + } + QString result = parseUiQualifiedId(node->qualifiedId) + ":"; if (!statement.isEmpty()) |