From 92672198ed0ecf5e014abf3a431a374e91067b27 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Tue, 6 Dec 2016 14:34:03 +0100 Subject: [PATCH] QGuiApplicationPrivate::processTouchEvent: add explanatory comments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It was very confusing to debug a problem involving detached touchpoints and not very clear how startPos is stored in activeTouchPoints. Change-Id: I5c04fb6b5647493a731774e0a1765404cbc8c7d6 Reviewed-by: Jan Arve Sæther --- src/gui/kernel/qguiapplication.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 1277e85d0a..4d1caa9232 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -2564,6 +2564,9 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To Q_ASSERT(w.data() != 0); // make the *scene* functions return the same as the *screen* functions + // Note: touchPoint is a reference to the one from activeTouchPoints, + // so we can modify it as long as we're careful NOT to call setters and + // otherwise NOT to cause the d-pointer to be detached. touchPoint.d->scenePos = touchPoint.screenPos(); touchPoint.d->verticalDiameter = touchPoint.screenRect().height(); touchPoint.d->horizontalDiameter = touchPoint.screenRect().width(); @@ -2622,8 +2625,8 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To QTouchEvent touchEvent(eventType, e->device, e->modifiers, - it.value().first, - it.value().second); + it.value().first, // state flags + it.value().second); // list of touchpoints touchEvent.setTimestamp(e->timestamp); touchEvent.setWindow(w); @@ -2640,6 +2643,9 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To touchPoint.d->verticalDiameter = rect.height(); touchPoint.d->horizontalDiameter = rect.width(); if (touchPoint.state() == Qt::TouchPointPressed) { + // touchPoint is actually a reference to one that is stored in activeTouchPoints, + // and we are now going to store the startPos and lastPos there, for the benefit + // of future moves and releases. It's important that the d-pointer is NOT detached. touchPoint.d->startPos = w->mapFromGlobal(touchPoint.startScreenPos().toPoint()) + delta; touchPoint.d->lastPos = w->mapFromGlobal(touchPoint.lastScreenPos().toPoint()) + delta; }