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
qopenxractionmapper.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
6
8
12
16
18{
19 m_controller = qobject_cast<QOpenXRController *>(parent());
20 if (m_controller && !m_controller->actionMapper())
21 m_controller->setActionMapper(this);
22}
23
24// returns true if inserted into m_actionMap
25bool QOpenXRActionMapper::insertAction(QOpenXrInputAction *action, InputAction id)
26{
27 Q_ASSERT(id > CustomAction && id < NumActions);
28 if (m_actionMap[id] == nullptr) {
29 m_actionMap[id] = action;
30 return true;
31 } else {
32 setOverflow(id);
33 return false;
34 }
35}
36
37void QOpenXRActionMapper::removeAction(QOpenXrInputAction *action)
38{
39 const auto idList = action->actionId();
40 for (const auto &id : idList) {
41 if (id != CustomAction && m_actionMap[id] == action)
42 m_actionMap[id] = nullptr;
43 }
44 m_extraActions.removeAll(action);
45}
46
47void QOpenXRActionMapper::handleInput(InputAction id, const char *shortName, float value)
48{
49 auto set = [](auto action, auto value) {
50 action->setValue(value);
51 // TODO: distinguish between bool and float values
52 action->setPressed(value > 0.9);
53 };
54
55 if (id == CustomAction) {
57 } else {
59 if (auto *action = m_actionMap[id])
60 set(action, value);
61
62 }
63
64 if (id == CustomAction || isOverflow(id)) {
65 for (auto *action : std::as_const(m_extraActions)) {
66 if ((action->actionId().isEmpty() && action->actionName() == QLatin1StringView(shortName)) || action->actionId().contains(id))
67 set(action, value);
68 }
69 }
70}
71
73{
74 const auto idList = action->actionId();
75 bool needsExtra = idList.isEmpty(); // We definitely need to add to m_extraActions if no actionId
76 for (const auto &id : idList) {
77 if (id != CustomAction)
78 needsExtra = !insertAction(action, id) || needsExtra; //make sure not to shortcut the function call
79 }
80 if (needsExtra)
81 m_extraActions.append(action);
82 connect(action, &QObject::destroyed, this, [this, action](){ removeAction(action); });
83}
84
85void QOpenXrInputAction::setValue(float newValue)
86{
87 if (qFuzzyCompare(m_value, newValue))
88 return;
89 m_value = newValue;
91}
92
94{
95 return m_pressed;
96}
97
98void QOpenXrInputAction::setPressed(bool newPressed)
99{
100 if (m_pressed == newPressed)
101 return;
102 m_pressed = newPressed;
104 if (newPressed)
105 emit triggered();
106}
107
109{
110 return m_actionName;
111}
112
114{
115 if (m_actionName == newActionName)
116 return;
117 m_actionName = newActionName;
119}
120
125
127{
128 return m_value;
129}
130
134
136{
137 auto *mapper = qobject_cast<QOpenXRActionMapper *>(parent());
138 if (mapper)
139 mapper->registerAction(this);
140}
141
142QList<QOpenXRActionMapper::InputAction> QOpenXrInputAction::actionId() const
143{
144 return m_actionIds;
145}
146
147void QOpenXrInputAction::setActionId(const QList<QOpenXRActionMapper::InputAction> &newActionId)
148{
149 if (m_actionIds == newActionId)
150 return;
151 m_actionIds = newActionId;
153}
154
bool isEmpty() const noexcept
Definition qlist.h:401
qsizetype removeAll(const AT &t)
Definition qlist.h:592
void append(parameter_type t)
Definition qlist.h:458
\inmodule QtCore
Definition qobject.h:103
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
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...
void handleInput(InputAction id, const char *shortName, float value)
void inputValueChange(InputAction id, QString shortName, float value)
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
QOpenXRActionMapper(QQuick3DObject *parent=nullptr)
void registerAction(QOpenXrInputAction *action)
void classBegin() override
Invoked after class creation, but before any properties have been set.
void setActionMapper(QOpenXRActionMapper *newActionMapper)
QOpenXRActionMapper * actionMapper
QOpenXrInputAction(QObject *parent=nullptr)
QList< QOpenXRActionMapper::InputAction > actionId
void setValue(float newValue)
void classBegin() override
Invoked after class creation, but before any properties have been set.
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
void setActionName(const QString &newActionName)
void setActionId(const QList< QOpenXRActionMapper::InputAction > &newActionId)
void setPressed(bool newPressed)
\qmltype Object3D \inqmlmodule QtQuick3D \instantiates QQuick3DObject \inherits QtObject
QQuick3DObject * parent
\qmlproperty Object3D QtQuick3D::Object3D::parent This property holds the parent of the Object3D in a...
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
Combined button and popup list for selecting options.
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
bool qFuzzyCompare(qfloat16 p1, qfloat16 p2) noexcept
Definition qfloat16.h:333
GLenum GLuint id
[7]
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define emit
QFuture< QSet< QChar > > set
[10]
QDataWidgetMapper * mapper
[0]
bool contains(const AT &t) const noexcept
Definition qlist.h:45