summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@nokia.com>2011-10-24 13:13:53 +1000
committerQt by Nokia <qt-info@nokia.com>2011-10-24 06:39:20 +0200
commit7cef4b6463fdb73ff602ade64b222333dd23e46c (patch)
tree6b08e4cf3acda314ff78fd9e2d83f836d4514d34 /src
parentf49bd470990b838bb2c1a79605621e2d8c786a0b (diff)
Allow commiting and then reusing a QTouchEventSequence for testing.
This method allows calls to stationary() to automatically remember the previous position for a given touch point id. Example usage: QTouchEventSequence sequence = QTest::touchEvent(&window); sequence.press(0, QPoint(10,10)).commit(); sequence.stationary(0).press(1, QPoint(40,10)).commit(); Task-number: QTBUG-22057 Change-Id: I489ab3d61f4637d2ed97d09ed0854afa814407a1 Reviewed-by: Jason McDonald <jason.mcdonald@nokia.com>
Diffstat (limited to 'src')
-rw-r--r--src/testlib/qtesttouch.h53
1 files changed, 33 insertions, 20 deletions
diff --git a/src/testlib/qtesttouch.h b/src/testlib/qtesttouch.h
index b5333f1114..b021934355 100644
--- a/src/testlib/qtesttouch.h
+++ b/src/testlib/qtesttouch.h
@@ -77,7 +77,6 @@ namespace QTest
~QTouchEventSequence()
{
commit();
- points.clear();
}
QTouchEventSequence& press(int touchId, const QPoint &pt, QWindow *window = 0)
{
@@ -102,7 +101,7 @@ namespace QTest
}
QTouchEventSequence& stationary(int touchId)
{
- QTouchEvent::TouchPoint &p = point(touchId);
+ QTouchEvent::TouchPoint &p = pointOrPreviousPoint(touchId);
p.setState(Qt::TouchPointStationary);
return *this;
}
@@ -131,6 +130,25 @@ namespace QTest
}
#endif
+ void commit()
+ {
+ if (!points.isEmpty()) {
+ if (targetWindow)
+ {
+ QWindowSystemInterface::handleTouchEvent(targetWindow,QEvent::None,deviceType, touchPointList(points.values()));
+ QTest::qWait(10);
+ }
+#ifdef QT_WIDGETS_LIB
+ else if (targetWidget)
+ {
+ qt_translateRawTouchEvent(targetWidget, deviceType, points.values());
+ }
+#endif
+ }
+ previousPoints = points;
+ points.clear();
+ }
+
private:
#ifdef QT_WIDGETS_LIB
QTouchEventSequence(QWidget *widget, QTouchEvent::DeviceType aDeviceType)
@@ -146,8 +164,6 @@ namespace QTest
targetWindow(window), deviceType(aDeviceType)
{
}
- QTouchEventSequence(const QTouchEventSequence &v);
- void operator=(const QTouchEventSequence&);
QTouchEvent::TouchPoint &point(int touchId)
{
@@ -155,6 +171,18 @@ namespace QTest
points[touchId] = QTouchEvent::TouchPoint(touchId);
return points[touchId];
}
+
+ QTouchEvent::TouchPoint &pointOrPreviousPoint(int touchId)
+ {
+ if (!points.contains(touchId)) {
+ if (previousPoints.contains(touchId))
+ points[touchId] = previousPoints.value(touchId);
+ else
+ points[touchId] = QTouchEvent::TouchPoint(touchId);
+ }
+ return points[touchId];
+ }
+
#ifdef QT_WIDGETS_LIB
QPoint mapToScreen(QWidget *widget, const QPoint &pt)
{
@@ -190,23 +218,8 @@ namespace QTest
}
return newList;
}
- void commit()
- {
- if(targetWindow)
- {
- QWindowSystemInterface::handleTouchEvent(targetWindow,QEvent::None,deviceType, touchPointList(points.values()));
- QTest::qWait(10);
- targetWindow = 0;
- }
-#ifdef QT_WIDGETS_LIB
- else if(targetWidget)
- {
- qt_translateRawTouchEvent(targetWidget, deviceType, points.values());
- targetWidget = 0;
- }
-#endif
- }
+ QMap<int, QTouchEvent::TouchPoint> previousPoints;
QMap<int, QTouchEvent::TouchPoint> points;
#ifdef QT_WIDGETS_LIB
QWidget *targetWidget;