diff options
author | Sean Harmer <sean.harmer@kdab.com> | 2017-01-25 10:41:32 +0000 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2017-01-27 12:34:54 +0000 |
commit | 5bd08543817328b5155201890031c4655f7d3b73 (patch) | |
tree | f25d365f5a84d17afde93f63d279e3bc87d2dded | |
parent | c1e425920331325f889053b921e66ea572234784 (diff) |
Add channelMapper property to QClipAnimator
Change-Id: I50a07e51188ae31f58e57d1baf98e22792ce88db
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
-rw-r--r-- | src/animation/backend/clipanimator.cpp | 10 | ||||
-rw-r--r-- | src/animation/backend/clipanimator_p.h | 4 | ||||
-rw-r--r-- | src/animation/frontend/qanimationaspect.cpp | 1 | ||||
-rw-r--r-- | src/animation/frontend/qclipanimator.cpp | 28 | ||||
-rw-r--r-- | src/animation/frontend/qclipanimator.h | 5 | ||||
-rw-r--r-- | src/animation/frontend/qclipanimator_p.h | 4 | ||||
-rw-r--r-- | tests/auto/animation/qclipanimator/tst_qclipanimator.cpp | 59 | ||||
-rw-r--r-- | tests/manual/animation-keyframe-simple/main.qml | 2 |
8 files changed, 108 insertions, 5 deletions
diff --git a/src/animation/backend/clipanimator.cpp b/src/animation/backend/clipanimator.cpp index 3b531422f..6b36212fa 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_mapperId() , m_running(false) { } @@ -56,9 +57,15 @@ void ClipAnimator::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr const auto typedChange = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<QClipAnimatorData>>(change); const auto &data = typedChange->data; m_clipId = data.clipId; + m_mapperId = data.mapperId; setRunning(data.running); } +void ClipAnimator::setMapperId(Qt3DCore::QNodeId mapperId) +{ + m_mapperId = mapperId; +} + void ClipAnimator::setRunning(bool running) { m_running = running; @@ -70,6 +77,7 @@ void ClipAnimator::cleanup() setEnabled(false); m_handler = nullptr; m_clipId = Qt3DCore::QNodeId(); + m_mapperId = Qt3DCore::QNodeId(); m_running = false; } @@ -80,6 +88,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("channelMapper")) + setMapperId(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 2091fb300..5dec684e5 100644 --- a/src/animation/backend/clipanimator_p.h +++ b/src/animation/backend/clipanimator_p.h @@ -66,6 +66,8 @@ public: void cleanup(); void setClipId(Qt3DCore::QNodeId clipId) { m_clipId = clipId; } Qt3DCore::QNodeId clipId() const { return m_clipId; } + void setMapperId(Qt3DCore::QNodeId mapperId); + Qt3DCore::QNodeId mapperId() const { return m_mapperId; } void setRunning(bool running); bool isRunning() const { return m_running; } @@ -78,7 +80,7 @@ private: void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) Q_DECL_FINAL; Qt3DCore::QNodeId m_clipId; - + Qt3DCore::QNodeId m_mapperId; bool m_running; }; diff --git a/src/animation/frontend/qanimationaspect.cpp b/src/animation/frontend/qanimationaspect.cpp index 82c633220..64e3f6449 100644 --- a/src/animation/frontend/qanimationaspect.cpp +++ b/src/animation/frontend/qanimationaspect.cpp @@ -86,6 +86,7 @@ QAnimationAspect::QAnimationAspect(QAnimationAspectPrivate &dd, QObject *parent) setObjectName(QStringLiteral("Animation Aspect")); Q_D(QAnimationAspect); qRegisterMetaType<Qt3DAnimation::QAnimationClip*>(); + qRegisterMetaType<Qt3DAnimation::QChannelMapper*>(); registerBackendType<QAnimationClip>( QSharedPointer<Animation::NodeFunctor<Animation::AnimationClip, Animation::AnimationClipManager>>::create(d->m_handler.data(), diff --git a/src/animation/frontend/qclipanimator.cpp b/src/animation/frontend/qclipanimator.cpp index a4861422f..485f13091 100644 --- a/src/animation/frontend/qclipanimator.cpp +++ b/src/animation/frontend/qclipanimator.cpp @@ -40,6 +40,7 @@ #include "qclipanimator.h" #include "qclipanimator_p.h" #include <Qt3DAnimation/qanimationclip.h> +#include <Qt3DAnimation/qchannelmapper.h> QT_BEGIN_NAMESPACE @@ -48,6 +49,7 @@ namespace Qt3DAnimation { QClipAnimatorPrivate::QClipAnimatorPrivate() : Qt3DCore::QComponentPrivate() , m_clip(nullptr) + , m_mapper(nullptr) , m_running(false) { } @@ -78,6 +80,12 @@ bool QClipAnimator::isRunning() const return d->m_running; } +QChannelMapper *QClipAnimator::channelMapper() const +{ + Q_D(const QClipAnimator); + return d->m_mapper; +} + void QClipAnimator::setClip(QAnimationClip *clip) { Q_D(QClipAnimator); @@ -107,12 +115,32 @@ void QClipAnimator::setRunning(bool running) emit runningChanged(running); } +void QClipAnimator::setChannelMapper(QChannelMapper *mapping) +{ + Q_D(QClipAnimator); + if (d->m_mapper == mapping) + return; + + if (d->m_mapper) + d->unregisterDestructionHelper(d->m_mapper); + + if (mapping && !mapping->parent()) + mapping->setParent(this); + d->m_mapper = mapping; + + // Ensures proper bookkeeping + if (d->m_mapper) + d->registerDestructionHelper(d->m_mapper, &QClipAnimator::setChannelMapper, d->m_mapper); + emit channelMapperChanged(mapping); +} + 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.mapperId = Qt3DCore::qIdForNode(d->m_mapper); data.running = d->m_running; return creationChange; } diff --git a/src/animation/frontend/qclipanimator.h b/src/animation/frontend/qclipanimator.h index 3e8426249..ab5d5e541 100644 --- a/src/animation/frontend/qclipanimator.h +++ b/src/animation/frontend/qclipanimator.h @@ -48,6 +48,7 @@ QT_BEGIN_NAMESPACE namespace Qt3DAnimation { class QAnimationClip; +class QChannelMapper; class QClipAnimatorPrivate; class QT3DANIMATIONSHARED_EXPORT QClipAnimator : public Qt3DCore::QComponent @@ -55,6 +56,7 @@ 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) + Q_PROPERTY(Qt3DAnimation::QChannelMapper *channelMapper READ channelMapper WRITE setChannelMapper NOTIFY channelMapperChanged) public: explicit QClipAnimator(Qt3DCore::QNode *parent = nullptr); @@ -62,14 +64,17 @@ public: Qt3DAnimation::QAnimationClip *clip() const; bool isRunning() const; + Qt3DAnimation::QChannelMapper *channelMapper() const; public Q_SLOTS: void setClip(Qt3DAnimation::QAnimationClip *clip); void setRunning(bool running); + void setChannelMapper(Qt3DAnimation::QChannelMapper *channelMapper); Q_SIGNALS: void clipChanged(Qt3DAnimation::QAnimationClip *clip); void runningChanged(bool running); + void channelMapperChanged(Qt3DAnimation::QChannelMapper *channelMapper); 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 fa4935ea3..c158c12d8 100644 --- a/src/animation/frontend/qclipanimator_p.h +++ b/src/animation/frontend/qclipanimator_p.h @@ -58,6 +58,8 @@ QT_BEGIN_NAMESPACE namespace Qt3DAnimation { +class QChannelMapper; + class QClipAnimatorPrivate : public Qt3DCore::QComponentPrivate { public: @@ -66,12 +68,14 @@ public: Q_DECLARE_PUBLIC(QClipAnimator) QAnimationClip *m_clip; + Qt3DAnimation::QChannelMapper *m_mapper; bool m_running; }; struct QClipAnimatorData { Qt3DCore::QNodeId clipId; + Qt3DCore::QNodeId mapperId; bool running; }; diff --git a/tests/auto/animation/qclipanimator/tst_qclipanimator.cpp b/tests/auto/animation/qclipanimator/tst_qclipanimator.cpp index 1ecadd0a3..59195606d 100644 --- a/tests/auto/animation/qclipanimator/tst_qclipanimator.cpp +++ b/tests/auto/animation/qclipanimator/tst_qclipanimator.cpp @@ -29,6 +29,7 @@ #include <QtTest/QTest> #include <Qt3DAnimation/qanimationclip.h> +#include <Qt3DAnimation/qchannelmapper.h> #include <Qt3DAnimation/qclipanimator.h> #include <Qt3DAnimation/private/qanimationclip_p.h> #include <Qt3DAnimation/private/qclipanimator_p.h> @@ -47,6 +48,7 @@ private Q_SLOTS: void initTestCase() { qRegisterMetaType<Qt3DAnimation::QAnimationClip*>(); + qRegisterMetaType<Qt3DAnimation::QChannelMapper*>(); } void checkDefaultConstruction() @@ -56,6 +58,7 @@ private Q_SLOTS: // THEN QCOMPARE(animator.clip(), static_cast<Qt3DAnimation::QAnimationClip *>(nullptr)); + QCOMPARE(animator.channelMapper(), static_cast<Qt3DAnimation::QChannelMapper *>(nullptr)); } void checkPropertyChanges() @@ -83,6 +86,27 @@ private Q_SLOTS: QCOMPARE(animator.clip(), newValue); QCOMPARE(spy.count(), 0); } + + { + // WHEN + QSignalSpy spy(&animator, SIGNAL(channelMapperChanged(Qt3DAnimation::QChannelMapper *))); + auto newValue = new Qt3DAnimation::QChannelMapper(); + animator.setChannelMapper(newValue); + + // THEN + QVERIFY(spy.isValid()); + QCOMPARE(animator.channelMapper(), newValue); + QCOMPARE(newValue->parent(), &animator); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + animator.setChannelMapper(newValue); + + // THEN + QCOMPARE(animator.channelMapper(), newValue); + QCOMPARE(spy.count(), 0); + } } void checkCreationData() @@ -91,6 +115,8 @@ private Q_SLOTS: Qt3DAnimation::QClipAnimator animator; auto clip = new Qt3DAnimation::QAnimationClip(); animator.setClip(clip); + auto mapper = new Qt3DAnimation::QChannelMapper(); + animator.setChannelMapper(mapper); // WHEN QVector<Qt3DCore::QNodeCreatedChangeBasePtr> creationChanges; @@ -101,7 +127,7 @@ private Q_SLOTS: // THEN { - QCOMPARE(creationChanges.size(), 2); + QCOMPARE(creationChanges.size(), 3); const auto creationChangeData = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<Qt3DAnimation::QClipAnimatorData>>(creationChanges.first()); const Qt3DAnimation::QClipAnimatorData data = creationChangeData->data; @@ -111,6 +137,7 @@ private Q_SLOTS: QCOMPARE(animator.isEnabled(), creationChangeData->isNodeEnabled()); QCOMPARE(animator.metaObject(), creationChangeData->metaObject()); QCOMPARE(animator.clip()->id(), data.clipId); + QCOMPARE(animator.channelMapper()->id(), data.mapperId); } // WHEN @@ -122,7 +149,7 @@ private Q_SLOTS: // THEN { - QCOMPARE(creationChanges.size(), 2); + QCOMPARE(creationChanges.size(), 3); const auto creationChangeData = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<Qt3DAnimation::QClipAnimatorData>>(creationChanges.first()); @@ -133,7 +160,7 @@ private Q_SLOTS: } } - void checkClipUpdate() + void checkPropertyUpdate() { // GIVEN TestArbiter arbiter; @@ -165,6 +192,32 @@ private Q_SLOTS: QCOMPARE(arbiter.events.size(), 0); } + // GIVEN + auto mapper = new Qt3DAnimation::QChannelMapper; + { + // WHEN + animator.setChannelMapper(mapper); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + auto change = arbiter.events.first().staticCast<Qt3DCore::QPropertyUpdatedChange>(); + QCOMPARE(change->propertyName(), "channelMapper"); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + QCOMPARE(change->value().value<Qt3DCore::QNodeId>(), mapper->id()); + + arbiter.events.clear(); + } + + { + // WHEN + animator.setChannelMapper(mapper); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 0); + } + } }; diff --git a/tests/manual/animation-keyframe-simple/main.qml b/tests/manual/animation-keyframe-simple/main.qml index 48a2a657f..587f851c5 100644 --- a/tests/manual/animation-keyframe-simple/main.qml +++ b/tests/manual/animation-keyframe-simple/main.qml @@ -42,7 +42,7 @@ DefaultSceneEntity { // mapping: AutomaticAnimationMapping {} // To do more, we can be explicit - mapping: ChannelMapper { + channelMapper: ChannelMapper { mappings: [ ChannelMapping { channelName: "Location"; target: cubeTransform; property: "translation" }, ChannelMapping { channelName: "Rotation"; target: cubeTransform; property: "rotation" }, |