diff options
author | Aaron McCarthy <aaron.mccarthy@jollamobile.com> | 2013-12-18 15:15:58 +1000 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-02-11 01:02:51 +0100 |
commit | 334b9f3b0c4acb77db7254380c4a96cea6d589a8 (patch) | |
tree | eac101b47ec011783c050189ed8f3dbdef65d0e1 | |
parent | 1e58cb04817a3ea6fbed45d5bbb9e6aea99b282d (diff) | |
download | qtlocation-334b9f3b0c4acb77db7254380c4a96cea6d589a8.tar.gz |
Fix declarative_ui tests.
Coordinates for map items located outside the view port cannot be
converted to and from screen coordinates. During tests pan the map so
that the items under tests are inside the view port.
Tests for panning the map and dragging map items were failing because
mapping between coordinates and screen position only works for visible
screen positions. The MouseAreas under test did not have
preventStealing set, which was causing the map to pan slightly prior to
item drag being detected.
Stop gesture detection for a touch point when the mouse is grabbed by a
child item.
Task-number: QTBUG-31797
Change-Id: I42a801d50c194c6fe9629f3b0de606b406ad8b8c
Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
-rw-r--r-- | examples/location/mapviewer/content/map/Marker.qml | 1 | ||||
-rw-r--r-- | src/imports/location/qdeclarativegeomap.cpp | 4 | ||||
-rw-r--r-- | src/imports/location/qdeclarativegeomapgesturearea.cpp | 4 | ||||
-rw-r--r-- | src/imports/location/qdeclarativegeomapitembase.cpp | 1 | ||||
-rw-r--r-- | src/imports/location/qdeclarativepolygonmapitem.cpp | 28 | ||||
-rw-r--r-- | tests/auto/declarative_ui/tst_map.qml | 10 | ||||
-rw-r--r-- | tests/auto/declarative_ui/tst_map_item.qml | 80 | ||||
-rw-r--r-- | tests/auto/declarative_ui/tst_map_item_details.qml | 19 | ||||
-rw-r--r-- | tests/auto/declarative_ui/tst_map_mouse.qml | 2 |
9 files changed, 105 insertions, 44 deletions
diff --git a/examples/location/mapviewer/content/map/Marker.qml b/examples/location/mapviewer/content/map/Marker.qml index ece34819..0e9f1537 100644 --- a/examples/location/mapviewer/content/map/Marker.qml +++ b/examples/location/mapviewer/content/map/Marker.qml @@ -67,6 +67,7 @@ MapQuickItem { anchors.fill: parent hoverEnabled : false drag.target: marker + preventStealing: true onPressed : { map.pressX = mouse.x diff --git a/src/imports/location/qdeclarativegeomap.cpp b/src/imports/location/qdeclarativegeomap.cpp index 14003c0f..a59b30e7 100644 --- a/src/imports/location/qdeclarativegeomap.cpp +++ b/src/imports/location/qdeclarativegeomap.cpp @@ -752,7 +752,7 @@ qreal QDeclarativeGeoMap::zoomLevel() const */ void QDeclarativeGeoMap::setCenter(const QGeoCoordinate ¢er) { - if (center == center_) + if (!mappingManagerInitialized_ && center == center_) return; center_ = center; @@ -925,6 +925,8 @@ bool QDeclarativeGeoMap::childMouseEventFilter(QQuickItem *item, QEvent *event) return gestureArea_->filterMapChildMouseEvent(static_cast<QMouseEvent *>(event)); else return false; + case QEvent::UngrabMouse: + return gestureArea_->filterMapChildMouseEvent(static_cast<QMouseEvent *>(event)); case QEvent::TouchBegin: case QEvent::TouchUpdate: case QEvent::TouchEnd: diff --git a/src/imports/location/qdeclarativegeomapgesturearea.cpp b/src/imports/location/qdeclarativegeomapgesturearea.cpp index dcc86bac..88925524 100644 --- a/src/imports/location/qdeclarativegeomapgesturearea.cpp +++ b/src/imports/location/qdeclarativegeomapgesturearea.cpp @@ -679,6 +679,10 @@ bool QDeclarativeGeoMapGestureArea::filterMapChildMouseEvent(QMouseEvent *event) case QEvent::MouseMove: used = mouseMoveEvent(event); break; + case QEvent::UngrabMouse: + touchPoints_.clear(); + update(); + break; default: used = false; break; diff --git a/src/imports/location/qdeclarativegeomapitembase.cpp b/src/imports/location/qdeclarativegeomapitembase.cpp index 087d9c6a..d53da881 100644 --- a/src/imports/location/qdeclarativegeomapitembase.cpp +++ b/src/imports/location/qdeclarativegeomapitembase.cpp @@ -207,6 +207,7 @@ bool QDeclarativeGeoMapItemBase::childMouseEventFilter(QQuickItem *item, QEvent if (contains(static_cast<QMouseEvent*>(event)->pos())) { return false; } else { + event->setAccepted(false); return true; } default: diff --git a/src/imports/location/qdeclarativepolygonmapitem.cpp b/src/imports/location/qdeclarativepolygonmapitem.cpp index 9ba9c4e7..55261ed1 100644 --- a/src/imports/location/qdeclarativepolygonmapitem.cpp +++ b/src/imports/location/qdeclarativepolygonmapitem.cpp @@ -351,7 +351,7 @@ QDeclarativePolygonMapItem::~QDeclarativePolygonMapItem() \qmlproperty color MapPolygon::border.color This property is part of the border property group. The border property - group holds the width and color used to draw the border of the circle. + group holds the width and color used to draw the border of the polygon. The width is in pixels and is independent of the zoom level of the map. @@ -546,23 +546,21 @@ void QDeclarativePolygonMapItem::updateMapItem() geometry_.updateSourcePoints(*map(), path_); geometry_.updateScreenPoints(*map()); - if (border_.color() != Qt::transparent && border_.width() > 0) { - QList<QGeoCoordinate> closedPath = path_; - closedPath << closedPath.first(); - borderGeometry_.updateSourcePoints(*map(), closedPath); + QList<QGeoCoordinate> closedPath = path_; + closedPath << closedPath.first(); + borderGeometry_.clear(); + borderGeometry_.updateSourcePoints(*map(), closedPath); + + if (border_.color() != Qt::transparent && border_.width() > 0) borderGeometry_.updateScreenPoints(*map(), border_.width()); - QList<QGeoMapItemGeometry *> geoms; - geoms << &geometry_ << &borderGeometry_; - QRectF combined = QGeoMapItemGeometry::translateToCommonOrigin(geoms); + QList<QGeoMapItemGeometry *> geoms; + geoms << &geometry_ << &borderGeometry_; + QRectF combined = QGeoMapItemGeometry::translateToCommonOrigin(geoms); + + setWidth(combined.width()); + setHeight(combined.height()); - setWidth(combined.width()); - setHeight(combined.height()); - } else { - borderGeometry_.clear(); - setWidth(geometry_.sourceBoundingBox().width()); - setHeight(geometry_.sourceBoundingBox().height()); - } setPositionOnMap(path_.at(0), -1 * geometry_.sourceBoundingBox().topLeft()); update(); } diff --git a/tests/auto/declarative_ui/tst_map.qml b/tests/auto/declarative_ui/tst_map.qml index 584b5a48..bf17a19f 100644 --- a/tests/auto/declarative_ui/tst_map.qml +++ b/tests/auto/declarative_ui/tst_map.qml @@ -67,6 +67,7 @@ Item { property variant coordinate2: QtPositioning.coordinate(12, 13) property variant coordinate3: QtPositioning.coordinate(50, 50, 0) property variant coordinate4: QtPositioning.coordinate(80, 80, 0) + property variant coordinate5: QtPositioning.coordinate(20, 180) property variant invalidCoordinate: QtPositioning.coordinate() property variant altitudelessCoordinate: QtPositioning.coordinate(50, 50) @@ -102,6 +103,15 @@ Item { map.center = coordinate2 compare(mapCenterSpy.count, 1) + // change center to dateline + mapCenterSpy.clear() + compare(mapCenterSpy.count, 0) + map.center = coordinate5 + compare(mapCenterSpy.count, 1) + compare(map.center, coordinate5) + + map.center = coordinate2 + verify(isNaN(map.center.altitude)); compare(map.center.longitude, 13) compare(map.center.latitude, 12) diff --git a/tests/auto/declarative_ui/tst_map_item.qml b/tests/auto/declarative_ui/tst_map_item.qml index 3afae572..80d5d132 100644 --- a/tests/auto/declarative_ui/tst_map_item.qml +++ b/tests/auto/declarative_ui/tst_map_item.qml @@ -99,7 +99,6 @@ Item { radius: 600000 MouseArea { anchors.fill: parent - onClicked: console.log('ext circle clicked') SignalSpy { id: extMapCircleClicked; target: parent; signalName: "clicked" } } } @@ -144,6 +143,7 @@ Item { id: preMapRectMa anchors.fill: parent drag.target: parent + preventStealing: true SignalSpy { id: preMapRectClicked; target: parent; signalName: "clicked" } SignalSpy { id: preMapRectActiveChanged; target: parent.drag; signalName: "activeChanged" } } @@ -159,11 +159,12 @@ Item { latitude: 10 longitude: 30 } - radius: 400000 + radius: 10000 MouseArea { id: preMapCircleMa anchors.fill: parent drag.target: parent + preventStealing: true SignalSpy { id: preMapCircleClicked; target: parent; signalName: "clicked" } SignalSpy { id: preMapCircleActiveChanged; target: parent.drag; signalName: "activeChanged" } } @@ -176,8 +177,10 @@ Item { MapQuickItem { id: preMapQuickItem MouseArea { + id: preMapQuickItemMa anchors.fill: parent drag.target: parent + preventStealing: true SignalSpy { id: preMapQuickItemClicked; target: parent; signalName: "clicked" } SignalSpy { id: preMapQuickItemActiveChanged; target: parent.drag; signalName: "activeChanged" } } @@ -258,30 +261,39 @@ Item { // precondition compare(preMapRectClicked.count, 0) compare(preMapCircleClicked.count, 0) + // click rect + map.center = preMapRect.topLeft var point = map.toScreenPosition(preMapRect.topLeft) mouseClick(map, point.x + 5, point.y + 5) compare(preMapRectClicked.count, 1) mouseClick(map, 1, 1) // no item hit compare(preMapRectClicked.count, 1) compare(preMapCircleClicked.count, 0) + // click circle, overlaps and is above rect - visualInspectionPoint() // marks good visual inspection point + map.center = preMapCircle.center point = map.toScreenPosition(preMapCircle.center) mouseClick(map, point.x - 5, point.y - 5) compare(preMapRectClicked.count, 1) compare(preMapCircleClicked.count, 1) + // click within circle bounding rect but not inside the circle geometry + map.center = preMapCircle.center.atDistanceAndAzimuth(preMapCircle.radius, -45) mouseClick(map, preMapCircle.x + 4, preMapCircle.y + 4) compare(preMapRectClicked.count, 2) compare(preMapCircleClicked.count, 1) + // click quick item compare(preMapQuickItemClicked.count, 0) + map.center = preMapQuickItem.coordinate point = map.toScreenPosition(preMapQuickItem.coordinate) mouseClick(map, point.x + 5, point.y + 5) compare(preMapQuickItemClicked.count, 1) + // click polygon compare (preMapPolygonClicked.count, 0) + map.center = preMapPolygon.path[1] point = map.toScreenPosition(preMapPolygon.path[1]) mouseClick(map, point.x - 5, point.y) compare(preMapPolygonClicked.count, 1) @@ -290,26 +302,31 @@ Item { map.clearMapItems() clear_data() compare (map.mapItems.length, 0) + map.center = preMapRect.topLeft point = map.toScreenPosition(preMapRect.topLeft) mouseClick(map, point.x + 5, point.y + 5) compare(preMapRectClicked.count, 0) visualInspectionPoint() + map.center = preMapCircle.center point = map.toScreenPosition(preMapCircle.center) mouseClick(map, point.x - 5, point.y - 5) compare(preMapRectClicked.count, 0) compare(preMapCircleClicked.count, 0) + map.center = preMapCircle.center.atDistanceAndAzimuth(preMapCircle.radius, -45) mouseClick(map, preMapCircle.x + 4, preMapCircle.y + 4) compare(preMapRectClicked.count, 0) compare(preMapCircleClicked.count, 0) compare(preMapQuickItemClicked.count, 0) + map.center = preMapQuickItem.coordinate point = map.toScreenPosition(preMapQuickItem.coordinate) mouseClick(map, point.x + 5, point.y + 5) compare(preMapQuickItemClicked.count, 0) + map.center = preMapPolygon.path[1] point = map.toScreenPosition(preMapPolygon.path[1]) mouseClick(map, point.x - 5, point.y) compare(preMapPolygonClicked.count, 0) - // re-add items and verify they are back (without needing to pan map etc.) + // re-add items and verify they are back // note: addition order is significant map.addMapItem(preMapRect) map.addMapItem(preMapCircle) @@ -319,20 +336,25 @@ Item { map.addMapItem(preMapRoute) compare (map.mapItems.length, 6) visualInspectionPoint() + map.center = preMapRect.topLeft point = map.toScreenPosition(preMapRect.topLeft) mouseClick(map, point.x + 5, point.y + 5) compare(preMapRectClicked.count, 1) + map.center = preMapCircle.center point = map.toScreenPosition(preMapCircle.center) mouseClick(map, point.x - 5, point.y - 5) compare(preMapRectClicked.count, 1) compare(preMapCircleClicked.count, 1) + map.center = preMapCircle.center.atDistanceAndAzimuth(preMapCircle.radius, -45) mouseClick(map, preMapCircle.x + 4, preMapCircle.y + 4) compare(preMapRectClicked.count, 2) compare(preMapCircleClicked.count, 1) compare(preMapQuickItemClicked.count, 0) + map.center = preMapQuickItem.coordinate point = map.toScreenPosition(preMapQuickItem.coordinate) mouseClick(map, point.x + 5, point.y + 5) compare(preMapQuickItemClicked.count, 1) + map.center = preMapPolygon.path[1] point = map.toScreenPosition(preMapPolygon.path[1]) mouseClick(map, point.x - 5, point.y) compare(preMapPolygonClicked.count, 1) @@ -340,41 +362,45 @@ Item { // item clips to map. not sure if this is sensible test map.addMapItem(extMapCircle) + map.center = extMapCircle.center visualInspectionPoint(); point = map.toScreenPosition(extMapCircle.center) mouseClick(map, point.x, point.y) compare(extMapCircleClicked.count, 1) mouseClick(map, point.x, -5) compare(extMapCircleClicked.count, 1) + map.removeMapItem(extMapCircle) map.addMapItem(extMapQuickItem) + map.center = extMapQuickItem.coordinate visualInspectionPoint(); point = map.toScreenPosition(extMapQuickItem.coordinate) mouseClick(map, point.x + 5, point.y + 5) compare(extMapQuickItemClicked.count, 1) mouseClick(map, map.width + 5, point.y + 5) compare(extMapQuickItemClicked.count, 1) + map.removeMapItem(extMapQuickItem) } function test_ab_drag() { clear_data() // basic drags, drag rectangle compare (preMapRectActiveChanged.count, 0) - var i = 0 + map.center = preMapRect.topLeft + var i var point = map.toScreenPosition(preMapRect.topLeft) + var targetCoordinate = map.toCoordinate(51, 51) mousePress(map, point.x + 5, point.y + 5) - for (i=0; i < 50; i += 5) { + for (i = 0; i < 50; i += 1) { wait(1) mouseMove(map, point.x + 5 - i, point.y + 5 - i) } mouseRelease(map, point.x + 5 - i, point.y + 5 - i) - visualInspectionPoint() compare (preMapRectActiveChanged.count, 2) - // coordinates update only (once) after drag has finished - compare (preMapRectTopLeftChanged.count, 1) - compare (preMapRectBottomRightChanged.count, 1) - verify(fuzzy_compare(preMapRect.topLeft.latitude, 27.2, 0.1)) - verify(fuzzy_compare(preMapRect.topLeft.longitude, 12.1, 0.1)) + verify(preMapRectTopLeftChanged.count > 1) + verify(preMapRectBottomRightChanged.count === preMapRectTopLeftChanged.count) + verify(fuzzy_compare(preMapRect.topLeft.latitude, targetCoordinate.latitude, 0.2)) + verify(fuzzy_compare(preMapRect.topLeft.longitude, targetCoordinate.longitude, 0.2)) var latH = preMapRect.bottomRight.latitude - preMapRect.topLeft.latitude var lonW = preMapRect.bottomRight.longitude - preMapRect.topLeft.longitude verify(fuzzy_compare(preMapRect.bottomRight.latitude, preMapRect.topLeft.latitude + latH, 0.1)) @@ -382,34 +408,38 @@ Item { // drag circle compare (preMapCircleActiveChanged.count, 0) + map.center = preMapCircle.center point = map.toScreenPosition(preMapCircle.center) + targetCoordinate = map.toCoordinate(51, 51) mousePress(map, point.x, point.y) - for (i=0; i < 50; i += 5) { + for (i = 0; i < 50; i += 1) { wait(1) mouseMove(map, point.x - i, point.y - i) } mouseRelease(map, point.x - i, point.y - i) visualInspectionPoint() - compare (preMapRectActiveChanged.count, 2) - compare (preMapCircleCenterChanged.count, 1) - verify(fuzzy_compare(preMapCircle.center.latitude, 17.7, 0.1)) - verify(fuzzy_compare(preMapCircle.center.longitude, 22.1, 0.1)) + compare(preMapRectActiveChanged.count, 2) + compare(preMapCircleActiveChanged.count, 2) + verify(preMapCircleCenterChanged.count > 1) + verify(fuzzy_compare(preMapCircle.center.latitude, targetCoordinate.latitude, 0.2)) + verify(fuzzy_compare(preMapCircle.center.longitude, targetCoordinate.longitude, 0.2)) // drag quick item compare (preMapQuickItemActiveChanged.count, 0) - i = 0 + map.center = preMapQuickItem.coordinate point = map.toScreenPosition(preMapQuickItem.coordinate) + targetCoordinate = map.toCoordinate(51, 51) mousePress(map, point.x + 5, point.y + 5) - for (i=0; i < 50; i += 5) { + for (i = 0; i < 50; i += 1) { wait(1) - mouseMove(map, point.x + i, point.y + i) + mouseMove(map, point.x - i, point.y - i) } - mouseRelease(map, point.x + i, point.y + i) + mouseRelease(map, point.x - i, point.y - i) visualInspectionPoint() - compare (preMapQuickItemActiveChanged.count, 2) - compare (preMapQuickItemCoordinateChanged.count, 1) - verify(fuzzy_compare(preMapQuickItem.coordinate.latitude, 29, 0.1)) - verify(fuzzy_compare(preMapQuickItem.coordinate.longitude, 10, 0.1)) + compare(preMapQuickItemActiveChanged.count, 2) + verify(preMapQuickItemCoordinateChanged.count > 1) + verify(fuzzy_compare(preMapQuickItem.coordinate.latitude, targetCoordinate.latitude, 0.2)) + verify(fuzzy_compare(preMapQuickItem.coordinate.longitude, targetCoordinate.longitude, 0.2)) } function test_ac_basic_properties() { diff --git a/tests/auto/declarative_ui/tst_map_item_details.qml b/tests/auto/declarative_ui/tst_map_item_details.qml index a15fc353..ca7ca8c2 100644 --- a/tests/auto/declarative_ui/tst_map_item_details.qml +++ b/tests/auto/declarative_ui/tst_map_item_details.qml @@ -112,6 +112,7 @@ Item { MouseArea { anchors.fill: parent drag.target: parent + preventStealing: true } } @@ -126,6 +127,7 @@ Item { MouseArea { anchors.fill: parent drag.target: parent + preventStealing: true } } @@ -134,6 +136,7 @@ Item { MouseArea { anchors.fill: parent drag.target: parent + preventStealing: true } coordinate { latitude: 20 @@ -158,6 +161,7 @@ Item { MouseArea { anchors.fill: parent drag.target: parent + preventStealing: true } } @@ -322,6 +326,7 @@ Item { clear_data() compare (extMapPolygon.border.width, 1.0) compare (extMapPolygonClicked.count, 0) + map.center = extMapPolygon.path[1] var point = map.toScreenPosition(extMapPolygon.path[1]) map.addMapItem(extMapPolygon) verify(extMapPolygon.path.length == 2) @@ -429,6 +434,7 @@ Item { extMapRectDateline.bottomRight.longitude = datelineCoordinateRight.longitude point = map.toScreenPosition(extMapRectDateline.bottomRight) verify(point.x > map.width / 2.0) + // move item edge onto dateline extMapRectDateline.topLeft.longitude = datelineCoordinate.longitude point = map.toScreenPosition(extMapRectDateline.topLeft) verify(point.x == map.width / 2.0) @@ -448,8 +454,9 @@ Item { // circle map.addMapItem(extMapCircleDateline) - verify(extMapCircleDateline.center.longitude == 180) - var point = map.toScreenPosition(extMapCircleDateline.center) + verify(extMapCircleDateline.center.longitude === 180) + map.center = datelineCoordinate + point = map.toScreenPosition(extMapCircleDateline.center) verify(point.x == map.width / 2.0) extMapCircleDateline.center.longitude = datelineCoordinateRight.longitude point = map.toScreenPosition(extMapCircleDateline.center) @@ -466,7 +473,8 @@ Item { // quickitem map.addMapItem(extMapQuickItemDateline) - verify(extMapQuickItemDateline.coordinate.longitude == 175) + map.center = datelineCoordinate + verify(extMapQuickItemDateline.coordinate.longitude === 175) point = map.toScreenPosition(extMapQuickItemDateline.coordinate) verify(point.x < map.width / 2.0) extMapQuickItemDateline.coordinate.longitude = datelineCoordinateRight.longitude @@ -484,6 +492,7 @@ Item { // polygon map.addMapItem(extMapPolygonDateline) + map.center = datelineCoordinate verify(extMapPolygonDateline.path[0].longitude == 175) verify(extMapPolygonDateline.path[1].longitude == -175) verify(extMapPolygonDateline.path[2].longitude == -175) @@ -530,6 +539,7 @@ Item { // polyline map.addMapItem(extMapPolylineDateline) + map.center = datelineCoordinate verify(extMapPolylineDateline.path[0].longitude == 175) verify(extMapPolylineDateline.path[1].longitude == -175) point = map.toScreenPosition(extMapPolylineDateline.path[0]) @@ -626,6 +636,7 @@ Item { // circle map.addMapItem(extMapCircleEdge) + map.center = datelineCoordinate verify(extMapCircleEdge.center.longitude == -15) var point = map.toScreenPosition(extMapCircleEdge.center) verify(point.x < map.width) @@ -647,6 +658,7 @@ Item { // quickitem map.addMapItem(extMapQuickItemEdge) + map.center = datelineCoordinate verify(extMapQuickItemEdge.coordinate.longitude == -15) point = map.toScreenPosition(extMapQuickItemEdge.coordinate) verify(point.x < map.width) @@ -666,6 +678,7 @@ Item { map.removeMapItem(extMapQuickItemEdge) // polygon + map.center = datelineCoordinate map.addMapItem(extMapPolygonEdge) verify(extMapPolygonEdge.path[0].longitude == -15) verify(extMapPolygonEdge.path[1].longitude == -5) diff --git a/tests/auto/declarative_ui/tst_map_mouse.qml b/tests/auto/declarative_ui/tst_map_mouse.qml index 189b7c7b..a8bff2e8 100644 --- a/tests/auto/declarative_ui/tst_map_mouse.qml +++ b/tests/auto/declarative_ui/tst_map_mouse.qml @@ -126,6 +126,8 @@ Item { property bool lastIsClick: false property bool lastAccepted: false; + preventStealing: true + // The following signal handlers use arguments[0] instead of mouse due to QTBUG-36560 onClicked: page.setMouseData(mouseUpper, arguments[0]) onDoubleClicked: page.setMouseData(mouseUpper, arguments[0]) |