diff options
author | Paul Lemire <paul.lemire@kdab.com> | 2016-08-25 11:19:10 +0200 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2016-11-18 18:45:02 +0000 |
commit | ab64b7ea8d134edd912e1b5a2fbb854463289c9d (patch) | |
tree | ceff4f1a517fcc03ee92c256fc2a449c65390059 /src/input | |
parent | 53597bea63dab181fdf5a039edcbb8c29e46997e (diff) |
Add PhysicalDeviceProxy: backend for QAbstractPhysicalDeviceProxy
Change-Id: I536df06d6013fd85e4c7a15364ae6926d472943d
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/input')
-rw-r--r-- | src/input/backend/backend.pri | 6 | ||||
-rw-r--r-- | src/input/backend/handle_types_p.h | 2 | ||||
-rw-r--r-- | src/input/backend/inputhandler.cpp | 2 | ||||
-rw-r--r-- | src/input/backend/inputhandler_p.h | 3 | ||||
-rw-r--r-- | src/input/backend/inputmanagers_p.h | 17 | ||||
-rw-r--r-- | src/input/backend/physicaldeviceproxy.cpp | 132 | ||||
-rw-r--r-- | src/input/backend/physicaldeviceproxy_p.h | 107 |
7 files changed, 267 insertions, 2 deletions
diff --git a/src/input/backend/backend.pri b/src/input/backend/backend.pri index 5c22f0e50..531bdd362 100644 --- a/src/input/backend/backend.pri +++ b/src/input/backend/backend.pri @@ -31,7 +31,8 @@ HEADERS += \ $$PWD/inputsequence_p.h \ $$PWD/inputsettings_p.h \ $$PWD/eventsourcesetterhelper_p.h \ - $$PWD/job_common_p.h + $$PWD/job_common_p.h \ + $$PWD/physicaldeviceproxy_p.h SOURCES += \ $$PWD/keyboarddevice.cpp \ @@ -61,6 +62,7 @@ SOURCES += \ $$PWD/inputchord.cpp \ $$PWD/inputsequence.cpp \ $$PWD/inputsettings.cpp \ - $$PWD/eventsourcesetterhelper.cpp + $$PWD/eventsourcesetterhelper.cpp \ + $$PWD/physicaldeviceproxy.cpp INCLUDEPATH += $$PWD diff --git a/src/input/backend/handle_types_p.h b/src/input/backend/handle_types_p.h index d81a1225b..cc78a68ba 100644 --- a/src/input/backend/handle_types_p.h +++ b/src/input/backend/handle_types_p.h @@ -72,6 +72,7 @@ class InputSequence; class InputChord; class LogicalDevice; class GenericDeviceBackendNode; +class PhysicalDeviceProxy; typedef Qt3DCore::QHandle<KeyboardDevice, 8> HKeyboardDevice; typedef Qt3DCore::QHandle<KeyboardHandler, 16> HKeyboardHandler; @@ -87,6 +88,7 @@ typedef Qt3DCore::QHandle<InputSequence, 16> HInputSequence; typedef Qt3DCore::QHandle<InputChord, 16> HInputChord; typedef Qt3DCore::QHandle<LogicalDevice, 16> HLogicalDevice; typedef Qt3DCore::QHandle<GenericDeviceBackendNode, 8> HGenericDeviceBackendNode; +typedef Qt3DCore::QHandle<PhysicalDeviceProxy, 16> HPhysicalDeviceProxy; } // namespace Input } // namespace Qt3DInput diff --git a/src/input/backend/inputhandler.cpp b/src/input/backend/inputhandler.cpp index fe2a04bd7..ba94029e5 100644 --- a/src/input/backend/inputhandler.cpp +++ b/src/input/backend/inputhandler.cpp @@ -72,6 +72,7 @@ InputHandler::InputHandler() , m_inputSequenceManager(new InputSequenceManager()) , m_logicalDeviceManager(new LogicalDeviceManager()) , m_genericPhysicalDeviceBackendNodeManager(new GenericDeviceBackendNodeManager) + , m_physicalDeviceProxyManager(new PhysicalDeviceProxyManager()) , m_settings(nullptr) , m_eventSourceSetter(new Qt3DInput::Input::EventSourceSetterHelper(this)) { @@ -100,6 +101,7 @@ InputHandler::~InputHandler() delete m_inputSequenceManager; delete m_logicalDeviceManager; delete m_genericPhysicalDeviceBackendNodeManager; + delete m_physicalDeviceProxyManager; } // Called in MainThread (by the EventSourceHelperSetter) diff --git a/src/input/backend/inputhandler_p.h b/src/input/backend/inputhandler_p.h index 2cfb56e3f..573a1f9dc 100644 --- a/src/input/backend/inputhandler_p.h +++ b/src/input/backend/inputhandler_p.h @@ -88,6 +88,7 @@ class InputSequenceManager; class LogicalDeviceManager; class GenericPhysicalDeviceManager; class GenericDeviceBackendNodeManager; +class PhysicalDeviceProxyManager; class InputSettings; class EventSourceSetterHelper; @@ -111,6 +112,7 @@ public: inline InputSequenceManager *inputSequenceManager() const { return m_inputSequenceManager; } inline LogicalDeviceManager *logicalDeviceManager() const { return m_logicalDeviceManager; } inline GenericDeviceBackendNodeManager *genericDeviceBackendNodeManager() const { return m_genericPhysicalDeviceBackendNodeManager; } + inline PhysicalDeviceProxyManager *physicalDeviceProxyManager() const { return m_physicalDeviceProxyManager; } inline InputSettings *inputSettings() const { return m_settings; } void appendKeyEvent(const QT_PREPEND_NAMESPACE(QKeyEvent) &event); @@ -175,6 +177,7 @@ private: InputSequenceManager *m_inputSequenceManager; LogicalDeviceManager *m_logicalDeviceManager; GenericDeviceBackendNodeManager *m_genericPhysicalDeviceBackendNodeManager; + PhysicalDeviceProxyManager *m_physicalDeviceProxyManager; QVector<Qt3DInput::QInputDeviceIntegration *> m_inputDeviceIntegrations; InputSettings *m_settings; QScopedPointer<EventSourceSetterHelper> m_eventSourceSetter; diff --git a/src/input/backend/inputmanagers_p.h b/src/input/backend/inputmanagers_p.h index 9473dbf45..d162ea519 100644 --- a/src/input/backend/inputmanagers_p.h +++ b/src/input/backend/inputmanagers_p.h @@ -68,6 +68,7 @@ #include <Qt3DInput/private/buttonaxisinput_p.h> #include <Qt3DInput/private/logicaldevice_p.h> #include <Qt3DInput/private/genericdevicebackendnode_p.h> +#include <Qt3DInput/private/physicaldeviceproxy_p.h> QT_BEGIN_NAMESPACE @@ -221,6 +222,22 @@ public: GenericDeviceBackendNodeManager() {} }; +class Q_AUTOTEST_EXPORT PhysicalDeviceProxyManager : public Qt3DCore::QResourceManager< + PhysicalDeviceProxy, + Qt3DCore::QNodeId, + 16, + Qt3DCore::ArrayAllocatingPolicy> +{ +public: + PhysicalDeviceProxyManager() {} + + void addPendingProxyToLoad(Qt3DCore::QNodeId id) { m_pendingProxies.push_back(id); } + QVector<Qt3DCore::QNodeId> takePendingProxiesToLoad() { return std::move(m_pendingProxies); } + +private: + QVector<Qt3DCore::QNodeId> m_pendingProxies; +}; + } // namespace Input } // namespace Qt3DInput diff --git a/src/input/backend/physicaldeviceproxy.cpp b/src/input/backend/physicaldeviceproxy.cpp new file mode 100644 index 000000000..3fd159134 --- /dev/null +++ b/src/input/backend/physicaldeviceproxy.cpp @@ -0,0 +1,132 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "physicaldeviceproxy_p.h" +#include <Qt3DCore/qpropertyupdatedchange.h> +#include <Qt3DInput/qabstractphysicaldevice.h> +#include <Qt3DInput/private/qabstractphysicaldeviceproxy_p_p.h> +#include <Qt3DInput/private/inputmanagers_p.h> +#include <QCoreApplication> + +QT_BEGIN_NAMESPACE + +namespace Qt3DInput { + +namespace Input { + +PhysicalDeviceProxy::PhysicalDeviceProxy() + : QBackendNode(QBackendNode::ReadWrite) + , m_manager(nullptr) +{ +} + +void PhysicalDeviceProxy::cleanup() +{ + QBackendNode::setEnabled(false); + m_deviceName.clear(); + m_manager = nullptr; +} + +QString PhysicalDeviceProxy::deviceName() const +{ + return m_deviceName; +} + +void PhysicalDeviceProxy::setManager(PhysicalDeviceProxyManager *manager) +{ + m_manager = manager; +} + +PhysicalDeviceProxyManager *PhysicalDeviceProxy::manager() const +{ + return m_manager; +} + +void PhysicalDeviceProxy::setDevice(QAbstractPhysicalDevice *device) +{ + // Move the device to the main thread + if (device != nullptr) + device->moveToThread(QCoreApplication::instance()->thread()); + + auto e = Qt3DCore::QPropertyUpdatedChangePtr::create(peerId()); + e->setDeliveryFlags(Qt3DCore::QSceneChange::DeliverToAll); + e->setPropertyName("device"); + e->setValue(QVariant::fromValue(device)); + notifyObservers(e); +} + +void PhysicalDeviceProxy::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) +{ + const auto typedChange = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<QAbstractPhysicalDeviceProxyData>>(change); + const QAbstractPhysicalDeviceProxyData &data = typedChange->data; + m_deviceName = data.deviceName; + + // Request to load the actual device + m_manager->addPendingProxyToLoad(peerId()); +} + +PhysicalDeviceProxyNodeFunctor::PhysicalDeviceProxyNodeFunctor(PhysicalDeviceProxyManager *manager) + : m_manager(manager) +{ +} + +Qt3DCore::QBackendNode *PhysicalDeviceProxyNodeFunctor::create(const Qt3DCore::QNodeCreatedChangeBasePtr &change) const +{ + HPhysicalDeviceProxy handle = m_manager->getOrAcquireHandle(change->subjectId()); + PhysicalDeviceProxy *backend = m_manager->data(handle); + backend->setManager(m_manager); + return backend; +} + +Qt3DCore::QBackendNode *PhysicalDeviceProxyNodeFunctor::get(Qt3DCore::QNodeId id) const +{ + return m_manager->lookupResource(id); +} + +void PhysicalDeviceProxyNodeFunctor::destroy(Qt3DCore::QNodeId id) const +{ + m_manager->releaseResource(id); +} + +} // namespace Input + +} // namespace Qt3DInput + +QT_END_NAMESPACE + diff --git a/src/input/backend/physicaldeviceproxy_p.h b/src/input/backend/physicaldeviceproxy_p.h new file mode 100644 index 000000000..dc7651edf --- /dev/null +++ b/src/input/backend/physicaldeviceproxy_p.h @@ -0,0 +1,107 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT3DINPUT_INPUT_PHYSICALDEVICEPROXY_P_H +#define QT3DINPUT_INPUT_PHYSICALDEVICEPROXY_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <Qt3DCore/qbackendnode.h> +#include <Qt3DCore/qnodeid.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DInput { + +class QAbstractPhysicalDevice; + +namespace Input { + +class PhysicalDeviceProxyManager; + +class Q_AUTOTEST_EXPORT PhysicalDeviceProxy : public Qt3DCore::QBackendNode +{ +public: + PhysicalDeviceProxy(); + void cleanup(); + + QString deviceName() const; + + void setManager(PhysicalDeviceProxyManager *manager); + PhysicalDeviceProxyManager *manager() const; + + // Called from a job to update the frontend + void setDevice(QAbstractPhysicalDevice *device); + +private: + void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) Q_DECL_FINAL; + + QString m_deviceName; + PhysicalDeviceProxyManager *m_manager; +}; + +class PhysicalDeviceProxyNodeFunctor: public Qt3DCore::QBackendNodeMapper +{ +public: + explicit PhysicalDeviceProxyNodeFunctor(PhysicalDeviceProxyManager *manager); + + Qt3DCore::QBackendNode *create(const Qt3DCore::QNodeCreatedChangeBasePtr &change) const Q_DECL_FINAL; + Qt3DCore::QBackendNode *get(Qt3DCore::QNodeId id) const Q_DECL_FINAL; + void destroy(Qt3DCore::QNodeId id) const Q_DECL_FINAL; + +private: + PhysicalDeviceProxyManager *m_manager; +}; + +} // namespace Input + +} // namespace Qt3DInput + +QT_END_NAMESPACE + +#endif // QT3DINPUT_INPUT_PHYSICALDEVICEPROXY_P_H |