aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2017-03-07 17:10:43 +0100
committerShawn Rutledge <shawn.rutledge@qt.io>2017-03-08 13:11:23 +0000
commit3b3c8103496f61ebc4b72e73035a4d43fcdd03b0 (patch)
tree76bcd2a06da851b94984a50a4e137155bfac682c
parent54bb88bc99a0ea3966b6bde2ba06e4ece237a32c (diff)
PointerHandlers: fix some grab notification and signal order problems
The singlePointHandlerProperties manual test showed how this was broken in a couple of ways after 8c659c6c723e4f5f97f46a4555a4765e85c26f1d : - When QQuickPointerTouchEvent::reset() is swapping one point instance for another, and consequently transferring the grabbers from one to another, it should not cause onGrabChanged to occur. Every point update was triggering DragHandler.onGrabChanged. - The order of signal emission is important so that sceneGrabPos will be correct in onGrabChanged. Change-Id: I62a302d6e54126ae10834b6d622e82aa0e434bab Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
-rw-r--r--src/quick/handlers/qquickpointersinglehandler.cpp7
-rw-r--r--src/quick/items/qquickevents.cpp11
-rw-r--r--src/quick/items/qquickevents_p_p.h2
3 files changed, 15 insertions, 5 deletions
diff --git a/src/quick/handlers/qquickpointersinglehandler.cpp b/src/quick/handlers/qquickpointersinglehandler.cpp
index d9a9d692ae..112c680d3c 100644
--- a/src/quick/handlers/qquickpointersinglehandler.cpp
+++ b/src/quick/handlers/qquickpointersinglehandler.cpp
@@ -148,15 +148,17 @@ bool QQuickPointerSingleHandler::wantsEventPoint(QQuickEventPoint *point)
void QQuickPointerSingleHandler::onGrabChanged(QQuickPointerHandler *grabber, QQuickEventPoint::GrabState stateChange, QQuickEventPoint *point)
{
- QQuickPointerHandler::onGrabChanged(grabber, stateChange, point);
if (grabber != this)
return;
switch (stateChange) {
case QQuickEventPoint::GrabExclusive:
+ m_sceneGrabPos = point->sceneGrabPos();
setActive(true);
- Q_FALLTHROUGH();
+ QQuickPointerHandler::onGrabChanged(grabber, stateChange, point);
+ break;
case QQuickEventPoint::GrabPassive:
m_sceneGrabPos = point->sceneGrabPos();
+ QQuickPointerHandler::onGrabChanged(grabber, stateChange, point);
break;
case QQuickEventPoint::OverrideGrabPassive:
return; // don't emit
@@ -165,6 +167,7 @@ void QQuickPointerSingleHandler::onGrabChanged(QQuickPointerHandler *grabber, QQ
case QQuickEventPoint::CancelGrabPassive:
case QQuickEventPoint::CancelGrabExclusive:
// the grab is lost or relinquished, so the point is no longer relevant
+ QQuickPointerHandler::onGrabChanged(grabber, stateChange, point);
reset();
break;
}
diff --git a/src/quick/items/qquickevents.cpp b/src/quick/items/qquickevents.cpp
index 49ed0f050e..61d843210e 100644
--- a/src/quick/items/qquickevents.cpp
+++ b/src/quick/items/qquickevents.cpp
@@ -650,6 +650,10 @@ void QQuickEventPoint::setGrabberPointerHandler(QQuickPointerHandler *grabber, b
if (exclusive) {
if (grabber != m_exclusiveGrabber.data()) {
if (grabber) {
+ // set variables before notifying the new grabber
+ m_exclusiveGrabber = QPointer<QObject>(grabber);
+ m_grabberIsHandler = true;
+ m_sceneGrabPos = m_scenePos;
grabber->onGrabChanged(grabber, GrabExclusive, this);
for (QPointer<QQuickPointerHandler> passiveGrabber : m_passiveGrabbers) {
if (passiveGrabber != grabber)
@@ -664,7 +668,7 @@ void QQuickEventPoint::setGrabberPointerHandler(QQuickPointerHandler *grabber, b
if (pointerEvent()->asPointerTouchEvent())
oldGrabberItem->touchUngrabEvent();
}
-
+ // set variables after notifying the old grabber
m_exclusiveGrabber = QPointer<QObject>(grabber);
m_grabberIsHandler = true;
m_sceneGrabPos = m_scenePos;
@@ -943,8 +947,9 @@ QQuickPointerEvent *QQuickPointerTouchEvent::reset(QEvent *event)
point->setGrabberItem(nullptr);
point->clearPassiveGrabbers();
} else {
- point->setExclusiveGrabber(grabbers.at(i));
- point->setPassiveGrabbers(passiveGrabberses.at(i));
+ // Restore the grabbers without notifying (don't call onGrabChanged)
+ point->m_exclusiveGrabber = grabbers.at(i);
+ point->m_passiveGrabbers = passiveGrabberses.at(i);
}
}
m_pointCount = newPointCount;
diff --git a/src/quick/items/qquickevents_p_p.h b/src/quick/items/qquickevents_p_p.h
index c4200ac550..2eebf131bc 100644
--- a/src/quick/items/qquickevents_p_p.h
+++ b/src/quick/items/qquickevents_p_p.h
@@ -370,6 +370,8 @@ private:
QSizeF m_ellipseDiameters;
QPointingDeviceUniqueId m_uniqueId;
+ friend class QQuickPointerTouchEvent;
+
Q_DISABLE_COPY(QQuickEventTouchPoint)
};