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 "qchannelmapper.h"
5#include "qchannelmapper_p.h"
6#include <Qt3DAnimation/qchannelmapping.h>
7
8QT_BEGIN_NAMESPACE
9
10namespace Qt3DAnimation {
11
12QChannelMapperPrivate::QChannelMapperPrivate()
13 : Qt3DCore::QNodePrivate()
14{
15}
16
17/*!
18 \class Qt3DAnimation::QChannelMapper
19 \inmodule Qt3DAnimation
20 \brief Allows to map the channels within the clip onto properties of
21 objects in the application.
22
23*/
24QChannelMapper::QChannelMapper(Qt3DCore::QNode *parent)
25 : Qt3DCore::QNode(*new QChannelMapperPrivate, parent)
26{
27}
28
29QChannelMapper::QChannelMapper(QChannelMapperPrivate &dd, Qt3DCore::QNode *parent)
30 : Qt3DCore::QNode(dd, parent)
31{
32}
33
34QChannelMapper::~QChannelMapper()
35{
36}
37
38void QChannelMapper::addMapping(QAbstractChannelMapping *mapping)
39{
40 Q_ASSERT(mapping);
41 Q_D(QChannelMapper);
42 if (!d->m_mappings.contains(t: mapping)) {
43 d->m_mappings.append(t: mapping);
44
45 // Ensures proper bookkeeping
46 d->registerDestructionHelper(node: mapping, func: &QChannelMapper::removeMapping, d->m_mappings);
47
48 // We need to add it as a child of the current node if it has been declared inline
49 // Or not previously added as a child of the current node so that
50 // 1) The backend gets notified about it's creation
51 // 2) When the current node is destroyed, it gets destroyed as well
52 if (!mapping->parent())
53 mapping->setParent(this);
54
55 d->update();
56 }
57}
58
59void QChannelMapper::removeMapping(QAbstractChannelMapping *mapping)
60{
61 Q_ASSERT(mapping);
62 Q_D(QChannelMapper);
63 if (!d->m_mappings.removeOne(t: mapping))
64 return;
65 d->update();
66 // Remove bookkeeping connection
67 d->unregisterDestructionHelper(node: mapping);
68}
69
70QList<QAbstractChannelMapping *> QChannelMapper::mappings() const
71{
72 Q_D(const QChannelMapper);
73 return d->m_mappings;
74}
75
76} // namespace Qt3DAnimation
77
78QT_END_NAMESPACE
79
80#include "moc_qchannelmapper.cpp"
81

source code of qt3d/src/animation/frontend/qchannelmapper.cpp