From eff73ee3197723eb1f5b35ec39bb496a40ab5343 Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Thu, 28 Jan 2021 15:53:51 +0100 Subject: Expose getter and setter names of C++ classes in qmltypes files This simply exports the name which are already available in the json files generated by moc. We do not consider whether the methods are non-private for now. MEMBER is not supported either, but might be added if the need actually arises. Fixes: QTBUG-90711 Change-Id: If3ee18c8ce60499676a7ee22df569cba0912e22f Reviewed-by: Ulf Hermann --- src/imports/tooling/Property.qml | 2 ++ src/qmlcompiler/qqmljstypedescriptionreader.cpp | 3 +++ src/qmltyperegistrar/qmltypescreator.cpp | 6 ++++++ tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp | 10 ++++++++-- tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h | 1 + 5 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/imports/tooling/Property.qml b/src/imports/tooling/Property.qml index 7c335a1dc9..de76df55b3 100644 --- a/src/imports/tooling/Property.qml +++ b/src/imports/tooling/Property.qml @@ -46,4 +46,6 @@ Member { property bool isList: false property int revision: 0 property string bindable + property string read + property string write } diff --git a/src/qmlcompiler/qqmljstypedescriptionreader.cpp b/src/qmlcompiler/qqmljstypedescriptionreader.cpp index b3ef6092a0..3457b6ec15 100644 --- a/src/qmlcompiler/qqmljstypedescriptionreader.cpp +++ b/src/qmlcompiler/qqmljstypedescriptionreader.cpp @@ -347,6 +347,9 @@ void QQmlJSTypeDescriptionReader::readProperty(UiObjectDefinition *ast, const QQ property.setRevision(readIntBinding(script)); } else if (id == QLatin1String("bindable")) { property.setBindable(readStringBinding(script)); + } else if (id == QLatin1String("read") || id == QLatin1String("write")) { + // QQmlJSMetaProperty currently does not make use of the getter and setter name + continue; } else { addWarning(script->firstSourceLocation(), tr("Expected only type, name, revision, isPointer, isReadonly, bindable, and" diff --git a/src/qmltyperegistrar/qmltypescreator.cpp b/src/qmltyperegistrar/qmltypescreator.cpp index b5a3cd749c..4dafdc4490 100644 --- a/src/qmltyperegistrar/qmltypescreator.cpp +++ b/src/qmltyperegistrar/qmltypescreator.cpp @@ -178,6 +178,12 @@ void QmlTypesCreator::writeProperties(const QJsonArray &properties, QSettoString())); writeType(obj, QLatin1String("type"), !obj.contains(QLatin1String("write")), true); + const auto read = obj.constFind(QLatin1String("read")); + if (read != obj.constEnd()) + m_qml.writeScriptBinding(QLatin1String("read"), enquote(read->toString())); + const auto write = obj.constFind(QLatin1String("write")); + if (write != obj.constEnd()) + m_qml.writeScriptBinding(QLatin1String("write"), enquote(write->toString())); m_qml.writeEndObject(); const QString notify = obj[QLatin1String("notify")].toString(); diff --git a/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp b/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp index b5efefba9a..f7a29948a0 100644 --- a/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp +++ b/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.cpp @@ -57,6 +57,12 @@ void tst_qmltyperegistrar::qmltypesHasHppClassAndNoext() QVERIFY(qmltypesData.contains("Noext")); } +void tst_qmltyperegistrar::qmltypesHasReadAndWrite() +{ + QVERIFY(qmltypesData.contains(R"(read: "eieiei")")); + QVERIFY(qmltypesData.contains(R"(write: "setEieiei")")); +} + void tst_qmltyperegistrar::qmltypesHasFileNames() { QVERIFY(qmltypesData.contains("file: \"hppheader.hpp\"")); @@ -79,8 +85,8 @@ void tst_qmltyperegistrar::superAndForeignTypes() QVERIFY(qmltypesData.contains("values: [\"Pixel\", \"Centimeter\", \"Inch\", \"Point\"]")); QVERIFY(qmltypesData.contains("name: \"SizeGadget\"")); QVERIFY(qmltypesData.contains("prototype: \"SizeEnums\"")); - QVERIFY(qmltypesData.contains("Property { name: \"height\"; type: \"int\" }")); - QVERIFY(qmltypesData.contains("Property { name: \"width\"; type: \"int\" }")); + QVERIFY(qmltypesData.contains("Property { name: \"height\"; type: \"int\"; read: \"height\"; write: \"setHeight\" }")); + QVERIFY(qmltypesData.contains("Property { name: \"width\"; type: \"int\"; read: \"width\"; write: \"setWidth\" }")); QVERIFY(qmltypesData.contains("Method { name: \"sizeToString\"; type: \"QString\" }")); QVERIFY(qmltypesData.contains("extension: \"SizeValueType\"")); } diff --git a/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h b/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h index 486009ea59..6267868375 100644 --- a/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h +++ b/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h @@ -158,6 +158,7 @@ private slots: void initTestCase(); void qmltypesHasForeign(); void qmltypesHasHppClassAndNoext(); + void qmltypesHasReadAndWrite(); void qmltypesHasFileNames(); void qmltypesHasFlags(); void superAndForeignTypes(); -- cgit v1.2.3