1/****************************************************************************
2**
3** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB).
4** Contact: http://www.qt-project.org/legal
5**
6** This file is part of the Qt3D module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL3$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see http://www.qt.io/terms-conditions. For further
15** information use the contact form at http://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPLv3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or later as published by the Free
28** Software Foundation and appearing in the file LICENSE.GPL included in
29** the packaging of this file. Please review the following information to
30** ensure the GNU General Public License version 2.0 requirements will be
31** met: http://www.gnu.org/licenses/gpl-2.0.html.
32**
33** $QT_END_LICENSE$
34**
35****************************************************************************/
36
37#include "channelmapping_p.h"
38#include <Qt3DAnimation/qchannelmapping.h>
39#include <Qt3DAnimation/qskeletonmapping.h>
40#include <Qt3DAnimation/qcallbackmapping.h>
41#include <Qt3DAnimation/private/qcallbackmapping_p.h>
42#include <Qt3DAnimation/private/qchannelmapping_p.h>
43#include <Qt3DAnimation/private/qskeletonmapping_p.h>
44#include <Qt3DAnimation/private/animationlogging_p.h>
45#include <Qt3DAnimation/private/qchannelmappingcreatedchange_p.h>
46#include <Qt3DAnimation/private/managers_p.h>
47#include <Qt3DCore/qabstractskeleton.h>
48
49QT_BEGIN_NAMESPACE
50
51namespace Qt3DAnimation {
52namespace Animation {
53
54ChannelMapping::ChannelMapping()
55 : BackendNode(ReadOnly)
56 , m_channelName()
57 , m_targetId()
58 , m_type(static_cast<int>(QVariant::Invalid))
59 , m_componentCount(0)
60 , m_propertyName(nullptr)
61 , m_callback(nullptr)
62 , m_skeletonId()
63 , m_mappingType(MappingType::ChannelMappingType)
64{
65}
66
67void ChannelMapping::cleanup()
68{
69 setEnabled(false);
70 m_channelName.clear();
71 m_targetId = Qt3DCore::QNodeId();
72 m_type = static_cast<int>(QVariant::Invalid);
73 m_propertyName = nullptr;
74 m_componentCount = 0;
75 m_callback = nullptr;
76 m_callbackFlags = {};
77 m_skeletonId = Qt3DCore::QNodeId();
78}
79
80void ChannelMapping::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime)
81{
82 BackendNode::syncFromFrontEnd(frontEnd, firstTime);
83 const QAbstractChannelMapping *node = qobject_cast<const QAbstractChannelMapping *>(object: frontEnd);
84 if (!node)
85 return;
86
87 const QChannelMapping *channelMapping = qobject_cast<const QChannelMapping *>(object: frontEnd);
88 if (channelMapping) {
89 m_mappingType = ChannelMappingType;
90 m_channelName = channelMapping->channelName();
91 m_targetId = Qt3DCore::qIdForNode(node: channelMapping->target());
92
93 QChannelMappingPrivate *d = static_cast<QChannelMappingPrivate *>(Qt3DCore::QNodePrivate::get(q: const_cast<QChannelMapping *>(channelMapping)));
94 m_type = d->m_type;
95 m_propertyName = d->m_propertyName;
96 m_componentCount = d->m_componentCount;
97 }
98
99 const QSkeletonMapping *skeletonMapping = qobject_cast<const QSkeletonMapping *>(object: frontEnd);
100 if (skeletonMapping) {
101 m_mappingType = SkeletonMappingType;
102 m_skeletonId = Qt3DCore::qIdForNode(node: skeletonMapping->skeleton());
103 }
104
105 const QCallbackMapping *callbackMapping = qobject_cast<const QCallbackMapping *>(object: frontEnd);
106 if (callbackMapping) {
107 m_mappingType = ChannelMappingType;
108 m_channelName = callbackMapping->channelName();
109
110 const QCallbackMappingPrivate *d = static_cast<const QCallbackMappingPrivate *>(Qt3DCore::QNodePrivate::get(q: callbackMapping));
111 m_type = d->m_type;
112 m_callback = d->m_callback;
113 m_callbackFlags = d->m_callbackFlags;
114 }
115}
116
117Skeleton *ChannelMapping::skeleton() const
118{
119 return m_handler->skeletonManager()->lookupResource(id: m_skeletonId);
120}
121
122} // namespace Animation
123} // namespace Qt3DAnimation
124
125QT_END_NAMESPACE
126

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