aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp
diff options
context:
space:
mode:
authorGunnar Sletta <gunnar.sletta@jollamobile.com>2014-04-03 11:16:42 +0000
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-05-05 16:02:45 +0200
commit6dc8f47bb05a8acb3cbcc697e0dc05356a01d4cf (patch)
tree81c7ebe9b3a55f2c8c4cdbc2fe6115024d145435 /tests/auto/quick/qquickwindow/tst_qquickwindow.cpp
parentc87ae78dd78f4a8cee040b5d27e7a6f2425f3aaf (diff)
Compress touch events in QQuickWindow.
Instead of sending multiple touch updates per frame, we store the last one and flush the pending events just before we enter into the scene graph sync phase. [ChangeLog][QtQuick] QQuickWindow will compresses touch events and delivers at most one touch event per frame. Done-with: Robin Burchell <robin.burchell@jollamobile.com> Change-Id: Ia0169bc4a3f0da67709b91ca65c326934b55d372 Reviewed-by: Laszlo Agocs <laszlo.agocs@digia.com> Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
Diffstat (limited to 'tests/auto/quick/qquickwindow/tst_qquickwindow.cpp')
-rw-r--r--tests/auto/quick/qquickwindow/tst_qquickwindow.cpp50
1 files changed, 33 insertions, 17 deletions
diff --git a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp
index 0e7b7c103a..18b0dd5132 100644
--- a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp
+++ b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp
@@ -49,6 +49,7 @@
#include <QtQuick/private/qquickrectangle_p.h>
#include "../../shared/util.h"
#include "../shared/visualtestutil.h"
+#include "../shared/viewtestutil.h"
#include <QSignalSpy>
#include <qpa/qwindowsysteminterface.h>
#include <private/qquickwindow_p.h>
@@ -520,7 +521,7 @@ void tst_qquickwindow::touchEvent_basic()
// press multiple points
QTest::touchEvent(window, touchDevice).press(0, topItem->mapToScene(pos).toPoint(),window)
.press(1, bottomItem->mapToScene(pos).toPoint(), window);
- QTest::qWait(50);
+ QQuickTouchUtils::flush(window);
QCOMPARE(topItem->lastEvent.touchPoints.count(), 1);
QVERIFY(middleItem->lastEvent.touchPoints.isEmpty());
QCOMPARE(bottomItem->lastEvent.touchPoints.count(), 1);
@@ -531,9 +532,9 @@ void tst_qquickwindow::touchEvent_basic()
// touch point on top item moves to bottom item, but top item should still receive the event
QTest::touchEvent(window, touchDevice).press(0, topItem->mapToScene(pos).toPoint(), window);
- QTest::qWait(50);
+ QQuickTouchUtils::flush(window);
QTest::touchEvent(window, touchDevice).move(0, bottomItem->mapToScene(pos).toPoint(), window);
- QTest::qWait(50);
+ QQuickTouchUtils::flush(window);
QCOMPARE(topItem->lastEvent.touchPoints.count(), 1);
COMPARE_TOUCH_DATA(topItem->lastEvent, makeTouchData(QEvent::TouchUpdate, window, Qt::TouchPointMoved,
makeTouchPoint(topItem, topItem->mapFromItem(bottomItem, pos), pos)));
@@ -541,9 +542,9 @@ void tst_qquickwindow::touchEvent_basic()
// touch point on bottom item moves to top item, but bottom item should still receive the event
QTest::touchEvent(window, touchDevice).press(0, bottomItem->mapToScene(pos).toPoint(), window);
- QTest::qWait(50);
+ QQuickTouchUtils::flush(window);
QTest::touchEvent(window, touchDevice).move(0, topItem->mapToScene(pos).toPoint(), window);
- QTest::qWait(50);
+ QQuickTouchUtils::flush(window);
QCOMPARE(bottomItem->lastEvent.touchPoints.count(), 1);
COMPARE_TOUCH_DATA(bottomItem->lastEvent, makeTouchData(QEvent::TouchUpdate, window, Qt::TouchPointMoved,
makeTouchPoint(bottomItem, bottomItem->mapFromItem(topItem, pos), pos)));
@@ -551,10 +552,10 @@ void tst_qquickwindow::touchEvent_basic()
// a single stationary press on an item shouldn't cause an event
QTest::touchEvent(window, touchDevice).press(0, topItem->mapToScene(pos).toPoint(), window);
- QTest::qWait(50);
+ QQuickTouchUtils::flush(window);
QTest::touchEvent(window, touchDevice).stationary(0)
.press(1, bottomItem->mapToScene(pos).toPoint(), window);
- QTest::qWait(50);
+ QQuickTouchUtils::flush(window);
QCOMPARE(topItem->lastEvent.touchPoints.count(), 1); // received press only, not stationary
QVERIFY(middleItem->lastEvent.touchPoints.isEmpty());
QCOMPARE(bottomItem->lastEvent.touchPoints.count(), 1);
@@ -566,12 +567,13 @@ void tst_qquickwindow::touchEvent_basic()
// Otherwise you will get an assertion failure:
// ASSERT: "itemForTouchPointId.isEmpty()" in file items/qquickwindow.cpp
QTest::touchEvent(window, touchDevice).release(0, pos.toPoint(), window).release(1, pos.toPoint(), window);
+ QQuickTouchUtils::flush(window);
// move touch point from top item to bottom, and release
QTest::touchEvent(window, touchDevice).press(0, topItem->mapToScene(pos).toPoint(),window);
- QTest::qWait(50);
+ QQuickTouchUtils::flush(window);
QTest::touchEvent(window, touchDevice).release(0, bottomItem->mapToScene(pos).toPoint(),window);
- QTest::qWait(50);
+ QQuickTouchUtils::flush(window);
QCOMPARE(topItem->lastEvent.touchPoints.count(), 1);
COMPARE_TOUCH_DATA(topItem->lastEvent, makeTouchData(QEvent::TouchEnd, window, Qt::TouchPointReleased,
makeTouchPoint(topItem, topItem->mapFromItem(bottomItem, pos), pos)));
@@ -580,12 +582,12 @@ void tst_qquickwindow::touchEvent_basic()
// release while another point is pressed
QTest::touchEvent(window, touchDevice).press(0, topItem->mapToScene(pos).toPoint(),window)
.press(1, bottomItem->mapToScene(pos).toPoint(), window);
- QTest::qWait(50);
+ QQuickTouchUtils::flush(window);
QTest::touchEvent(window, touchDevice).move(0, bottomItem->mapToScene(pos).toPoint(), window);
- QTest::qWait(50);
+ QQuickTouchUtils::flush(window);
QTest::touchEvent(window, touchDevice).release(0, bottomItem->mapToScene(pos).toPoint(), window)
.stationary(1);
- QTest::qWait(50);
+ QQuickTouchUtils::flush(window);
QCOMPARE(topItem->lastEvent.touchPoints.count(), 1);
QVERIFY(middleItem->lastEvent.touchPoints.isEmpty());
QCOMPARE(bottomItem->lastEvent.touchPoints.count(), 1);
@@ -833,12 +835,15 @@ void tst_qquickwindow::touchEvent_velocity()
tp.area = QRectF(pos, QSizeF(4, 4));
points << tp;
QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, points);
+ QGuiApplication::processEvents();
+ QQuickTouchUtils::flush(window);
points[0].state = Qt::TouchPointMoved;
points[0].area.adjust(5, 5, 5, 5);
QVector2D velocity(1.5, 2.5);
points[0].velocity = velocity;
QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, points);
- QCoreApplication::processEvents();
+ QGuiApplication::processEvents();
+ QQuickTouchUtils::flush(window);
QCOMPARE(item->touchEventCount, 2);
QCOMPARE(item->lastEvent.touchPoints.count(), 1);
QCOMPARE(item->lastVelocity, velocity);
@@ -850,7 +855,8 @@ void tst_qquickwindow::touchEvent_velocity()
QVector2D transformedVelocity = transformMatrix.mapVector(velocity).toVector2D();
points[0].area.adjust(5, 5, 5, 5);
QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, points);
- QCoreApplication::processEvents();
+ QGuiApplication::processEvents();
+ QQuickTouchUtils::flush(window);
QCOMPARE(item->lastVelocity, transformedVelocity);
QPoint itemLocalPos = item->mapFromScene(window->mapFromGlobal(points[0].area.center().toPoint())).toPoint();
QPoint itemLocalPosFromEvent = item->lastEvent.touchPoints[0].pos().toPoint();
@@ -858,7 +864,8 @@ void tst_qquickwindow::touchEvent_velocity()
points[0].state = Qt::TouchPointReleased;
QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, points);
- QCoreApplication::processEvents();
+ QGuiApplication::processEvents();
+ QQuickTouchUtils::flush(window);
delete item;
}
@@ -890,14 +897,19 @@ void tst_qquickwindow::mouseFromTouch_basic()
tp.area = QRectF(pos, QSizeF(4, 4));
points << tp;
QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, points);
+ QGuiApplication::processEvents();
+ QQuickTouchUtils::flush(window);
points[0].state = Qt::TouchPointMoved;
points[0].area.adjust(5, 5, 5, 5);
QVector2D velocity(1.5, 2.5);
points[0].velocity = velocity;
QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, points);
+ QGuiApplication::processEvents();
+ QQuickTouchUtils::flush(window);
points[0].state = Qt::TouchPointReleased;
QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, points);
- QCoreApplication::processEvents();
+ QGuiApplication::processEvents();
+ QQuickTouchUtils::flush(window);
// The item should have received a mouse press, move, and release.
QCOMPARE(item->mousePressNum, 1);
@@ -916,16 +928,20 @@ void tst_qquickwindow::mouseFromTouch_basic()
points[0].velocity = velocity;
points[0].area = QRectF(pos, QSizeF(4, 4));
QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, points);
+ QGuiApplication::processEvents();
+ QQuickTouchUtils::flush(window);
points[0].state = Qt::TouchPointMoved;
points[0].area.adjust(5, 5, 5, 5);
QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, points);
- QCoreApplication::processEvents();
+ QGuiApplication::processEvents();
+ QQuickTouchUtils::flush(window);
QCOMPARE(item->lastMousePos.toPoint(), item->mapFromScene(window->mapFromGlobal(points[0].area.center().toPoint())).toPoint());
QCOMPARE(item->lastVelocityFromMouseMove, transformedVelocity);
points[0].state = Qt::TouchPointReleased;
QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, points);
QCoreApplication::processEvents();
+ QQuickTouchUtils::flush(window);
delete item;
}