20 #include <qpa/qwindowsysteminterface.h>
21 #include <QtGui/QGuiApplication>
25 #include <TouchRegistry.h>
30 TestUtil::TestUtil(QObject *parent)
34 , m_installedTouchRegistry(false)
43 TestUtil::isInstanceOf(QObject *obj, QString name)
45 if (!obj)
return false;
46 bool result = obj->inherits(name.toUtf8());
48 const QMetaObject *metaObject = obj->metaObject();
49 while (!result && metaObject) {
50 const QString className = metaObject->className();
51 const QString qmlName = className.left(className.indexOf(
"_QMLTYPE_"));
52 result = qmlName == name;
53 metaObject = metaObject->superClass();
59 TouchEventSequenceWrapper *TestUtil::touchEvent()
63 ensureTouchRegistryInstalled();
65 return new TouchEventSequenceWrapper(
66 QTest::touchEvent(m_targetWindow, m_touchDevice,
false));
69 void TestUtil::ensureTargetWindow()
71 if (!m_targetWindow && !QGuiApplication::topLevelWindows().isEmpty())
72 m_targetWindow = QGuiApplication::topLevelWindows()[0];
75 void TestUtil::ensureTouchDevice()
78 m_touchDevice =
new QTouchDevice;
79 m_touchDevice->setType(QTouchDevice::TouchScreen);
80 QWindowSystemInterface::registerTouchDevice(m_touchDevice);
84 void TestUtil::ensureTouchRegistryInstalled()
86 if (m_installedTouchRegistry)
89 TouchRegistry *touchRegistry;
90 if (TouchRegistry::instance() ==
nullptr) {
93 touchRegistry =
new TouchRegistry(
this,
new FakeTimerFactory);
95 touchRegistry = TouchRegistry::instance();
96 if (touchRegistry->parent() !=
this) {
98 m_installedTouchRegistry =
true;
102 ensureTargetWindow();
104 if (m_targetWindow) {
105 QQuickView *view = qobject_cast<QQuickView*>(m_targetWindow);
107 view->installEventFilter(touchRegistry);
108 touchRegistry->setParent(view);
109 m_installedTouchRegistry =
true;