summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuan Jose Casafranca <juan.casafranca@kdab.com>2018-07-03 11:48:48 +0200
committerJuan José Casafranca <juan.casafranca@kdab.com>2018-07-11 13:30:56 +0000
commitc39e20dcc693b525f2ee2259e864487d664c3856 (patch)
treec4331e8027cffabe5e96c874a099d1cd0b33b925
parentcb2405886dadffd3c787f64f2ca02c5f40810b72 (diff)
Check animator can be played in frontend and backend
We check that the animator can be played in the frontend. Each animator subclass must implement their own canPlay method. In the backend we correctly check the clipAnimator can be played Task-number: QTBUG-69369 Change-Id: If8bca9b73321e2bfdb4d68ddc286df0109ee91f1 Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
-rw-r--r--src/animation/backend/findrunningclipanimatorsjob.cpp2
-rw-r--r--src/animation/frontend/qabstractclipanimator.cpp8
-rw-r--r--src/animation/frontend/qabstractclipanimator_p.h2
-rw-r--r--src/animation/frontend/qclipanimator.cpp9
-rw-r--r--src/animation/frontend/qclipanimator_p.h2
-rw-r--r--tests/auto/animation/qclipanimator/tst_qclipanimator.cpp27
6 files changed, 49 insertions, 1 deletions
diff --git a/src/animation/backend/findrunningclipanimatorsjob.cpp b/src/animation/backend/findrunningclipanimatorsjob.cpp
index a9b0a85ed..b55c84e77 100644
--- a/src/animation/backend/findrunningclipanimatorsjob.cpp
+++ b/src/animation/backend/findrunningclipanimatorsjob.cpp
@@ -73,7 +73,7 @@ void FindRunningClipAnimatorsJob::run()
// TODO: Actually check if this is needed first, currently we re-build this every time
// canRun (or the normalized time) is true.
- if (!canRun && !(seeking || running))
+ if (!canRun || !(seeking || running))
continue;
// The clip animator needs to know how to map fcurve values through to properties on QNodes.
diff --git a/src/animation/frontend/qabstractclipanimator.cpp b/src/animation/frontend/qabstractclipanimator.cpp
index ba5d9456b..238dbea8c 100644
--- a/src/animation/frontend/qabstractclipanimator.cpp
+++ b/src/animation/frontend/qabstractclipanimator.cpp
@@ -57,6 +57,11 @@ QAbstractClipAnimatorPrivate::QAbstractClipAnimatorPrivate()
{
}
+bool QAbstractClipAnimatorPrivate::canPlay() const
+{
+ return true;
+}
+
/*!
\qmltype AbstractClipAnimator
\instantiates Qt3DAnimation::QAbstractClipAnimator
@@ -234,6 +239,9 @@ void QAbstractClipAnimator::setRunning(bool running)
if (d->m_running == running)
return;
+ if (running && !d->canPlay())
+ return;
+
d->m_running = running;
emit runningChanged(running);
}
diff --git a/src/animation/frontend/qabstractclipanimator_p.h b/src/animation/frontend/qabstractclipanimator_p.h
index e65ee160c..bf9504909 100644
--- a/src/animation/frontend/qabstractclipanimator_p.h
+++ b/src/animation/frontend/qabstractclipanimator_p.h
@@ -65,6 +65,8 @@ class QAbstractClipAnimatorPrivate : public Qt3DCore::QComponentPrivate
public:
QAbstractClipAnimatorPrivate();
+ virtual bool canPlay() const;
+
Q_DECLARE_PUBLIC(QAbstractClipAnimator)
Qt3DAnimation::QChannelMapper *m_mapper;
diff --git a/src/animation/frontend/qclipanimator.cpp b/src/animation/frontend/qclipanimator.cpp
index c14715494..398758820 100644
--- a/src/animation/frontend/qclipanimator.cpp
+++ b/src/animation/frontend/qclipanimator.cpp
@@ -53,6 +53,15 @@ QClipAnimatorPrivate::QClipAnimatorPrivate()
{
}
+bool QClipAnimatorPrivate::canPlay() const
+{
+ if (m_clip && m_mapper)
+ return true;
+
+ qWarning("ClipAnimators need a clip and a mapper to be played");
+ return false;
+}
+
/*!
\qmltype ClipAnimator
\instantiates Qt3DAnimation::QClipAnimator
diff --git a/src/animation/frontend/qclipanimator_p.h b/src/animation/frontend/qclipanimator_p.h
index fe40ed442..2f6d05b2e 100644
--- a/src/animation/frontend/qclipanimator_p.h
+++ b/src/animation/frontend/qclipanimator_p.h
@@ -64,6 +64,8 @@ class QClipAnimatorPrivate : public Qt3DAnimation::QAbstractClipAnimatorPrivate
public:
QClipAnimatorPrivate();
+ bool canPlay() const override;
+
Q_DECLARE_PUBLIC(QClipAnimator)
QAbstractAnimationClip *m_clip;
diff --git a/tests/auto/animation/qclipanimator/tst_qclipanimator.cpp b/tests/auto/animation/qclipanimator/tst_qclipanimator.cpp
index f41803b13..0b28228d9 100644
--- a/tests/auto/animation/qclipanimator/tst_qclipanimator.cpp
+++ b/tests/auto/animation/qclipanimator/tst_qclipanimator.cpp
@@ -155,6 +155,33 @@ private Q_SLOTS:
}
}
+ void checkRunning()
+ {
+ // GIVEN
+ Qt3DAnimation::QClipAnimator animator;
+ animator.stop();
+
+ {
+ // WHEN
+ animator.setRunning(true);
+
+ // THEN
+ QCOMPARE(animator.isRunning(), false);
+ }
+
+ {
+ // WHEN
+ Qt3DAnimation::QChannelMapper *mapper = new Qt3DAnimation::QChannelMapper;
+ Qt3DAnimation::QAnimationClip *clip = new Qt3DAnimation::QAnimationClip;
+ animator.setClip(clip);
+ animator.setChannelMapper(mapper);
+ animator.setRunning(true);
+
+ // THEN
+ QCOMPARE(animator.isRunning(), true);
+ }
+ }
+
void checkCreationData()
{
// GIVEN