aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/auto/qml/qmlformat/data/largeBindings.formatted.qml7
-rw-r--r--tests/auto/qml/qmlformat/data/largeBindings.qml4
-rw-r--r--tests/auto/qml/qmlformat/tst_qmlformat.cpp7
-rw-r--r--tools/qmlformat/dumpastvisitor.cpp12
4 files changed, 30 insertions, 0 deletions
diff --git a/tests/auto/qml/qmlformat/data/largeBindings.formatted.qml b/tests/auto/qml/qmlformat/data/largeBindings.formatted.qml
new file mode 100644
index 0000000000..1118c661ed
--- /dev/null
+++ b/tests/auto/qml/qmlformat/data/largeBindings.formatted.qml
@@ -0,0 +1,7 @@
+QtObject {
+ smallButNeedsBraces: {
+ if (foo) {
+ bar();
+ }
+ }
+}
diff --git a/tests/auto/qml/qmlformat/data/largeBindings.qml b/tests/auto/qml/qmlformat/data/largeBindings.qml
new file mode 100644
index 0000000000..7bbc365c13
--- /dev/null
+++ b/tests/auto/qml/qmlformat/data/largeBindings.qml
@@ -0,0 +1,4 @@
+QtObject
+{
+ smallButNeedsBraces: if (foo) { bar(); }
+}
diff --git a/tests/auto/qml/qmlformat/tst_qmlformat.cpp b/tests/auto/qml/qmlformat/tst_qmlformat.cpp
index ba34f0f923..0e0bc53857 100644
--- a/tests/auto/qml/qmlformat/tst_qmlformat.cpp
+++ b/tests/auto/qml/qmlformat/tst_qmlformat.cpp
@@ -52,6 +52,7 @@ private Q_SLOTS:
void testReadOnlyProps();
void testVerbatimStrings();
+ void testLargeBindings();
#if !defined(QTEST_CROSS_COMPILED) // sources not available when cross compiled
void testExample();
@@ -224,6 +225,12 @@ void TestQmlformat::testVerbatimStrings()
readTestFile("verbatimString.formatted.qml"));
}
+void TestQmlformat::testLargeBindings()
+{
+ QCOMPARE(runQmlformat(testFile("largeBindings.qml"), false, true),
+ readTestFile("largeBindings.formatted.qml"));
+}
+
void TestQmlformat::testLineEndings()
{
// macos
diff --git a/tools/qmlformat/dumpastvisitor.cpp b/tools/qmlformat/dumpastvisitor.cpp
index a92bd83c70..ef6e234cc3 100644
--- a/tools/qmlformat/dumpastvisitor.cpp
+++ b/tools/qmlformat/dumpastvisitor.cpp
@@ -1115,8 +1115,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())