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 /src/quick/items/qquickrectangle.cpp | |
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 'src/quick/items/qquickrectangle.cpp')
-rw-r--r-- | src/quick/items/qquickrectangle.cpp | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/quick/items/qquickrectangle.cpp b/src/quick/items/qquickrectangle.cpp index 0c532bcd4c..65284eb532 100644 --- a/src/quick/items/qquickrectangle.cpp +++ b/src/quick/items/qquickrectangle.cpp @@ -1,6 +1,5 @@ /**************************************************************************** ** -** Copyright (C) 2017 Crimson AS <info@crimson.no> ** Copyright (C) 2016 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** @@ -270,9 +269,11 @@ QGradientStops QQuickGradient::gradientStops() const void QQuickGradient::doUpdate() { - static_cast<QQuickItem*>(parent())->update(); + emit updated(); } +int QQuickRectanglePrivate::doUpdateSlotIdx = -1; + /*! \qmltype Rectangle \instantiates QQuickRectangle @@ -326,6 +327,11 @@ QQuickRectangle::QQuickRectangle(QQuickItem *parent) setFlag(ItemHasContents); } +void QQuickRectangle::doUpdate() +{ + update(); +} + /*! \qmlproperty bool QtQuick::Rectangle::antialiasing @@ -390,7 +396,16 @@ void QQuickRectangle::setGradient(QQuickGradient *gradient) Q_D(QQuickRectangle); if (d->gradient == gradient) return; + static int updatedSignalIdx = -1; + if (updatedSignalIdx < 0) + updatedSignalIdx = QMetaMethod::fromSignal(&QQuickGradient::updated).methodIndex(); + if (d->doUpdateSlotIdx < 0) + d->doUpdateSlotIdx = QQuickRectangle::staticMetaObject.indexOfSlot("doUpdate()"); + if (d->gradient) + QMetaObject::disconnect(d->gradient, updatedSignalIdx, this, d->doUpdateSlotIdx); d->gradient = gradient; + if (d->gradient) + QMetaObject::connect(d->gradient, updatedSignalIdx, this, d->doUpdateSlotIdx); update(); } |