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#ifndef QT3DINPUT_INPUT_UTILS_P_H
5#define QT3DINPUT_INPUT_UTILS_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists for the convenience
12// of other Qt classes. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <Qt3DInput/private/inputhandler_p.h>
19#include <Qt3DInput/private/inputmanagers_p.h>
20#include <Qt3DInput/private/physicaldeviceproxy_p.h>
21#include <Qt3DInput/private/qinputdeviceintegration_p.h>
22#include <Qt3DInput/private/qabstractphysicaldevicebackendnode_p.h>
23
24QT_BEGIN_NAMESPACE
25
26namespace Qt3DInput {
27
28namespace Input {
29
30namespace Utils {
31
32template<class InputClass>
33QAbstractPhysicalDeviceBackendNode *physicalDeviceForInput(InputClass *input, InputHandler *handler)
34{
35 // Note: the source device can be a proxy
36 // in which case sourceDeviceId should be the proxy's device id
37 Qt3DCore::QNodeId sourceDeviceId = input->sourceDevice();
38
39 {
40 PhysicalDeviceProxy *deviceProxy = nullptr;
41 if ((deviceProxy = handler->physicalDeviceProxyManager()->lookupResource(id: sourceDeviceId)) != nullptr)
42 sourceDeviceId = deviceProxy->physicalDeviceId();
43 }
44
45 // Early return if the sourceDeviceId is null
46 if (!sourceDeviceId.isNull()) {
47 const auto integrations = handler->inputDeviceIntegrations();
48 for (QInputDeviceIntegration *integration : integrations) {
49 QAbstractPhysicalDeviceBackendNode *physicalDeviceBackend = integration->physicalDevice(id: sourceDeviceId);
50 if (physicalDeviceBackend)
51 return physicalDeviceBackend;
52 }
53 }
54
55 return nullptr;
56}
57
58} // Utils
59
60} // Input
61
62} // Qt3DInput
63
64QT_END_NAMESPACE
65
66
67#endif // QT3DINPUT_INPUT_UTILS_P_H
68

source code of qt3d/src/input/backend/utils_p.h