1// Copyright (C) 2015 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 "qaction.h"
5#include "qaction_p.h"
6
7#include <Qt3DInput/qabstractactioninput.h>
8
9#include <Qt3DCore/private/qnode_p.h>
10
11QT_BEGIN_NAMESPACE
12
13namespace Qt3DInput {
14
15/*!
16 \class Qt3DInput::QAction
17 \inmodule Qt3DInput
18 \inherits Qt3DCore::QNode
19 \brief Links a set of QAbstractActionInput that trigger the same event.
20 \since 5.7
21*/
22
23/*!
24 \qmltype Action
25 \inqmlmodule Qt3D.Input
26 \instantiates Qt3DInput::QAction
27 \brief QML frontend for the Qt3DInput::QAction C++ class.
28
29 Links a set of AbstractActionInput that trigger the same event.
30 \since 5.7
31*/
32
33/*!
34 Constructs a new QAction instance with parent \a parent.
35 */
36QAction::QAction(Qt3DCore::QNode *parent)
37 : Qt3DCore::QNode(*new QActionPrivate(), parent)
38{
39}
40
41/*! \internal */
42QAction::~QAction()
43{
44}
45
46/*!
47 \qmlproperty bool Qt3D.Input::Action::action
48*/
49
50/*!
51 \property QAction::active
52
53 Holds \c true if the action is active.
54
55 Note this property is not updated when the action is disabled.
56 */
57bool QAction::isActive() const
58{
59 Q_D(const QAction);
60 return d->m_active;
61}
62
63/*!
64 \qmlproperty list<AbstractActionInput> Qt3D.Input::Action::inputs
65
66 The list of AbstractActionInput that must be triggered to trigger this Action.
67*/
68
69/*!
70 Append QAbstractActionInput \a input to the list of inputs that can trigger this action.
71 */
72void QAction::addInput(QAbstractActionInput *input)
73{
74 Q_D(QAction);
75 if (!d->m_inputs.contains(t: input)) {
76 d->m_inputs.push_back(t: input);
77
78 if (!input->parent())
79 input->setParent(this);
80
81 // Ensures proper bookkeeping
82 d->registerDestructionHelper(node: input, func: &QAction::removeInput, d->m_inputs);
83
84 d->update();
85 }
86}
87
88/*!
89 Remove QAbstractActionInput \a input to the list of inputs that can trigger this action.
90 */
91void QAction::removeInput(QAbstractActionInput *input)
92{
93 Q_D(QAction);
94 if (d->m_inputs.contains(t: input)) {
95
96 d->update();
97
98 d->m_inputs.removeOne(t: input);
99
100 // Remove bookkeeping connection
101 d->unregisterDestructionHelper(node: input);
102 }
103}
104
105/*!
106 Returns the list of inputs that can trigger this action.
107 */
108QList<QAbstractActionInput *> QAction::inputs() const
109{
110 Q_D(const QAction);
111 return d->m_inputs;
112}
113
114} // Qt3DInput
115
116QT_END_NAMESPACE
117
118#include "moc_qaction.cpp"
119

source code of qt3d/src/input/frontend/qaction.cpp