summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/input/frontend/frontend.pri7
-rw-r--r--src/input/frontend/qaxisaccumulator.cpp274
-rw-r--r--src/input/frontend/qaxisaccumulator.h99
-rw-r--r--src/input/frontend/qaxisaccumulator_p.h87
-rw-r--r--tests/auto/input/input.pro3
-rw-r--r--tests/auto/input/qaxisaccumulator/qaxisaccumulator.pro11
-rw-r--r--tests/auto/input/qaxisaccumulator/tst_qaxisaccumulator.cpp226
7 files changed, 704 insertions, 3 deletions
diff --git a/src/input/frontend/frontend.pri b/src/input/frontend/frontend.pri
index 93b3e0839..67c93d2b9 100644
--- a/src/input/frontend/frontend.pri
+++ b/src/input/frontend/frontend.pri
@@ -43,7 +43,9 @@ HEADERS += \
$$PWD/qinputsequence_p.h \
$$PWD/qinputchord_p.h \
$$PWD/qphysicaldevicecreatedchange.h \
- $$PWD/qphysicaldevicecreatedchange_p.h
+ $$PWD/qphysicaldevicecreatedchange_p.h \
+ $$PWD/qaxisaccumulator.h \
+ $$PWD/qaxisaccumulator_p.h
SOURCES += \
@@ -71,7 +73,8 @@ SOURCES += \
$$PWD/qinputchord.cpp \
$$PWD/qinputsequence.cpp \
$$PWD/qinputsettings.cpp \
- $$PWD/qphysicaldevicecreatedchange.cpp
+ $$PWD/qphysicaldevicecreatedchange.cpp \
+ $$PWD/qaxisaccumulator.cpp
qtHaveModule(gamepad) {
QT += gamepad
diff --git a/src/input/frontend/qaxisaccumulator.cpp b/src/input/frontend/qaxisaccumulator.cpp
new file mode 100644
index 000000000..d205bce16
--- /dev/null
+++ b/src/input/frontend/qaxisaccumulator.cpp
@@ -0,0 +1,274 @@
+/****************************************************************************
+**
+** 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 "qaxisaccumulator.h"
+#include "qaxisaccumulator_p.h"
+#include <Qt3DInput/qaxis.h>
+#include <Qt3DCore/qnodecreatedchange.h>
+#include <Qt3DCore/qpropertyupdatedchange.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DInput {
+
+/*!
+ Constructs a new QAxisAccumulator instance with \a parent.
+ \class Qt3DInput::QAxisAccumulator
+ \inmodule Qt3DInput
+ \inherits Qt3DCore::QNode
+ \brief QAxisAccumulator processes velocity or acceleration data from a QAxis.
+ \since 5.8
+
+ A Qt3DInput::QAxis reports the current position of an axis on an input
+ device. When the axis is returned to its neutral position the value of that
+ axis returns to 0. Often, it is required to have the input from an axis
+ control a variable in other ways, for example treating the value from the
+ Qt3DInput::QAxis as a velocity (first derivative with respect to time) or
+ as an acceleration (second derivative with respect to time). This can be
+ done with user code or with a Qt3DLogic::QFrameAction but those approached
+ are not ideal as they add more work to the main thread and are inherently
+ imperative. The Qt3DInput::QAxisAccumulator class allows for this common
+ task to be performed on the Qt 3D backend and be specified in a declarative
+ manner.
+*/
+
+/*!
+ \qmltype AxisAccumulator
+ \inqmlmodule Qt3D.Input
+ \instantiates Qt3DInput::QAxisAccumulator
+ \brief QML frontend for the Qt3DInput::QAxisAccumulator C++ class.
+ \since 5.8
+
+ An Axis reports the current position of an axis on an input device. When the
+ axis is returned to its neutral position the value of that axis returns to 0.
+ Often, it is required to have the input from an axis control a variable in
+ other ways, for example treating the value from the Axis as a velocity (first
+ derivative with respect to time) or as an acceleration (second derivative with
+ respect to time). This can be done with user code or with a FrameAction but
+ those approached are not ideal as they add more work to the main thread and
+ are inherently imperative. The AxisAccumulator class allows for this common
+ task to be performed on the Qt 3D backend and be specified in a declarative
+ manner.
+*/
+
+/*!
+ \qmlproperty int Qt3D.Inpit::Axis::value
+ \readonly
+
+ Holds the value accumulated from the sourceAxis.
+*/
+
+/*!
+ * \enum Qt3DInput::QAxisAccumulator::SourceAxisType
+ *
+ * \value Velocity
+ * \value Acceleration
+ */
+
+/*! \internal */
+QAxisAccumulatorPrivate::QAxisAccumulatorPrivate()
+ : Qt3DCore::QNodePrivate()
+ , m_sourceAxis(nullptr)
+ , m_sourceAxisType(QAxisAccumulator::Velocity)
+ , m_scale(1.0f)
+ , m_value(0.0f)
+{
+}
+
+/*! \internal */
+void QAxisAccumulatorPrivate::setValue(float value)
+{
+ if (value != m_value) {
+ m_value = value;
+ q_func()->valueChanged(m_value);
+ }
+}
+
+/*!
+ Constructs a new QAxisAccumulator instance with parent \a parent.
+ */
+QAxisAccumulator::QAxisAccumulator(Qt3DCore::QNode *parent)
+ : Qt3DCore::QNode(*new QAxisAccumulatorPrivate, parent)
+{
+}
+
+/*! \internal */
+QAxisAccumulator::~QAxisAccumulator()
+{
+}
+
+/*!
+ \qmlproperty Axis Qt3D.Input::AxisAccumulator::sourceAxis
+
+ The Axis for which the accumulator should integrate axis values.
+ */
+
+/*!
+ \return QAxis for which the accumulator should integrate axis values.
+ */
+QAxis *QAxisAccumulator::sourceAxis() const
+{
+ Q_D(const QAxisAccumulator);
+ return d->m_sourceAxis;
+}
+
+/*!
+ \qmlproperty SourceAxisType Qt3D.Input::AxisAccumulator::sourceAxisType
+
+ The sourceAxisType property specifies how the accumulator treats the values
+ from the source axis.
+ */
+
+/*!
+ \return how the accumulator treats the value of the sourceAxis.
+ */
+QAxisAccumulator::SourceAxisType QAxisAccumulator::sourceAxisType() const
+{
+ Q_D(const QAxisAccumulator);
+ return d->m_sourceAxisType;
+}
+
+/*!
+ \qmlproperty real Qt3D.Input::AxisAccumulator::value
+
+ The accumulated (integrated) value.
+ */
+
+/*!
+ \return the accumulated (integrated) value.
+ */
+float QAxisAccumulator::value() const
+{
+ Q_D(const QAxisAccumulator);
+ return d->m_value;
+}
+
+/*!
+ \qmlproperty real Qt3D.Input::AxisAccumulator::value
+
+ The amount to scale the axis value by when accumulating. This can be
+ thought of as the maximum velocity or acceleration the axis can
+ control.
+ */
+
+/*!
+ The amount to scale the axis value by when accumulating. This can be
+ thought of as the maximum velocity or acceleration the axis can
+ control.
+
+ \return the amount the input axis values are scaled by.
+ */
+float QAxisAccumulator::scale() const
+{
+ Q_D(const QAxisAccumulator);
+ return d->m_scale;
+}
+
+/*!
+ Sets the source axis from which the accumulator should receive values from to
+ \a sourceAxis. How these values are treated is controlled by the sourceAxisType
+ and scale properties.
+ */
+void QAxisAccumulator::setSourceAxis(QAxis *sourceAxis)
+{
+ Q_D(QAxisAccumulator);
+ if (d->m_sourceAxis == sourceAxis)
+ return;
+
+ if (d->m_sourceAxis)
+ d->unregisterDestructionHelper(d->m_sourceAxis);
+
+ if (sourceAxis && !sourceAxis->parent())
+ sourceAxis->setParent(this);
+ d->m_sourceAxis = sourceAxis;
+
+ // Ensures proper bookkeeping
+ if (d->m_sourceAxis)
+ d->registerDestructionHelper(d->m_sourceAxis, &QAxisAccumulator::setSourceAxis, d->m_sourceAxis);
+
+ emit sourceAxisChanged(sourceAxis);
+}
+
+/*!
+ Sets how the accumulator treats the values originating from the source axis.
+ */
+void QAxisAccumulator::setSourceAxisType(QAxisAccumulator::SourceAxisType sourceAxisType)
+{
+ Q_D(QAxisAccumulator);
+ if (d->m_sourceAxisType == sourceAxisType)
+ return;
+
+ d->m_sourceAxisType = sourceAxisType;
+ emit sourceAxisTypeChanged(sourceAxisType);
+}
+
+void QAxisAccumulator::setScale(float scale)
+{
+ Q_D(QAxisAccumulator);
+ if (d->m_scale == scale)
+ return;
+
+ d->m_scale = scale;
+ emit scaleChanged(scale);
+}
+
+/*! \internal */
+void QAxisAccumulator::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &change)
+{
+ Q_D(QAxisAccumulator);
+ auto e = qSharedPointerCast<Qt3DCore::QPropertyUpdatedChange>(change);
+ if (e->type() == Qt3DCore::PropertyUpdated && e->propertyName() == QByteArrayLiteral("value"))
+ d->setValue(e->value().toFloat());
+}
+
+/*! \internal */
+Qt3DCore::QNodeCreatedChangeBasePtr QAxisAccumulator::createNodeCreationChange() const
+{
+ auto creationChange = Qt3DCore::QNodeCreatedChangePtr<QAxisAccumulatorData>::create(this);
+ auto &data = creationChange->data;
+ Q_D(const QAxisAccumulator);
+ data.sourceAxisId = qIdForNode(d->m_sourceAxis);
+ data.sourceAxisType = d->m_sourceAxisType;
+ data.scale = d->m_scale;
+ return creationChange;
+}
+
+} // namespace Qt3DInput
+
+QT_END_NAMESPACE
diff --git a/src/input/frontend/qaxisaccumulator.h b/src/input/frontend/qaxisaccumulator.h
new file mode 100644
index 000000000..c62e4c35f
--- /dev/null
+++ b/src/input/frontend/qaxisaccumulator.h
@@ -0,0 +1,99 @@
+/****************************************************************************
+**
+** 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_QAXISACCUMULATOR_H
+#define QT3DINPUT_QAXISACCUMULATOR_H
+
+#include <Qt3DInput/qt3dinput_global.h>
+#include <Qt3DCore/qnode.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DInput {
+
+class QAxis;
+class QAxisAccumulatorPrivate;
+
+class QT3DINPUTSHARED_EXPORT QAxisAccumulator : public Qt3DCore::QNode
+{
+ Q_OBJECT
+ Q_PROPERTY(Qt3DInput::QAxis *sourceAxis READ sourceAxis WRITE setSourceAxis NOTIFY sourceAxisChanged)
+ Q_PROPERTY(SourceAxisType sourceAxisType READ sourceAxisType WRITE setSourceAxisType NOTIFY sourceAxisTypeChanged)
+ Q_PROPERTY(float scale READ scale WRITE setScale NOTIFY scaleChanged)
+ Q_PROPERTY(float value READ value NOTIFY valueChanged)
+
+public:
+ enum SourceAxisType {
+ Velocity,
+ Acceleration
+ };
+ Q_ENUM(SourceAxisType)
+
+ QAxisAccumulator(Qt3DCore::QNode *parent = nullptr);
+ ~QAxisAccumulator();
+
+ Qt3DInput::QAxis *sourceAxis() const;
+ SourceAxisType sourceAxisType() const;
+ float value() const;
+ float scale() const;
+
+public Q_SLOTS:
+ void setSourceAxis(Qt3DInput::QAxis *sourceAxis);
+ void setSourceAxisType(QAxisAccumulator::SourceAxisType sourceAxisType);
+ void setScale(float scale);
+
+Q_SIGNALS:
+ void sourceAxisChanged(Qt3DInput::QAxis *sourceAxis);
+ void sourceAxisTypeChanged(QAxisAccumulator::SourceAxisType sourceAxisType);
+ void valueChanged(float value);
+ void scaleChanged(float scale);
+
+protected:
+ void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &change) Q_DECL_OVERRIDE;
+
+private:
+ Q_DECLARE_PRIVATE(QAxisAccumulator)
+ Qt3DCore::QNodeCreatedChangeBasePtr createNodeCreationChange() const Q_DECL_OVERRIDE;
+};
+
+} // namespace Qt3DInput
+
+QT_END_NAMESPACE
+
+#endif // QT3DINPUT_QAXISACCUMULATOR_H
diff --git a/src/input/frontend/qaxisaccumulator_p.h b/src/input/frontend/qaxisaccumulator_p.h
new file mode 100644
index 000000000..a07284009
--- /dev/null
+++ b/src/input/frontend/qaxisaccumulator_p.h
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** 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_QAXISACCUMULATOR_P_H
+#define QT3DINPUT_QAXISACCUMULATOR_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/private/qnode_p.h>
+#include <Qt3DInput/qaxisaccumulator.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DInput {
+
+class QAxisAccumulatorPrivate : public Qt3DCore::QNodePrivate
+{
+public:
+ QAxisAccumulatorPrivate();
+
+ Q_DECLARE_PUBLIC(QAxisAccumulator)
+
+ void setValue(float value);
+
+ QAxis *m_sourceAxis;
+ QAxisAccumulator::SourceAxisType m_sourceAxisType;
+ float m_scale;
+ float m_value;
+};
+
+struct QAxisAccumulatorData
+{
+ Qt3DCore::QNodeId sourceAxisId;
+ QAxisAccumulator::SourceAxisType sourceAxisType;
+ float scale;
+};
+
+} // Qt3DInput
+
+QT_END_NAMESPACE
+
+#endif // QT3DINPUT_QAXISACCUMULATOR_P_H
diff --git a/tests/auto/input/input.pro b/tests/auto/input/input.pro
index 58d2f6aa7..56be4b576 100644
--- a/tests/auto/input/input.pro
+++ b/tests/auto/input/input.pro
@@ -15,5 +15,6 @@ contains(QT_CONFIG, private_tests) {
abstractaxisinput \
analogaxisinput \
buttonaxisinput \
- keyboardhandler
+ keyboardhandler \
+ qaxisaccumulator
}
diff --git a/tests/auto/input/qaxisaccumulator/qaxisaccumulator.pro b/tests/auto/input/qaxisaccumulator/qaxisaccumulator.pro
new file mode 100644
index 000000000..dfc53d12a
--- /dev/null
+++ b/tests/auto/input/qaxisaccumulator/qaxisaccumulator.pro
@@ -0,0 +1,11 @@
+TEMPLATE = app
+
+TARGET = tst_qaxisaccumulator
+
+QT += core-private 3dcore 3dcore-private 3dinput 3dinput-private testlib
+
+CONFIG += testcase
+
+SOURCES += tst_qaxisaccumulator.cpp
+
+include(../../render/commons/commons.pri)
diff --git a/tests/auto/input/qaxisaccumulator/tst_qaxisaccumulator.cpp b/tests/auto/input/qaxisaccumulator/tst_qaxisaccumulator.cpp
new file mode 100644
index 000000000..de7079f31
--- /dev/null
+++ b/tests/auto/input/qaxisaccumulator/tst_qaxisaccumulator.cpp
@@ -0,0 +1,226 @@
+/****************************************************************************
+**
+** 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:GPL-EXCEPT$
+** 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 General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** 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-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QTest>
+#include <Qt3DCore/private/qnode_p.h>
+#include <Qt3DCore/private/qscene_p.h>
+#include <Qt3DCore/private/qnodecreatedchangegenerator_p.h>
+
+#include <Qt3DInput/qaxis.h>
+#include <Qt3DInput/qaxisaccumulator.h>
+#include <Qt3DInput/private/qaxisaccumulator_p.h>
+
+#include <Qt3DCore/QPropertyUpdatedChange>
+#include <Qt3DCore/QPropertyNodeAddedChange>
+#include <Qt3DCore/QPropertyNodeRemovedChange>
+
+#include "testpostmanarbiter.h"
+
+class tst_QAxisAccumulator: public Qt3DInput::QAxisAccumulator
+{
+ Q_OBJECT
+public:
+ tst_QAxisAccumulator()
+ {
+ }
+
+private Q_SLOTS:
+
+ void checkCreationChange_data()
+ {
+ QTest::addColumn<QSharedPointer<Qt3DInput::QAxisAccumulator>>("accumulator");
+ QTest::addColumn<Qt3DInput::QAxis *>("sourceAxis");
+ QTest::addColumn<Qt3DInput::QAxisAccumulator::SourceAxisType>("sourceAxisType");
+ QTest::addColumn<float>("scale");
+
+ {
+ auto accumulator = QSharedPointer<Qt3DInput::QAxisAccumulator>::create();
+ QTest::newRow("defaultConstructed")
+ << accumulator
+ << static_cast<Qt3DInput::QAxis *>(nullptr)
+ << Qt3DInput::QAxisAccumulator::Velocity
+ << 1.0f;
+ }
+
+ {
+ auto accumulator = QSharedPointer<Qt3DInput::QAxisAccumulator>::create();
+ Qt3DInput::QAxis *axis = new Qt3DInput::QAxis();
+ accumulator->setSourceAxis(axis);
+ QTest::newRow("withSourceAxis")
+ << accumulator
+ << axis
+ << Qt3DInput::QAxisAccumulator::Velocity
+ << 1.0f;
+ }
+
+ {
+ auto accumulator = QSharedPointer<Qt3DInput::QAxisAccumulator>::create();
+ accumulator->setSourceAxisType(Qt3DInput::QAxisAccumulator::Acceleration);
+ accumulator->setScale(2.5f);
+ Qt3DInput::QAxis *axis = new Qt3DInput::QAxis();
+ accumulator->setSourceAxis(axis);
+ QTest::newRow("accelerationNonUniformScale")
+ << accumulator
+ << axis
+ << Qt3DInput::QAxisAccumulator::Acceleration
+ << 2.5f;
+ }
+ }
+
+ void checkCreationChange()
+ {
+ // GIVEN
+ QFETCH(QSharedPointer<Qt3DInput::QAxisAccumulator>, accumulator);
+ QFETCH(Qt3DInput::QAxis *, sourceAxis);
+ QFETCH(Qt3DInput::QAxisAccumulator::SourceAxisType, sourceAxisType);
+ QFETCH(float, scale);
+
+ // WHEN
+ Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(accumulator.data());
+ QVector<Qt3DCore::QNodeCreatedChangeBasePtr> creationChanges = creationChangeGenerator.creationChanges();
+
+ // THEN
+ QCOMPARE(creationChanges.size(), sourceAxis ? 2 : 1);
+
+ const auto creationChangeData =
+ qSharedPointerCast<Qt3DCore::QNodeCreatedChange<Qt3DInput::QAxisAccumulatorData>>(creationChanges.first());
+ const Qt3DInput::QAxisAccumulatorData &creationData = creationChangeData->data;
+
+ // THEN
+ QCOMPARE(accumulator->id(), creationChangeData->subjectId());
+ QCOMPARE(accumulator->isEnabled(), creationChangeData->isNodeEnabled());
+ QCOMPARE(accumulator->metaObject(), creationChangeData->metaObject());
+ if (sourceAxis)
+ QCOMPARE(sourceAxis->id(), creationData.sourceAxisId);
+ QCOMPARE(sourceAxisType, creationData.sourceAxisType);
+ QCOMPARE(scale, creationData.scale);
+ }
+
+ void checkPropertyUpdates()
+ {
+ // GIVEN
+ TestArbiter arbiter;
+ QScopedPointer<Qt3DInput::QAxisAccumulator> accumulator(new Qt3DInput::QAxisAccumulator());
+ arbiter.setArbiterOnNode(accumulator.data());
+ Qt3DInput::QAxis *axis = new Qt3DInput::QAxis;
+
+ // WHEN
+ accumulator->setSourceAxis(axis);
+ QCoreApplication::processEvents();
+
+ // THEN
+ QCOMPARE(arbiter.events.size(), 1);
+ Qt3DCore::QPropertyUpdatedChangePtr change = arbiter.events.first().staticCast<Qt3DCore::QPropertyUpdatedChange>();
+ QCOMPARE(change->propertyName(), "sourceAxis");
+ QCOMPARE(change->value().value<Qt3DCore::QNodeId>(), axis->id());
+ QCOMPARE(change->type(), Qt3DCore::PropertyUpdated);
+
+ arbiter.events.clear();
+
+ // WHEN
+ accumulator->setScale(2.0f);
+ QCoreApplication::processEvents();
+
+ // THEN
+ QCOMPARE(arbiter.events.size(), 1);
+ change = arbiter.events.first().staticCast<Qt3DCore::QPropertyUpdatedChange>();
+ QCOMPARE(change->propertyName(), "scale");
+ QCOMPARE(change->value().toFloat(), 2.0f);
+ QCOMPARE(change->type(), Qt3DCore::PropertyUpdated);
+
+ arbiter.events.clear();
+
+ // WHEN
+ accumulator->setSourceAxisType(Qt3DInput::QAxisAccumulator::Acceleration);
+ QCoreApplication::processEvents();
+
+ // THEN
+ QCOMPARE(arbiter.events.size(), 1);
+ change = arbiter.events.first().staticCast<Qt3DCore::QPropertyUpdatedChange>();
+ QCOMPARE(change->propertyName(), "sourceAxisType");
+ QCOMPARE(change->value().value<Qt3DInput::QAxisAccumulator::SourceAxisType>(), Qt3DInput::QAxisAccumulator::Acceleration);
+ QCOMPARE(change->type(), Qt3DCore::PropertyUpdated);
+
+ arbiter.events.clear();
+ }
+
+ void checkValuePropertyChanged()
+ {
+ // GIVEN
+ QCOMPARE(value(), 0.0f);
+
+ // Note: simulate backend change to frontend
+ // WHEN
+ Qt3DCore::QPropertyUpdatedChangePtr valueChange(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId()));
+ valueChange->setPropertyName("value");
+ valueChange->setValue(383.0f);
+ sceneChangeEvent(valueChange);
+
+ // THEN
+ QCOMPARE(value(), 383.0f);
+ }
+
+ void checkAxisInputBookkeeping()
+ {
+ // GIVEN
+ QScopedPointer<Qt3DInput::QAxisAccumulator> accumulator(new Qt3DInput::QAxisAccumulator);
+ {
+ // WHEN
+ Qt3DInput::QAxis axis;
+ accumulator->setSourceAxis(&axis);
+
+ // THEN
+ QCOMPARE(axis.parent(), accumulator.data());
+ QCOMPARE(accumulator->sourceAxis(), &axis);
+ }
+
+ // THEN (Should not crash and parameter be unset)
+ QCOMPARE(accumulator->sourceAxis(), nullptr);
+
+ {
+ // WHEN
+ Qt3DInput::QAxisAccumulator someOtherAccumulator;
+ QScopedPointer<Qt3DInput::QAxis> axis(new Qt3DInput::QAxis(&someOtherAccumulator));
+ accumulator->setSourceAxis(axis.data());
+
+ // THEN
+ QCOMPARE(axis->parent(), &someOtherAccumulator);
+ QCOMPARE(accumulator->sourceAxis(), axis.data());
+
+ // WHEN
+ accumulator.reset();
+ axis.reset();
+
+ // THEN Should not crash when the input is destroyed (tests for failed removal of destruction helper)
+ }
+ }
+};
+
+QTEST_MAIN(tst_QAxisAccumulator)
+
+#include "tst_qaxisaccumulator.moc"