From d1a28bd3731e188f5ce3c3f7d41d141d5ad0c17d Mon Sep 17 00:00:00 2001 From: Andrei Golubev Date: Thu, 14 Apr 2022 11:07:19 +0200 Subject: qmltc: Support setting Gradient property of Rectangle Fixes: QTBUG-102560 Change-Id: I7c339d2807a723f38e18e06b944362449d89ad7a Reviewed-by: Ulf Hermann (cherry picked from commit e98faf1df401268dc6966b39963547a4de6f9171) Reviewed-by: Fabian Kosmale --- tests/auto/qml/qmltc/data/CMakeLists.txt | 2 ++ .../qml/qmltc/data/cpptypes/typewithproperties.cpp | 13 ++++++++ .../qml/qmltc/data/cpptypes/typewithproperties.h | 10 ++++++ tests/auto/qml/qmltc/data/gradients.qml | 11 +++++++ tests/auto/qml/qmltc/data/qjsvalueAssignments.qml | 6 ++++ tests/auto/qml/qmltc/tst_qmltc.cpp | 36 ++++++++++++++++++++++ tests/auto/qml/qmltc/tst_qmltc.h | 2 ++ 7 files changed, 80 insertions(+) create mode 100644 tests/auto/qml/qmltc/data/gradients.qml create mode 100644 tests/auto/qml/qmltc/data/qjsvalueAssignments.qml (limited to 'tests/auto/qml') diff --git a/tests/auto/qml/qmltc/data/CMakeLists.txt b/tests/auto/qml/qmltc/data/CMakeLists.txt index 1ba3ee8ac1..73da55d30a 100644 --- a/tests/auto/qml/qmltc/data/CMakeLists.txt +++ b/tests/auto/qml/qmltc/data/CMakeLists.txt @@ -24,6 +24,8 @@ set(qml_sources importNamespace.qml ComponentType.qml componentTypes.qml + gradients.qml + qjsvalueAssignments.qml signalHandlers.qml javaScriptFunctions.qml diff --git a/tests/auto/qml/qmltc/data/cpptypes/typewithproperties.cpp b/tests/auto/qml/qmltc/data/cpptypes/typewithproperties.cpp index fe4fc41020..d0ea6c4c9f 100644 --- a/tests/auto/qml/qmltc/data/cpptypes/typewithproperties.cpp +++ b/tests/auto/qml/qmltc/data/cpptypes/typewithproperties.cpp @@ -45,6 +45,11 @@ int TypeWithProperties::d() const return m_d; } +QJSValue TypeWithProperties::jsvalue() const +{ + return m_jsvalue; +} + void TypeWithProperties::setA(double a_) { m_a = a_; @@ -70,6 +75,10 @@ void TypeWithProperties::setD(int d_) Q_EMIT dSignal(u"d changed"_qs, d_); } } +void TypeWithProperties::setJsValue(const QJSValue &value) +{ + m_jsvalue = value; +} QBindable TypeWithProperties::bindableA() { @@ -79,3 +88,7 @@ QBindable TypeWithProperties::bindableD() { return QBindable(&m_d); } +QBindable TypeWithProperties::bindableJsValue() +{ + return QBindable(&m_jsvalue); +} \ No newline at end of file diff --git a/tests/auto/qml/qmltc/data/cpptypes/typewithproperties.h b/tests/auto/qml/qmltc/data/cpptypes/typewithproperties.h index 64625103f4..689f667643 100644 --- a/tests/auto/qml/qmltc/data/cpptypes/typewithproperties.h +++ b/tests/auto/qml/qmltc/data/cpptypes/typewithproperties.h @@ -34,6 +34,7 @@ #include #include #include +#include class TypeWithProperties : public QObject { @@ -45,10 +46,14 @@ class TypeWithProperties : public QObject Q_PROPERTY(QVariant c READ c WRITE setC NOTIFY cWeirdSignal) Q_PROPERTY(int d READ d WRITE setD NOTIFY dSignal BINDABLE bindableD) + // special + Q_PROPERTY(QJSValue jsvalue READ jsvalue WRITE setJsValue BINDABLE bindableJsValue) + QProperty m_a { 0.0 }; QString m_b; QProperty m_c; QProperty m_d; + QProperty m_jsvalue; public: TypeWithProperties(QObject *parent = nullptr) : QObject(parent) { } @@ -58,13 +63,18 @@ public: QVariant c() const; int d() const; + QJSValue jsvalue() const; + void setA(double); void setB(const QString &); void setC(const QVariant &); void setD(int); + void setJsValue(const QJSValue &); + QBindable bindableA(); QBindable bindableD(); + QBindable bindableJsValue(); Q_SIGNALS: void bChanged(); diff --git a/tests/auto/qml/qmltc/data/gradients.qml b/tests/auto/qml/qmltc/data/gradients.qml new file mode 100644 index 0000000000..008b0431da --- /dev/null +++ b/tests/auto/qml/qmltc/data/gradients.qml @@ -0,0 +1,11 @@ +import QtQuick 2.12 + +Item +{ + Rectangle{ + gradient: Gradient { + GradientStop { position: 0.0; color: "black" } + GradientStop { position: 1.0; color: "yellow" } + } + } +} diff --git a/tests/auto/qml/qmltc/data/qjsvalueAssignments.qml b/tests/auto/qml/qmltc/data/qjsvalueAssignments.qml new file mode 100644 index 0000000000..5ac909e1eb --- /dev/null +++ b/tests/auto/qml/qmltc/data/qjsvalueAssignments.qml @@ -0,0 +1,6 @@ +import QtQuick +import QmltcTests 1.0 + +TypeWithProperties { + jsvalue: true +} diff --git a/tests/auto/qml/qmltc/tst_qmltc.cpp b/tests/auto/qml/qmltc/tst_qmltc.cpp index 74e1ebeea7..47b802a21b 100644 --- a/tests/auto/qml/qmltc/tst_qmltc.cpp +++ b/tests/auto/qml/qmltc/tst_qmltc.cpp @@ -44,6 +44,8 @@ #include "deferredproperties_group.h" #include "deferredproperties_attached.h" #include "deferredproperties_complex.h" +#include "gradients.h" +#include "qjsvalueassignments.h" #include "signalhandlers.h" #include "javascriptfunctions.h" @@ -656,6 +658,40 @@ void tst_qmltc::deferredProperties() } } +// QTBUG-102560 +void tst_qmltc::gradients() +{ + QQmlEngine e; + PREPEND_NAMESPACE(gradients) created(&e); + QQmlListReference children(&created, "data"); + QCOMPARE(children.size(), 1); + QQuickRectangle *rect = qobject_cast(children.at(0)); + QVERIFY(rect); + QVERIFY(rect->gradient().isQObject()); + + QQuickGradient *gradient = qobject_cast(rect->gradient().toQObject()); + QVERIFY(gradient); + QQmlListProperty stops = gradient->stops(); + QCOMPARE(stops.count(&stops), 2); + QQuickGradientStop *stop0 = stops.at(&stops, 0); + QVERIFY(stop0); + QQuickGradientStop *stop1 = stops.at(&stops, 1); + QVERIFY(stop1); + + QCOMPARE(stop0->position(), 0.0); + QCOMPARE(stop1->position(), 1.0); + QCOMPARE(stop0->color(), QColor("black")); + QCOMPARE(stop1->color(), QColor("yellow")); +} + +void tst_qmltc::jsvalueAssignments() +{ + QQmlEngine e; + PREPEND_NAMESPACE(qjsvalueAssignments) created(&e); + QVERIFY(created.jsvalue().isBool()); + QVERIFY(created.jsvalue().toBool()); +} + void tst_qmltc::signalHandlers() { QQmlEngine e; diff --git a/tests/auto/qml/qmltc/tst_qmltc.h b/tests/auto/qml/qmltc/tst_qmltc.h index 5ce8a189da..b92c8eed18 100644 --- a/tests/auto/qml/qmltc/tst_qmltc.h +++ b/tests/auto/qml/qmltc/tst_qmltc.h @@ -54,6 +54,8 @@ private slots: void importNamespace(); void componentTypes(); void deferredProperties(); + void gradients(); // QTBUG-102560 + void jsvalueAssignments(); void signalHandlers(); void jsFunctions(); -- cgit v1.2.3