diff options
author | Paul Lemire <paul.lemire@kdab.com> | 2016-06-14 10:13:41 +0200 |
---|---|---|
committer | Paul Lemire <paul.lemire@kdab.com> | 2016-06-30 19:15:37 +0000 |
commit | 9cf9f631f89f9de8c603606d11d47e72d10a6ee7 (patch) | |
tree | 3f3ab59bf1c0417b99973c49fac8ee8cfe581345 /src/input | |
parent | 593543675deb0387635e7eadc28ae6b88a60a4e7 (diff) |
Fix MouseHandler/SourceDevice mouse event dispatching
The MouseHandler was retrieving a MouseDevice pointer and registering
itself against the MouseDevice from a MouseDevice Id.
But this goes against the nature of Qt3D where you have no garantee
about the creation order. So even though the MouseDevice Id was correct
the MouseDevice retrieved was null at that point. This in turn meant
that the MouseHandler wasn't registered and that not even would be transmitted.
This is now fixed by only storing the id and performing the lookup only
when we are sure everything as been created.
Change-Id: I947e95648b1f9f9239527db588fa99b3f12f48dd
Task-number: QTBUG-54067
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src/input')
-rw-r--r-- | src/input/backend/inputhandler.cpp | 21 | ||||
-rw-r--r-- | src/input/backend/mousedevice.cpp | 16 | ||||
-rw-r--r-- | src/input/backend/mousedevice_p.h | 6 | ||||
-rw-r--r-- | src/input/backend/mousehandler.cpp | 10 |
4 files changed, 14 insertions, 39 deletions
diff --git a/src/input/backend/inputhandler.cpp b/src/input/backend/inputhandler.cpp index 51e94b1bd..a26ebce61 100644 --- a/src/input/backend/inputhandler.cpp +++ b/src/input/backend/inputhandler.cpp @@ -251,13 +251,20 @@ QVector<Qt3DCore::QAspectJobPtr> InputHandler::mouseJobs() controller->updateMouseEvents(mouseEvents); // Event dispacthing job if (!mouseEvents.isEmpty() || !wheelEvents.empty()) { - const QVector<Qt3DCore::QNodeId> mouseInputs = controller->mouseInputs(); - for (QNodeId input : mouseInputs) { - MouseEventDispatcherJob *job = new MouseEventDispatcherJob(input, - mouseEvents, - wheelEvents); - job->setInputHandler(this); - jobs.append(QAspectJobPtr(job)); + // Send the events to the mouse handlers that have for sourceDevice controller + const QVector<HMouseHandler> activeMouseHandlers = m_mouseInputManager->activeHandles(); + for (HMouseHandler mouseHandlerHandle : activeMouseHandlers) { + + MouseHandler *mouseHandler = m_mouseInputManager->data(mouseHandlerHandle); + Q_ASSERT(mouseHandler); + + if (mouseHandler->mouseDevice() == controller->peerId()) { + MouseEventDispatcherJob *job = new MouseEventDispatcherJob(mouseHandler->peerId(), + mouseEvents, + wheelEvents); + job->setInputHandler(this); + jobs.append(QAspectJobPtr(job)); + } } } } diff --git a/src/input/backend/mousedevice.cpp b/src/input/backend/mousedevice.cpp index 4fe8f9a86..09ab677f3 100644 --- a/src/input/backend/mousedevice.cpp +++ b/src/input/backend/mousedevice.cpp @@ -76,17 +76,6 @@ void MouseDevice::setInputHandler(InputHandler *handler) m_inputHandler = handler; } -void MouseDevice::addMouseInput(Qt3DCore::QNodeId input) -{ - if (!m_mouseInputs.contains(input)) - m_mouseInputs.append(input); -} - -void MouseDevice::removeMouseInput(Qt3DCore::QNodeId input) -{ - m_mouseInputs.removeOne(input); -} - float MouseDevice::axisValue(int axisIdentifier) const { switch (axisIdentifier) { @@ -116,11 +105,6 @@ bool MouseDevice::isButtonPressed(int buttonIdentifier) const return false; } -QVector<Qt3DCore::QNodeId> MouseDevice::mouseInputs() const -{ - return m_mouseInputs; -} - void MouseDevice::updateMouseEvents(const QList<QT_PREPEND_NAMESPACE(QMouseEvent)> &events) { if (!events.isEmpty()) { diff --git a/src/input/backend/mousedevice_p.h b/src/input/backend/mousedevice_p.h index 73cbd67c2..723945554 100644 --- a/src/input/backend/mousedevice_p.h +++ b/src/input/backend/mousedevice_p.h @@ -72,14 +72,9 @@ public: void setInputHandler(InputHandler *handler); - void addMouseInput(Qt3DCore::QNodeId input); - void removeMouseInput(Qt3DCore::QNodeId input); - float axisValue(int axisIdentifier) const Q_DECL_OVERRIDE; bool isButtonPressed(int buttonIdentifier) const Q_DECL_OVERRIDE; - QVector<Qt3DCore::QNodeId> mouseInputs() const; - void updateMouseEvents(const QList<QT_PREPEND_NAMESPACE(QMouseEvent)> &events); protected: @@ -88,7 +83,6 @@ protected: private: void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) Q_DECL_FINAL; - QVector<Qt3DCore::QNodeId> m_mouseInputs; InputHandler *m_inputHandler; struct MouseState { diff --git a/src/input/backend/mousehandler.cpp b/src/input/backend/mousehandler.cpp index 638c090e5..b7b748843 100644 --- a/src/input/backend/mousehandler.cpp +++ b/src/input/backend/mousehandler.cpp @@ -115,17 +115,7 @@ void MouseHandler::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) void MouseHandler::setDevice(Qt3DCore::QNodeId device) { - if (!m_mouseDevice.isNull()) { - MouseDevice *device = m_inputHandler->mouseDeviceManager()->lookupResource(m_mouseDevice); - if (device) - device->removeMouseInput(peerId()); - } m_mouseDevice = device; - if (!m_mouseDevice.isNull()) { - MouseDevice *device = m_inputHandler->mouseDeviceManager()->lookupResource(m_mouseDevice); - if (device) - device->addMouseInput(peerId()); - } } MouseHandlerFunctor::MouseHandlerFunctor(InputHandler *handler) |