summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSean Harmer <sean.harmer@kdab.com>2016-08-11 16:49:33 +0100
committerJani Heikkinen <jani.heikkinen@qt.io>2016-12-07 05:53:23 +0000
commitdd6866e7b278c0feb5155144e0709cfc2f99fa96 (patch)
treec733b4b3f69c35b2e441283ed4583d9940caaff8 /src
parenta2c6c81f5c67390629a313ff7ba985d0967ca1fa (diff)
Add backend class for AxisAccumulator and tests
Change-Id: I2d6071c11054eff7d5a574ce3a3dba54dd9bad12 Reviewed-by: Kevin Ottens <kevin.ottens@kdab.com>
Diffstat (limited to 'src')
-rw-r--r--src/input/backend/axisaccumulator.cpp113
-rw-r--r--src/input/backend/axisaccumulator_p.h93
-rw-r--r--src/input/backend/backend.pri6
3 files changed, 210 insertions, 2 deletions
diff --git a/src/input/backend/axisaccumulator.cpp b/src/input/backend/axisaccumulator.cpp
new file mode 100644
index 000000000..4843f35f3
--- /dev/null
+++ b/src/input/backend/axisaccumulator.cpp
@@ -0,0 +1,113 @@
+/****************************************************************************
+**
+** 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 "axisaccumulator_p.h"
+#include <Qt3DInput/private/qaxisaccumulator_p.h>
+#include <Qt3DCore/qpropertyupdatedchange.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DInput {
+namespace Input {
+
+AxisAccumulator::AxisAccumulator()
+ : Qt3DCore::QBackendNode(ReadWrite)
+ , m_sourceAxisId()
+ , m_sourceAxisType(QAxisAccumulator::Velocity)
+ , m_scale(1.0f)
+ , m_value(0.0f)
+{
+}
+
+void AxisAccumulator::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change)
+{
+ const auto typedChange = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<QAxisAccumulatorData>>(change);
+ const auto &data = typedChange->data;
+ m_sourceAxisId = data.sourceAxisId;
+ m_sourceAxisType = data.sourceAxisType;
+ m_scale = data.scale;
+}
+
+void AxisAccumulator::cleanup()
+{
+ QBackendNode::setEnabled(false);
+ m_sourceAxisId = Qt3DCore::QNodeId();
+ m_sourceAxisType = QAxisAccumulator::Velocity;
+ m_scale = 1.0f;
+ m_value = 0.0f;
+}
+
+void AxisAccumulator::setValue(float value)
+{
+ if (isEnabled() && value != m_value) {
+ m_value = value;
+
+ // Send a change to the frontend
+ auto e = Qt3DCore::QPropertyUpdatedChangePtr::create(peerId());
+ e->setDeliveryFlags(Qt3DCore::QSceneChange::DeliverToAll);
+ e->setPropertyName("value");
+ e->setValue(m_value);
+ notifyObservers(e);
+ }
+}
+
+void AxisAccumulator::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e)
+{
+ switch (e->type()) {
+ case Qt3DCore::PropertyUpdated: {
+ const auto change = qSharedPointerCast<Qt3DCore::QPropertyUpdatedChange>(e);
+ if (change->propertyName() == QByteArrayLiteral("sourceAxis"))
+ m_sourceAxisId = change->value().value<Qt3DCore::QNodeId>();
+ else if (change->propertyName() == QByteArrayLiteral("sourceAxisType"))
+ m_sourceAxisType = change->value().value<QAxisAccumulator::SourceAxisType>();
+ else if (change->propertyName() == QByteArrayLiteral("scale"))
+ m_scale = change->value().toFloat();
+ break;
+ }
+
+ default:
+ break;
+ }
+ QBackendNode::sceneChangeEvent(e);
+}
+
+} // namespace Input
+} // namespace Qt3DInput
+
+QT_END_NAMESPACE
diff --git a/src/input/backend/axisaccumulator_p.h b/src/input/backend/axisaccumulator_p.h
new file mode 100644
index 000000000..8ddc9951b
--- /dev/null
+++ b/src/input/backend/axisaccumulator_p.h
@@ -0,0 +1,93 @@
+/****************************************************************************
+**
+** 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_AXISACCUMULATOR_H
+#define QT3DINPUT_INPUT_AXISACCUMULATOR_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>
+
+#include <Qt3DInput/qaxisaccumulator.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DInput {
+namespace Input {
+
+class Q_AUTOTEST_EXPORT AxisAccumulator : public Qt3DCore::QBackendNode
+{
+public:
+ AxisAccumulator();
+ void cleanup();
+
+ Qt3DCore::QNodeId sourceAxisId() const { return m_sourceAxisId; }
+ QAxisAccumulator::SourceAxisType sourceAxisType() const { return m_sourceAxisType; }
+ float scale() const { return m_scale; }
+
+ float value() const Q_DECL_NOTHROW { return m_value; }
+ void setValue(float value);
+
+ void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) Q_DECL_OVERRIDE;
+
+private:
+ void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) Q_DECL_FINAL;
+
+ Qt3DCore::QNodeId m_sourceAxisId;
+ QAxisAccumulator::SourceAxisType m_sourceAxisType;
+ float m_scale;
+ float m_value;
+};
+
+} // namespace Input
+} // namespace Qt3DInput
+
+QT_END_NAMESPACE
+
+#endif // QT3DINPUT_INPUT_AXISACCUMULATOR_H
diff --git a/src/input/backend/backend.pri b/src/input/backend/backend.pri
index 846fb1705..a0f6df9f0 100644
--- a/src/input/backend/backend.pri
+++ b/src/input/backend/backend.pri
@@ -34,7 +34,8 @@ HEADERS += \
$$PWD/job_common_p.h \
$$PWD/physicaldeviceproxy_p.h \
$$PWD/loadproxydevicejob_p.h \
- $$PWD/utils_p.h
+ $$PWD/utils_p.h \
+ $$PWD/axisaccumulator_p.h
SOURCES += \
$$PWD/keyboarddevice.cpp \
@@ -66,6 +67,7 @@ SOURCES += \
$$PWD/inputsettings.cpp \
$$PWD/eventsourcesetterhelper.cpp \
$$PWD/physicaldeviceproxy.cpp \
- $$PWD/loadproxydevicejob.cpp
+ $$PWD/loadproxydevicejob.cpp \
+ $$PWD/axisaccumulator.cpp
INCLUDEPATH += $$PWD