Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qquick3dxractionmapper.cpp
Go to the documentation of this file.
1// Copyright (C) 2024 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
5
7
8QQuick3DXrActionMapper::QQuick3DXrActionMapper(QObject *parent) : QObject(parent)
9{
10}
11
13{
14 return quint16(id) | (quint32(hand) << 16);
15}
16
18{
19 return QString::number(hand) + name;
20}
21
27
29{
30 auto *that = instance();
31 auto set = [](auto action, auto value) {
32 action->setValue(value);
33 // TODO: distinguish between bool and float values
34 action->setPressed(value > 0.9);
35 };
36
37 const QLatin1StringView name(shortName);
38 emit that->inputValueChange(id, name, value); // TODO: emit signal from public class (XrController?)
39
40 QList<QQuick3DXrInputAction *> actions;
42 actions = that->m_customActions.values(actionStringKey(name, hand));
43 } else {
44 actions = that->m_actions.values(actionIntKey(id, hand));
45 }
46
47 for (const auto &action : std::as_const(actions))
48 set(action, value);
49}
50
51// Note: it is the responsibility of the caller to call removeAction() before changing actionId/actionName
53{
54 auto *that = instance();
55
56 const auto &idList = action->actionId();
57 const auto hand = action->hand();
58
59 if (idList.isEmpty()) {
60 that->m_customActions.insert(actionStringKey(action->actionName(), hand), action);
61 } else {
62 for (const auto &id : idList) {
64 that->m_actions.insert(actionIntKey(id, hand), action);
65 }
66 }
67
68 connect(action, &QObject::destroyed, that, [that, action](){ that->removeAction(action); });
69}
70
72{
73 auto *that = instance();
74
75 const auto idList = action->actionId();
76 const auto hand = action->hand();
77 if (idList.isEmpty()) {
78 that->m_customActions.remove(action->actionName(), action);
79 } else {
80 for (const auto &id : idList) {
82 that->m_actions.remove(actionIntKey(id, hand));
83 }
84 }
85}
86
95{
96 if (qFuzzyCompare(m_value, newValue))
97 return;
98 m_value = newValue;
100}
101
111{
112 return m_pressed;
113}
114
116{
117 if (m_pressed == newPressed)
118 return;
119 m_pressed = newPressed;
121 if (newPressed)
122 emit triggered();
123}
124
133{
134 return m_actionName;
135}
136
138{
139 if (m_actionName == newActionName)
140 return;
141 const bool needsRemap = m_actionIds.isEmpty() && m_componentComplete;
142 if (needsRemap)
144 m_actionName = newActionName;
145 if (needsRemap)
148}
149
154
164{
165 return m_value;
166}
167
171
173{
175 m_componentComplete = true;
176}
177
237QList<QQuick3DXrInputAction::Action> QQuick3DXrInputAction::actionId() const
238{
239 return m_actionIds;
240}
241
242void QQuick3DXrInputAction::setActionId(const QList<Action> &newActionId)
243{
244 if (m_actionIds == newActionId)
245 return;
246
247 if (m_componentComplete)
249
250 m_actionIds = newActionId;
251
252 if (m_componentComplete)
254
256}
257
258
260{
261 return m_hand;
262}
263
265{
266 if (m_hand == newHand)
267 return;
268 m_hand = newHand;
270}
271
bool isEmpty() const noexcept
Definition qlist.h:402
\inmodule QtCore
Definition qobject.h:103
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
void destroyed(QObject *=nullptr)
This signal is emitted immediately before the object obj is destroyed, after any instances of QPointe...
static void registerAction(QQuick3DXrInputAction *action)
static void handleInput(QQuick3DXrInputAction::Action id, QQuick3DXrInputAction::Hand hand, const char *shortName, float value)
static QQuick3DXrActionMapper * instance()
static void removeAction(QQuick3DXrInputAction *action)
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
void classBegin() override
Invoked after class creation, but before any properties have been set.
void setPressed(bool newPressed)
void setActionId(const QList< Action > &newActionId)
void setActionName(const QString &newActionName)
QQuick3DXrInputAction(QObject *parent=nullptr)
void setValue(float newValue)
\qmltype XrInputAction \inherits Item \inqmlmodule QtQuick3D.Xr
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:8095
Combined button and popup list for selecting options.
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
bool qFuzzyCompare(qfloat16 p1, qfloat16 p2) noexcept
Definition qfloat16.h:333
GLuint name
static quint32 actionIntKey(const QQuick3DXrInputAction::Action id, const QQuick3DXrInputAction::Hand hand)
static QString actionStringKey(const QString &name, const QQuick3DXrInputAction::Hand hand)
#define emit
unsigned int quint32
Definition qtypes.h:50
unsigned short quint16
Definition qtypes.h:48
QFuture< QSet< QChar > > set
[10]