diff options
author | Robin Burchell <robin.burchell@crimson.no> | 2017-06-01 13:16:28 +0200 |
---|---|---|
committer | Robin Burchell <robin.burchell@crimson.no> | 2017-06-01 11:34:15 +0000 |
commit | 651a4f7e094f844cac3740744d148102bbf7689f (patch) | |
tree | 07b423230120d5dd3c0292e4b5efe05c4ed11ef9 /tests/auto/quick/qquickrectangle | |
parent | c158ca8be49a75026e83751dfd825c5bdd63189a (diff) |
Revert "QQuickRectangle: Optimize setGradient"
This reverts commit 9709d04ba7787c853a1ddbeed0347eab27c0924f.
We changed this from using a signal for notification to using parenting. But
this cannot be done for two related reasons: the first:
QtObject {
property Gradient someGradient: Gradient {
id: someGradient
}
}
...
Rectangle {
gradient: someGradient
}
... should work, and no longer did, because the Gradient's parent was
the QtObject, not the Rectangle it was tied to. And secondly:
Rectangle {
id: rectOne
gradient: Gradient {
id: someGradient
}
}
Rectangle {
id: rectTwo
gradient: someGradient
}
... also didn't work anymore, as the Gradient was only notifying a
single Item about changes to it.
The easiest way to fix this is to just revert back to using a signal
connection.
This also caused problems in qtquickcontrols autotests.
Change-Id: Ic07dd02e9920596d0c047bfc23995b3be8c96c49
Task-number: QTBUG-60268
Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
Diffstat (limited to 'tests/auto/quick/qquickrectangle')
3 files changed, 109 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickrectangle/data/gradient-multiple.qml b/tests/auto/quick/qquickrectangle/data/gradient-multiple.qml new file mode 100644 index 0000000000..d58c857008 --- /dev/null +++ b/tests/auto/quick/qquickrectangle/data/gradient-multiple.qml @@ -0,0 +1,30 @@ +import QtQuick 2.0 + +Item { + property alias firstRectangle: r1 + property alias secondRectangle: r2 + Rectangle { + id: r1 + gradient: someObject.someGradient + anchors.fill: parent + } + Rectangle { + id: r2 + gradient: someObject.someGradient + anchors.fill: parent + } + + function changeGradient() { + firstStop.color = "red" + secondStop.color = "blue" + } + + QtObject { + id: someObject + property Gradient someGradient: Gradient { + GradientStop { id: firstStop; position: 0.0; color: "gray" } + GradientStop { id: secondStop; position: 1.0; color: "white" } + } + } +} + diff --git a/tests/auto/quick/qquickrectangle/data/gradient-separate.qml b/tests/auto/quick/qquickrectangle/data/gradient-separate.qml new file mode 100644 index 0000000000..8ae3f3296b --- /dev/null +++ b/tests/auto/quick/qquickrectangle/data/gradient-separate.qml @@ -0,0 +1,20 @@ +import QtQuick 2.0 + +Rectangle { + + function changeGradient() { + firstStop.color = "red" + secondStop.color = "blue" + } + + QtObject { + id: someObject + property Gradient someGradient: Gradient { + GradientStop { id: firstStop; position: 0.0; color: "gray" } + GradientStop { id: secondStop; position: 1.0; color: "white" } + } + } + + gradient: someObject.someGradient +} + diff --git a/tests/auto/quick/qquickrectangle/tst_qquickrectangle.cpp b/tests/auto/quick/qquickrectangle/tst_qquickrectangle.cpp index 65c7e387a0..0d79592e37 100644 --- a/tests/auto/quick/qquickrectangle/tst_qquickrectangle.cpp +++ b/tests/auto/quick/qquickrectangle/tst_qquickrectangle.cpp @@ -32,6 +32,7 @@ #include <QtQml/qqmlengine.h> #include <QtQml/qqmlcomponent.h> #include <QtQuick/qquickview.h> +#include <private/qquickitem_p.h> #include <private/qquickrectangle_p.h> #include "../../shared/util.h" @@ -46,6 +47,8 @@ private slots: void color(); void gradient(); void gradient_border(); + void gradient_separate(); + void gradient_multiple(); void antialiasing(); private: @@ -111,6 +114,62 @@ void tst_qquickrectangle::gradient_border() QVERIFY(QTest::qWaitForWindowExposed(&view)); } +// A gradient not defined inline with the Rectangle using it should still change +// that Rectangle. +void tst_qquickrectangle::gradient_separate() +{ + QQuickView view; + view.setSource(testFileUrl("gradient-separate.qml")); + view.show(); + + QVERIFY(QTest::qWaitForWindowExposed(&view)); + + QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(view.rootObject()); + QVERIFY(rect); + + // Start off clean + QQuickItemPrivate *rectPriv = QQuickItemPrivate::get(rect); + bool isDirty = rectPriv->dirtyAttributes & QQuickItemPrivate::Content; + QVERIFY(!isDirty); + + QMetaObject::invokeMethod(rect, "changeGradient"); + + // Changing the gradient should have scheduled an update of the item. + isDirty = rectPriv->dirtyAttributes & QQuickItemPrivate::Content; + QVERIFY(isDirty); +} + +// When a gradient is changed, every Rectangle connected to it must update. +void tst_qquickrectangle::gradient_multiple() +{ + QQuickView view; + view.setSource(testFileUrl("gradient-multiple.qml")); + view.show(); + + QVERIFY(QTest::qWaitForWindowExposed(&view)); + + QQuickRectangle *firstRect = qobject_cast<QQuickRectangle*>(view.rootObject()->property("firstRectangle").value<QObject*>()); + QQuickRectangle *secondRect = qobject_cast<QQuickRectangle*>(view.rootObject()->property("secondRectangle").value<QObject*>()); + QVERIFY(firstRect); + QVERIFY(secondRect); + + // Start off clean + QQuickItemPrivate *firstRectPriv = QQuickItemPrivate::get(firstRect); + QQuickItemPrivate *secondRectPriv = QQuickItemPrivate::get(secondRect); + bool firstIsDirty = firstRectPriv->dirtyAttributes & QQuickItemPrivate::Content; + bool secondIsDirty = secondRectPriv->dirtyAttributes & QQuickItemPrivate::Content; + QVERIFY(!firstIsDirty); + QVERIFY(!secondIsDirty); + + QMetaObject::invokeMethod(view.rootObject(), "changeGradient"); + + // Changing the gradient should have scheduled an update of both items + firstIsDirty = firstRectPriv->dirtyAttributes & QQuickItemPrivate::Content; + secondIsDirty = secondRectPriv->dirtyAttributes & QQuickItemPrivate::Content; + QVERIFY(firstIsDirty); + QVERIFY(secondIsDirty); +} + void tst_qquickrectangle::antialiasing() { QQmlComponent component(&engine); |