diff options
author | Mike Krus <mike.krus@kdab.com> | 2019-09-19 14:53:13 +0100 |
---|---|---|
committer | Mike Krus <mike.krus@kdab.com> | 2019-09-20 08:18:39 +0100 |
commit | 009c6042bd1b1c0a2e03d18a47223e82d7fec082 (patch) | |
tree | f7d862e26097626426539d084eab782449d16c7d | |
parent | 7ec980c9487fc046ef8bfa2220c149442f9d9aab (diff) |
Update QClock to use direct sync
Change-Id: I37183c67b3f6e8b08a1b050693879aa811cf48c9
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
-rw-r--r-- | src/animation/backend/clock.cpp | 26 | ||||
-rw-r--r-- | src/animation/backend/clock_p.h | 4 | ||||
-rw-r--r-- | src/animation/frontend/qanimationaspect.cpp | 2 | ||||
-rw-r--r-- | tests/auto/animation/clock/tst_clock.cpp | 18 |
4 files changed, 17 insertions, 33 deletions
diff --git a/src/animation/backend/clock.cpp b/src/animation/backend/clock.cpp index f5b2bd1d3..ab30f735c 100644 --- a/src/animation/backend/clock.cpp +++ b/src/animation/backend/clock.cpp @@ -52,28 +52,16 @@ Clock::Clock() { } -void Clock::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) +void Clock::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) { - const auto typedChange = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<QClockData>>(change); - const auto &data = typedChange->data; - m_playbackRate = data.playbackRate; -} - -void Clock::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) -{ - switch (e->type()) { - case Qt3DCore::PropertyUpdated: { - const auto change = qSharedPointerCast<Qt3DCore::QPropertyUpdatedChange>(e); - if (change->propertyName() == QByteArrayLiteral("playbackRate")) { - m_playbackRate = change.data()->value().toDouble(); - } - break; - } + BackendNode::syncFromFrontEnd(frontEnd, firstTime); + const QClock *node = qobject_cast<const QClock *>(frontEnd); + if (!node) + return; - default: - break; + if (!qFuzzyCompare(m_playbackRate, node->playbackRate())) { + m_playbackRate = node->playbackRate(); } - QBackendNode::sceneChangeEvent(e); } void Clock::cleanup() diff --git a/src/animation/backend/clock_p.h b/src/animation/backend/clock_p.h index 10987655a..b4a60b3a7 100644 --- a/src/animation/backend/clock_p.h +++ b/src/animation/backend/clock_p.h @@ -61,15 +61,13 @@ class Q_AUTOTEST_EXPORT Clock : public BackendNode public: Clock(); - void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e); + void syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) override; void cleanup(); void setPlaybackRate(double playbackRate) { m_playbackRate = playbackRate; } double playbackRate() const { return m_playbackRate; } private: - void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) final; - double m_playbackRate; }; diff --git a/src/animation/frontend/qanimationaspect.cpp b/src/animation/frontend/qanimationaspect.cpp index ad0929284..a76916409 100644 --- a/src/animation/frontend/qanimationaspect.cpp +++ b/src/animation/frontend/qanimationaspect.cpp @@ -107,7 +107,7 @@ QAnimationAspect::QAnimationAspect(QAnimationAspectPrivate &dd, QObject *parent) registerBackendType<QAbstractAnimationClip, true>( QSharedPointer<Animation::NodeFunctor<Animation::AnimationClip, Animation::AnimationClipLoaderManager>>::create(d->m_handler.data(), d->m_handler->animationClipLoaderManager())); - registerBackendType<QClock>( + registerBackendType<QClock, true>( QSharedPointer<Animation::NodeFunctor<Animation::Clock, Animation::ClockManager>>::create(d->m_handler.data(), d->m_handler->clockManager())); registerBackendType<QClipAnimator>( diff --git a/tests/auto/animation/clock/tst_clock.cpp b/tests/auto/animation/clock/tst_clock.cpp index a81adfe7b..793a01b25 100644 --- a/tests/auto/animation/clock/tst_clock.cpp +++ b/tests/auto/animation/clock/tst_clock.cpp @@ -50,7 +50,7 @@ private Q_SLOTS: clock.setPlaybackRate(10.5); // WHEN - simulateInitialization(&clock, &backendClock); + simulateInitializationSync(&clock, &backendClock); // THEN QCOMPARE(backendClock.playbackRate(), clock.playbackRate()); @@ -69,7 +69,7 @@ private Q_SLOTS: clock.setPlaybackRate(10.5); // WHEN - simulateInitialization(&clock, &backendClock); + simulateInitializationSync(&clock, &backendClock); backendClock.cleanup(); // THEN @@ -79,15 +79,15 @@ private Q_SLOTS: void checkSceneChangeEvents() { // GIVEN + Qt3DAnimation::QClock clock; Qt3DAnimation::Animation::Clock backendClock; + simulateInitializationSync(&clock, &backendClock); { // WHEN const bool newValue = false; - const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); - change->setPropertyName("enabled"); - change->setValue(newValue); - backendClock.sceneChangeEvent(change); + clock.setEnabled(newValue); + backendClock.syncFromFrontEnd(&clock, false); // THEN QCOMPARE(backendClock.isEnabled(), newValue); @@ -95,10 +95,8 @@ private Q_SLOTS: { // WHEN const double newPlaybackRateValue = 2.0; - const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); - change->setPropertyName("playbackRate"); - change->setValue(newPlaybackRateValue); - backendClock.sceneChangeEvent(change); + clock.setPlaybackRate(newPlaybackRateValue); + backendClock.syncFromFrontEnd(&clock, false); // THEN QCOMPARE(backendClock.playbackRate(), newPlaybackRateValue); |