1// Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB).
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "channelmapper_p.h"
5#include <Qt3DAnimation/qchannelmapper.h>
6#include <Qt3DAnimation/qchannelmapping.h>
7#include <Qt3DAnimation/private/qchannelmapper_p.h>
8#include <Qt3DAnimation/private/animationlogging_p.h>
9#include <Qt3DAnimation/private/managers_p.h>
10
11#include <algorithm>
12
13QT_BEGIN_NAMESPACE
14
15namespace Qt3DAnimation {
16namespace Animation {
17
18ChannelMapper::ChannelMapper()
19 : BackendNode(ReadOnly)
20 , m_mappingIds()
21 , m_isDirty(true)
22{
23}
24
25void ChannelMapper::cleanup()
26{
27 setEnabled(false);
28 m_mappingIds.clear();
29 m_mappings.clear();
30 m_isDirty = true;
31}
32
33void ChannelMapper::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime)
34{
35 BackendNode::syncFromFrontEnd(frontEnd, firstTime);
36 const QChannelMapper *node = qobject_cast<const QChannelMapper *>(object: frontEnd);
37 if (!node)
38 return;
39
40 auto ids = Qt3DCore::qIdsForNodes(nodes: node->mappings());
41 std::sort(first: std::begin(cont&: ids), last: std::end(cont&: ids));
42 m_isDirty = firstTime;
43 if (m_mappingIds != ids) {
44 m_mappingIds = ids;
45 setDirty(Handler::ChannelMappingsDirty);
46 m_isDirty = true;
47 }
48}
49
50void ChannelMapper::updateMappings() const
51{
52 m_mappings.clear();
53 m_mappings.reserve(asize: m_mappingIds.size());
54 const auto mappingManager = m_handler->channelMappingManager();
55 for (const auto &mappingId : m_mappingIds) {
56 const auto mapping = mappingManager->lookupResource(id: mappingId);
57 Q_ASSERT(mapping);
58 m_mappings.push_back(t: mapping);
59 }
60 m_isDirty = false;
61}
62
63} // namespace Animation
64} // namespace Qt3DAnimation
65
66QT_END_NAMESPACE
67

source code of qt3d/src/animation/backend/channelmapper.cpp