summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSean Harmer <sean.harmer@kdab.com>2017-01-23 08:57:04 +0000
committerSean Harmer <sean.harmer@kdab.com>2017-01-27 12:34:49 +0000
commit0070276340e15872362858928d6858ae31e07f7e (patch)
treed1e13ef663ca26d2e6856755e36ea8b70c4b3401
parenteda313e0855f94e317cd656ad9c83ef086e17625 (diff)
Add running property to QClipAnimator
Change-Id: I5ef29ada7fd6584674d98162f7106177e199b720 Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
-rw-r--r--src/animation/backend/clipanimator.cpp11
-rw-r--r--src/animation/backend/clipanimator_p.h6
-rw-r--r--src/animation/backend/handler.cpp22
-rw-r--r--src/animation/backend/handler_p.h3
-rw-r--r--src/animation/frontend/qanimationclip_p.h1
-rw-r--r--src/animation/frontend/qclipanimator.cpp18
-rw-r--r--src/animation/frontend/qclipanimator.h4
-rw-r--r--src/animation/frontend/qclipanimator_p.h2
-rw-r--r--tests/auto/animation/clipanimator/tst_clipanimator.cpp19
9 files changed, 86 insertions, 0 deletions
diff --git a/src/animation/backend/clipanimator.cpp b/src/animation/backend/clipanimator.cpp
index a0e62c636..3b531422f 100644
--- a/src/animation/backend/clipanimator.cpp
+++ b/src/animation/backend/clipanimator.cpp
@@ -47,6 +47,7 @@ namespace Animation {
ClipAnimator::ClipAnimator()
: BackendNode(ReadOnly)
, m_clipId()
+ , m_running(false)
{
}
@@ -55,6 +56,13 @@ void ClipAnimator::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr
const auto typedChange = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<QClipAnimatorData>>(change);
const auto &data = typedChange->data;
m_clipId = data.clipId;
+ setRunning(data.running);
+}
+
+void ClipAnimator::setRunning(bool running)
+{
+ m_running = running;
+ m_handler->setClipAnimatorRunning(peerId(), m_running);
}
void ClipAnimator::cleanup()
@@ -62,6 +70,7 @@ void ClipAnimator::cleanup()
setEnabled(false);
m_handler = nullptr;
m_clipId = Qt3DCore::QNodeId();
+ m_running = false;
}
void ClipAnimator::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e)
@@ -71,6 +80,8 @@ void ClipAnimator::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e)
const auto change = qSharedPointerCast<Qt3DCore::QPropertyUpdatedChange>(e);
if (change->propertyName() == QByteArrayLiteral("clip"))
setClipId(change->value().value<Qt3DCore::QNodeId>());
+ else if (change->propertyName() == QByteArrayLiteral("running"))
+ setRunning(change->value().toBool());
break;
}
diff --git a/src/animation/backend/clipanimator_p.h b/src/animation/backend/clipanimator_p.h
index 87039cec7..2091fb300 100644
--- a/src/animation/backend/clipanimator_p.h
+++ b/src/animation/backend/clipanimator_p.h
@@ -66,6 +66,10 @@ public:
void cleanup();
void setClipId(Qt3DCore::QNodeId clipId) { m_clipId = clipId; }
Qt3DCore::QNodeId clipId() const { return m_clipId; }
+
+ void setRunning(bool running);
+ bool isRunning() const { return m_running; }
+
void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) Q_DECL_OVERRIDE;
void setHandler(Handler *handler) { m_handler = handler; }
@@ -74,6 +78,8 @@ private:
void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) Q_DECL_FINAL;
Qt3DCore::QNodeId m_clipId;
+
+ bool m_running;
};
} // namespace Animation
diff --git a/src/animation/backend/handler.cpp b/src/animation/backend/handler.cpp
index 0da9ba4dd..da0df67d1 100644
--- a/src/animation/backend/handler.cpp
+++ b/src/animation/backend/handler.cpp
@@ -69,6 +69,28 @@ void Handler::setDirty(DirtyFlag flag, Qt3DCore::QNodeId nodeId)
}
}
+void Handler::setClipAnimatorRunning(Qt3DCore::QNodeId clipAnimatorId, bool running)
+{
+ const auto handle = m_clipAnimatorManager->lookupHandle(clipAnimatorId);
+ if (handle.isNull())
+ return;
+
+ // Add clip to running set if not already present
+ if (running && !m_runningClipAnimators.contains(handle))
+ m_runningClipAnimators.push_back(handle);
+
+ // If being marked as not running, remove from set of running clips
+ if (!running) {
+ const auto it = std::find_if(m_runningClipAnimators.begin(),
+ m_runningClipAnimators.end(),
+ [handle](const HClipAnimator &h) { return h == handle; });
+ if (it != m_runningClipAnimators.end())
+ m_runningClipAnimators.erase(it);
+ }
+
+ qCDebug(HandlerLogic) << "Running clips:" << m_runningClipAnimators;
+}
+
QVector<Qt3DCore::QAspectJobPtr> Handler::jobsToExecute(qint64 time)
{
Q_UNUSED(time);
diff --git a/src/animation/backend/handler_p.h b/src/animation/backend/handler_p.h
index 8a5f1bfd4..abcea1f7e 100644
--- a/src/animation/backend/handler_p.h
+++ b/src/animation/backend/handler_p.h
@@ -86,6 +86,8 @@ public:
void setDirty(DirtyFlag flag, Qt3DCore::QNodeId nodeId);
+ void setClipAnimatorRunning(Qt3DCore::QNodeId clipAnimatorId, bool running);
+
AnimationClipManager *animationClipManager() const Q_DECL_NOTHROW { return m_animationClipManager.data(); }
ClipAnimatorManager *clipAnimatorManager() const Q_DECL_NOTHROW { return m_clipAnimatorManager.data(); }
BlendedClipAnimatorManager *blendedClipAnimatorManager() const Q_DECL_NOTHROW { return m_blendedClipAnimatorManager.data(); }
@@ -100,6 +102,7 @@ private:
QScopedPointer<ConductedClipAnimatorManager> m_conductedClipAnimatorManager;
QVector<HAnimationClip> m_dirtyAnimationClips;
+ QVector<HClipAnimator> m_runningClipAnimators;
QSharedPointer<LoadAnimationClipJob> m_loadAnimationClipJob;
diff --git a/src/animation/frontend/qanimationclip_p.h b/src/animation/frontend/qanimationclip_p.h
index e55facfbf..87ebf99e1 100644
--- a/src/animation/frontend/qanimationclip_p.h
+++ b/src/animation/frontend/qanimationclip_p.h
@@ -68,6 +68,7 @@ public:
struct QAnimationClipData
{
QUrl source;
+ bool running;
};
} // namespace Qt3DAnimation
diff --git a/src/animation/frontend/qclipanimator.cpp b/src/animation/frontend/qclipanimator.cpp
index 5e3051fb1..a4861422f 100644
--- a/src/animation/frontend/qclipanimator.cpp
+++ b/src/animation/frontend/qclipanimator.cpp
@@ -48,6 +48,7 @@ namespace Qt3DAnimation {
QClipAnimatorPrivate::QClipAnimatorPrivate()
: Qt3DCore::QComponentPrivate()
, m_clip(nullptr)
+ , m_running(false)
{
}
@@ -71,6 +72,12 @@ QAnimationClip *QClipAnimator::clip() const
return d->m_clip;
}
+bool QClipAnimator::isRunning() const
+{
+ Q_D(const QClipAnimator);
+ return d->m_running;
+}
+
void QClipAnimator::setClip(QAnimationClip *clip)
{
Q_D(QClipAnimator);
@@ -90,12 +97,23 @@ void QClipAnimator::setClip(QAnimationClip *clip)
emit clipChanged(clip);
}
+void QClipAnimator::setRunning(bool running)
+{
+ Q_D(QClipAnimator);
+ if (d->m_running == running)
+ return;
+
+ d->m_running = running;
+ emit runningChanged(running);
+}
+
Qt3DCore::QNodeCreatedChangeBasePtr QClipAnimator::createNodeCreationChange() const
{
auto creationChange = Qt3DCore::QNodeCreatedChangePtr<QClipAnimatorData>::create(this);
auto &data = creationChange->data;
Q_D(const QClipAnimator);
data.clipId = Qt3DCore::qIdForNode(d->m_clip);
+ data.running = d->m_running;
return creationChange;
}
diff --git a/src/animation/frontend/qclipanimator.h b/src/animation/frontend/qclipanimator.h
index 1b43cddd1..3e8426249 100644
--- a/src/animation/frontend/qclipanimator.h
+++ b/src/animation/frontend/qclipanimator.h
@@ -54,18 +54,22 @@ class QT3DANIMATIONSHARED_EXPORT QClipAnimator : public Qt3DCore::QComponent
{
Q_OBJECT
Q_PROPERTY(Qt3DAnimation::QAnimationClip *clip READ clip WRITE setClip NOTIFY clipChanged)
+ Q_PROPERTY(bool running READ isRunning WRITE setRunning NOTIFY runningChanged)
public:
explicit QClipAnimator(Qt3DCore::QNode *parent = nullptr);
~QClipAnimator();
Qt3DAnimation::QAnimationClip *clip() const;
+ bool isRunning() const;
public Q_SLOTS:
void setClip(Qt3DAnimation::QAnimationClip *clip);
+ void setRunning(bool running);
Q_SIGNALS:
void clipChanged(Qt3DAnimation::QAnimationClip *clip);
+ void runningChanged(bool running);
protected:
QClipAnimator(QClipAnimatorPrivate &dd, Qt3DCore::QNode *parent = nullptr);
diff --git a/src/animation/frontend/qclipanimator_p.h b/src/animation/frontend/qclipanimator_p.h
index a22d20720..fa4935ea3 100644
--- a/src/animation/frontend/qclipanimator_p.h
+++ b/src/animation/frontend/qclipanimator_p.h
@@ -66,11 +66,13 @@ public:
Q_DECLARE_PUBLIC(QClipAnimator)
QAnimationClip *m_clip;
+ bool m_running;
};
struct QClipAnimatorData
{
Qt3DCore::QNodeId clipId;
+ bool running;
};
} // namespace Qt3DAnimation
diff --git a/tests/auto/animation/clipanimator/tst_clipanimator.cpp b/tests/auto/animation/clipanimator/tst_clipanimator.cpp
index 0e6489089..b19f60da2 100644
--- a/tests/auto/animation/clipanimator/tst_clipanimator.cpp
+++ b/tests/auto/animation/clipanimator/tst_clipanimator.cpp
@@ -45,7 +45,9 @@ private Q_SLOTS:
void checkPeerPropertyMirroring()
{
// GIVEN
+ Qt3DAnimation::Animation::Handler handler;
Qt3DAnimation::Animation::ClipAnimator backendAnimator;
+ backendAnimator.setHandler(&handler);
Qt3DAnimation::QClipAnimator animator;
auto clip = new Qt3DAnimation::QAnimationClip();
@@ -58,22 +60,27 @@ private Q_SLOTS:
QCOMPARE(backendAnimator.peerId(), animator.id());
QCOMPARE(backendAnimator.isEnabled(), animator.isEnabled());
QCOMPARE(backendAnimator.clipId(), clip->id());
+ QCOMPARE(backendAnimator.isRunning(), animator.isRunning());
}
void checkInitialAndCleanedUpState()
{
// GIVEN
+ Qt3DAnimation::Animation::Handler handler;
Qt3DAnimation::Animation::ClipAnimator backendAnimator;
+ backendAnimator.setHandler(&handler);
// THEN
QVERIFY(backendAnimator.peerId().isNull());
QCOMPARE(backendAnimator.isEnabled(), false);
QCOMPARE(backendAnimator.clipId(), Qt3DCore::QNodeId());
+ QCOMPARE(backendAnimator.isRunning(), false);
// GIVEN
Qt3DAnimation::QClipAnimator animator;
auto clip = new Qt3DAnimation::QAnimationClip();
animator.setClip(clip);
+ animator.setRunning(true);
// WHEN
simulateInitialization(&animator, &backendAnimator);
@@ -83,12 +90,15 @@ private Q_SLOTS:
// THEN
QCOMPARE(backendAnimator.clipId(), Qt3DCore::QNodeId());
QCOMPARE(backendAnimator.isEnabled(), false);
+ QCOMPARE(backendAnimator.isRunning(), false);
}
void checkPropertyChanges()
{
// GIVEN
+ Qt3DAnimation::Animation::Handler handler;
Qt3DAnimation::Animation::ClipAnimator backendAnimator;
+ backendAnimator.setHandler(&handler);
Qt3DCore::QPropertyUpdatedChangePtr updateChange;
// WHEN
@@ -109,6 +119,15 @@ private Q_SLOTS:
// THEN
QCOMPARE(backendAnimator.clipId(), newClip->id());
+
+ // WHEN
+ updateChange.reset(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId()));
+ updateChange->setPropertyName("running");
+ updateChange->setValue(true);
+ backendAnimator.sceneChangeEvent(updateChange);
+
+ // THEN
+ QCOMPARE(backendAnimator.isRunning(), true);
}
};