diff options
author | Paolo Angelelli <paolo.angelelli@qt.io> | 2016-10-11 13:36:06 +0200 |
---|---|---|
committer | Paolo Angelelli <paolo.angelelli@qt.io> | 2017-01-25 13:25:38 +0000 |
commit | a66306d3d8eab810b769a536095dbfa2a0eb6ce2 (patch) | |
tree | 61843e32114732b10c238d25535c89c95911d0c1 /tests | |
parent | be13464a488ccc2837b0c178ff16086be341e570 (diff) | |
download | qtlocation-a66306d3d8eab810b769a536095dbfa2a0eb6ce2.tar.gz |
Add rotation and tilt controls to QDeclarativeGeoMap
QDeclarativeGeoMap currently does not provide any mean to set bearing
and tilt into qgeocameradata.
It has been not a problem since QGeoTiledMap and sons did not support
it.
External renderers however support it, so this patch adds QML api
calls to control these parameters, and adapt the existing logic
to take them into consideration in camera-related
calls, as well as in the afterViewportChange handlers of the Map
Items.
This patch also sligthly modifies the QML api to make the handling
of all the bounded camera property more homogeneous.
Minimum and maximum zoom levels prior plugin initialization
aren't -1 anymore, but are some valid lower and upper bounds
for this property, that is 0 and 30.
in this way all the 2 bounded properties (zoomLevel and
tilt) behave the same, in that they can be freely set before plugin
initialization, within reasonable predefined bounds, and, after that,
they may be clamped depending on the actual plugin capabilities.
Autotests for the QML part of the API included.
Change-Id: I9d09e32698a7330388e465e8ea7523ee39577d34
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/declarative_ui/tst_map.qml | 44 | ||||
-rw-r--r-- | tests/auto/qgeotiledmapscene/tst_qgeotiledmapscene.cpp | 19 |
2 files changed, 58 insertions, 5 deletions
diff --git a/tests/auto/declarative_ui/tst_map.qml b/tests/auto/declarative_ui/tst_map.qml index 998a06d4..1c0f4719 100644 --- a/tests/auto/declarative_ui/tst_map.qml +++ b/tests/auto/declarative_ui/tst_map.qml @@ -84,6 +84,12 @@ Item { Map {id: coordinateMap; plugin: herePlugin; center: coordinate3; width: 1000; height: 1000; zoomLevel: 15 } + Map {id: mapTiltBearing; plugin: testPlugin; center: coordinate1; + width: 1000; height: 1000; zoomLevel: 4; bearing: 45.0; tilt: 25.0 } + + Map {id: mapTiltBearingHere; plugin: herePlugin; center: coordinate1; + width: 1000; height: 1000; zoomLevel: 4; bearing: 45.0; tilt: 25.0 } + MapParameter { id: testParameter type: "cameraCenter_test" @@ -161,11 +167,11 @@ Item { fuzzyCompare(center.latitude, -33, 0.1) fuzzyCompare(center.longitude, -47, 0.1) - testParameter.center = mapPar.center + testParameter.center = mapPar.center // map.center has not been affected as it lives in the Declarative Map mapPar.addMapParameter(testParameter) compare(mapPar.mapParameters.length, 1) - var center = mapPar.toCoordinate(Qt.point((mapPar.width - 1) / 2.0, (mapPar.height - 1) / 2.0)) + center = mapPar.toCoordinate(Qt.point((mapPar.width - 1) / 2.0, (mapPar.height - 1) / 2.0)) fuzzyCompare(center.latitude, 10, 0.1) fuzzyCompare(center.longitude, 11, 0.1) @@ -349,6 +355,40 @@ Item { mapCenterSpy.clear() } + function test_map_tilt_bearing() + { + compare(map.bearing, 0.0) + compare(map.tilt, 0.0) + compare(mapTiltBearing.bearing, 45.0) + compare(mapTiltBearing.tilt, 25.0) + compare(mapTiltBearingHere.bearing, 0.0) + compare(mapTiltBearingHere.tilt, 0.0) + + mapTiltBearing.bearing = 0.0 + mapTiltBearing.tilt = 0.0 + compare(mapTiltBearing.bearing, 0.0) + compare(mapTiltBearing.tilt, 0.0) + + mapTiltBearing.bearing = 480.0 + mapTiltBearing.tilt = 140.0 + compare(mapTiltBearing.bearing, 120.0) + compare(mapTiltBearing.tilt, 60.0) + + mapTiltBearing.tilt = -140.0 + compare(mapTiltBearing.tilt, 0.0) + + mapTiltBearingHere.bearing = 45.0 + mapTiltBearingHere.tilt = 25.0 + compare(mapTiltBearingHere.bearing, 0.0) + compare(mapTiltBearingHere.tilt, 0.0) + + mapTiltBearing.bearing = 45.0 + mapTiltBearing.tilt = 25.0 + mapTiltBearing.zoomLevel = 8.0 + compare(mapTiltBearing.bearing, 45.0) + compare(mapTiltBearing.tilt, 25.0) + } + function test_coordinate_conversion() { wait(1000) diff --git a/tests/auto/qgeotiledmapscene/tst_qgeotiledmapscene.cpp b/tests/auto/qgeotiledmapscene/tst_qgeotiledmapscene.cpp index 91b3eda8..6b3dc1f6 100644 --- a/tests/auto/qgeotiledmapscene/tst_qgeotiledmapscene.cpp +++ b/tests/auto/qgeotiledmapscene/tst_qgeotiledmapscene.cpp @@ -152,7 +152,7 @@ class tst_QGeoTiledMapScene : public QObject screenY = 0.0; mercatorX = cameraCenterX - scaledHalfLengthX; mercatorY = cameraCenterY - scaledHalfLengthY; - row (name + QString("_topLeftrScreen"), screenX, screenX2, screenY, cameraCenterX, cameraCenterY, + row (name + QString("_topLeftScreen"), screenX, screenX2, screenY, cameraCenterX, cameraCenterY, zoom, tileSize, screenWidth, screenHeight, mercatorX, mercatorY); // top @@ -288,6 +288,12 @@ class tst_QGeoTiledMapScene : public QObject screenCameraPositions(name, zoom, tileSize, screenWidth, screenHeight); } + // Calculates the distance in mercator space of 2 x coordinates, assuming that 1 == 0 + double wrappedMercatorDistance(double x1, double x2) + { + return qMin(qMin(qAbs(x1 - 1.0 - x2), qAbs(x1 - x2)), qAbs(x1 + 1.0 - x2)); + } + private slots: void screenToMercatorPositions(){ QFETCH(double, screenX); @@ -324,8 +330,15 @@ class tst_QGeoTiledMapScene : public QObject QDoubleVector2D point(screenX,screenY); QDoubleVector2D mercartorPos = projection.unwrapMapProjection(projection.itemPositionToWrappedMapProjection(point)); - QCOMPARE(mercartorPos.x(), mercatorX); - QCOMPARE(mercartorPos.y(), mercatorY); + const double tolerance = 0.00000000001; // FuzzyCompare is too strict here + QVERIFY2(wrappedMercatorDistance(mercartorPos.x(), mercatorX) < tolerance, + qPrintable(QString("Accepted: %1 , Actual: %2") + .arg(QString::number(mercatorX)) + .arg(QString::number(mercartorPos.x())))); + QVERIFY2(qAbs(mercartorPos.y() - mercatorY) < tolerance, + qPrintable(QString("Accepted: %1 , Actual: %2") + .arg(QString::number(mercatorY)) + .arg(QString::number(mercartorPos.y())))); } void screenToMercatorPositions_data() |