qmldom: follow the QML code conventions when reformatting

Reorder the attributes according to the sequence defined in the QML
Coding Conventions.

Change-Id: I4f71c51e86c33100ce2d9622cf7ed6e03d672453
Pick-to: 6.2
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
Fawzi Mohamed 2021-09-03 11:17:24 +02:00
parent eb415d93b9
commit 872f033fc5
9 changed files with 93 additions and 31 deletions

View File

@ -825,7 +825,7 @@ void QmlObject::writeOut(DomItem &self, OutWriter &ow, QString onTarget) const
}
}
}
if (counter != ow.counter())
if (counter != ow.counter() || !idStr().isEmpty())
spacerId = ow.addNewlinesAutospacerCallback(2);
for (auto pDefs : propertyDefs.values()) {
for (auto pDef : pDefs.values()) {
@ -855,7 +855,32 @@ void QmlObject::writeOut(DomItem &self, OutWriter &ow, QString onTarget) const
}
}
ow.removeTextAddCallback(spacerId);
// check more than the name?
QList<DomItem> signalList, methodList;
for (auto ms : field(self, Fields::methods).values()) {
for (auto m : ms.values()) {
const MethodInfo *mPtr = m.as<MethodInfo>();
if (mPtr && mPtr->methodType == MethodInfo::MethodType::Signal)
signalList.append(m);
else
methodList.append(m);
}
}
if (counter != ow.counter())
spacerId = ow.addNewlinesAutospacerCallback(2);
for (auto &sig : signalList) {
ow.ensureNewline();
sig.writeOut(ow);
ow.ensureNewline();
}
ow.removeTextAddCallback(spacerId);
if (counter != ow.counter())
spacerId = ow.addNewlinesAutospacerCallback(2);
for (auto &method : methodList) {
ow.ensureNewline();
method.writeOut(ow);
ow.ensureNewline();
}
ow.removeTextAddCallback(spacerId);
QList<DomItem> normalBindings, signalHandlers, delayedBindings;
for (auto bName : bindings.sortedKeys()) {
bool skipFirstNormal = m_propertyDefs.contains(bName);
@ -878,22 +903,17 @@ void QmlObject::writeOut(DomItem &self, OutWriter &ow, QString onTarget) const
}
if (counter != ow.counter())
spacerId = ow.addNewlinesAutospacerCallback(2);
for (auto b : normalBindings)
for (auto &b : normalBindings)
b.writeOut(ow);
ow.removeTextAddCallback(spacerId);
if (counter != ow.counter())
spacerId = ow.addNewlinesAutospacerCallback(2);
for (auto ms : field(self, Fields::methods).values()) {
for (auto m : ms.values()) {
ow.ensureNewline();
m.writeOut(ow);
ow.ensureNewline();
}
}
for (auto &b : delayedBindings)
b.writeOut(ow);
ow.removeTextAddCallback(spacerId);
if (counter != ow.counter())
spacerId = ow.addNewlinesAutospacerCallback(2);
for (auto b : signalHandlers)
for (auto &b : signalHandlers)
b.writeOut(ow);
ow.removeTextAddCallback(spacerId);
if (counter != ow.counter())
@ -914,11 +934,6 @@ void QmlObject::writeOut(DomItem &self, OutWriter &ow, QString onTarget) const
}
ow.removeTextAddCallback(spacerId);
}
if (counter != ow.counter())
spacerId = ow.addNewlinesAutospacerCallback(2);
for (auto b : delayedBindings)
b.writeOut(ow);
ow.removeTextAddCallback(spacerId);
ow.decreaseIndent(1, baseIndent);
ow.ensureNewline().write(u"}");
}

View File

@ -1 +1 @@
/* This file is licensed under the not a license license 1. You may not comply 2. Goodbye */ // Importing this is very important import QtQuick 5.15 // Muddling the waters! import QtQuick.Models 3.14 as muddle // Importing that is important too import Z import That import This // THIS IS VERY IMPORTANT! import Y import X.Z import X.Y import A.LLOHA import A.B.B.A // This comment is related to Item Item { // This to id // Also id. (line 2) // This is the third id // fourth id comment id: foo // This to enum enum Foo { A = 3, // This is A B, // This is B C = 4, // This is C D // This is D } // Orphan comment // Another orphan // More orphans property variant some_array_literal: [30, 20, Math["PI"], [4, 3, 2], "foo", 0.3] property bool some_bool: false default property bool some_default_bool: 500 % 5 !== 0 // some_default_bool // some_read_only_bool readonly property bool some_read_only_bool: Math.sin(3) && (aFunc()[30] + 5) | 2 != 0 property bool something_computed: function (x) { const PI = 3, DAYS_PER_YEAR = 365.25; var x = 3 + 2; x["bla"] = 50; // This is an orphan inside something_computed // Are these getting duplicated? // This one to var few! var few = new WhatEver(); x += Math.sin(3); x--; --x; x++; ++x; for (var x = 0; x < 100; x++) { x++; console.log("Foo"); } for (var x in [3, 2, 1]) { y++; console.log("Bar"); } while (true) { console.log("Wee"); } with (foo) { bar; x += 5; } // This is related to with! x3: do { console.log("Hello"); } while (3 == 0) try { dangerous(); } catch (e) { console.log(e); } finally { console.log("What else?"); } switch (x) { case 0: x = 1; break; case 1: x = 5; break; case 4: x = 100; break; } if (x == 50) { console.log("true"); } else if (x == 50) { console.log("other thing"); } else { console.log("false"); } if (x == 50) { console.log("true"); } else if (x == 50) { console.log("other thing"); x--; } else { console.log("false"); } // Another orphan inside something_computed return "foobar"; }() x: 3 // Very cool // This one to aFunc() function aFunc() { var x = 3; return x; } signal say(string name, bool caps) x: 3 // Very cool Text { x: 3 // Very cool text: "Bla" signal boo(int count, int times, real duration) } myFavouriteThings: [ // This is an orphan // This is a cool text Text { }, // This is a cool rectangle Rectangle { } ] // This comment is related to the property animation PropertyAnimation on x { id: foo2 x: 3 signal say(string name, bool caps) } }
/* This file is licensed under the not a license license 1. You may not comply 2. Goodbye */ // Importing this is very important import QtQuick 5.15 // Muddling the waters! import QtQuick.Models 3.14 as muddle // Importing that is important too import Z import That import This // THIS IS VERY IMPORTANT! import Y import X.Z import X.Y import A.LLOHA import A.B.B.A // This comment is related to Item Item { // This to id // Also id. (line 2) // This is the third id // fourth id comment id: foo // This to enum enum Foo { A = 3, // This is A B, // This is B C = 4, // This is C D // This is D } // Orphan comment // Another orphan // More orphans property variant some_array_literal: [30, 20, Math["PI"], [4, 3, 2], "foo", 0.3] property bool some_bool: false default property bool some_default_bool: 500 % 5 !== 0 // some_default_bool // some_read_only_bool readonly property bool some_read_only_bool: Math.sin(3) && (aFunc()[30] + 5) | 2 != 0 property bool something_computed: function (x) { const PI = 3, DAYS_PER_YEAR = 365.25; var x = 3 + 2; x["bla"] = 50; // This is an orphan inside something_computed // Are these getting duplicated? // This one to var few! var few = new WhatEver(); x += Math.sin(3); x--; --x; x++; ++x; for (var x = 0; x < 100; x++) { x++; console.log("Foo"); } for (var x in [3, 2, 1]) { y++; console.log("Bar"); } while (true) { console.log("Wee"); } with (foo) { bar; x += 5; } // This is related to with! x3: do { console.log("Hello"); } while (3 == 0) try { dangerous(); } catch (e) { console.log(e); } finally { console.log("What else?"); } switch (x) { case 0: x = 1; break; case 1: x = 5; break; case 4: x = 100; break; } if (x == 50) { console.log("true"); } else if (x == 50) { console.log("other thing"); } else { console.log("false"); } if (x == 50) { console.log("true"); } else if (x == 50) { console.log("other thing"); x--; } else { console.log("false"); } // Another orphan inside something_computed return "foobar"; }() signal say(string name, bool caps) // This one to aFunc() function aFunc() { var x = 3; return x; } // This one to aFunc() myFavouriteThings: [ // This is an orphan // This is a cool text Text { }, // This is a cool rectangle Rectangle { } ] // This comment is related to the property animation PropertyAnimation on x { id: foo2 x: 3 y: x + 3 } Component.onCompleted: console.log("Foo!") Text { x: 3 // Very cool signal boo(int count, int times, real duration) text: "Bla" } }

View File

@ -5,6 +5,11 @@ import QtQuick 2.15
/* multi
line */ // comment after multi line
Item {
function method(x) // function comment
{ // just returns the double of x
return 2 * x; // yep twice as much
} // post method
// binding comment
a: {
// header
@ -26,11 +31,6 @@ Item {
// footer
}
// post binding comment
function method(x) // function comment
{ // just returns the double of x
return 2 * x; // yep twice as much
} // post method
}
// footer file comment
/* second comment */ /* third comment */

View File

@ -5,6 +5,11 @@ import QtQuick 2.15
/* multi
line */ // comment after multi line
Item {
function method(x) // function comment
{ // just returns the double of x
return 2 * x; // yep twice as much
} // post method
// binding comment
a: {
// header
@ -26,11 +31,6 @@ Item {
// footer
}
// post binding comment
function method(x) // function comment
{ // just returns the double of x
return 2 * x; // yep twice as much
} // post method
}
// footer file comment
/* second comment */ /* third comment */

View File

@ -31,8 +31,6 @@ Window {
return 45;
}
text: root.text
function f(v = 4) {
let c = 0;
return {
@ -42,6 +40,8 @@ Window {
}()
};
}
text: root.text
}
}
}

View File

@ -0,0 +1,45 @@
pragma pippo
import QtQuick 2.15
import QtQuick.Window 2.15
Window {
visible: true
width: 640
height: 480
title: qsTr("Scroll")
Rectangle {
anchors.fill: parent
ListView {
width: parent.width
model: {
MySingleton.mySignal();
20;
}
delegate: ItemDelegate {
id: root
text: "Item " + (index + 1)
width: parent.width
Rectangle {
text: "bla"
}
MyComponent {
text: root.text
function f(v = 4) {
let c = 0;
return {
"a": function () {
if (b == 0)
c += 78 * 5 * v;
}()
};
}
property int a: {
return 45;
}
}
}
}
}
}

View File

@ -48,8 +48,6 @@ Window {
}
]
text: root.text
function f(v) {
let c = 0;
return {
@ -59,6 +57,8 @@ Window {
}()
};
}
text: root.text
}
}
}

View File

@ -2,6 +2,7 @@ import QtQuick 2.15
Item {
id: theFoo
required data
required property Item theItem

View File

@ -2,6 +2,7 @@ import QtQuick 2.15
Item {
id: theFoo
required data
required property Item theItem