summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSean Harmer <sean.harmer@kdab.com>2017-04-07 15:32:04 +0100
committerSean Harmer <sean.harmer@kdab.com>2017-04-12 18:37:26 +0000
commit90667286d9ab851f6735fc53dd7aaa3881167b3d (patch)
tree089a3d453e2f76cb1284cb62e6d98c31da7e6ed1
parent6cf41cf05ca8d1b6caddcdf54767d1926ccae323 (diff)
Add a flag to AnimationClipLoader to track where its data comes from
Nicer than implicitly tracking it via m_source.isEmpty(). Change-Id: I120cb3728504b2bbc77d5959711a3f94731399ce Reviewed-by: Mike Krus <mike.krus@kdab.com>
-rw-r--r--src/animation/backend/animationcliploader.cpp18
-rw-r--r--src/animation/backend/animationcliploader_p.h16
-rw-r--r--tests/auto/animation/animationcliploader/tst_animationcliploader.cpp1
-rw-r--r--tests/auto/animation/animationutils/tst_animationutils.cpp5
4 files changed, 37 insertions, 3 deletions
diff --git a/src/animation/backend/animationcliploader.cpp b/src/animation/backend/animationcliploader.cpp
index 8892cffcd..36390a284 100644
--- a/src/animation/backend/animationcliploader.cpp
+++ b/src/animation/backend/animationcliploader.cpp
@@ -59,6 +59,7 @@ AnimationClipLoader::AnimationClipLoader()
, m_source()
, m_status(QAnimationClipLoader::NotReady)
, m_clipData()
+ , m_dataType(Unknown)
, m_name()
, m_channels()
, m_duration(0.0f)
@@ -70,6 +71,7 @@ void AnimationClipLoader::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeB
const auto loaderTypedChange = qSharedPointerDynamicCast<Qt3DCore::QNodeCreatedChange<QAnimationClipLoaderData>>(change);
if (loaderTypedChange) {
const auto &data = loaderTypedChange->data;
+ m_dataType = File;
m_source = data.source;
if (!m_source.isEmpty())
setDirty(Handler::AnimationClipDirty);
@@ -79,6 +81,7 @@ void AnimationClipLoader::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeB
const auto clipTypedChange = qSharedPointerDynamicCast<Qt3DCore::QNodeCreatedChange<QAnimationClipChangeData>>(change);
if (clipTypedChange) {
const auto &data = clipTypedChange->data;
+ m_dataType = Data;
m_clipData = data.clipData;
if (m_clipData.isValid())
setDirty(Handler::AnimationClipDirty);
@@ -93,6 +96,7 @@ void AnimationClipLoader::cleanup()
m_source.clear();
m_clipData.clearChannels();
m_status = QAnimationClipLoader::NotReady;
+ m_dataType = Unknown;
m_channels.clear();
m_duration = 0.0f;
@@ -117,9 +121,11 @@ void AnimationClipLoader::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e)
case Qt3DCore::PropertyUpdated: {
const auto change = qSharedPointerCast<Qt3DCore::QPropertyUpdatedChange>(e);
if (change->propertyName() == QByteArrayLiteral("source")) {
+ Q_ASSERT(m_dataType == File);
m_source = change->value().toUrl();
setDirty(Handler::AnimationClipDirty);
} else if (change->propertyName() == QByteArrayLiteral("clipData")) {
+ Q_ASSERT(m_dataType == Data);
m_clipData = change->value().value<Qt3DAnimation::QAnimationClipData>();
if (m_clipData.isValid())
setDirty(Handler::AnimationClipDirty);
@@ -143,10 +149,18 @@ void AnimationClipLoader::loadAnimation()
clearData();
// Load the data
- if (!m_source.isEmpty())
+ switch (m_dataType) {
+ case File:
loadAnimationFromUrl();
- else
+ break;
+
+ case Data:
loadAnimationFromData();
+ break;
+
+ default:
+ Q_UNREACHABLE();
+ }
// Update the duration
const float t = findDuration();
diff --git a/src/animation/backend/animationcliploader_p.h b/src/animation/backend/animationcliploader_p.h
index 3ac1f7907..b9f21615c 100644
--- a/src/animation/backend/animationcliploader_p.h
+++ b/src/animation/backend/animationcliploader_p.h
@@ -84,6 +84,20 @@ public:
int channelCount() const { return m_channelComponentCount; }
int channelComponentBaseIndex(int channelGroupIndex) const;
+ // Allow unit tests to set the data type
+#if !defined(QT_BUILD_INTERNAL)
+private:
+#endif
+ enum ClipDataType {
+ Unknown,
+ File,
+ Data
+ };
+#if defined(QT_BUILD_INTERNAL)
+public:
+ void setDataType(ClipDataType dataType) { m_dataType = dataType; }
+#endif
+
private:
void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) Q_DECL_FINAL;
void loadAnimationFromUrl();
@@ -94,8 +108,8 @@ private:
QUrl m_source;
QAnimationClipLoader::Status m_status;
-
QAnimationClipData m_clipData;
+ ClipDataType m_dataType;
QString m_name;
QVector<Channel> m_channels;
diff --git a/tests/auto/animation/animationcliploader/tst_animationcliploader.cpp b/tests/auto/animation/animationcliploader/tst_animationcliploader.cpp
index 35c0d5e54..09798e7d6 100644
--- a/tests/auto/animation/animationcliploader/tst_animationcliploader.cpp
+++ b/tests/auto/animation/animationcliploader/tst_animationcliploader.cpp
@@ -97,6 +97,7 @@ private Q_SLOTS:
Qt3DAnimation::Animation::AnimationClipLoader backendClip;
Qt3DAnimation::Animation::Handler handler;
backendClip.setHandler(&handler);
+ backendClip.setDataType(Qt3DAnimation::Animation::AnimationClipLoader::File);
Qt3DCore::QPropertyUpdatedChangePtr updateChange;
// WHEN
diff --git a/tests/auto/animation/animationutils/tst_animationutils.cpp b/tests/auto/animation/animationutils/tst_animationutils.cpp
index 17815f5db..282ceb829 100644
--- a/tests/auto/animation/animationutils/tst_animationutils.cpp
+++ b/tests/auto/animation/animationutils/tst_animationutils.cpp
@@ -163,6 +163,7 @@ public:
auto clipId = Qt3DCore::QNodeId::createId();
AnimationClipLoader *clip = handler->animationClipLoaderManager()->getOrCreateResource(clipId);
setPeerId(clip, clipId);
+ clip->setDataType(AnimationClipLoader::File);
clip->setSource(source);
clip->loadAnimation();
return clip;
@@ -2367,6 +2368,7 @@ private Q_SLOTS:
targetIndices.push_back({ 11 });
auto *clip = new AnimationClipLoader();
+ clip->setDataType(AnimationClipLoader::File);
clip->setSource(QUrl("qrc:/clip3.json"));
clip->loadAnimation();
@@ -2396,6 +2398,7 @@ private Q_SLOTS:
targetIndices.push_back({ 11 });
auto *clip = new AnimationClipLoader();
+ clip->setDataType(AnimationClipLoader::File);
clip->setSource(QUrl("qrc:/clip3.json"));
clip->loadAnimation();
@@ -2425,6 +2428,7 @@ private Q_SLOTS:
targetIndices.push_back({ 11 });
auto *clip = new AnimationClipLoader();
+ clip->setDataType(AnimationClipLoader::File);
clip->setSource(QUrl("qrc:/clip3.json"));
clip->loadAnimation();
@@ -2454,6 +2458,7 @@ private Q_SLOTS:
targetIndices.push_back({ 11 });
auto *clip = new AnimationClipLoader();
+ clip->setDataType(AnimationClipLoader::File);
clip->setSource(QUrl("qrc:/clip3.json"));
clip->loadAnimation();