diff options
author | Mike Krus <mike.krus@kdab.com> | 2019-09-20 07:09:45 +0100 |
---|---|---|
committer | Mike Krus <mike.krus@kdab.com> | 2019-09-23 06:27:45 +0100 |
commit | 5815bb74788f9c0f355754d6a56cfa527684ea98 (patch) | |
tree | 692cfd678d5fe4dc2d727bfb3dba352884400347 /src/animation | |
parent | c7f10617a0be44cf2b61fdc0809fafe7a0aef49a (diff) |
Update QChannelMapper to use direct sync
Change-Id: I066b6742cc272155f55322e3aaf73e28980341d0
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src/animation')
-rw-r--r-- | src/animation/backend/channelmapper.cpp | 47 | ||||
-rw-r--r-- | src/animation/backend/channelmapper_p.h | 3 | ||||
-rw-r--r-- | src/animation/frontend/qanimationaspect.cpp | 2 | ||||
-rw-r--r-- | src/animation/frontend/qchannelmapper.cpp | 12 |
4 files changed, 19 insertions, 45 deletions
diff --git a/src/animation/backend/channelmapper.cpp b/src/animation/backend/channelmapper.cpp index 48a1335fa..7ea07557b 100644 --- a/src/animation/backend/channelmapper.cpp +++ b/src/animation/backend/channelmapper.cpp @@ -36,6 +36,7 @@ #include "channelmapper_p.h" #include <Qt3DAnimation/qchannelmapper.h> +#include <Qt3DAnimation/qchannelmapping.h> #include <Qt3DAnimation/private/qchannelmapper_p.h> #include <Qt3DAnimation/private/animationlogging_p.h> #include <Qt3DAnimation/private/managers_p.h> @@ -43,6 +44,8 @@ #include <Qt3DCore/qpropertynodeaddedchange.h> #include <Qt3DCore/qpropertynoderemovedchange.h> +#include <algorithm> + QT_BEGIN_NAMESPACE namespace Qt3DAnimation { @@ -55,14 +58,6 @@ ChannelMapper::ChannelMapper() { } -void ChannelMapper::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) -{ - const auto typedChange = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<QChannelMapperData>>(change); - const auto &data = typedChange->data; - m_mappingIds = data.mappingIds; - m_isDirty = true; -} - void ChannelMapper::cleanup() { setEnabled(false); @@ -71,33 +66,21 @@ void ChannelMapper::cleanup() m_isDirty = true; } -void ChannelMapper::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) +void ChannelMapper::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) { - switch (e->type()) { - case Qt3DCore::PropertyValueAdded: { - const auto change = qSharedPointerCast<Qt3DCore::QPropertyNodeAddedChange>(e); - if (change->propertyName() == QByteArrayLiteral("mappings")) { - m_mappingIds.push_back(change->addedNodeId()); - setDirty(Handler::ChannelMappingsDirty); - m_isDirty = true; - } - break; - } - - case Qt3DCore::PropertyValueRemoved: { - const auto change = qSharedPointerCast<Qt3DCore::QPropertyNodeRemovedChange>(e); - if (change->propertyName() == QByteArrayLiteral("mappings")) { - m_mappingIds.removeOne(change->removedNodeId()); - setDirty(Handler::ChannelMappingsDirty); - m_isDirty = true; - } - break; - } + BackendNode::syncFromFrontEnd(frontEnd, firstTime); + const QChannelMapper *node = qobject_cast<const QChannelMapper *>(frontEnd); + if (!node) + return; - default: - break; + auto ids = Qt3DCore::qIdsForNodes(node->mappings()); + std::sort(std::begin(ids), std::end(ids)); + m_isDirty = firstTime; + if (m_mappingIds != ids) { + m_mappingIds = ids; + setDirty(Handler::ChannelMappingsDirty); + m_isDirty = true; } - QBackendNode::sceneChangeEvent(e); } void ChannelMapper::updateMappings() const diff --git a/src/animation/backend/channelmapper_p.h b/src/animation/backend/channelmapper_p.h index fd99c8dbd..45a3e789e 100644 --- a/src/animation/backend/channelmapper_p.h +++ b/src/animation/backend/channelmapper_p.h @@ -69,7 +69,7 @@ public: void cleanup(); - void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) override; + void syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) override; void setMappingIds(const QVector<Qt3DCore::QNodeId> &mappingIds) { m_mappingIds = mappingIds; } QVector<Qt3DCore::QNodeId> mappingIds() const { return m_mappingIds; } @@ -82,7 +82,6 @@ public: } private: - void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) final; void updateMappings() const; QVector<Qt3DCore::QNodeId> m_mappingIds; diff --git a/src/animation/frontend/qanimationaspect.cpp b/src/animation/frontend/qanimationaspect.cpp index c0659a809..744346e1f 100644 --- a/src/animation/frontend/qanimationaspect.cpp +++ b/src/animation/frontend/qanimationaspect.cpp @@ -119,7 +119,7 @@ QAnimationAspect::QAnimationAspect(QAnimationAspectPrivate &dd, QObject *parent) registerBackendType<QAbstractChannelMapping, true>( QSharedPointer<Animation::NodeFunctor<Animation::ChannelMapping, Animation::ChannelMappingManager>>::create(d->m_handler.data(), d->m_handler->channelMappingManager())); - registerBackendType<QChannelMapper>( + registerBackendType<QChannelMapper, true>( QSharedPointer<Animation::NodeFunctor<Animation::ChannelMapper, Animation::ChannelMapperManager>>::create(d->m_handler.data(), d->m_handler->channelMapperManager())); registerBackendType<QLerpClipBlend, true>( diff --git a/src/animation/frontend/qchannelmapper.cpp b/src/animation/frontend/qchannelmapper.cpp index 82ce5ebbe..34b5ffbe6 100644 --- a/src/animation/frontend/qchannelmapper.cpp +++ b/src/animation/frontend/qchannelmapper.cpp @@ -87,11 +87,7 @@ void QChannelMapper::addMapping(QAbstractChannelMapping *mapping) if (!mapping->parent()) mapping->setParent(this); - if (d->m_changeArbiter != nullptr) { - const auto change = Qt3DCore::QPropertyNodeAddedChangePtr::create(id(), mapping); - change->setPropertyName("mappings"); - d->notifyObservers(change); - } + d->update(); } } @@ -99,12 +95,8 @@ void QChannelMapper::removeMapping(QAbstractChannelMapping *mapping) { Q_ASSERT(mapping); Q_D(QChannelMapper); - if (d->m_changeArbiter != nullptr) { - const auto change = Qt3DCore::QPropertyNodeRemovedChangePtr::create(id(), mapping); - change->setPropertyName("mappings"); - d->notifyObservers(change); - } d->m_mappings.removeOne(mapping); + d->update(); // Remove bookkeeping connection d->unregisterDestructionHelper(mapping); } |