on xenial help sign in
Make Ubuntu.Gestures components install TouchRegistry by themselves

That way Ubuntu.Gestures users don't have to write C++ code to do it. TouchRegistry then being an implementation detail they don't have to know about. Approved by: Mirco Müller

commit12fdb5fc366b11b85a13f4677dcaf6c9c8ef87e7 authorDaniel d'Andrada <daniel.dandrada@canonical.com> dateMon 18 May 2015, 23:04 (11 years ago) parentffbe66d0561266
20 files changed+155−183
libs/UbuntuGestures/CandidateInactivityTimer.cpp+7−2 libs/UbuntuGestures/CandidateInactivityTimer.h+3−1 libs/UbuntuGestures/Timer.cpp−10 libs/UbuntuGestures/Timer.h+1−1 libs/UbuntuGestures/TouchRegistry.cpp+16−12 libs/UbuntuGestures/TouchRegistry.h+8−6 plugins/Ubuntu/Gestures/DirectionalDragArea.cpp+2 plugins/Ubuntu/Gestures/TouchGate.cpp+10 plugins/Ubuntu/Gestures/TouchGate.h+1 src/Dash/main.cpp−6 src/main.cpp−5 tests/libs/UbuntuGestures/tst_TouchRegistry.cpp+75−76 tests/plugins/Ubuntu/Gestures/GestureTest.cpp+2−1 tests/plugins/Ubuntu/Gestures/tst_DirectionalDragArea.cpp+20−20 tests/plugins/Ubuntu/Gestures/tst_TouchGate.cpp+1−2 tests/qmltests/Components/tst_DragHandle.cpp−8 tests/uqmlscene/main.cpp−10 tests/utils/modules/Unity/Test/UnityTestCase.qml−2 tests/utils/modules/Unity/Test/testutil.cpp+8−20 tests/utils/modules/Unity/Test/testutil.h+1−1
libs/UbuntuGestures/CandidateInactivityTimer.cpp+7−2
@@ -19,12 +19,12 @@
1919namespace UbuntuGestures {
2020
2121CandidateInactivityTimer::CandidateInactivityTimer(int touchId, QQuickItem *candidate,
22− AbstractTimerFactory &timerFactory, QObject *parent)
22+ AbstractTimer *timer, QObject *parent)
2323 : QObject(parent)
24+ , m_timer(timer)
2425 , m_touchId(touchId)
2526 , m_candidate(candidate)
2627{
27− m_timer = timerFactory.createTimer(this);
2828 connect(m_timer, &AbstractTimer::timeout,
2929 this, &CandidateInactivityTimer::onTimeout);
3030 m_timer->setInterval(durationMs);
@@ -32,6 +32,11 @@ CandidateInactivityTimer::CandidateInactivityTimer(int touchId, QQuickItem *cand
3232 m_timer->start();
3333}
3434
35+CandidateInactivityTimer::~CandidateInactivityTimer()
36+{
37+ delete m_timer;
38+}
39+
3540void CandidateInactivityTimer::onTimeout()
3641{
3742 qWarning("[TouchRegistry] Candidate for touch %d defaulted!", m_touchId);
libs/UbuntuGestures/CandidateInactivityTimer.h+3−1
@@ -29,9 +29,11 @@ class UBUNTUGESTURES_EXPORT CandidateInactivityTimer : public QObject {
2929 Q_OBJECT
3030public:
3131 CandidateInactivityTimer(int touchId, QQuickItem *candidate,
32− AbstractTimerFactory &timerFactory,
32+ AbstractTimer *timer,
3333 QObject *parent = nullptr);
3434
35+ virtual ~CandidateInactivityTimer();
36+
3537 const int durationMs = 1000;
3638
3739Q_SIGNALS:
libs/UbuntuGestures/Timer.cpp−10
@@ -115,16 +115,6 @@ FakeTimerFactory::FakeTimerFactory()
115115 m_timeSource.reset(new FakeTimeSource);
116116}
117117
118−FakeTimerFactory::~FakeTimerFactory()
119−{
120− for (int i = 0; i < timers.count(); ++i) {
121− FakeTimer *timer = timers[i].data();
122− if (timer) {
123− delete timer;
124− }
125− }
126−}
127−
128118void FakeTimerFactory::updateTime(qint64 targetTime)
129119{
130120 qint64 minTimeoutTime = targetTime;
libs/UbuntuGestures/Timer.h+1−1
@@ -101,7 +101,7 @@ class UBUNTUGESTURES_EXPORT FakeTimerFactory : public AbstractTimerFactory
101101{
102102public:
103103 FakeTimerFactory();
104− virtual ~FakeTimerFactory();
104+ virtual ~FakeTimerFactory() {}
105105
106106 void updateTime(qint64 msecsSinceReference);
107107 QSharedPointer<TimeSource> timeSource() { return m_timeSource; }
libs/UbuntuGestures/TouchRegistry.cpp+16−12
@@ -41,20 +41,10 @@ using namespace UbuntuGestures;
4141TouchRegistry *TouchRegistry::m_instance = nullptr;
4242
4343TouchRegistry::TouchRegistry(QObject *parent)
44− : TouchRegistry(parent, new TimerFactory)
45−{
46−}
47−
48−TouchRegistry::TouchRegistry(QObject *parent, AbstractTimerFactory *timerFactory)
4944 : QObject(parent)
5045 , m_inDispatchLoop(false)
51− , m_timerFactory(timerFactory)
46+ , m_timerFactory(new TimerFactory)
5247{
53− if (m_instance == nullptr) {
54− m_instance = this;
55− } else {
56− qFatal("Cannot have more than one instance of TouchRegistry. It must be a singleton.");
57− }
5848}
5949
6050TouchRegistry::~TouchRegistry()
@@ -64,6 +54,20 @@ TouchRegistry::~TouchRegistry()
6454 delete m_timerFactory;
6555}
6656
57+TouchRegistry *TouchRegistry::instance()
58+{
59+ if (m_instance == nullptr) {
60+ m_instance = new TouchRegistry;
61+ }
62+ return m_instance;
63+}
64+
65+void TouchRegistry::setTimerFactory(AbstractTimerFactory *timerFactory)
66+{
67+ delete m_timerFactory;
68+ m_timerFactory = timerFactory;
69+}
70+
6771void TouchRegistry::update(const QTouchEvent *event)
6872{
6973 #if TOUCHREGISTRY_DEBUG
@@ -261,7 +265,7 @@ void TouchRegistry::addCandidateOwnerForTouch(int id, QQuickItem *candidate)
261265 candidateInfo.state = CandidateInfo::Undecided;
262266 candidateInfo.item = candidate;
263267 candidateInfo.inactivityTimer = new CandidateInactivityTimer(id, candidate,
264− *m_timerFactory,
268+ m_timerFactory->createTimer(),
265269 this);
266270 connect(candidateInfo.inactivityTimer, &CandidateInactivityTimer::candidateDefaulted,
267271 this, &TouchRegistry::rejectCandidateOwnerForTouch);
libs/UbuntuGestures/TouchRegistry.h+8−6
@@ -25,6 +25,7 @@
2525
2626#include "UbuntuGesturesGlobal.h"
2727#include "CandidateInactivityTimer.h"
28+#include "Timer.h"
2829#include "Pool.h"
2930
3031namespace UbuntuGestures {
@@ -93,15 +94,10 @@ class UBUNTUGESTURES_EXPORT TouchRegistry : public QObject
9394{
9495 Q_OBJECT
9596public:
96− TouchRegistry(QObject *parent = nullptr);
97− // Useful for tests, where you should feed a fake timer
98− TouchRegistry(QObject *parent, UbuntuGestures::AbstractTimerFactory *timerFactory);
99−
10097 virtual ~TouchRegistry();
10198
10299 // Returns a pointer to the application's TouchRegistry instance.
103− // If no instance has been allocated, null is returned.
104− static TouchRegistry *instance() { return m_instance; }
100+ static TouchRegistry *instance();
105101
106102 void update(const QTouchEvent *event);
107103
@@ -128,10 +124,16 @@ public:
128124 // but would nonetheless like to be kept up-to-date on its state.
129125 void addTouchWatcher(int touchId, QQuickItem *watcherItem);
130126
127+ // Useful for tests, where you should use fake timers
128+ void setTimerFactory(UbuntuGestures::AbstractTimerFactory *timerFactory);
129+
131130private Q_SLOTS:
132131 void rejectCandidateOwnerForTouch(int id, QQuickItem *candidate);
133132
134133private:
134+ // Only instance() can cronstruct one
135+ TouchRegistry(QObject *parent = nullptr);
136+
135137 class CandidateInfo {
136138 public:
137139 enum {
plugins/Ubuntu/Gestures/DirectionalDragArea.cpp+2
@@ -712,6 +712,8 @@ void DirectionalDragArea::itemChange(ItemChange change, const ItemChangeData &va
712712{
713713 if (change == QQuickItem::ItemSceneChange) {
714714 if (value.window != nullptr) {
715+ value.window->installEventFilter(TouchRegistry::instance());
716+
715717 // TODO: Handle window->screen() changes (ie window changing screens)
716718 qreal pixelsPerMm = value.window->screen()->physicalDotsPerInch() / 25.4;
717719 d->setPixelsPerMm(pixelsPerMm);
plugins/Ubuntu/Gestures/TouchGate.cpp+10
@@ -18,6 +18,7 @@
1818
1919#include <QCoreApplication>
2020#include <QDebug>
21+#include <QQuickWindow>
2122
2223#include <TouchOwnershipEvent.h>
2324#include <TouchRegistry.h>
@@ -102,6 +103,15 @@ void TouchGate::touchEvent(QTouchEvent *event)
102103 }
103104}
104105
106+void TouchGate::itemChange(ItemChange change, const ItemChangeData &value)
107+{
108+ if (change == QQuickItem::ItemSceneChange) {
109+ if (value.window != nullptr) {
110+ value.window->installEventFilter(TouchRegistry::instance());
111+ }
112+ }
113+}
114+
105115void TouchGate::touchOwnershipEvent(TouchOwnershipEvent *event)
106116{
107117 // TODO: Optimization: batch those actions as TouchOwnershipEvents
plugins/Ubuntu/Gestures/TouchGate.h+1
@@ -57,6 +57,7 @@ Q_SIGNALS:
5757
5858protected:
5959 void touchEvent(QTouchEvent *event) override;
60+ void itemChange(ItemChange change, const ItemChangeData &value) override;
6061
6162private Q_SLOTS:
6263 void onEnabledChanged();
src/Dash/main.cpp−6
@@ -31,9 +31,6 @@
3131#include "../ApplicationArguments.h"
3232#include "../CachingNetworkManagerFactory.h"
3333
34−// Ubuntu Gestures
35−#include <TouchRegistry.h>
36−
3734int main(int argc, const char *argv[])
3835{
3936 QGuiApplication *application = new QGuiApplication(argc, (char**)argv);
@@ -91,9 +88,6 @@ int main(int argc, const char *argv[])
9188 view->setTitle("Scopes");
9289 view->rootContext()->setContextProperty("applicationArguments", &qmlArgs);
9390
94− TouchRegistry touchRegistry;
95− view->installEventFilter(&touchRegistry);
96−
9791 // You will need this if you want to interact with touch-only components using a mouse
9892 // Needed only when manually testing on a desktop.
9993 MouseTouchAdaptor *mouseTouchAdaptor = 0;
src/main.cpp−5
@@ -32,9 +32,6 @@
3232#include "CachingNetworkManagerFactory.h"
3333#include "UnityCommandLineParser.h"
3434
35−// Ubuntu Gestures
36−#include <TouchRegistry.h>
37−
3835int main(int argc, const char *argv[])
3936{
4037 bool isMirServer = false;
@@ -89,8 +86,6 @@ int main(int argc, const char *argv[])
8986 if (parser.hasFrameless()) {
9087 view->setFlags(Qt::FramelessWindowHint);
9188 }
92− TouchRegistry touchRegistry;
93− view->installEventFilter(&touchRegistry);
9489
9590 // You will need this if you want to interact with touch-only components using a mouse
9691 // Needed only when manually testing on a desktop.
tests/libs/UbuntuGestures/tst_TouchRegistry.cpp+75−76
@@ -53,8 +53,8 @@ private Q_SLOTS:
5353 void initTestCase() {} // will be called before the first test function is executed
5454 void cleanupTestCase() {} // will be called after the last test function was executed.
5555
56− void init() {} // called right before each and every test function is executed
57− void cleanup() {} // called right after each and every test function is executed
56+ void init(); // called right before each and every test function is executed
57+ void cleanup(); // called right after each and every test function is executed
5858
5959 void requestWithNoCandidates();
6060 void lateCandidateRequestGetsNothing();
@@ -67,11 +67,23 @@ private Q_SLOTS:
6767 void rejectingTouchfterItsEnd();
6868 void removeOldUndecidedCandidates();
6969 void interimOwnerWontGetUnownedTouchEvents();
70+
71+private:
72+ TouchRegistry *touchRegistry;
7073};
7174
75+void tst_TouchRegistry::init()
76+{
77+ touchRegistry = TouchRegistry::instance();
78+}
79+
80+void tst_TouchRegistry::cleanup()
81+{
82+ delete touchRegistry;
83+}
84+
7285void tst_TouchRegistry::requestWithNoCandidates()
7386{
74− TouchRegistry touchRegistry;
7587 DummyCandidate candidate;
7688
7789 {
@@ -83,17 +95,16 @@ void tst_TouchRegistry::requestWithNoCandidates()
8395 Qt::NoModifier,
8496 Qt::TouchPointPressed,
8597 touchPoints);
86− touchRegistry.update(&touchEvent);
98+ touchRegistry->update(&touchEvent);
8799 }
88100
89− touchRegistry.requestTouchOwnership(0, &candidate);
101+ touchRegistry->requestTouchOwnership(0, &candidate);
90102
91103 QVERIFY(candidate.ownedTouches.contains(0));
92104}
93105
94106void tst_TouchRegistry::lateCandidateRequestGetsNothing()
95107{
96− TouchRegistry touchRegistry;
97108 DummyCandidate earlyCandidate;
98109 earlyCandidate.setObjectName("early");
99110 DummyCandidate lateCandidate;
@@ -108,21 +119,21 @@ void tst_TouchRegistry::lateCandidateRequestGetsNothing()
108119 Qt::NoModifier,
109120 Qt::TouchPointPressed,
110121 touchPoints);
111− touchRegistry.update(&touchEvent);
122+ touchRegistry->update(&touchEvent);
112123 }
113124
114− touchRegistry.addCandidateOwnerForTouch(0, &earlyCandidate);
115− touchRegistry.addCandidateOwnerForTouch(0, &lateCandidate);
125+ touchRegistry->addCandidateOwnerForTouch(0, &earlyCandidate);
126+ touchRegistry->addCandidateOwnerForTouch(0, &lateCandidate);
116127
117128 QVERIFY(earlyCandidate.ownedTouches.isEmpty());
118129 QVERIFY(lateCandidate.ownedTouches.isEmpty());
119130
120− touchRegistry.requestTouchOwnership(0, &lateCandidate);
131+ touchRegistry->requestTouchOwnership(0, &lateCandidate);
121132
122133 QVERIFY(earlyCandidate.ownedTouches.isEmpty());
123134 QVERIFY(lateCandidate.ownedTouches.isEmpty());
124135
125− touchRegistry.requestTouchOwnership(0, &earlyCandidate);
136+ touchRegistry->requestTouchOwnership(0, &earlyCandidate);
126137
127138 QVERIFY(earlyCandidate.ownedTouches.contains(0));
128139 QVERIFY(lateCandidate.ownedTouches.isEmpty());
@@ -130,7 +141,6 @@ void tst_TouchRegistry::lateCandidateRequestGetsNothing()
130141
131142void tst_TouchRegistry::lateCandidateGestOwnershipOnceEarlyCandidateQuits()
132143{
133− TouchRegistry touchRegistry;
134144 DummyCandidate earlyCandidate;
135145 DummyCandidate lateCandidate;
136146
@@ -143,21 +153,21 @@ void tst_TouchRegistry::lateCandidateGestOwnershipOnceEarlyCandidateQuits()
143153 Qt::NoModifier,
144154 Qt::TouchPointPressed,
145155 touchPoints);
146− touchRegistry.update(&touchEvent);
156+ touchRegistry->update(&touchEvent);
147157 }
148158
149− touchRegistry.addCandidateOwnerForTouch(0, &earlyCandidate);
150− touchRegistry.addCandidateOwnerForTouch(0, &lateCandidate);
159+ touchRegistry->addCandidateOwnerForTouch(0, &earlyCandidate);
160+ touchRegistry->addCandidateOwnerForTouch(0, &lateCandidate);
151161
152162 QVERIFY(earlyCandidate.ownedTouches.isEmpty());
153163 QVERIFY(lateCandidate.ownedTouches.isEmpty());
154164
155− touchRegistry.requestTouchOwnership(0, &lateCandidate);
165+ touchRegistry->requestTouchOwnership(0, &lateCandidate);
156166
157167 QVERIFY(earlyCandidate.ownedTouches.isEmpty());
158168 QVERIFY(lateCandidate.ownedTouches.isEmpty());
159169
160− touchRegistry.removeCandidateOwnerForTouch(0, &earlyCandidate);
170+ touchRegistry->removeCandidateOwnerForTouch(0, &earlyCandidate);
161171
162172 QVERIFY(earlyCandidate.ownedTouches.isEmpty());
163173 QVERIFY(lateCandidate.ownedTouches.contains(0));
@@ -165,7 +175,6 @@ void tst_TouchRegistry::lateCandidateGestOwnershipOnceEarlyCandidateQuits()
165175
166176void tst_TouchRegistry::dispatchesTouchEventsToCandidates()
167177{
168− TouchRegistry touchRegistry;
169178 QQuickItem rootItem;
170179
171180 DummyCandidate candidate0;
@@ -190,10 +199,10 @@ void tst_TouchRegistry::dispatchesTouchEventsToCandidates()
190199 Qt::NoModifier,
191200 Qt::TouchPointPressed,
192201 touchPoints);
193− touchRegistry.update(&touchEvent);
202+ touchRegistry->update(&touchEvent);
194203 }
195204
196− touchRegistry.addCandidateOwnerForTouch(0, &candidate0);
205+ touchRegistry->addCandidateOwnerForTouch(0, &candidate0);
197206
198207 {
199208 QList<QTouchEvent::TouchPoint> touchPoints;
@@ -208,7 +217,7 @@ void tst_TouchRegistry::dispatchesTouchEventsToCandidates()
208217 Qt::NoModifier,
209218 Qt::TouchPointPressed | Qt::TouchPointMoved,
210219 touchPoints);
211− touchRegistry.update(&touchEvent);
220+ touchRegistry->update(&touchEvent);
212221 }
213222
214223 // candidate0 should have received an update on the touch he's interested on.
@@ -220,7 +229,7 @@ void tst_TouchRegistry::dispatchesTouchEventsToCandidates()
220229 QCOMPARE(candidate0.unownedTouchEvents[0].touchPoints[0].rect().x(), 11 - candidate0.x());
221230 QCOMPARE(candidate0.unownedTouchEvents[0].touchPoints[0].rect().y(), 11 - candidate0.y());
222231
223− touchRegistry.addCandidateOwnerForTouch(1, &candidate1);
232+ touchRegistry->addCandidateOwnerForTouch(1, &candidate1);
224233
225234 {
226235 QList<QTouchEvent::TouchPoint> touchPoints;
@@ -235,7 +244,7 @@ void tst_TouchRegistry::dispatchesTouchEventsToCandidates()
235244 Qt::NoModifier,
236245 Qt::TouchPointPressed | Qt::TouchPointMoved,
237246 touchPoints);
238− touchRegistry.update(&touchEvent);
247+ touchRegistry->update(&touchEvent);
239248 }
240249
241250 // candidate0 gets updates only for touch 0 and
@@ -252,7 +261,6 @@ void tst_TouchRegistry::dispatchesTouchEventsToCandidates()
252261
253262void tst_TouchRegistry::dispatchesTouchEventsToWatchers()
254263{
255− TouchRegistry touchRegistry;
256264 QQuickItem rootItem;
257265
258266 DummyCandidate watcher;
@@ -271,10 +279,10 @@ void tst_TouchRegistry::dispatchesTouchEventsToWatchers()
271279 Qt::NoModifier,
272280 Qt::TouchPointPressed,
273281 touchPoints);
274− touchRegistry.update(&touchEvent);
282+ touchRegistry->update(&touchEvent);
275283 }
276284
277− touchRegistry.addTouchWatcher(0, &watcher);
285+ touchRegistry->addTouchWatcher(0, &watcher);
278286
279287 {
280288 QList<QTouchEvent::TouchPoint> touchPoints;
@@ -289,7 +297,7 @@ void tst_TouchRegistry::dispatchesTouchEventsToWatchers()
289297 Qt::NoModifier,
290298 Qt::TouchPointPressed | Qt::TouchPointMoved,
291299 touchPoints);
292− touchRegistry.update(&touchEvent);
300+ touchRegistry->update(&touchEvent);
293301 }
294302
295303 // watcher should have received an update on the touch he's interested on.
@@ -314,7 +322,7 @@ void tst_TouchRegistry::dispatchesTouchEventsToWatchers()
314322 Qt::NoModifier,
315323 Qt::TouchPointPressed | Qt::TouchPointMoved,
316324 touchPoints);
317− touchRegistry.update(&touchEvent);
325+ touchRegistry->update(&touchEvent);
318326 }
319327
320328 // watcher gets updates only for touch 0
@@ -326,7 +334,6 @@ void tst_TouchRegistry::dispatchesTouchEventsToWatchers()
326334
327335void tst_TouchRegistry::keepDispatchingToWatchersAfterLastCandidateGivesUp()
328336{
329− TouchRegistry touchRegistry;
330337 DummyCandidate item;
331338
332339 {
@@ -338,10 +345,10 @@ void tst_TouchRegistry::keepDispatchingToWatchersAfterLastCandidateGivesUp()
338345 Qt::NoModifier,
339346 Qt::TouchPointPressed,
340347 touchPoints);
341− touchRegistry.update(&touchEvent);
348+ touchRegistry->update(&touchEvent);
342349 }
343350
344− touchRegistry.addCandidateOwnerForTouch(0, &item);
351+ touchRegistry->addCandidateOwnerForTouch(0, &item);
345352
346353 {
347354 QList<QTouchEvent::TouchPoint> touchPoints;
@@ -354,7 +361,7 @@ void tst_TouchRegistry::keepDispatchingToWatchersAfterLastCandidateGivesUp()
354361 Qt::NoModifier,
355362 Qt::TouchPointPressed | Qt::TouchPointMoved,
356363 touchPoints);
357− touchRegistry.update(&touchEvent);
364+ touchRegistry->update(&touchEvent);
358365 }
359366
360367 QCOMPARE(item.unownedTouchEvents.count(), 1);
@@ -362,7 +369,7 @@ void tst_TouchRegistry::keepDispatchingToWatchersAfterLastCandidateGivesUp()
362369 QCOMPARE(item.unownedTouchEvents[0].touchPoints[0].id(), 0);
363370 item.unownedTouchEvents.clear();
364371
365− touchRegistry.addTouchWatcher(1, &item);
372+ touchRegistry->addTouchWatcher(1, &item);
366373
367374 {
368375 QList<QTouchEvent::TouchPoint> touchPoints;
@@ -375,7 +382,7 @@ void tst_TouchRegistry::keepDispatchingToWatchersAfterLastCandidateGivesUp()
375382 Qt::NoModifier,
376383 Qt::TouchPointMoved,
377384 touchPoints);
378− touchRegistry.update(&touchEvent);
385+ touchRegistry->update(&touchEvent);
379386 }
380387
381388 QCOMPARE(item.unownedTouchEvents.count(), 1);
@@ -395,7 +402,7 @@ void tst_TouchRegistry::keepDispatchingToWatchersAfterLastCandidateGivesUp()
395402 Qt::NoModifier,
396403 Qt::TouchPointReleased | Qt::TouchPointMoved,
397404 touchPoints);
398− touchRegistry.update(&touchEvent);
405+ touchRegistry->update(&touchEvent);
399406 }
400407
401408 QCOMPARE(item.unownedTouchEvents.count(), 1);
@@ -404,7 +411,7 @@ void tst_TouchRegistry::keepDispatchingToWatchersAfterLastCandidateGivesUp()
404411 QVERIFY(item.unownedTouchEvents[0].containsTouchWithId(1));
405412 item.unownedTouchEvents.clear();
406413
407− touchRegistry.removeCandidateOwnerForTouch(0, &item);
414+ touchRegistry->removeCandidateOwnerForTouch(0, &item);
408415
409416 {
410417 QList<QTouchEvent::TouchPoint> touchPoints;
@@ -415,7 +422,7 @@ void tst_TouchRegistry::keepDispatchingToWatchersAfterLastCandidateGivesUp()
415422 Qt::NoModifier,
416423 Qt::TouchPointReleased,
417424 touchPoints);
418− touchRegistry.update(&touchEvent);
425+ touchRegistry->update(&touchEvent);
419426 }
420427
421428 QCOMPARE(item.unownedTouchEvents.count(), 1);
@@ -423,7 +430,7 @@ void tst_TouchRegistry::keepDispatchingToWatchersAfterLastCandidateGivesUp()
423430 QVERIFY(item.unownedTouchEvents[0].containsTouchWithId(1));
424431 item.unownedTouchEvents.clear();
425432
426− QVERIFY(touchRegistry.m_touchInfoPool.isEmpty());
433+ QVERIFY(touchRegistry->m_touchInfoPool.isEmpty());
427434}
428435
429436/*
@@ -432,7 +439,6 @@ void tst_TouchRegistry::keepDispatchingToWatchersAfterLastCandidateGivesUp()
432439 */
433440void tst_TouchRegistry::candidatesAndWatchers_1()
434441{
435− TouchRegistry touchRegistry;
436442 DummyCandidate item;
437443
438444 {
@@ -444,10 +450,10 @@ void tst_TouchRegistry::candidatesAndWatchers_1()
444450 Qt::NoModifier,
445451 Qt::TouchPointPressed,
446452 touchPoints);
447− touchRegistry.update(&touchEvent);
453+ touchRegistry->update(&touchEvent);
448454 }
449455
450− touchRegistry.addCandidateOwnerForTouch(0, &item);
456+ touchRegistry->addCandidateOwnerForTouch(0, &item);
451457
452458 {
453459 QList<QTouchEvent::TouchPoint> touchPoints;
@@ -460,14 +466,14 @@ void tst_TouchRegistry::candidatesAndWatchers_1()
460466 Qt::NoModifier,
461467 Qt::TouchPointPressed | Qt::TouchPointMoved,
462468 touchPoints);
463− touchRegistry.update(&touchEvent);
469+ touchRegistry->update(&touchEvent);
464470 }
465471
466− touchRegistry.addTouchWatcher(1, &item);
472+ touchRegistry->addTouchWatcher(1, &item);
467473
468− touchRegistry.removeCandidateOwnerForTouch(0, &item);
474+ touchRegistry->removeCandidateOwnerForTouch(0, &item);
469475
470− touchRegistry.addTouchWatcher(0, &item);
476+ touchRegistry->addTouchWatcher(0, &item);
471477
472478 {
473479 QList<QTouchEvent::TouchPoint> touchPoints;
@@ -480,7 +486,7 @@ void tst_TouchRegistry::candidatesAndWatchers_1()
480486 Qt::NoModifier,
481487 Qt::TouchPointReleased | Qt::TouchPointMoved,
482488 touchPoints);
483− touchRegistry.update(&touchEvent);
489+ touchRegistry->update(&touchEvent);
484490 }
485491
486492 {
@@ -492,10 +498,10 @@ void tst_TouchRegistry::candidatesAndWatchers_1()
492498 Qt::NoModifier,
493499 Qt::TouchPointReleased,
494500 touchPoints);
495− touchRegistry.update(&touchEvent);
501+ touchRegistry->update(&touchEvent);
496502 }
497503
498− QVERIFY(touchRegistry.m_touchInfoPool.isEmpty());
504+ QVERIFY(touchRegistry->m_touchInfoPool.isEmpty());
499505
500506 item.unownedTouchEvents.clear();
501507
@@ -508,7 +514,7 @@ void tst_TouchRegistry::candidatesAndWatchers_1()
508514 Qt::NoModifier,
509515 Qt::TouchPointPressed,
510516 touchPoints);
511− touchRegistry.update(&touchEvent);
517+ touchRegistry->update(&touchEvent);
512518 }
513519
514520 // Haven't made any subscription for that new touch 0.
@@ -521,8 +527,6 @@ void tst_TouchRegistry::candidatesAndWatchers_1()
521527 */
522528void tst_TouchRegistry::candidatesAndWatchers_2()
523529{
524− TouchRegistry touchRegistry;
525−
526530 DummyCandidate directionalDragArea;
527531 directionalDragArea.setObjectName("DirectionalDragArea");
528532
@@ -539,14 +543,14 @@ void tst_TouchRegistry::candidatesAndWatchers_2()
539543 Qt::NoModifier,
540544 Qt::TouchPointPressed,
541545 touchPoints);
542− touchRegistry.update(&touchEvent);
546+ touchRegistry->update(&touchEvent);
543547 }
544548
545549 // [TouchRegistry] addCandidateOwnerForTouch id 0 candidate DirectionalDragArea
546− touchRegistry.addCandidateOwnerForTouch(0, &directionalDragArea);
550+ touchRegistry->addCandidateOwnerForTouch(0, &directionalDragArea);
547551
548552 // [TouchRegistry] requestTouchOwnership id 0 candidate TouchGate
549− touchRegistry.requestTouchOwnership(0, &touchGate);
553+ touchRegistry->requestTouchOwnership(0, &touchGate);
550554
551555 //[TouchRegistry] got TouchUpdate (id:0, state:moved, scenePos:(147,1023)) (id:1, state:pressed, scenePos:(327,792))
552556 {
@@ -560,24 +564,24 @@ void tst_TouchRegistry::candidatesAndWatchers_2()
560564 Qt::NoModifier,
561565 Qt::TouchPointPressed | Qt::TouchPointMoved,
562566 touchPoints);
563− touchRegistry.update(&touchEvent);
567+ touchRegistry->update(&touchEvent);
564568 }
565569
566570 // [TouchRegistry] addTouchWatcher id 1 watcher DirectionalDragArea
567− touchRegistry.addTouchWatcher(1, &directionalDragArea);
571+ touchRegistry->addTouchWatcher(1, &directionalDragArea);
568572
569573 // [TouchRegistry] removeCandidateOwnerForTouch id 0 candidate DirectionalDragArea
570− touchRegistry.removeCandidateOwnerForTouch(0, &directionalDragArea);
574+ touchRegistry->removeCandidateOwnerForTouch(0, &directionalDragArea);
571575
572576 //[TouchRegistry] sending TouchWonershipEvent(id = 0 gained) to candidate TouchGate
573577 QCOMPARE(touchGate.ownedTouches.count(), 1);
574578 QVERIFY(touchGate.ownedTouches.contains(0));
575579
576580 // [TouchRegistry] addTouchWatcher id 0 watcher DirectionalDragArea
577− touchRegistry.addTouchWatcher(0, &directionalDragArea);
581+ touchRegistry->addTouchWatcher(0, &directionalDragArea);
578582
579583 // [TouchRegistry] requestTouchOwnership id 1 candidate TouchGate
580− touchRegistry.requestTouchOwnership(1, &touchGate);
584+ touchRegistry->requestTouchOwnership(1, &touchGate);
581585
582586 //[TouchRegistry] sending TouchWonershipEvent(id = 1 gained) to candidate TouchGate
583587 QCOMPARE(touchGate.ownedTouches.count(), 2);
@@ -598,7 +602,7 @@ void tst_TouchRegistry::candidatesAndWatchers_2()
598602 Qt::NoModifier,
599603 Qt::TouchPointMoved,
600604 touchPoints);
601− touchRegistry.update(&touchEvent);
605+ touchRegistry->update(&touchEvent);
602606 }
603607
604608 //vvvvv DDA Watchers are being ignored from now on vvvvvvv
@@ -624,7 +628,7 @@ void tst_TouchRegistry::candidatesAndWatchers_2()
624628 Qt::NoModifier,
625629 Qt::TouchPointMoved | Qt::TouchPointReleased,
626630 touchPoints);
627− touchRegistry.update(&touchEvent);
631+ touchRegistry->update(&touchEvent);
628632 }
629633
630634 QCOMPARE(directionalDragArea.unownedTouchEvents.count(), 1);
@@ -646,7 +650,7 @@ void tst_TouchRegistry::candidatesAndWatchers_2()
646650 Qt::NoModifier,
647651 Qt::TouchPointReleased,
648652 touchPoints);
649− touchRegistry.update(&touchEvent);
653+ touchRegistry->update(&touchEvent);
650654 }
651655
652656 QCOMPARE(directionalDragArea.unownedTouchEvents.count(), 1);
@@ -658,7 +662,6 @@ void tst_TouchRegistry::candidatesAndWatchers_2()
658662
659663void tst_TouchRegistry::rejectingTouchfterItsEnd()
660664{
661− TouchRegistry touchRegistry;
662665 DummyCandidate earlyCandidate;
663666 DummyCandidate lateCandidate;
664667
@@ -671,16 +674,16 @@ void tst_TouchRegistry::rejectingTouchfterItsEnd()
671674 Qt::NoModifier,
672675 Qt::TouchPointPressed,
673676 touchPoints);
674− touchRegistry.update(&touchEvent);
677+ touchRegistry->update(&touchEvent);
675678 }
676679
677− touchRegistry.addCandidateOwnerForTouch(0, &earlyCandidate);
678− touchRegistry.addCandidateOwnerForTouch(0, &lateCandidate);
680+ touchRegistry->addCandidateOwnerForTouch(0, &earlyCandidate);
681+ touchRegistry->addCandidateOwnerForTouch(0, &lateCandidate);
679682
680683 QVERIFY(earlyCandidate.ownedTouches.isEmpty());
681684 QVERIFY(lateCandidate.ownedTouches.isEmpty());
682685
683− touchRegistry.requestTouchOwnership(0, &lateCandidate);
686+ touchRegistry->requestTouchOwnership(0, &lateCandidate);
684687
685688 QVERIFY(earlyCandidate.ownedTouches.isEmpty());
686689 QVERIFY(lateCandidate.ownedTouches.isEmpty());
@@ -694,25 +697,25 @@ void tst_TouchRegistry::rejectingTouchfterItsEnd()
694697 Qt::NoModifier,
695698 Qt::TouchPointPressed,
696699 touchPoints);
697− touchRegistry.update(&touchEvent);
700+ touchRegistry->update(&touchEvent);
698701 }
699702
700703 QVERIFY(earlyCandidate.ownedTouches.isEmpty());
701704 QVERIFY(lateCandidate.ownedTouches.isEmpty());
702705
703− touchRegistry.removeCandidateOwnerForTouch(0, &earlyCandidate);
706+ touchRegistry->removeCandidateOwnerForTouch(0, &earlyCandidate);
704707
705708 QCOMPARE(lateCandidate.ownedTouches.count(), 1);
706709 QCOMPARE(lateCandidate.ownedTouches.contains(0), 1);
707710
708711 // Check that there's no trace left of touch 0 as we no longer need to keep tabs on it.
709− QVERIFY(!touchRegistry.findTouchInfo(0));
712+ QVERIFY(!touchRegistry->findTouchInfo(0));
710713}
711714
712715void tst_TouchRegistry::removeOldUndecidedCandidates()
713716{
714717 FakeTimerFactory *fakeTimerFactory = new FakeTimerFactory;
715− TouchRegistry *touchRegistry = new TouchRegistry(nullptr, fakeTimerFactory);
718+ touchRegistry->setTimerFactory(fakeTimerFactory);
716719
717720 DummyCandidate undecidedCandidate;
718721 undecidedCandidate.setObjectName("undecided");
@@ -749,8 +752,6 @@ void tst_TouchRegistry::removeOldUndecidedCandidates()
749752 QVERIFY(undecidedCandidate.lostTouches.contains(0));
750753 QVERIFY(candidateThatWantsTouch.ownedTouches.contains(0));
751754 QVERIFY(candidateThatWantsTouch.lostTouches.isEmpty());
752−
753− delete touchRegistry;
754755}
755756
756757/*
@@ -762,7 +763,7 @@ void tst_TouchRegistry::removeOldUndecidedCandidates()
762763void tst_TouchRegistry::interimOwnerWontGetUnownedTouchEvents()
763764{
764765 FakeTimerFactory *fakeTimerFactory = new FakeTimerFactory;
765− TouchRegistry *touchRegistry = new TouchRegistry(nullptr, fakeTimerFactory);
766+ touchRegistry->setTimerFactory(fakeTimerFactory);
766767
767768 DummyCandidate undecidedCandidate;
768769 undecidedCandidate.setObjectName("undecided");
@@ -814,8 +815,6 @@ void tst_TouchRegistry::interimOwnerWontGetUnownedTouchEvents()
814815
815816 QCOMPARE(undecidedCandidate.unownedTouchEvents.count(), 2);
816817 QCOMPARE(interimOwner.unownedTouchEvents.count(), 0);
817−
818− delete touchRegistry;
819818}
820819
821820////////////// TouchMemento //////////
tests/plugins/Ubuntu/Gestures/GestureTest.cpp+2−1
@@ -53,7 +53,8 @@ void GestureTest::init()
5353
5454 m_fakeTimerFactory = new FakeTimerFactory;
5555
56− m_touchRegistry = new TouchRegistry(nullptr, m_fakeTimerFactory);
56+ m_touchRegistry = TouchRegistry::instance();
57+ m_touchRegistry->setTimerFactory(m_fakeTimerFactory);
5758 m_view->installEventFilter(m_touchRegistry);
5859
5960 qApp->processEvents();
tests/plugins/Ubuntu/Gestures/tst_DirectionalDragArea.cpp+20−20
@@ -202,7 +202,7 @@ void tst_DirectionalDragArea::dragWithShortDirectionChange()
202202 DirectionalDragArea *edgeDragArea =
203203 m_view->rootObject()->findChild<DirectionalDragArea*>("hpDragArea");
204204 QVERIFY(edgeDragArea != 0);
205− edgeDragArea->d->setRecognitionTimer(m_fakeTimerFactory->createTimer());
205+ edgeDragArea->d->setRecognitionTimer(m_fakeTimerFactory->createTimer(edgeDragArea));
206206 edgeDragArea->d->setTimeSource(m_fakeTimerFactory->timeSource());
207207
208208 QPointF initialTouchPos = calculateInitialTouchPos(edgeDragArea);
@@ -297,7 +297,7 @@ void tst_DirectionalDragArea::sceneXAndX()
297297 DirectionalDragArea *edgeDragArea =
298298 m_view->rootObject()->findChild<DirectionalDragArea*>("hnDragArea");
299299 QVERIFY(edgeDragArea != 0);
300− edgeDragArea->d->setRecognitionTimer(m_fakeTimerFactory->createTimer());
300+ edgeDragArea->d->setRecognitionTimer(m_fakeTimerFactory->createTimer(edgeDragArea));
301301 edgeDragArea->d->setTimeSource(m_fakeTimerFactory->timeSource());
302302 edgeDragArea->setImmediateRecognition(true);
303303
@@ -326,7 +326,7 @@ void tst_DirectionalDragArea::sceneYAndY()
326326 DirectionalDragArea *edgeDragArea =
327327 m_view->rootObject()->findChild<DirectionalDragArea*>("vnDragArea");
328328 QVERIFY(edgeDragArea != 0);
329− edgeDragArea->d->setRecognitionTimer(m_fakeTimerFactory->createTimer());
329+ edgeDragArea->d->setRecognitionTimer(m_fakeTimerFactory->createTimer(edgeDragArea));
330330 edgeDragArea->d->setTimeSource(m_fakeTimerFactory->timeSource());
331331 edgeDragArea->setImmediateRecognition(true);
332332
@@ -357,7 +357,7 @@ void tst_DirectionalDragArea::twoFingerTap()
357357 DirectionalDragArea *edgeDragArea =
358358 m_view->rootObject()->findChild<DirectionalDragArea*>("hpDragArea");
359359 QVERIFY(edgeDragArea != 0);
360− edgeDragArea->d->setRecognitionTimer(m_fakeTimerFactory->createTimer());
360+ edgeDragArea->d->setRecognitionTimer(m_fakeTimerFactory->createTimer(edgeDragArea));
361361 edgeDragArea->d->setTimeSource(m_fakeTimerFactory->timeSource());
362362
363363 // Make touches evenly spaced along the edgeDragArea
@@ -439,7 +439,7 @@ void tst_DirectionalDragArea::movingDDA()
439439 DirectionalDragArea *edgeDragArea =
440440 rightwardsLauncher->findChild<DirectionalDragArea*>("hpDragArea");
441441 Q_ASSERT(edgeDragArea != 0);
442− edgeDragArea->d->setRecognitionTimer(m_fakeTimerFactory->createTimer());
442+ edgeDragArea->d->setRecognitionTimer(m_fakeTimerFactory->createTimer(edgeDragArea));
443443 edgeDragArea->d->setTimeSource(m_fakeTimerFactory->timeSource());
444444
445445 QPointF initialTouchPos = calculateInitialTouchPos(edgeDragArea);
@@ -479,7 +479,7 @@ void tst_DirectionalDragArea::ignoreOldFinger()
479479 DirectionalDragArea *edgeDragArea =
480480 m_view->rootObject()->findChild<DirectionalDragArea*>("hpDragArea");
481481 Q_ASSERT(edgeDragArea != 0);
482− edgeDragArea->d->setRecognitionTimer(m_fakeTimerFactory->createTimer());
482+ edgeDragArea->d->setRecognitionTimer(m_fakeTimerFactory->createTimer(edgeDragArea));
483483 edgeDragArea->d->setTimeSource(m_fakeTimerFactory->timeSource());
484484
485485 // Make touches evenly spaced along the edgeDragArea
@@ -542,7 +542,7 @@ void tst_DirectionalDragArea::rotated()
542542 DirectionalDragArea *edgeDragArea =
543543 rightwardsLauncher->findChild<DirectionalDragArea*>("hpDragArea");
544544 Q_ASSERT(edgeDragArea != 0);
545− edgeDragArea->d->setRecognitionTimer(m_fakeTimerFactory->createTimer());
545+ edgeDragArea->d->setRecognitionTimer(m_fakeTimerFactory->createTimer(edgeDragArea));
546546 edgeDragArea->d->setTimeSource(m_fakeTimerFactory->timeSource());
547547
548548 QPointF initialTouchPos = calculateInitialTouchPos(edgeDragArea);
@@ -582,7 +582,7 @@ void tst_DirectionalDragArea::sceneDistance()
582582 DirectionalDragArea *edgeDragArea =
583583 rightwardsLauncher->findChild<DirectionalDragArea*>("hpDragArea");
584584 Q_ASSERT(edgeDragArea != 0);
585− edgeDragArea->d->setRecognitionTimer(m_fakeTimerFactory->createTimer());
585+ edgeDragArea->d->setRecognitionTimer(m_fakeTimerFactory->createTimer(edgeDragArea));
586586 edgeDragArea->d->setTimeSource(m_fakeTimerFactory->timeSource());
587587
588588 // to disable the position smoothing so that we can more easily check sceneDistance values
@@ -640,7 +640,7 @@ void tst_DirectionalDragArea::disabledWhileDragging()
640640 DirectionalDragArea *edgeDragArea =
641641 m_view->rootObject()->findChild<DirectionalDragArea*>("hpDragArea");
642642 Q_ASSERT(edgeDragArea != 0);
643− edgeDragArea->d->setRecognitionTimer(m_fakeTimerFactory->createTimer());
643+ edgeDragArea->d->setRecognitionTimer(m_fakeTimerFactory->createTimer(edgeDragArea));
644644 edgeDragArea->d->setTimeSource(m_fakeTimerFactory->timeSource());
645645
646646 QPointF touchPoint = calculateInitialTouchPos(edgeDragArea);
@@ -678,7 +678,7 @@ void tst_DirectionalDragArea::oneFingerDownFollowedByLateSecondFingerDown()
678678 DirectionalDragArea *edgeDragArea =
679679 m_view->rootObject()->findChild<DirectionalDragArea*>("hpDragArea");
680680 Q_ASSERT(edgeDragArea != 0);
681− edgeDragArea->d->setRecognitionTimer(m_fakeTimerFactory->createTimer());
681+ edgeDragArea->d->setRecognitionTimer(m_fakeTimerFactory->createTimer(edgeDragArea));
682682 edgeDragArea->d->setTimeSource(m_fakeTimerFactory->timeSource());
683683
684684 // Disable some constraints we're not interested in
@@ -753,7 +753,7 @@ void tst_DirectionalDragArea::givesUpWhenLosesTouch()
753753 DirectionalDragArea *edgeDragArea =
754754 m_view->rootObject()->findChild<DirectionalDragArea*>("hpDragArea");
755755 Q_ASSERT(edgeDragArea != 0);
756− edgeDragArea->d->setRecognitionTimer(m_fakeTimerFactory->createTimer());
756+ edgeDragArea->d->setRecognitionTimer(m_fakeTimerFactory->createTimer(edgeDragArea));
757757 edgeDragArea->d->setTimeSource(m_fakeTimerFactory->timeSource());
758758
759759 // Disable some constraints we're not interested in
@@ -798,7 +798,7 @@ void tst_DirectionalDragArea::threeFingerDrag()
798798 DirectionalDragArea *edgeDragArea =
799799 m_view->rootObject()->findChild<DirectionalDragArea*>("hpDragArea");
800800 Q_ASSERT(edgeDragArea != 0);
801− edgeDragArea->d->setRecognitionTimer(m_fakeTimerFactory->createTimer());
801+ edgeDragArea->d->setRecognitionTimer(m_fakeTimerFactory->createTimer(edgeDragArea));
802802 edgeDragArea->d->setTimeSource(m_fakeTimerFactory->timeSource());
803803
804804 // Disable some constraints we're not interested in
@@ -867,7 +867,7 @@ void tst_DirectionalDragArea::immediateRecognitionWhenConstraintsDisabled()
867867 DirectionalDragArea *edgeDragArea =
868868 m_view->rootObject()->findChild<DirectionalDragArea*>("hpDragArea");
869869 Q_ASSERT(edgeDragArea != 0);
870− edgeDragArea->d->setRecognitionTimer(m_fakeTimerFactory->createTimer());
870+ edgeDragArea->d->setRecognitionTimer(m_fakeTimerFactory->createTimer(edgeDragArea));
871871 edgeDragArea->d->setTimeSource(m_fakeTimerFactory->timeSource());
872872
873873 // Disable the minimum amount of constraints to ensure immediate recognition
@@ -900,7 +900,7 @@ void tst_DirectionalDragArea::withdrawTouchOwnershipCandidacyIfDisabledDuringRec
900900 DirectionalDragArea *edgeDragArea =
901901 m_view->rootObject()->findChild<DirectionalDragArea*>("hpDragArea");
902902 Q_ASSERT(edgeDragArea != 0);
903− edgeDragArea->d->setRecognitionTimer(m_fakeTimerFactory->createTimer());
903+ edgeDragArea->d->setRecognitionTimer(m_fakeTimerFactory->createTimer(edgeDragArea));
904904 edgeDragArea->d->setTimeSource(m_fakeTimerFactory->timeSource());
905905
906906 QPointF touchPoint = calculateInitialTouchPos(edgeDragArea);
@@ -964,7 +964,7 @@ void tst_DirectionalDragArea::gettingTouchOwnershipMakesMouseAreaBehindGetCancel
964964 DirectionalDragArea *edgeDragArea =
965965 m_view->rootObject()->findChild<DirectionalDragArea*>("hpDragArea");
966966 QVERIFY(edgeDragArea != nullptr);
967− edgeDragArea->d->setRecognitionTimer(m_fakeTimerFactory->createTimer());
967+ edgeDragArea->d->setRecognitionTimer(m_fakeTimerFactory->createTimer(edgeDragArea));
968968 edgeDragArea->d->setTimeSource(m_fakeTimerFactory->timeSource());
969969
970970 QQuickMouseArea *mouseArea =
@@ -1014,7 +1014,7 @@ void tst_DirectionalDragArea::interleavedTouches()
10141014 DirectionalDragArea *edgeDragArea =
10151015 m_view->rootObject()->findChild<DirectionalDragArea*>("hpDragArea");
10161016 QVERIFY(edgeDragArea != 0);
1017− edgeDragArea->d->setRecognitionTimer(m_fakeTimerFactory->createTimer());
1017+ edgeDragArea->d->setRecognitionTimer(m_fakeTimerFactory->createTimer(edgeDragArea));
10181018 edgeDragArea->d->setTimeSource(m_fakeTimerFactory->timeSource());
10191019
10201020 QPointF touch0 = edgeDragArea->mapToScene(
@@ -1109,7 +1109,7 @@ void tst_DirectionalDragArea::makoRightEdgeDrag()
11091109 DirectionalDragArea *edgeDragArea =
11101110 m_view->rootObject()->findChild<DirectionalDragArea*>("hnDragArea");
11111111 QVERIFY(edgeDragArea != nullptr);
1112− edgeDragArea->d->setRecognitionTimer(m_fakeTimerFactory->createTimer());
1112+ edgeDragArea->d->setRecognitionTimer(m_fakeTimerFactory->createTimer(edgeDragArea));
11131113 edgeDragArea->d->setTimeSource(m_fakeTimerFactory->timeSource());
11141114
11151115 StatusSpy *statusSpy = new StatusSpy(edgeDragArea);
@@ -1154,7 +1154,7 @@ void tst_DirectionalDragArea::makoRightEdgeDrag_verticalDownwards()
11541154 DirectionalDragArea *edgeDragArea =
11551155 m_view->rootObject()->findChild<DirectionalDragArea*>("hnDragArea");
11561156 QVERIFY(edgeDragArea != nullptr);
1157− edgeDragArea->d->setRecognitionTimer(m_fakeTimerFactory->createTimer());
1157+ edgeDragArea->d->setRecognitionTimer(m_fakeTimerFactory->createTimer(edgeDragArea));
11581158 edgeDragArea->d->setTimeSource(m_fakeTimerFactory->timeSource());
11591159
11601160 edgeDragArea->d->setPixelsPerMm(320.0 /*mako ppi*/ * 0.03937 /* inches per mm*/);
@@ -1198,7 +1198,7 @@ void tst_DirectionalDragArea::makoLeftEdgeDrag_slowStart()
11981198 DirectionalDragArea *edgeDragArea =
11991199 m_view->rootObject()->findChild<DirectionalDragArea*>("hpDragArea");
12001200 QVERIFY(edgeDragArea != nullptr);
1201− edgeDragArea->d->setRecognitionTimer(m_fakeTimerFactory->createTimer());
1201+ edgeDragArea->d->setRecognitionTimer(m_fakeTimerFactory->createTimer(edgeDragArea));
12021202 edgeDragArea->d->setTimeSource(m_fakeTimerFactory->timeSource());
12031203
12041204 edgeDragArea->d->setPixelsPerMm(320.0 /*mako ppi*/ * 0.03937 /* inches per mm*/);
@@ -1262,7 +1262,7 @@ void tst_DirectionalDragArea::makoLeftEdgeDrag_movesSlightlyBackwardsOnStart()
12621262 DirectionalDragArea *edgeDragArea =
12631263 m_view->rootObject()->findChild<DirectionalDragArea*>("hpDragArea");
12641264 QVERIFY(edgeDragArea != nullptr);
1265− edgeDragArea->d->setRecognitionTimer(m_fakeTimerFactory->createTimer());
1265+ edgeDragArea->d->setRecognitionTimer(m_fakeTimerFactory->createTimer(edgeDragArea));
12661266 edgeDragArea->d->setTimeSource(m_fakeTimerFactory->timeSource());
12671267
12681268 edgeDragArea->d->setPixelsPerMm(320.0 /*mako ppi*/ * 0.03937 /* inches per mm*/);
tests/plugins/Ubuntu/Gestures/tst_TouchGate.cpp+1−2
@@ -95,10 +95,9 @@ void tst_TouchGate::cleanupTestCase()
9595
9696void tst_TouchGate::init()
9797{
98− touchRegistry = new TouchRegistry;
98+ touchRegistry = TouchRegistry::instance();
9999
100100 view = createView();
101− view->installEventFilter(touchRegistry);
102101 view->setSource(QUrl::fromLocalFile("touchGateExample.qml"));
103102 view->show();
104103 QVERIFY(QTest::qWaitForWindowExposed(view));
tests/qmltests/Components/tst_DragHandle.cpp−8
@@ -26,7 +26,6 @@
2626#include <DirectionalDragArea.h>
2727#include <DirectionalDragArea_p.h>
2828#include <Timer.h>
29−#include <TouchRegistry.h>
3029
3130using namespace UbuntuGestures;
3231
@@ -61,7 +60,6 @@ private:
6160
6261 QQuickView *createView();
6362 QQuickView *m_view;
64− TouchRegistry *m_touchRegistry;
6563 QTouchDevice *m_device;
6664 FakeTimer *m_fakeTimer;
6765 QSharedPointer<FakeTimeSource> m_fakeTimeSource;
@@ -85,10 +83,7 @@ void tst_DragHandle::cleanupTestCase()
8583
8684void tst_DragHandle::init()
8785{
88− m_touchRegistry = new TouchRegistry;
89−
9086 m_view = createView();
91− m_view->installEventFilter(m_touchRegistry);
9287 m_view->setSource(QUrl::fromLocalFile(TEST_DIR"/tst_DragHandle.qml"));
9388 m_view->show();
9489 QVERIFY(QTest::qWaitForWindowExposed(m_view));
@@ -108,9 +103,6 @@ void tst_DragHandle::cleanup()
108103 delete m_view;
109104 m_view = 0;
110105
111− delete m_touchRegistry;
112− m_touchRegistry = 0;
113−
114106 delete m_fakeTimer;
115107 m_fakeTimer = 0;
116108
tests/uqmlscene/main.cpp−10
@@ -63,9 +63,6 @@
6363#include <QtCore/QTranslator>
6464#include <QtCore/QLibraryInfo>
6565
66−// UbuntuGestures lib
67−#include <TouchRegistry.h>
68−
6966#define UQMLSCENE_DEBUG_ACTIVE_FOCUS 0
7067
7168#if UQMLSCENE_DEBUG_ACTIVE_FOCUS
@@ -434,11 +431,6 @@ int main(int argc, char ** argv)
434431 app.setOrganizationName("Qt Project");
435432 app.setOrganizationDomain("qt-project.org");
436433
437− // Create it before loading the module, so that TestUtil
438− // doesn't create one with a fake timer factory.
439− // When interacting manually with a test we want the real deal.
440− new TouchRegistry;
441−
442434#ifndef QT_NO_TRANSLATION
443435 QTranslator translator;
444436 QTranslator qtTranslator;
@@ -512,8 +504,6 @@ int main(int argc, char ** argv)
512504 #if UQMLSCENE_DEBUG_ACTIVE_FOCUS
513505 activeFocusLogger.setWindow(qxView);
514506 #endif
515− TouchRegistry::instance()->setParent(qxView);
516− qxView->installEventFilter(TouchRegistry::instance());
517507 window = qxView;
518508 // Set window default properties; the qml can still override them
519509 QString oname = contentItem->objectName();
tests/utils/modules/Unity/Test/UnityTestCase.qml−2
@@ -382,8 +382,6 @@ TestCase {
382382 }
383383
384384 Component.onCompleted: {
385− UT.Util.ensureTouchRegistryInstalled();
386−
387385 var rootItem = parent;
388386 while (rootItem.parent != undefined) {
389387 rootItem = rootItem.parent;
tests/utils/modules/Unity/Test/testutil.cpp+8−20
@@ -31,6 +31,7 @@ TestUtil::TestUtil(QObject *parent)
3131 : QObject(parent)
3232 , m_targetWindow(0)
3333 , m_touchDevice(0)
34+ , m_putFakeTimerFactoryInTouchRegistry(false)
3435{
3536}
3637
@@ -59,7 +60,13 @@ TouchEventSequenceWrapper *TestUtil::touchEvent(QQuickItem *item)
5960{
6061 ensureTargetWindow();
6162 ensureTouchDevice();
62− ensureTouchRegistryInstalled();
63+
64+ // Tests can be *very* slow to run and we don't want things timing out because
65+ // of that. So give it fake timers to use (they will never time out)
66+ if (!m_putFakeTimerFactoryInTouchRegistry) {
67+ TouchRegistry::instance()->setTimerFactory(new FakeTimerFactory);
68+ m_putFakeTimerFactoryInTouchRegistry = true;
69+ }
6370
6471 return new TouchEventSequenceWrapper(
6572 QTest::touchEvent(m_targetWindow, m_touchDevice, /* autoCommit */ false), item);
@@ -79,22 +86,3 @@ void TestUtil::ensureTouchDevice()
7986 QWindowSystemInterface::registerTouchDevice(m_touchDevice);
8087 }
8188}
82−
83−void TestUtil::ensureTouchRegistryInstalled()
84−{
85− if (TouchRegistry::instance())
86− return;
87−
88− if (!m_targetWindow)
89− return;
90−
91− // Tests can be *very* slow to run and we don't want things timing out because
92− // of that. So give it fake timers to use (they will never time out)
93− TouchRegistry *touchRegistry = new TouchRegistry(this, new FakeTimerFactory);
94−
95− QQuickView *view = qobject_cast<QQuickView*>(m_targetWindow);
96− if (view) {
97− view->installEventFilter(touchRegistry);
98− touchRegistry->setParent(view);
99− }
100−}
tests/utils/modules/Unity/Test/testutil.h+1−1
@@ -34,7 +34,6 @@ public:
3434
3535 Q_INVOKABLE bool isInstanceOf(QObject*, QString);
3636 Q_INVOKABLE TouchEventSequenceWrapper *touchEvent(QQuickItem *item);
37− Q_INVOKABLE void ensureTouchRegistryInstalled();
3837
3938private:
4039 void ensureTargetWindow();
@@ -42,6 +41,7 @@ private:
4241
4342 QWindow *m_targetWindow;
4443 QTouchDevice *m_touchDevice;
44+ bool m_putFakeTimerFactoryInTouchRegistry;
4545};
4646
4747QML_DECLARE_TYPE(TestUtil)