From 78175fa89bc95b88466ecf1ac8b42244762e62e2 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Tue, 26 Sep 2017 15:21:50 +0100 Subject: Add convenience function to ChannelMapper to return list of Mappings Caches the resolution of node ids to ChannelMappings. Updated test to check this new feature. Change-Id: I0c2f539c2bd91e7918b98c5b60c9ca486b63ec08 Reviewed-by: Kevin Ottens --- src/animation/backend/channelmapper.cpp | 20 ++++++++++++++++++++ src/animation/backend/channelmapper_p.h | 12 ++++++++++++ 2 files changed, 32 insertions(+) (limited to 'src') diff --git a/src/animation/backend/channelmapper.cpp b/src/animation/backend/channelmapper.cpp index 0e5555096..48a1335fa 100644 --- a/src/animation/backend/channelmapper.cpp +++ b/src/animation/backend/channelmapper.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -50,6 +51,7 @@ namespace Animation { ChannelMapper::ChannelMapper() : BackendNode(ReadOnly) , m_mappingIds() + , m_isDirty(true) { } @@ -58,12 +60,15 @@ void ChannelMapper::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr const auto typedChange = qSharedPointerCast>(change); const auto &data = typedChange->data; m_mappingIds = data.mappingIds; + m_isDirty = true; } void ChannelMapper::cleanup() { setEnabled(false); m_mappingIds.clear(); + m_mappings.clear(); + m_isDirty = true; } void ChannelMapper::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) @@ -74,6 +79,7 @@ void ChannelMapper::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) if (change->propertyName() == QByteArrayLiteral("mappings")) { m_mappingIds.push_back(change->addedNodeId()); setDirty(Handler::ChannelMappingsDirty); + m_isDirty = true; } break; } @@ -83,6 +89,7 @@ void ChannelMapper::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) if (change->propertyName() == QByteArrayLiteral("mappings")) { m_mappingIds.removeOne(change->removedNodeId()); setDirty(Handler::ChannelMappingsDirty); + m_isDirty = true; } break; } @@ -93,6 +100,19 @@ void ChannelMapper::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) QBackendNode::sceneChangeEvent(e); } +void ChannelMapper::updateMappings() const +{ + m_mappings.clear(); + m_mappings.reserve(m_mappingIds.size()); + const auto mappingManager = m_handler->channelMappingManager(); + for (const auto &mappingId : m_mappingIds) { + const auto mapping = mappingManager->lookupResource(mappingId); + Q_ASSERT(mapping); + m_mappings.push_back(mapping); + } + m_isDirty = false; +} + } // namespace Animation } // namespace Qt3DAnimation diff --git a/src/animation/backend/channelmapper_p.h b/src/animation/backend/channelmapper_p.h index 710de01ab..8d8f03511 100644 --- a/src/animation/backend/channelmapper_p.h +++ b/src/animation/backend/channelmapper_p.h @@ -74,10 +74,22 @@ public: void setMappingIds(const QVector &mappingIds) { m_mappingIds = mappingIds; } QVector mappingIds() const { return m_mappingIds; } + QVector mappings() const + { + if (m_isDirty) + updateMappings(); + return m_mappings; + } + private: void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) Q_DECL_FINAL; + void updateMappings() const; QVector m_mappingIds; + + // Cached data + mutable QVector m_mappings; + mutable bool m_isDirty; }; } // namespace Animation -- cgit v1.2.3