summaryrefslogtreecommitdiffstats
path: root/src/animation
diff options
context:
space:
mode:
authorMike Krus <mike.krus@kdab.com>2019-09-19 21:45:25 +0100
committerMike Krus <mike.krus@kdab.com>2019-09-23 06:27:37 +0100
commitc7f10617a0be44cf2b61fdc0809fafe7a0aef49a (patch)
tree26d1a362e9966e77eafe4d4d766f4312557de864 /src/animation
parent42e11789e4a2de7729ccba30dc465ca48e09e5e7 (diff)
Update mapping classes to use direct sync
QChannelMapping, QSkeletonMapping and QCallbackMapping updated. Change-Id: I10b78d86856f6ad01fbb313fdcbe9f87f6d926ac Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src/animation')
-rw-r--r--src/animation/backend/channelmapping.cpp96
-rw-r--r--src/animation/backend/channelmapping_p.h4
-rw-r--r--src/animation/frontend/qanimationaspect.cpp2
-rw-r--r--src/animation/frontend/qcallbackmapping.cpp15
-rw-r--r--src/animation/frontend/qchannelmapping.cpp25
5 files changed, 43 insertions, 99 deletions
diff --git a/src/animation/backend/channelmapping.cpp b/src/animation/backend/channelmapping.cpp
index 2323182c6..83e7322da 100644
--- a/src/animation/backend/channelmapping.cpp
+++ b/src/animation/backend/channelmapping.cpp
@@ -36,13 +36,15 @@
#include "channelmapping_p.h"
#include <Qt3DAnimation/qchannelmapping.h>
+#include <Qt3DAnimation/qskeletonmapping.h>
+#include <Qt3DAnimation/qcallbackmapping.h>
#include <Qt3DAnimation/private/qcallbackmapping_p.h>
#include <Qt3DAnimation/private/qchannelmapping_p.h>
#include <Qt3DAnimation/private/qskeletonmapping_p.h>
#include <Qt3DAnimation/private/animationlogging_p.h>
#include <Qt3DAnimation/private/qchannelmappingcreatedchange_p.h>
#include <Qt3DAnimation/private/managers_p.h>
-#include <Qt3DCore/qpropertyupdatedchange.h>
+#include <Qt3DCore/qabstractskeleton.h>
QT_BEGIN_NAMESPACE
@@ -63,43 +65,6 @@ ChannelMapping::ChannelMapping()
{
}
-void ChannelMapping::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change)
-{
- const auto createdChange = qSharedPointerCast<QChannelMappingCreatedChangeBase>(change);
- switch (createdChange->type()) {
- case QChannelMappingCreatedChangeBase::ChannelMapping: {
- const auto typedChange = qSharedPointerCast<QChannelMappingCreatedChange<QChannelMappingData>>(change);
- const auto &data = typedChange->data;
- m_channelName = data.channelName;
- m_targetId = data.targetId;
- m_type = data.type;
- m_componentCount = data.componentCount;
- m_propertyName = data.propertyName;
- m_mappingType = ChannelMappingType;
- break;
- }
-
- case QChannelMappingCreatedChangeBase::SkeletonMapping: {
- const auto typedChange = qSharedPointerCast<QChannelMappingCreatedChange<QSkeletonMappingData>>(change);
- const auto &data = typedChange->data;
- m_skeletonId = data.skeletonId;
- m_mappingType = SkeletonMappingType;
- break;
- }
-
- case QChannelMappingCreatedChangeBase::CallbackMapping: {
- const auto typedChange = qSharedPointerCast<QChannelMappingCreatedChange<QCallbackMappingData>>(change);
- const auto &data = typedChange->data;
- m_channelName = data.channelName;
- m_type = data.type;
- m_callback = data.callback;
- m_callbackFlags = data.callbackFlags;
- m_mappingType = ChannelMappingType;
- break;
- }
- }
-}
-
void ChannelMapping::cleanup()
{
setEnabled(false);
@@ -113,34 +78,41 @@ void ChannelMapping::cleanup()
m_skeletonId = Qt3DCore::QNodeId();
}
-void ChannelMapping::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e)
+void ChannelMapping::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime)
{
- switch (e->type()) {
- case Qt3DCore::PropertyUpdated: {
- const auto change = qSharedPointerCast<Qt3DCore::QPropertyUpdatedChange>(e);
- if (change->propertyName() == QByteArrayLiteral("channelName"))
- m_channelName = change->value().toString();
- else if (change->propertyName() == QByteArrayLiteral("target"))
- m_targetId = change->value().value<Qt3DCore::QNodeId>();
- else if (change->propertyName() == QByteArrayLiteral("type"))
- m_type = change->value().toInt();
- else if (change->propertyName() == QByteArrayLiteral("propertyName"))
- m_propertyName = static_cast<const char *>(const_cast<const void *>(change->value().value<void *>()));
- else if (change->propertyName() == QByteArrayLiteral("componentCount"))
- m_componentCount = change->value().toInt();
- else if (change->propertyName() == QByteArrayLiteral("callback"))
- m_callback = static_cast<QAnimationCallback *>(change->value().value<void *>());
- else if (change->propertyName() == QByteArrayLiteral("callbackFlags"))
- m_callbackFlags = QAnimationCallback::Flags(change->value().toInt());
- else if (change->propertyName() == QByteArrayLiteral("skeleton"))
- m_skeletonId = change->value().value<Qt3DCore::QNodeId>();
- break;
+ BackendNode::syncFromFrontEnd(frontEnd, firstTime);
+ const QAbstractChannelMapping *node = qobject_cast<const QAbstractChannelMapping *>(frontEnd);
+ if (!node)
+ return;
+
+ const QChannelMapping *channelMapping = qobject_cast<const QChannelMapping *>(frontEnd);
+ if (channelMapping) {
+ m_mappingType = ChannelMappingType;
+ m_channelName = channelMapping->channelName();
+ m_targetId = Qt3DCore::qIdForNode(channelMapping->target());
+
+ QChannelMappingPrivate *d = static_cast<QChannelMappingPrivate *>(Qt3DCore::QNodePrivate::get(const_cast<QChannelMapping *>(channelMapping)));
+ m_type = d->m_type;
+ m_propertyName = d->m_propertyName;
+ m_componentCount = d->m_componentCount;
}
- default:
- break;
+ const QSkeletonMapping *skeletonMapping = qobject_cast<const QSkeletonMapping *>(frontEnd);
+ if (skeletonMapping) {
+ m_mappingType = SkeletonMappingType;
+ m_skeletonId = Qt3DCore::qIdForNode(skeletonMapping->skeleton());
+ }
+
+ const QCallbackMapping *callbackMapping = qobject_cast<const QCallbackMapping *>(frontEnd);
+ if (callbackMapping) {
+ m_mappingType = ChannelMappingType;
+ m_channelName = channelMapping->channelName();
+
+ const QCallbackMappingPrivate *d = static_cast<const QCallbackMappingPrivate *>(Qt3DCore::QNodePrivate::get(channelMapping));
+ m_type = d->m_type;
+ m_callback = d->m_callback;
+ m_callbackFlags = d->m_callbackFlags;
}
- QBackendNode::sceneChangeEvent(e);
}
Skeleton *ChannelMapping::skeleton() const
diff --git a/src/animation/backend/channelmapping_p.h b/src/animation/backend/channelmapping_p.h
index aa30e84ee..a0ff5f1ca 100644
--- a/src/animation/backend/channelmapping_p.h
+++ b/src/animation/backend/channelmapping_p.h
@@ -76,7 +76,7 @@ public:
void cleanup();
- void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) override;
+ void syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) override;
void setChannelName(const QString &channelName) { m_channelName = channelName; }
QString channelName() const { return m_channelName; }
@@ -107,8 +107,6 @@ public:
MappingType mappingType() const { return m_mappingType; }
private:
- void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) final;
-
// Properties from QChannelMapping
QString m_channelName;
Qt3DCore::QNodeId m_targetId;
diff --git a/src/animation/frontend/qanimationaspect.cpp b/src/animation/frontend/qanimationaspect.cpp
index 986ab3d22..c0659a809 100644
--- a/src/animation/frontend/qanimationaspect.cpp
+++ b/src/animation/frontend/qanimationaspect.cpp
@@ -116,7 +116,7 @@ QAnimationAspect::QAnimationAspect(QAnimationAspectPrivate &dd, QObject *parent)
registerBackendType<QBlendedClipAnimator, true>(
QSharedPointer<Animation::NodeFunctor<Animation::BlendedClipAnimator, Animation::BlendedClipAnimatorManager>>::create(d->m_handler.data(),
d->m_handler->blendedClipAnimatorManager()));
- registerBackendType<QAbstractChannelMapping>(
+ registerBackendType<QAbstractChannelMapping, true>(
QSharedPointer<Animation::NodeFunctor<Animation::ChannelMapping, Animation::ChannelMappingManager>>::create(d->m_handler.data(),
d->m_handler->channelMappingManager()));
registerBackendType<QChannelMapper>(
diff --git a/src/animation/frontend/qcallbackmapping.cpp b/src/animation/frontend/qcallbackmapping.cpp
index c0163da80..f312ddaa5 100644
--- a/src/animation/frontend/qcallbackmapping.cpp
+++ b/src/animation/frontend/qcallbackmapping.cpp
@@ -130,24 +130,15 @@ void QCallbackMapping::setCallback(int type, QAnimationCallback *callback, QAnim
Q_D(QCallbackMapping);
if (d->m_type != type) {
d->m_type = type;
- auto e = Qt3DCore::QPropertyUpdatedChangePtr::create(id());
- e->setPropertyName("type");
- e->setValue(QVariant(d->m_type));
- notifyObservers(e);
+ d->update();
}
if (d->m_callback != callback) {
d->m_callback = callback;
- auto e = Qt3DCore::QPropertyUpdatedChangePtr::create(id());
- e->setPropertyName("callback");
- e->setValue(QVariant::fromValue(static_cast<void *>(d->m_callback)));
- notifyObservers(e);
+ d->update();
}
if (d->m_callbackFlags != flags) {
d->m_callbackFlags = flags;
- auto e = Qt3DCore::QPropertyUpdatedChangePtr::create(id());
- e->setPropertyName("callbackFlags");
- e->setValue(QVariant::fromValue(int(d->m_callbackFlags)));
- notifyObservers(e);
+ d->update();
}
}
diff --git a/src/animation/frontend/qchannelmapping.cpp b/src/animation/frontend/qchannelmapping.cpp
index 8f6ebe9ab..fa89d5042 100644
--- a/src/animation/frontend/qchannelmapping.cpp
+++ b/src/animation/frontend/qchannelmapping.cpp
@@ -147,37 +147,20 @@ void QChannelMappingPrivate::updatePropertyNameTypeAndComponentCount()
if (m_type != type) {
m_type = type;
-
- // Send update to the backend
- Q_Q(QChannelMapping);
- auto e = Qt3DCore::QPropertyUpdatedChangePtr::create(q->id());
- e->setPropertyName("type");
- e->setValue(QVariant(m_type));
- notifyObservers(e);
+ update();
}
if (m_componentCount != componentCount) {
m_componentCount = componentCount;
-
- // Send update to the backend
- Q_Q(QChannelMapping);
- auto e = Qt3DCore::QPropertyUpdatedChangePtr::create(q->id());
- e->setPropertyName("componentCount");
- e->setValue(QVariant(m_componentCount));
- notifyObservers(e);
+ update();
}
if (qstrcmp(m_propertyName, propertyName) != 0) {
m_propertyName = propertyName;
-
- // Send update to the backend
- Q_Q(QChannelMapping);
- auto e = Qt3DCore::QPropertyUpdatedChangePtr::create(q->id());
- e->setPropertyName("propertyName");
- e->setValue(QVariant::fromValue(const_cast<void *>(static_cast<const void *>(m_propertyName))));
- notifyObservers(e);
+ update();
}
}
+
/*!
\class QChannelMapping
\inherits Qt3DCore::QNode