aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSemih Yavuz <semih.yavuz@qt.io>2024-08-28 14:01:38 +0200
committerSemih Yavuz <semih.yavuz@qt.io>2024-09-04 12:16:30 +0300
commit0ba440a291159adb76394e5cbd53d13e92306cc4 (patch)
treeb031300a3860d741ef53a93071e697a12da74717
parent5688d45261a1d6fc7e1887fe29885a8dc2c4938b (diff)
qmlformat: respect the type annotated signal form
A qml signal can have both a(int x) and a(x: int) form. qmlformat currently converts the type annotated signal form into type prefixed form. It should respect the order. Task-number: QTBUG-128423 Change-Id: I746ea66949abc72e8012974b3fb0a06878950b77 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> (cherry picked from commit 67ab9e5a1102472ea734a35ef2906e2ec4545ce0) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> (cherry picked from commit 1186f254f5a9303869d799ee34e491d042e5736e)
-rw-r--r--src/qmldom/qqmldomastcreator.cpp2
-rw-r--r--src/qmldom/qqmldomelements.cpp10
-rw-r--r--src/qmldom/qqmldomelements_p.h6
-rw-r--r--tests/auto/qml/qmlformat/data/signal.formatted.qml5
-rw-r--r--tests/auto/qml/qmlformat/data/signal.qml5
-rw-r--r--tests/auto/qml/qmlformat/tst_qmlformat.cpp3
6 files changed, 27 insertions, 4 deletions
diff --git a/src/qmldom/qqmldomastcreator.cpp b/src/qmldom/qqmldomastcreator.cpp
index 77d224b0c4..5cd17b5640 100644
--- a/src/qmldom/qqmldomastcreator.cpp
+++ b/src/qmldom/qqmldomastcreator.cpp
@@ -419,6 +419,8 @@ bool QQmlDomAstCreator::visit(AST::UiPublicMember *el)
param.name = args->name.toString();
param.typeName = args->type ? args->type->toString() : QString();
index_type idx = index_type(mInfo.parameters.size());
+ if (!args->colonToken.isValid())
+ param.typeAnnotationStyle = MethodParameter::TypeAnnotationStyle::Prefix;
mInfo.parameters.append(param);
auto argLocs = FileLocations::ensure(nodeStack.last().fileLocations,
Path::Field(Fields::parameters).index(idx),
diff --git a/src/qmldom/qqmldomelements.cpp b/src/qmldom/qqmldomelements.cpp
index 4a1e79b40d..2323ca8ed3 100644
--- a/src/qmldom/qqmldomelements.cpp
+++ b/src/qmldom/qqmldomelements.cpp
@@ -1889,9 +1889,13 @@ void MethodInfo::writeOut(const DomItem &self, OutWriter &ow) const
first = false;
else
ow.write(u", ");
- if (const MethodParameter *argPtr = arg.as<MethodParameter>())
- argPtr->writeOutSignal(arg, ow);
- else
+
+ if (const MethodParameter *argPtr = arg.as<MethodParameter>()) {
+ if (argPtr->typeAnnotationStyle == MethodParameter::TypeAnnotationStyle::Prefix)
+ argPtr->writeOutSignal(arg, ow);
+ else
+ argPtr->writeOut(arg, ow);
+ } else
qCWarning(domLog) << "failed to cast to MethodParameter";
}
ow.writeRegion(RightParenthesisRegion);
diff --git a/src/qmldom/qqmldomelements_p.h b/src/qmldom/qqmldomelements_p.h
index 22a6bcf20b..5e5b1e8610 100644
--- a/src/qmldom/qqmldomelements_p.h
+++ b/src/qmldom/qqmldomelements_p.h
@@ -673,7 +673,10 @@ class QMLDOM_EXPORT MethodParameter
{
public:
constexpr static DomType kindValue = DomType::MethodParameter;
-
+ enum class TypeAnnotationStyle {
+ Prefix, // a(int x)
+ Suffix, // a(x : int)
+ };
bool iterateDirectSubpaths(const DomItem &self, DirectVisitor visitor) const;
void writeOut(const DomItem &self, OutWriter &ow) const;
@@ -694,6 +697,7 @@ public:
std::shared_ptr<ScriptExpression> value;
QList<QmlObject> annotations;
RegionComments comments;
+ TypeAnnotationStyle typeAnnotationStyle = TypeAnnotationStyle::Suffix;
};
class QMLDOM_EXPORT MethodInfo : public AttributeInfo
diff --git a/tests/auto/qml/qmlformat/data/signal.formatted.qml b/tests/auto/qml/qmlformat/data/signal.formatted.qml
new file mode 100644
index 0000000000..9b4a373b9e
--- /dev/null
+++ b/tests/auto/qml/qmlformat/data/signal.formatted.qml
@@ -0,0 +1,5 @@
+import QtQuick
+
+Item {
+ signal a(int x, y: int)
+}
diff --git a/tests/auto/qml/qmlformat/data/signal.qml b/tests/auto/qml/qmlformat/data/signal.qml
new file mode 100644
index 0000000000..a1833b19c9
--- /dev/null
+++ b/tests/auto/qml/qmlformat/data/signal.qml
@@ -0,0 +1,5 @@
+import QtQuick
+
+Item {
+ signal a(int x, y : int)
+}
diff --git a/tests/auto/qml/qmlformat/tst_qmlformat.cpp b/tests/auto/qml/qmlformat/tst_qmlformat.cpp
index 5e3c8cbd9d..cddb2cf962 100644
--- a/tests/auto/qml/qmlformat/tst_qmlformat.cpp
+++ b/tests/auto/qml/qmlformat/tst_qmlformat.cpp
@@ -369,6 +369,9 @@ void TestQmlformat::testFormat_data()
QTest::newRow("enumWithValues")
<< "enumWithValues.qml"
<< "enumWithValues.formatted.qml" << QStringList{} << RunOption::OnCopy;
+ QTest::newRow("typeAnnotatedSignal")
+ << "signal.qml"
+ << "signal.formatted.qml" << QStringList{} << RunOption::OnCopy;
}
void TestQmlformat::testFormat()