diff options
author | Mike Krus <mike.krus@kdab.com> | 2019-09-30 16:38:32 +0100 |
---|---|---|
committer | Mike Krus <mike.krus@kdab.com> | 2019-10-01 09:17:52 +0100 |
commit | f06e898718851914bcb4c1d2410e7fd0bc776874 (patch) | |
tree | 3e5c5223ba90b9f598a920540a1290702a80d69a | |
parent | 812bc78ce4b88f612b0d4880723547fe09181f93 (diff) |
Update QLogicalDevice to use direct sync
Change-Id: I6e176c19ceda3ca1c0bf03da4d78fe92ec3344a7
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
-rw-r--r-- | src/input/backend/logicaldevice.cpp | 42 | ||||
-rw-r--r-- | src/input/backend/logicaldevice_p.h | 8 | ||||
-rw-r--r-- | src/input/frontend/qinputaspect.cpp | 2 | ||||
-rw-r--r-- | src/input/frontend/qlogicaldevice.cpp | 25 | ||||
-rw-r--r-- | tests/auto/input/logicaldevice/tst_logicaldevice.cpp | 51 | ||||
-rw-r--r-- | tests/auto/input/qlogicaldevice/tst_qlogicaldevice.cpp | 42 |
6 files changed, 55 insertions, 115 deletions
diff --git a/src/input/backend/logicaldevice.cpp b/src/input/backend/logicaldevice.cpp index 5fcfb07bb..6bea0d85d 100644 --- a/src/input/backend/logicaldevice.cpp +++ b/src/input/backend/logicaldevice.cpp @@ -56,18 +56,10 @@ namespace Qt3DInput { namespace Input { LogicalDevice::LogicalDevice() - : QBackendNode() + : BackendNode() { } -void LogicalDevice::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) -{ - const auto typedChange = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<QLogicalDeviceData>>(change); - const auto &data = typedChange->data; - m_actions = data.actionIds; - m_axes = data.axisIds; -} - void LogicalDevice::cleanup() { QBackendNode::setEnabled(false); @@ -75,31 +67,15 @@ void LogicalDevice::cleanup() m_axes.clear(); } -void LogicalDevice::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) +void LogicalDevice::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) { - switch (e->type()) { - case Qt3DCore::PropertyValueAdded: { - const auto change = qSharedPointerCast<Qt3DCore::QPropertyNodeAddedChange>(e); - if (change->propertyName() == QByteArrayLiteral("axis")) - m_axes.push_back(change->addedNodeId()); - else if (change->propertyName() == QByteArrayLiteral("action")) - m_actions.push_back(change->addedNodeId()); - break; - } - - case Qt3DCore::PropertyValueRemoved: { - const auto change = qSharedPointerCast<Qt3DCore::QPropertyNodeRemovedChange>(e); - if (change->propertyName() == QByteArrayLiteral("axis")) - m_axes.removeOne(change->removedNodeId()); - else if (change->propertyName() == QByteArrayLiteral("action")) - m_actions.removeOne(change->removedNodeId()); - break; - } - - default: - break; - } - QBackendNode::sceneChangeEvent(e); + BackendNode::syncFromFrontEnd(frontEnd, firstTime); + const QLogicalDevice *node = qobject_cast<const QLogicalDevice *>(frontEnd); + if (!node) + return; + + m_actions = Qt3DCore::qIdsForNodes(node->actions()); + m_axes = Qt3DCore::qIdsForNodes(node->axes()); } LogicalDeviceNodeFunctor::LogicalDeviceNodeFunctor(LogicalDeviceManager *manager) diff --git a/src/input/backend/logicaldevice_p.h b/src/input/backend/logicaldevice_p.h index 138a54777..292f2a5c3 100644 --- a/src/input/backend/logicaldevice_p.h +++ b/src/input/backend/logicaldevice_p.h @@ -51,7 +51,7 @@ // We mean it. // -#include <Qt3DCore/qbackendnode.h> +#include <Qt3DInput/private/backendnode_p.h> #include <Qt3DCore/qnodeid.h> QT_BEGIN_NAMESPACE @@ -62,7 +62,7 @@ namespace Input { class LogicalDeviceManager; -class Q_AUTOTEST_EXPORT LogicalDevice : public Qt3DCore::QBackendNode +class Q_AUTOTEST_EXPORT LogicalDevice : public BackendNode { public: LogicalDevice(); @@ -71,11 +71,9 @@ public: inline QVector<Qt3DCore::QNodeId> axes() const { return m_axes; } inline QVector<Qt3DCore::QNodeId> actions() const { return m_actions; } - void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) override; + void syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) override; private: - void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) final; - QVector<Qt3DCore::QNodeId> m_axes; QVector<Qt3DCore::QNodeId> m_actions; }; diff --git a/src/input/frontend/qinputaspect.cpp b/src/input/frontend/qinputaspect.cpp index 110d9877f..6985e71c8 100644 --- a/src/input/frontend/qinputaspect.cpp +++ b/src/input/frontend/qinputaspect.cpp @@ -158,7 +158,7 @@ QInputAspect::QInputAspect(QInputAspectPrivate &dd, QObject *parent) registerBackendType<QActionInput, true>(QBackendNodeMapperPtr(new Input::InputNodeFunctor<Input::ActionInput, Input::ActionInputManager>(d_func()->m_inputHandler->actionInputManager()))); registerBackendType<QInputChord, true>(QBackendNodeMapperPtr(new Input::InputNodeFunctor<Input::InputChord, Input::InputChordManager>(d_func()->m_inputHandler->inputChordManager()))); registerBackendType<QInputSequence, true>(QBackendNodeMapperPtr(new Input::InputNodeFunctor<Input::InputSequence, Input::InputSequenceManager>(d_func()->m_inputHandler->inputSequenceManager()))); - registerBackendType<QLogicalDevice>(QBackendNodeMapperPtr(new Input::LogicalDeviceNodeFunctor(d_func()->m_inputHandler->logicalDeviceManager()))); + registerBackendType<QLogicalDevice, true>(QBackendNodeMapperPtr(new Input::LogicalDeviceNodeFunctor(d_func()->m_inputHandler->logicalDeviceManager()))); registerBackendType<QGenericInputDevice, true>(QBackendNodeMapperPtr(new Input::GenericDeviceBackendFunctor(this, d_func()->m_inputHandler.data()))); registerBackendType<QInputSettings>(QBackendNodeMapperPtr(new Input::InputSettingsFunctor(d_func()->m_inputHandler.data()))); registerBackendType<QAbstractPhysicalDeviceProxy>(QBackendNodeMapperPtr(new Input::PhysicalDeviceProxyNodeFunctor(d_func()->m_inputHandler->physicalDeviceProxyManager()))); diff --git a/src/input/frontend/qlogicaldevice.cpp b/src/input/frontend/qlogicaldevice.cpp index 1e7033962..8869d2116 100644 --- a/src/input/frontend/qlogicaldevice.cpp +++ b/src/input/frontend/qlogicaldevice.cpp @@ -176,11 +176,7 @@ void QLogicalDevice::addAction(QAction *action) // Ensures proper bookkeeping d->registerDestructionHelper(action, &QLogicalDevice::removeAction, d->m_actions); - if (d->m_changeArbiter != nullptr) { - const auto change = Qt3DCore::QPropertyNodeAddedChangePtr::create(id(), action); - change->setPropertyName("action"); - d->notifyObservers(change); - } + d->update(); } } @@ -191,12 +187,7 @@ void QLogicalDevice::removeAction(QAction *action) { Q_D(QLogicalDevice); if (d->m_actions.contains(action)) { - - if (d->m_changeArbiter != nullptr) { - const auto change = Qt3DCore::QPropertyNodeRemovedChangePtr::create(id(), action); - change->setPropertyName("action"); - d->notifyObservers(change); - } + d->update(); d->m_actions.removeOne(action); @@ -236,11 +227,7 @@ void QLogicalDevice::addAxis(QAxis *axis) // Ensures proper bookkeeping d->registerDestructionHelper(axis, &QLogicalDevice::removeAxis, d->m_axes); - if (d->m_changeArbiter != nullptr) { - const auto change = Qt3DCore::QPropertyNodeAddedChangePtr::create(id(), axis); - change->setPropertyName("axis"); - d->notifyObservers(change); - } + d->update(); } } @@ -251,11 +238,7 @@ void QLogicalDevice::removeAxis(QAxis *axis) { Q_D(QLogicalDevice); if (d->m_axes.contains(axis)) { - if (d->m_changeArbiter != nullptr) { - const auto change = Qt3DCore::QPropertyNodeRemovedChangePtr::create(id(), axis); - change->setPropertyName("axis"); - d->notifyObservers(change); - } + d->update(); d->m_axes.removeOne(axis); diff --git a/tests/auto/input/logicaldevice/tst_logicaldevice.cpp b/tests/auto/input/logicaldevice/tst_logicaldevice.cpp index 58c8c7fcb..8dbe24762 100644 --- a/tests/auto/input/logicaldevice/tst_logicaldevice.cpp +++ b/tests/auto/input/logicaldevice/tst_logicaldevice.cpp @@ -59,24 +59,19 @@ private Q_SLOTS: void checkCleanupState() { // GIVEN + Qt3DInput::QLogicalDevice logicalDevice; Qt3DInput::Input::LogicalDevice backendLogicalDevice; + simulateInitializationSync(&logicalDevice, &backendLogicalDevice); // WHEN backendLogicalDevice.setEnabled(true); // WHEN - { - Qt3DInput::QAxis newValue; - const auto change = Qt3DCore::QPropertyNodeAddedChangePtr::create(Qt3DCore::QNodeId(), &newValue); - change->setPropertyName("axis"); - backendLogicalDevice.sceneChangeEvent(change); - } - { - Qt3DInput::QAction newValue; - const auto change = Qt3DCore::QPropertyNodeAddedChangePtr::create(Qt3DCore::QNodeId(), &newValue); - change->setPropertyName("action"); - backendLogicalDevice.sceneChangeEvent(change); - } + Qt3DInput::QAxis newAxisValue; + Qt3DInput::QAction newActionValue; + logicalDevice.addAxis(&newAxisValue); + logicalDevice.addAction(&newActionValue); + backendLogicalDevice.syncFromFrontEnd(&logicalDevice, false); // THEN QCOMPARE(backendLogicalDevice.axes().size(), 1); @@ -104,7 +99,7 @@ private Q_SLOTS: { // WHEN Qt3DInput::Input::LogicalDevice backendLogicalDevice; - simulateInitialization(&logicalDevice, &backendLogicalDevice); + simulateInitializationSync(&logicalDevice, &backendLogicalDevice); // THEN QCOMPARE(backendLogicalDevice.isEnabled(), true); @@ -118,7 +113,7 @@ private Q_SLOTS: // WHEN Qt3DInput::Input::LogicalDevice backendLogicalDevice; logicalDevice.setEnabled(false); - simulateInitialization(&logicalDevice, &backendLogicalDevice); + simulateInitializationSync(&logicalDevice, &backendLogicalDevice); // THEN QCOMPARE(backendLogicalDevice.isEnabled(), false); @@ -128,15 +123,15 @@ private Q_SLOTS: void checkSceneChangeEvents() { // GIVEN + Qt3DInput::QLogicalDevice logicalDevice; Qt3DInput::Input::LogicalDevice backendLogicalDevice; + simulateInitializationSync(&logicalDevice, &backendLogicalDevice); { // WHEN const bool newValue = false; - const auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(Qt3DCore::QNodeId()); - change->setPropertyName("enabled"); - change->setValue(newValue); - backendLogicalDevice.sceneChangeEvent(change); + logicalDevice.setEnabled(newValue); + backendLogicalDevice.syncFromFrontEnd(&logicalDevice, false); // THEN QCOMPARE(backendLogicalDevice.isEnabled(), newValue); @@ -144,18 +139,16 @@ private Q_SLOTS: { // WHEN Qt3DInput::QAxis newValue; - const auto change = Qt3DCore::QPropertyNodeAddedChangePtr::create(Qt3DCore::QNodeId(), &newValue); - change->setPropertyName("axis"); - backendLogicalDevice.sceneChangeEvent(change); + logicalDevice.addAxis(&newValue); + backendLogicalDevice.syncFromFrontEnd(&logicalDevice, false); // THEN QCOMPARE(backendLogicalDevice.axes().size(), 1); QCOMPARE(backendLogicalDevice.axes().first(), newValue.id()); // WHEN - const auto change2 = Qt3DCore::QPropertyNodeRemovedChangePtr::create(Qt3DCore::QNodeId(), &newValue); - change2->setPropertyName("axis"); - backendLogicalDevice.sceneChangeEvent(change2); + logicalDevice.removeAxis(&newValue); + backendLogicalDevice.syncFromFrontEnd(&logicalDevice, false); // THEN QCOMPARE(backendLogicalDevice.axes().size(), 0); @@ -163,18 +156,16 @@ private Q_SLOTS: { // WHEN Qt3DInput::QAction newValue; - const auto change = Qt3DCore::QPropertyNodeAddedChangePtr::create(Qt3DCore::QNodeId(), &newValue); - change->setPropertyName("action"); - backendLogicalDevice.sceneChangeEvent(change); + logicalDevice.addAction(&newValue); + backendLogicalDevice.syncFromFrontEnd(&logicalDevice, false); // THEN QCOMPARE(backendLogicalDevice.actions().size(), 1); QCOMPARE(backendLogicalDevice.actions().first(), newValue.id()); // WHEN - const auto change2 = Qt3DCore::QPropertyNodeRemovedChangePtr::create(Qt3DCore::QNodeId(), &newValue); - change2->setPropertyName("action"); - backendLogicalDevice.sceneChangeEvent(change2); + logicalDevice.removeAction(&newValue); + backendLogicalDevice.syncFromFrontEnd(&logicalDevice, false); // THEN QCOMPARE(backendLogicalDevice.actions().size(), 0); diff --git a/tests/auto/input/qlogicaldevice/tst_qlogicaldevice.cpp b/tests/auto/input/qlogicaldevice/tst_qlogicaldevice.cpp index f81fcee41..5baef08fa 100644 --- a/tests/auto/input/qlogicaldevice/tst_qlogicaldevice.cpp +++ b/tests/auto/input/qlogicaldevice/tst_qlogicaldevice.cpp @@ -122,56 +122,48 @@ private Q_SLOTS: QCoreApplication::processEvents(); // THEN - QCOMPARE(arbiter.events.size(), 1); - Qt3DCore::QPropertyNodeAddedChangePtr nodeAddedChange = arbiter.events.first().staticCast<Qt3DCore::QPropertyNodeAddedChange>(); - QCOMPARE(nodeAddedChange->propertyName(), "action"); - QCOMPARE(nodeAddedChange->addedNodeId(), action->id()); - QCOMPARE(nodeAddedChange->type(), Qt3DCore::PropertyValueAdded); + QCOMPARE(arbiter.events.size(), 0); + QCOMPARE(arbiter.dirtyNodes.size(), 1); + QCOMPARE(arbiter.dirtyNodes.front(), logicalDevice.data()); - arbiter.events.clear(); + arbiter.dirtyNodes.clear(); // WHEN logicalDevice->removeAction(action); QCoreApplication::processEvents(); // THEN - QCOMPARE(arbiter.events.size(), 1); - Qt3DCore::QPropertyNodeRemovedChangePtr nodeRemovedChange = arbiter.events.first().staticCast<Qt3DCore::QPropertyNodeRemovedChange>(); - QCOMPARE(nodeRemovedChange->propertyName(), "action"); - QCOMPARE(nodeRemovedChange->removedNodeId(), action->id()); - QCOMPARE(nodeRemovedChange->type(), Qt3DCore::PropertyValueRemoved); + QCOMPARE(arbiter.events.size(), 0); + QCOMPARE(arbiter.dirtyNodes.size(), 1); + QCOMPARE(arbiter.dirtyNodes.front(), logicalDevice.data()); - arbiter.events.clear(); + arbiter.dirtyNodes.clear(); // WHEN Qt3DInput::QAxis *axis = new Qt3DInput::QAxis(logicalDevice.data()); QCoreApplication::processEvents(); - arbiter.events.clear(); + arbiter.dirtyNodes.clear(); logicalDevice->addAxis(axis); QCoreApplication::processEvents(); // THEN - QCOMPARE(arbiter.events.size(), 1); - nodeAddedChange = arbiter.events.first().staticCast<Qt3DCore::QPropertyNodeAddedChange>(); - QCOMPARE(nodeAddedChange->propertyName(), "axis"); - QCOMPARE(nodeAddedChange->addedNodeId(), axis->id()); - QCOMPARE(nodeAddedChange->type(), Qt3DCore::PropertyValueAdded); + QCOMPARE(arbiter.events.size(), 0); + QCOMPARE(arbiter.dirtyNodes.size(), 1); + QCOMPARE(arbiter.dirtyNodes.front(), logicalDevice.data()); - arbiter.events.clear(); + arbiter.dirtyNodes.clear(); // WHEN logicalDevice->removeAxis(axis); QCoreApplication::processEvents(); // THEN - QCOMPARE(arbiter.events.size(), 1); - nodeRemovedChange = arbiter.events.first().staticCast<Qt3DCore::QPropertyNodeRemovedChange>(); - QCOMPARE(nodeRemovedChange->propertyName(), "axis"); - QCOMPARE(nodeRemovedChange->removedNodeId(), axis->id()); - QCOMPARE(nodeRemovedChange->type(), Qt3DCore::PropertyValueRemoved); + QCOMPARE(arbiter.events.size(), 0); + QCOMPARE(arbiter.dirtyNodes.size(), 1); + QCOMPARE(arbiter.dirtyNodes.front(), logicalDevice.data()); - arbiter.events.clear(); + arbiter.dirtyNodes.clear(); } void checkAxisBookkeeping() |