diff options
author | Andrei Golubev <andrei.golubev@qt.io> | 2022-01-27 15:02:00 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-01-31 12:41:53 +0000 |
commit | 802f081151b6fc188db5974ff7cd2e1e6337a691 (patch) | |
tree | 072f6d60aecf52816b62ba0fb5393bba067f1cc7 | |
parent | 63b4180aeb60afd4e991786eb3002baa2a628a35 (diff) |
Distinguish property change signals from user-defined signals
Do not expose this information to qmltypes just yet, though,
as this seems irrelevant at the moment
Change-Id: Iffd8901ef9899a0fff226e8799bf45c1d688b92b
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
(cherry picked from commit b1bb4c8e5f0d4a65f36b2002bcdaf9bfcbed8c77)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/qmlcompiler/qqmljsmetatypes_p.h | 7 | ||||
-rw-r--r-- | src/qmlcompiler/qqmljsscope.cpp | 1 | ||||
-rw-r--r-- | tests/auto/qml/qqmljsscope/data/signalCreationDifferences.qml | 9 | ||||
-rw-r--r-- | tests/auto/qml/qqmljsscope/tst_qqmljsscope.cpp | 23 |
4 files changed, 40 insertions, 0 deletions
diff --git a/src/qmlcompiler/qqmljsmetatypes_p.h b/src/qmlcompiler/qqmljsmetatypes_p.h index ed859f7f6f..8e97dedfdc 100644 --- a/src/qmlcompiler/qqmljsmetatypes_p.h +++ b/src/qmlcompiler/qqmljsmetatypes_p.h @@ -192,6 +192,12 @@ public: m_isJavaScriptFunction = isJavaScriptFunction; } + bool isImplicitQmlPropertyChangeSignal() const { return m_isImplicitQmlPropertyChangeSignal; } + void setIsImplicitQmlPropertyChangeSignal(bool isPropertyChangeSignal) + { + m_isImplicitQmlPropertyChangeSignal = isPropertyChangeSignal; + } + bool isValid() const { return !m_name.isEmpty(); } const QVector<QQmlJSAnnotation>& annotations() const { return m_annotations; } @@ -253,6 +259,7 @@ private: int m_revision = 0; bool m_isConstructor = false; bool m_isJavaScriptFunction = false; + bool m_isImplicitQmlPropertyChangeSignal = false; }; class QQmlJSMetaProperty diff --git a/src/qmlcompiler/qqmljsscope.cpp b/src/qmlcompiler/qqmljsscope.cpp index 44c22c82e4..14817b0d64 100644 --- a/src/qmlcompiler/qqmljsscope.cpp +++ b/src/qmlcompiler/qqmljsscope.cpp @@ -123,6 +123,7 @@ void QQmlJSScope::insertPropertyIdentifier(const QQmlJSMetaProperty &property) addOwnProperty(property); QQmlJSMetaMethod method(property.propertyName() + u"Changed"_qs, u"void"_qs); method.setMethodType(QQmlJSMetaMethod::Signal); + method.setIsImplicitQmlPropertyChangeSignal(true); addOwnMethod(method); } diff --git a/tests/auto/qml/qqmljsscope/data/signalCreationDifferences.qml b/tests/auto/qml/qqmljsscope/data/signalCreationDifferences.qml new file mode 100644 index 0000000000..a241a4a84a --- /dev/null +++ b/tests/auto/qml/qqmljsscope/data/signalCreationDifferences.qml @@ -0,0 +1,9 @@ +import QtQml +QtObject { + property string myProperty: "foobar" + + signal mySignal() + + property int conflictingProperty: 42 + signal conflictingPropertyChanged(a: real, c: string) +} diff --git a/tests/auto/qml/qqmljsscope/tst_qqmljsscope.cpp b/tests/auto/qml/qqmljsscope/tst_qqmljsscope.cpp index f95e48d51e..69eb271984 100644 --- a/tests/auto/qml/qqmljsscope/tst_qqmljsscope.cpp +++ b/tests/auto/qml/qqmljsscope/tst_qqmljsscope.cpp @@ -97,6 +97,7 @@ private Q_SLOTS: void initTestCase() override; void orderedBindings(); + void signalCreationDifferences(); public: tst_qqmljsscope() : QQmlDataTest(QT_QMLTEST_DATADIR) { } @@ -140,5 +141,27 @@ void tst_qqmljsscope::orderedBindings() QCOMPARE(std::next(itemsBindingsBegin)->objectType()->baseTypeName(), u"Text"_qs); } +void tst_qqmljsscope::signalCreationDifferences() +{ + QQmlJSScope::ConstPtr root = run(u"signalCreationDifferences.qml"_qs); + QVERIFY(root); + + QVERIFY(root->hasOwnProperty(u"myProperty"_qs)); + QVERIFY(root->hasOwnProperty(u"conflictingProperty"_qs)); + QCOMPARE(root->ownMethods(u"mySignal"_qs).size(), 1); + + const auto conflicting = root->ownMethods(u"conflictingPropertyChanged"_qs); + QCOMPARE(conflicting.size(), 2); + QCOMPARE(conflicting[0].methodType(), QQmlJSMetaMethod::Signal); + QCOMPARE(conflicting[1].methodType(), QQmlJSMetaMethod::Signal); + + const QQmlJSMetaMethod *explicitMethod = nullptr; + if (conflicting[0].isImplicitQmlPropertyChangeSignal()) + explicitMethod = &conflicting[1]; + else + explicitMethod = &conflicting[0]; + QCOMPARE(explicitMethod->parameterNames(), QStringList({ u"a"_qs, u"c"_qs })); +} + QTEST_MAIN(tst_qqmljsscope) #include "tst_qqmljsscope.moc" |