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 "qabstractphysicaldevice.h" |
5 | #include "qabstractphysicaldevice_p.h" |
6 | |
7 | #include <Qt3DInput/qaxissetting.h> |
8 | |
9 | #include <Qt3DCore/private/qnode_p.h> |
10 | |
11 | QT_BEGIN_NAMESPACE |
12 | |
13 | namespace Qt3DInput { |
14 | |
15 | /*! \internal */ |
16 | QAbstractPhysicalDevicePrivate::QAbstractPhysicalDevicePrivate() |
17 | : m_axisSettings() |
18 | { |
19 | } |
20 | |
21 | /*! \internal */ |
22 | QAbstractPhysicalDevicePrivate::~QAbstractPhysicalDevicePrivate() |
23 | { |
24 | } |
25 | |
26 | /*! |
27 | \class Qt3DInput::QAbstractPhysicalDevice |
28 | \inmodule Qt3DInput |
29 | \inherits Qt3DCore::QNode |
30 | \brief QAbstractPhysicalDevice is the base class used by Qt3d to interact with arbitrary input devices. |
31 | |
32 | \since 5.6 |
33 | */ |
34 | |
35 | /*! |
36 | \qmltype AbstractPhysicalDevice |
37 | \inqmlmodule Qt3D.Input |
38 | \instantiates Qt3DInput::QAbstractPhysicalDevice |
39 | \brief QML frontend for the abstract Qt3DInput::QAbstractPhysicalDevice C++ class. |
40 | |
41 | The base class used by Qt3d to interact with arbitrary input devices. |
42 | |
43 | \since 5.6 |
44 | */ |
45 | |
46 | /*! |
47 | Constructs a new QAbstractPhysicalDevice instance with \a parent. |
48 | */ |
49 | QAbstractPhysicalDevice::QAbstractPhysicalDevice(Qt3DCore::QNode *parent) |
50 | : Qt3DCore::QNode(*new QAbstractPhysicalDevicePrivate, parent) |
51 | { |
52 | } |
53 | |
54 | /*! \internal */ |
55 | QAbstractPhysicalDevice::~QAbstractPhysicalDevice() |
56 | { |
57 | } |
58 | |
59 | QAbstractPhysicalDevice::QAbstractPhysicalDevice(QAbstractPhysicalDevicePrivate &dd, Qt3DCore::QNode *parent) |
60 | : Qt3DCore::QNode(dd, parent) |
61 | { |
62 | } |
63 | |
64 | /*! |
65 | \return the number of axis this device has. |
66 | */ |
67 | int QAbstractPhysicalDevice::axisCount() const |
68 | { |
69 | Q_D(const QAbstractPhysicalDevice); |
70 | return d->m_axesHash.size(); |
71 | } |
72 | |
73 | /*! |
74 | \return the number of buttons this device has. |
75 | */ |
76 | int QAbstractPhysicalDevice::buttonCount() const |
77 | { |
78 | Q_D(const QAbstractPhysicalDevice); |
79 | return d->m_buttonsHash.size(); |
80 | } |
81 | |
82 | /*! |
83 | \return a list of the names of device's axis. |
84 | */ |
85 | QStringList QAbstractPhysicalDevice::axisNames() const |
86 | { |
87 | Q_D(const QAbstractPhysicalDevice); |
88 | return d->m_axesHash.keys(); |
89 | } |
90 | |
91 | /*! |
92 | \return a list of the names of device's buttons. |
93 | */ |
94 | QStringList QAbstractPhysicalDevice::buttonNames() const |
95 | { |
96 | Q_D(const QAbstractPhysicalDevice); |
97 | return d->m_buttonsHash.keys(); |
98 | } |
99 | |
100 | /*! |
101 | \return the integer identifer of the axis \a name or -1 if it does not exist on this device. |
102 | */ |
103 | int QAbstractPhysicalDevice::axisIdentifier(const QString &name) const |
104 | { |
105 | Q_D(const QAbstractPhysicalDevice); |
106 | auto it = d->m_axesHash.find(key: name); |
107 | if (it != d->m_axesHash.end()) |
108 | return *it; |
109 | return -1; |
110 | } |
111 | |
112 | /*! |
113 | \return the integer identifer of the button \a name or -1 if it does not exist on this device. |
114 | */ |
115 | int QAbstractPhysicalDevice::buttonIdentifier(const QString &name) const |
116 | { |
117 | Q_D(const QAbstractPhysicalDevice); |
118 | auto it = d->m_buttonsHash.find(key: name); |
119 | if (it != d->m_buttonsHash.end()) |
120 | return *it; |
121 | return -1; |
122 | } |
123 | |
124 | /*! |
125 | Add the axisSetting \a axisSetting to this device. |
126 | */ |
127 | void QAbstractPhysicalDevice::addAxisSetting(QAxisSetting *axisSetting) |
128 | { |
129 | Q_D(QAbstractPhysicalDevice); |
130 | if (axisSetting && !d->m_axisSettings.contains(t: axisSetting)) { |
131 | d->update(); |
132 | d->m_axisSettings.push_back(t: axisSetting); |
133 | } |
134 | } |
135 | |
136 | /*! |
137 | Remove the axisSetting \a axisSetting to this device. |
138 | */ |
139 | void QAbstractPhysicalDevice::removeAxisSetting(QAxisSetting *axisSetting) |
140 | { |
141 | Q_D(QAbstractPhysicalDevice); |
142 | if (axisSetting && d->m_axisSettings.contains(t: axisSetting)) { |
143 | d->update(); |
144 | d->m_axisSettings.removeOne(t: axisSetting); |
145 | } |
146 | } |
147 | |
148 | /*! |
149 | Returns the axisSettings associated with this device. |
150 | */ |
151 | QList<QAxisSetting *> QAbstractPhysicalDevice::axisSettings() const |
152 | { |
153 | Q_D(const QAbstractPhysicalDevice); |
154 | return d->m_axisSettings; |
155 | } |
156 | |
157 | /* |
158 | Used to notify observers that an axis value has been changed. |
159 | */ |
160 | void QAbstractPhysicalDevicePrivate::postAxisEvent(int axis, qreal value) |
161 | { |
162 | m_pendingAxisEvents.push_back(t: {axis, value}); |
163 | update(); |
164 | } |
165 | |
166 | /* |
167 | Used to notify observers that an button value has been changed. |
168 | */ |
169 | void QAbstractPhysicalDevicePrivate::postButtonEvent(int button, qreal value) |
170 | { |
171 | m_pendingButtonsEvents.push_back(t: {button, value}); |
172 | update(); |
173 | } |
174 | |
175 | } |
176 | |
177 | QT_END_NAMESPACE |
178 | |
179 | #include "moc_qabstractphysicaldevice.cpp" |
180 |