touchEvent.setTouchPoints(eventPoints);
touchEvent.setTimestamp(event->timestamp());
+ for (int i = 0; i < matchingPoints.count(); ++i)
+ itemForTouchPointId[matchingPoints[i].id()] = item;
+
touchEvent.accept();
q->sendEvent(item, &touchEvent);
if (touchEvent.isAccepted()) {
- for (int i=0; i<matchingPoints.count(); i++) {
- itemForTouchPointId[matchingPoints[i].id()] = item;
+ for (int i = 0; i < matchingPoints.count(); ++i)
acceptedNewPoints->insert(matchingPoints[i].id());
- }
+ } else {
+ for (int i = 0; i < matchingPoints.count(); ++i)
+ if (itemForTouchPointId.value(matchingPoints[i].id()) == item)
+ itemForTouchPointId.remove(matchingPoints[i].id());
}
}
}
Q_OBJECT
public:
TestTouchItem(QQuickItem *parent = 0)
- : QQuickRectangle(parent), acceptEvents(true), mousePressId(0)
+ : QQuickRectangle(parent), acceptEvents(true), mousePressId(0),
+ spinLoopWhenPressed(false), touchEventCount(0)
{
border()->setWidth(1);
setAcceptedMouseButtons(Qt::LeftButton);
mousePressNum = 0;
}
+ void clearTouchEventCounter()
+ {
+ touchEventCount = 0;
+ }
+
bool acceptEvents;
TouchEventData lastEvent;
int mousePressId;
+ bool spinLoopWhenPressed;
+ int touchEventCount;
+
protected:
virtual void touchEvent(QTouchEvent *event) {
if (!acceptEvents) {
event->ignore();
return;
}
+ ++touchEventCount;
lastEvent = makeTouchData(event->type(), event->window(), event->touchPointStates(), event->touchPoints());
event->accept();
+ if (spinLoopWhenPressed && event->touchPointStates().testFlag(Qt::TouchPointPressed)) {
+ QCoreApplication::processEvents();
+ }
}
virtual void mousePressEvent(QMouseEvent *) {
void touchEvent_propagation();
void touchEvent_propagation_data();
void touchEvent_cancel();
+ void touchEvent_reentrant();
void clearCanvas();
delete canvas;
}
+void tst_qquickcanvas::touchEvent_reentrant()
+{
+ TestTouchItem::clearMousePressCounter();
+
+ QQuickCanvas *canvas = new QQuickCanvas;
+ canvas->resize(250, 250);
+ canvas->setPos(100, 100);
+ canvas->show();
+
+ TestTouchItem *item = new TestTouchItem(canvas->rootItem());
+
+ item->spinLoopWhenPressed = true; // will call processEvents() from the touch handler
+
+ item->setPos(QPointF(50, 50));
+ item->setSize(QSizeF(150, 150));
+ QPointF pos(60, 60);
+
+ // None of these should commit from the dtor.
+ QTest::QTouchEventSequence press = QTest::touchEvent(canvas, touchDevice, false).press(0, pos.toPoint(), canvas);
+ pos += QPointF(2, 2);
+ QTest::QTouchEventSequence move = QTest::touchEvent(canvas, touchDevice, false).move(0, pos.toPoint(), canvas);
+ QTest::QTouchEventSequence release = QTest::touchEvent(canvas, touchDevice, false).release(0, pos.toPoint(), canvas);
+
+ // Now commit (i.e. call QWindowSystemInterface::handleTouchEvent), but do not process the events yet.
+ press.commit(false);
+ move.commit(false);
+ release.commit(false);
+
+ QCoreApplication::processEvents();
+
+ QTRY_COMPARE(item->touchEventCount, 3);
+
+ delete item;
+ delete canvas;
+}
+
void tst_qquickcanvas::clearCanvas()
{
QQuickCanvas *canvas = new QQuickCanvas;