summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2016-01-19 11:53:05 +0100
committerPaul Lemire <paul.lemire@kdab.com>2016-01-19 15:21:25 +0000
commit549013598404fa0b9b48c196adf2570c9e2103a8 (patch)
tree52e64ae0c0b4a2f44c1a9876c175ca1ecb30eb74 /src
parentda6a67b131879d0157b9774017c857bdfeff78c2 (diff)
QInputAspect/InputHandler: add EventSourceSetterHelper member
Change-Id: I4445f150016db8a79997ecc5324e42b024b489b8 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src')
-rw-r--r--src/core/aspects/qaspectengine.cpp15
-rw-r--r--src/input/backend/inputhandler.cpp13
-rw-r--r--src/input/backend/inputhandler_p.h9
-rw-r--r--src/input/frontend/qinputaspect.cpp11
4 files changed, 32 insertions, 16 deletions
diff --git a/src/core/aspects/qaspectengine.cpp b/src/core/aspects/qaspectengine.cpp
index eefe020cb..3aa2b0f95 100644
--- a/src/core/aspects/qaspectengine.cpp
+++ b/src/core/aspects/qaspectengine.cpp
@@ -169,18 +169,9 @@ void QAspectEnginePrivate::shutdown()
void QAspectEngine::setData(const QVariantMap &data)
{
Q_D(QAspectEngine);
-
- // We need to initialize the EventFilterService in the main thread
- // as we can register event filters only on QObjects of the same thread
- QObject *eventSource = Q_NULLPTR;
- const QVariant &eventSourceVariant = data.value(QStringLiteral("eventSource"));
- if (eventSourceVariant.isValid() &&
- (eventSource = eventSourceVariant.value<QObject *>()) != Q_NULLPTR) {
- QEventFilterService *eventFilterService = d->m_aspectThread->aspectManager()->serviceLocator()->eventFilterService();
- if (eventFilterService != Q_NULLPTR)
- eventFilterService->initialize(eventSource);
- }
-
+ // Note: setData in the AspectManager is called in the main thread
+ // which in turns calls onInitialize on each aspects in the main thread
+ // We should keep the call to onInitialize in the main thread
QMetaObject::invokeMethod(d->m_aspectThread->aspectManager(),
"setData",
Qt::BlockingQueuedConnection,
diff --git a/src/input/backend/inputhandler.cpp b/src/input/backend/inputhandler.cpp
index 483772c8e..452fe0e8f 100644
--- a/src/input/backend/inputhandler.cpp
+++ b/src/input/backend/inputhandler.cpp
@@ -43,6 +43,7 @@
#include "mouseeventdispatcherjob_p.h"
#include <Qt3DCore/private/qeventfilterservice_p.h>
#include "inputsettings_p.h"
+#include "eventsourcesetterhelper_p.h"
QT_BEGIN_NAMESPACE
@@ -69,12 +70,17 @@ InputHandler::InputHandler()
, m_logicalDeviceManager(new LogicalDeviceManager())
, m_genericPhysicalDeviceBackendNodeManager(new GenericDeviceBackendNodeManager)
, m_settings(Q_NULLPTR)
+ , m_eventSourceSetter(Q_NULLPTR)
{
m_keyboardEventFilter->setInputHandler(this);
m_mouseEventFilter->setInputHandler(this);
}
-// Called in MainThread
+InputHandler::~InputHandler()
+{
+}
+
+// Called in MainThread (by the EventSourceHelperSetter)
void InputHandler::registerEventFilters(QEventFilterService *service)
{
clearPendingKeyEvents();
@@ -227,6 +233,11 @@ void InputHandler::setInputSettings(InputSettings *settings)
m_settings = settings;
}
+void InputHandler::setEventSourceHelper(EventSourceSetterHelper *helper)
+{
+ m_eventSourceSetter.reset(helper);
+}
+
} // namespace Input
} // namespace Qt3DInput
diff --git a/src/input/backend/inputhandler_p.h b/src/input/backend/inputhandler_p.h
index c2a8fe77f..3ba1e3885 100644
--- a/src/input/backend/inputhandler_p.h
+++ b/src/input/backend/inputhandler_p.h
@@ -84,13 +84,13 @@ class LogicalDeviceManager;
class GenericPhysicalDeviceManager;
class GenericDeviceBackendNodeManager;
class InputSettings;
+class EventSourceSetterHelper;
class InputHandler
{
public:
InputHandler();
-
- void registerEventFilters(Qt3DCore::QEventFilterService *service);
+ ~InputHandler();
inline KeyboardControllerManager *keyboardControllerManager() const { return m_keyboardControllerManager; }
inline KeyboardInputManager *keyboardInputManager() const { return m_keyboardInputManager; }
@@ -132,6 +132,7 @@ public:
void addInputDeviceIntegration(QInputDeviceIntegration *inputIntegration);
void setInputSettings(InputSettings *settings);
+ void setEventSourceHelper(EventSourceSetterHelper *helper);
private:
KeyboardControllerManager *m_keyboardControllerManager;
@@ -160,6 +161,10 @@ private:
GenericDeviceBackendNodeManager *m_genericPhysicalDeviceBackendNodeManager;
QVector<Qt3DInput::QInputDeviceIntegration *> m_inputDeviceIntegrations;
InputSettings *m_settings;
+ QScopedPointer<EventSourceSetterHelper> m_eventSourceSetter;
+
+ void registerEventFilters(Qt3DCore::QEventFilterService *service);
+ friend class EventSourceSetterHelper;
};
} // namespace Input
diff --git a/src/input/frontend/qinputaspect.cpp b/src/input/frontend/qinputaspect.cpp
index f6aecf454..31170935d 100644
--- a/src/input/frontend/qinputaspect.cpp
+++ b/src/input/frontend/qinputaspect.cpp
@@ -82,6 +82,7 @@
#include <Qt3DInput/private/keyboardmousegenericdeviceintegration_p.h>
#include <Qt3DInput/private/genericdevicebackendnode_p.h>
#include <Qt3DInput/private/inputsettings_p.h>
+#include <Qt3DInput/private/eventsourcesetterhelper_p.h>
QT_BEGIN_NAMESPACE
@@ -209,7 +210,15 @@ void QInputAspect::onInitialize(const QVariantMap &)
{
Q_D(QInputAspect);
Qt3DCore::QEventFilterService *eventService = d->services()->eventFilterService();
- d->m_inputHandler->registerEventFilters(eventService);
+ Q_ASSERT(eventService);
+
+ // Create event source setter helper in the main thread
+ Qt3DInput::Input::EventSourceSetterHelper *helper =
+ new Qt3DInput::Input::EventSourceSetterHelper(eventService,
+ d->m_inputHandler.data());
+
+ // Set it on the input handler which will also handle its lifetime
+ d->m_inputHandler->setEventSourceHelper(helper);
}
void QInputAspect::onCleanup()