diff options
author | Alex Blasche <alexander.blasche@theqtcompany.com> | 2015-01-13 15:37:41 +0100 |
---|---|---|
committer | Alex Blasche <alexander.blasche@theqtcompany.com> | 2015-01-19 14:04:33 +0100 |
commit | 56b64120c3b143c57dde2da12142be6d133415c8 (patch) | |
tree | 3641b3dfdcc8403593cdbe2e0c613685c4c4ab31 | |
parent | 648bde7a3a122297f0a159a511fc7e3fda22940c (diff) | |
download | qtlocation-56b64120c3b143c57dde2da12142be6d133415c8.tar.gz |
Don't override user's Map.zoomLevel when initializing QGeoCameraData
The user-chosen zoom level was reset during QGeoMap initialization.
This was caused by the construction of the QGeoMapController which in
turn constructed the first QGeoCameraData instance which had a default
initialised zoom level of 9. This default zoom level was immidiately
set as the maps zoom level which in turn invalidated the user's choice.
[ChangeLog][QtLocation][QML Map] Prevents overriding of user chosen
map zoom level during initialization.
Task-number: QTBUG-40779
Change-Id: I074632111738ffad041a7c54040168abca018fa2
Reviewed-by: Michal Klocek <michal.klocek@digia.com>
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
-rw-r--r-- | src/imports/location/qdeclarativegeomap.cpp | 5 | ||||
-rw-r--r-- | tests/auto/declarative_ui/tst_map.qml | 20 | ||||
-rw-r--r-- | tests/auto/declarative_ui/tst_map_item.qml | 2 |
3 files changed, 25 insertions, 2 deletions
diff --git a/src/imports/location/qdeclarativegeomap.cpp b/src/imports/location/qdeclarativegeomap.cpp index 6283adc3..74dc7e2b 100644 --- a/src/imports/location/qdeclarativegeomap.cpp +++ b/src/imports/location/qdeclarativegeomap.cpp @@ -462,6 +462,10 @@ void QDeclarativeGeoMap::mappingManagerInitialized() map_ = mappingManager_->createMap(this); gestureArea_->setMap(map_); + // once mappingManagerInitilized_ is set zoomLevel() returns the default initialised + // zoom level of the map controller. Overwrite it here to whatever the user chose. + map_->mapController()->setZoom(zoomLevel_); + //The zoom level limits are only restricted by the plugins values, if the user has set a more //strict zoom level limit before initialization nothing is done here. if (mappingManager_->cameraCapabilities().minimumZoomLevel() > gestureArea_->minimumZoomLevel()) @@ -493,7 +497,6 @@ void QDeclarativeGeoMap::mappingManagerInitialized() SLOT(mapZoomLevelChanged(qreal))); map_->mapController()->setCenter(center_); - map_->mapController()->setZoom(zoomLevel_); QList<QGeoMapType> types = mappingManager_->supportedMapTypes(); for (int i = 0; i < types.size(); ++i) { diff --git a/tests/auto/declarative_ui/tst_map.qml b/tests/auto/declarative_ui/tst_map.qml index 02de8bdf..02fd6360 100644 --- a/tests/auto/declarative_ui/tst_map.qml +++ b/tests/auto/declarative_ui/tst_map.qml @@ -63,10 +63,18 @@ Item { property variant invalidCoordinate: QtPositioning.coordinate() property variant altitudelessCoordinate: QtPositioning.coordinate(50, 50) + Map { id: mapZoomOnCompleted; width: 200; height: 200; + zoomLevel: 3; center: coordinate1; plugin: testPlugin; + Component.onCompleted: { zoomLevel = 7 } } + 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: nokiaPlugin; center: coordinate3; width: 1000; height: 1000; zoomLevel: 15} SignalSpy {id: mapCenterSpy; target: map; signalName: 'centerChanged'} + SignalSpy {id: mapZoomSpy; target: mapZoomOnCompleted; signalName: 'zoomLevelChanged'} TestCase { when: windowShown @@ -148,6 +156,18 @@ Item { compare(map.maximumZoomLevel, 20) } + function test_zoom() { + wait(100) + compare(mapZoomOnCompleted.zoomLevel, 7) + compare(mapZoomDefault.zoomLevel, 8) + compare(mapZoomUserInit.zoomLevel, 4) + + mapZoomSpy.clear() + mapZoomOnCompleted.zoomLevel = 6 + tryCompare(mapZoomSpy, "count", 1) + + } + function test_pan() { map.center.latitude = 30 map.center.longitude = 60 diff --git a/tests/auto/declarative_ui/tst_map_item.qml b/tests/auto/declarative_ui/tst_map_item.qml index 0f4f8aec..1076b6cc 100644 --- a/tests/auto/declarative_ui/tst_map_item.qml +++ b/tests/auto/declarative_ui/tst_map_item.qml @@ -115,7 +115,7 @@ Item { Map { id: map; x: 20; y: 20; width: 200; height: 200 - zoomLevel: 3 + zoomLevel: 9 center: mapDefaultCenter plugin: testPlugin; |