diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2017-12-11 14:40:17 +0100 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2017-12-13 12:38:49 +0000 |
commit | 417b8459c3311fbf397fe82b9e76580469ec8ce8 (patch) | |
tree | ca48f3606e055437b5482df5864565df201666c5 /src | |
parent | f38d6c5bd2eba72d68018f39581263d8b43de238 (diff) |
Dial: use deferred execution
Task-number: QTBUG-50992
Change-Id: I432be00d81344ce129bc8906370555b134fdf423
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/quicktemplates2/qquickdial.cpp | 30 | ||||
-rw-r--r-- | src/quicktemplates2/qquickdial_p.h | 1 |
2 files changed, 27 insertions, 4 deletions
diff --git a/src/quicktemplates2/qquickdial.cpp b/src/quicktemplates2/qquickdial.cpp index c0e2c8ed..46085c47 100644 --- a/src/quicktemplates2/qquickdial.cpp +++ b/src/quicktemplates2/qquickdial.cpp @@ -35,6 +35,7 @@ ****************************************************************************/ #include "qquickdial_p.h" +#include "qquickdeferredexecute_p_p.h" #include <QtCore/qmath.h> #include <QtQuick/private/qquickflickable_p.h> @@ -122,6 +123,8 @@ public: void handleRelease(const QPointF &point) override; void handleUngrab() override; + void executeHandle(bool complete = false); + qreal from; qreal to; qreal value; @@ -133,7 +136,7 @@ public: QQuickDial::SnapMode snapMode; bool wrap; bool live; - QQuickItem *handle; + QQuickDeferredPointer<QQuickItem> handle; }; qreal QQuickDialPrivate::valueAt(qreal position) const @@ -253,6 +256,20 @@ void QQuickDialPrivate::handleUngrab() q->setPressed(false); } +static inline QString handleName() { return QStringLiteral("handle"); } + +void QQuickDialPrivate::executeHandle(bool complete) +{ + Q_Q(QQuickDial); + if (handle.wasExecuted()) + return; + + if (!handle) + quickBeginDeferred(q, handleName(), handle); + if (complete) + quickCompleteDeferred(q, handleName(), handle); +} + QQuickDial::QQuickDial(QQuickItem *parent) : QQuickControl(*(new QQuickDialPrivate), parent) { @@ -524,7 +541,9 @@ void QQuickDial::setPressed(bool pressed) */ QQuickItem *QQuickDial::handle() const { - Q_D(const QQuickDial); + QQuickDialPrivate *d = const_cast<QQuickDialPrivate *>(d_func()); + if (!d->handle) + d->executeHandle(); return d->handle; } @@ -534,11 +553,12 @@ void QQuickDial::setHandle(QQuickItem *handle) if (handle == d->handle) return; - QQuickControlPrivate::destroyDelegate(d->handle, this); + delete d->handle; d->handle = handle; if (d->handle && !d->handle->parentItem()) d->handle->setParentItem(this); - emit handleChanged(); + if (!d->handle.isExecuting()) + emit handleChanged(); } /*! @@ -730,6 +750,8 @@ void QQuickDial::mirrorChange() void QQuickDial::componentComplete() { Q_D(QQuickDial); + d->executeHandle(true); + d->executeBackground(true); QQuickControl::componentComplete(); setValue(d->value); d->updatePosition(); diff --git a/src/quicktemplates2/qquickdial_p.h b/src/quicktemplates2/qquickdial_p.h index 296f7986..d7bab0ad 100644 --- a/src/quicktemplates2/qquickdial_p.h +++ b/src/quicktemplates2/qquickdial_p.h @@ -72,6 +72,7 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickDial : public QQuickControl Q_PROPERTY(QQuickItem *handle READ handle WRITE setHandle NOTIFY handleChanged FINAL) // 2.2 (Qt 5.9) Q_PROPERTY(bool live READ live WRITE setLive NOTIFY liveChanged FINAL REVISION 2) + Q_CLASSINFO("DeferredPropertyNames", "background,handle") public: explicit QQuickDial(QQuickItem *parent = nullptr); |