diff options
author | Paolo Angelelli <paolo.angelelli@theqtcompany.com> | 2016-02-01 10:45:24 +0100 |
---|---|---|
committer | Paolo Angelelli <paolo.angelelli@theqtcompany.com> | 2016-03-02 14:41:22 +0000 |
commit | 820f79284248e5fcc9910282055e67f07c918559 (patch) | |
tree | 8bdfb0b283f463b13453c04c5a28f6734cf568f5 /tests | |
parent | 3a079a1e6761f3a26223e360d22530f22b5aeade (diff) | |
download | qtlocation-820f79284248e5fcc9910282055e67f07c918559.tar.gz |
Adjustment for the minimum zoom level to prevent gray bands
This patch introduces a lower bound for the minimum zoom level of
a map element so that it becomes canvas size dependent, and it will also
prevent the map from being smaller than the canvas size in either
dimension, avoiding gray bands.
It also bounds the center of the map so that the map cannot be panned or
flicked out of bounds.
The documentation for QDeclarativeGeoMap::minimumZoomLevel has been
modified to reflect the new behavior.
A few testcases have been modified to reflect this new behavior and its
implications.
Change-Id: I3c8160d0295e8dda2f7001e8fec68a5200ea2172
Reviewed-by: Michal Klocek <michal.klocek@theqtcompany.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/declarative_ui/tst_map.qml | 34 | ||||
-rw-r--r-- | tests/auto/declarative_ui/tst_map_mouse.qml | 2 | ||||
-rw-r--r-- | tests/auto/qgeomapcontroller/tst_qgeomapcontroller.cpp | 40 |
3 files changed, 60 insertions, 16 deletions
diff --git a/tests/auto/declarative_ui/tst_map.qml b/tests/auto/declarative_ui/tst_map.qml index 202fc958..c6620635 100644 --- a/tests/auto/declarative_ui/tst_map.qml +++ b/tests/auto/declarative_ui/tst_map.qml @@ -60,16 +60,30 @@ Item { Map { id: mapZoomOnCompleted; width: 200; height: 200; zoomLevel: 3; center: coordinate1; plugin: testPlugin; - Component.onCompleted: { zoomLevel = 7 } } + Component.onCompleted: { + zoomLevel = 7 + } + } + SignalSpy {id: mapZoomSpy; target: mapZoomOnCompleted; signalName: 'zoomLevelChanged'} + Map { id: mapZoomDefault; width: 200; height: 200; center: coordinate1; plugin: testPlugin; } - Map { id: mapZoomUserInit; width: 200; height: 200; - zoomLevel: 4; center: coordinate1; plugin: testPlugin; } - Map {id: map; plugin: testPlugin; center: coordinate1; width: 100; height: 100} - Map {id: coordinateMap; plugin: herePlugin; center: coordinate3; width: 1000; height: 1000; zoomLevel: 15} + Map { id: mapZoomUserInit; width: 210; height: 210; + zoomLevel: 4; center: coordinate1; plugin: testPlugin; + Component.onCompleted: { + console.log("mapZoomUserInit completed") + } + } + + Map {id: map; plugin: testPlugin; center: coordinate1; width: 100; height: 100} SignalSpy {id: mapCenterSpy; target: map; signalName: 'centerChanged'} - SignalSpy {id: mapZoomSpy; target: mapZoomOnCompleted; signalName: 'zoomLevelChanged'} + + Map {id: coordinateMap; plugin: herePlugin; center: coordinate3; + width: 1000; height: 1000; zoomLevel: 15 } + + + TestCase { when: windowShown @@ -156,7 +170,7 @@ Item { function test_zoom() { - wait(100) + wait(1000) compare(mapZoomOnCompleted.zoomLevel, 7) compare(mapZoomDefault.zoomLevel, 8) compare(mapZoomUserInit.zoomLevel, 4) @@ -164,7 +178,6 @@ Item { mapZoomSpy.clear() mapZoomOnCompleted.zoomLevel = 6 tryCompare(mapZoomSpy, "count", 1) - } function test_pan() @@ -264,10 +277,13 @@ Item { point = coordinateMap.fromCoordinate(altitudelessCoordinate) verify (point.x > 495 && point.x < 505) verify (point.y > 495 && point.y < 505) - // out of map area + // out of map area in view + //var oldZoomLevel = coordinateMap.zoomLevel + //coordinateMap.zoomLevel = 8 point = coordinateMap.fromCoordinate(coordinate4) verify(isNaN(point.x)) verify(isNaN(point.y)) + //coordinateMap.zoomLevel = oldZoomLevel // invalid coordinates point = coordinateMap.fromCoordinate(invalidCoordinate) verify(isNaN(point.x)) diff --git a/tests/auto/declarative_ui/tst_map_mouse.qml b/tests/auto/declarative_ui/tst_map_mouse.qml index 92603233..99aff03d 100644 --- a/tests/auto/declarative_ui/tst_map_mouse.qml +++ b/tests/auto/declarative_ui/tst_map_mouse.qml @@ -288,7 +288,7 @@ Item { clear_data() wait(500); // on map but without mouse area - var startZoomLevel = 6 + var startZoomLevel = 6.20 map.zoomLevel = startZoomLevel mouseWheel(map, 5, 5, 15, 5, Qt.LeftButton, Qt.NoModifiers) //see QDeclarativeGeoMapGestureArea::handleWheelEvent diff --git a/tests/auto/qgeomapcontroller/tst_qgeomapcontroller.cpp b/tests/auto/qgeomapcontroller/tst_qgeomapcontroller.cpp index cc1b4e4a..a5650e42 100644 --- a/tests/auto/qgeomapcontroller/tst_qgeomapcontroller.cpp +++ b/tests/auto/qgeomapcontroller/tst_qgeomapcontroller.cpp @@ -34,7 +34,7 @@ #include <QtLocation/private/qgeomappingmanager_p.h> #include <QtLocation/private/qgeomapcontroller_p.h> #include <QtLocation/private/qgeocameracapabilities_p.h> - +#include <cmath> /* for std::abs(double) */ QT_USE_NAMESPACE @@ -135,18 +135,29 @@ void tst_QGeoMapController::signalsConstructedTest() void tst_QGeoMapController::constructorTest_data() { QTest::addColumn<QGeoCoordinate>("center"); + QTest::addColumn<QGeoCoordinate>("expectedCenter"); QTest::addColumn<double>("bearing"); QTest::addColumn<double>("tilt"); QTest::addColumn<double>("roll"); QTest::addColumn<double>("zoom"); - QTest::newRow("zeros") << QGeoCoordinate() << 0.0 << 0.0 << 0.0 << 0.0; - QTest::newRow("valid") << QGeoCoordinate(10.0, 20.5, 30.8) << 0.1 << 0.2 << 0.3 << 2.0; - QTest::newRow("negative values") << QGeoCoordinate(-50, -20, 100) << -0.1 << -0.2 << -0.3 << 1.0; + QTest::newRow("zeros") << QGeoCoordinate() << QGeoCoordinate() << 0.0 << 0.0 << 0.0 << 0.0; + QTest::newRow("valid") << QGeoCoordinate(10.0, 20.5, 30.8) << QGeoCoordinate(10.0, 20.5, 30.8) << 0.1 << 0.2 << 0.3 << 2.0; + QTest::newRow("negative values") << QGeoCoordinate(-50, -20, 100) << QGeoCoordinate(-50, -20, 100) << -0.1 << -0.2 << -0.3 << 1.0; + QTest::newRow("clamped center negative") << QGeoCoordinate(-89, -45, 0) << QGeoCoordinate(-80.8728, -45, 0) << -0.1 << -0.2 << -0.3 << 1.0; + QTest::newRow("clamped center positive") << QGeoCoordinate(86, 38, 0) << QGeoCoordinate(80.8728, 38, 0) << -0.1 << -0.2 << -0.3 << 1.0; +} + +bool almostEqual(float x, float y) // qFuzzyCompare is too strict for this test +{ + const float epsilon = 1e-5; + return std::abs(x - y) <= epsilon * std::abs(x); + // see Knuth section 4.2.2 pages 217-218 } void tst_QGeoMapController::constructorTest() { QFETCH(QGeoCoordinate, center); + QFETCH(QGeoCoordinate, expectedCenter); QFETCH(double, bearing); QFETCH(double, tilt); QFETCH(double, roll); @@ -163,10 +174,27 @@ void tst_QGeoMapController::constructorTest() m_map->setCameraData(cameraData); QGeoMapController mapController(m_map.data()); + // make sure the values come out the same // also make sure the values match what they were actually set to - QCOMPARE(mapController.center(), cameraData.center()); - QCOMPARE(mapController.center(), center); + if (qIsNaN(cameraData.center().longitude())) { + QVERIFY(qIsNaN(mapController.center().longitude())); + } else { + QCOMPARE(mapController.center().longitude(), expectedCenter.longitude()); + } + if (qIsNaN(cameraData.center().altitude())) { + QVERIFY(qIsNaN(mapController.center().altitude())); + } else { + QCOMPARE(mapController.center().altitude(), expectedCenter.altitude()); + } + + // Verify that the latitude is either what was set or that it has been clamped correctly + if (qIsNaN(cameraData.center().latitude())) { + QVERIFY(qIsNaN(mapController.center().latitude())); + } else { + QVERIFY(almostEqual(mapController.center().latitude(), expectedCenter.latitude())); + } + QCOMPARE(mapController.zoom(), cameraData.zoomLevel()); QCOMPARE(mapController.zoom(), zoom); |