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 "qcallbackmapping.h"
5#include "qcallbackmapping_p.h"
6
7#include <QtCore/qmetaobject.h>
8#include <QtCore/QMetaProperty>
9
10QT_BEGIN_NAMESPACE
11
12namespace Qt3DAnimation {
13
14QCallbackMappingPrivate::QCallbackMappingPrivate()
15 : QAbstractChannelMappingPrivate()
16 , m_channelName()
17 , m_type(static_cast<int>(QMetaType::UnknownType))
18 , m_callback(nullptr)
19{
20 m_mappingType = QAbstractChannelMappingPrivate::CallbackMapping;
21}
22
23/*!
24 \class Qt3DAnimation::QCallbackMapping
25 \inherits Qt3DCore::QAbstractChannelMapping
26 \inmodule Qt3DAnimation
27 \brief Allows to map the channels within the clip onto an invocation
28 of a callback object.
29*/
30
31QCallbackMapping::QCallbackMapping(Qt3DCore::QNode *parent)
32 : QAbstractChannelMapping(*new QCallbackMappingPrivate, parent)
33{
34}
35
36QCallbackMapping::QCallbackMapping(QCallbackMappingPrivate &dd, Qt3DCore::QNode *parent)
37 : QAbstractChannelMapping(dd, parent)
38{
39}
40
41QCallbackMapping::~QCallbackMapping()
42{
43}
44
45QString QCallbackMapping::channelName() const
46{
47 Q_D(const QCallbackMapping);
48 return d->m_channelName;
49}
50
51QAnimationCallback *QCallbackMapping::callback() const
52{
53 Q_D(const QCallbackMapping);
54 return d->m_callback;
55}
56
57void QCallbackMapping::setChannelName(const QString &channelName)
58{
59 Q_D(QCallbackMapping);
60 if (d->m_channelName == channelName)
61 return;
62
63 d->m_channelName = channelName;
64 emit channelNameChanged(channelName);
65}
66
67/*!
68 Associates a \a callback object with this channel mapping.
69
70 Such mappings do not have to have a target object and property name. When
71 the \a callback object is set, every change in the animated value will lead
72 to invoking the callback's
73 \l {Qt3DAnimation::QAnimationCallback::valueChanged}{valueChanged} function either
74 on the gui/main thread, or directly on one of the thread pool's worker
75 thread. This is controlled by \a flags.
76
77 \a type specifies the type (for example, QMetaType::QVector3D,
78 QMetaType::QColor, or QMetaType::Float) of the animated value. When animating
79 node properties this does not need to be provided separately, however it
80 becomes important to supply this when there is only a callback.
81
82 \note A mapping can be associated both with a node property and a
83 callback. It is important however that \a type matches the type of the
84 property in this case. Note also that for properties of type QVariant (for
85 example, QParameter::value), the \a type is the type of the value stored in
86 the QVariant.
87
88 \note The \a callback pointer is expected to stay valid while any
89 associated animators are running.
90 */
91void QCallbackMapping::setCallback(int type, QAnimationCallback *callback, QAnimationCallback::Flags flags)
92{
93 Q_D(QCallbackMapping);
94 if (d->m_type != type) {
95 d->m_type = type;
96 d->update();
97 }
98 if (d->m_callback != callback) {
99 d->m_callback = callback;
100 d->update();
101 }
102 if (d->m_callbackFlags != flags) {
103 d->m_callbackFlags = flags;
104 d->update();
105 }
106}
107
108} // namespace Qt3DAnimation
109
110QT_END_NAMESPACE
111
112#include "moc_qcallbackmapping.cpp"
113

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