diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2017-12-11 14:30:12 +0100 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2017-12-13 12:38:46 +0000 |
commit | f38d6c5bd2eba72d68018f39581263d8b43de238 (patch) | |
tree | 734d7249c705e694bdd58b3e601402f03e299a59 /src/quicktemplates2/qquickslider.cpp | |
parent | d9e740d2ccf8c1d3caacfcd95537718048e3a7ba (diff) |
Slider: use deferred execution
Note: It is important to repeat the names of the deferred properties
in base classes. The QML engine ask for the class info from the meta-
object. A class info declaration in a sub-class overshadows the class
info declaration by the same name in the base class.
Task-number: QTBUG-50992
Change-Id: Ib674b943db2f0bf196c9386ea22b511715c0a98f
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/quicktemplates2/qquickslider.cpp')
-rw-r--r-- | src/quicktemplates2/qquickslider.cpp | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/src/quicktemplates2/qquickslider.cpp b/src/quicktemplates2/qquickslider.cpp index da2f402f..d4cbf61c 100644 --- a/src/quicktemplates2/qquickslider.cpp +++ b/src/quicktemplates2/qquickslider.cpp @@ -36,6 +36,7 @@ #include "qquickslider_p.h" #include "qquickcontrol_p_p.h" +#include "qquickdeferredexecute_p_p.h" #include <QtQuick/private/qquickwindow_p.h> @@ -112,6 +113,8 @@ public: void handleRelease(const QPointF &point) override; void handleUngrab() override; + void executeHandle(bool complete = false); + qreal from; qreal to; qreal value; @@ -122,7 +125,7 @@ public: QPointF pressPoint; Qt::Orientation orientation; QQuickSlider::SnapMode snapMode; - QQuickItem *handle; + QQuickDeferredPointer<QQuickItem> handle; }; qreal QQuickSliderPrivate::snapPosition(qreal position) const @@ -235,6 +238,20 @@ void QQuickSliderPrivate::handleUngrab() q->setPressed(false); } +static inline QString handleName() { return QStringLiteral("handle"); } + +void QQuickSliderPrivate::executeHandle(bool complete) +{ + Q_Q(QQuickSlider); + if (handle.wasExecuted()) + return; + + if (!handle) + quickBeginDeferred(q, handleName(), handle); + if (complete) + quickCompleteDeferred(q, handleName(), handle); +} + QQuickSlider::QQuickSlider(QQuickItem *parent) : QQuickControl(*(new QQuickSliderPrivate), parent) { @@ -485,7 +502,9 @@ void QQuickSlider::setOrientation(Qt::Orientation orientation) */ QQuickItem *QQuickSlider::handle() const { - Q_D(const QQuickSlider); + QQuickSliderPrivate *d = const_cast<QQuickSliderPrivate *>(d_func()); + if (!d->handle) + d->executeHandle(); return d->handle; } @@ -495,11 +514,12 @@ void QQuickSlider::setHandle(QQuickItem *handle) if (d->handle == handle) return; - QQuickControlPrivate::destroyDelegate(d->handle, this); + delete d->handle; d->handle = handle; if (handle && !handle->parentItem()) handle->setParentItem(this); - emit handleChanged(); + if (!d->handle.isExecuting()) + emit handleChanged(); } /*! @@ -704,6 +724,8 @@ void QQuickSlider::mirrorChange() void QQuickSlider::componentComplete() { Q_D(QQuickSlider); + d->executeHandle(true); + d->executeBackground(true); QQuickControl::componentComplete(); setValue(d->value); d->updatePosition(); |