summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichal Klocek <michal.klocek@theqtcompany.com>2016-06-23 15:48:28 +0200
committerMichal Klocek <michal.klocek@theqtcompany.com>2016-06-24 14:10:26 +0000
commit24ecdc6c962ff40096782bffc24b7d6623c4a87e (patch)
treefbbf6a2c35a6643ea99d97729fd7f6e6bc0fd612
parent93e4645cde4ad8ca00c2bcdacd6150d80f81bc1c (diff)
downloadqtlocation-24ecdc6c962ff40096782bffc24b7d6623c4a87e.tar.gz
A fix for not working setVisibleRegion
Setting the visibleRegion, than changing the map center or zoom and than setting it again does not work. Fix the issue by invalidating the region on the zoom or center change. Task-number: QTBUG-54141 Change-Id: I4e680f146312e3a3aa90e27fae213042cc2b2a42 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
-rw-r--r--src/imports/location/qdeclarativegeomap.cpp19
-rw-r--r--src/imports/location/qdeclarativegeomap_p.h2
-rw-r--r--tests/auto/declarative_ui/tst_map_item_fit_viewport.qml21
3 files changed, 39 insertions, 3 deletions
diff --git a/src/imports/location/qdeclarativegeomap.cpp b/src/imports/location/qdeclarativegeomap.cpp
index 2ef5d79d..7647a70b 100644
--- a/src/imports/location/qdeclarativegeomap.cpp
+++ b/src/imports/location/qdeclarativegeomap.cpp
@@ -182,7 +182,8 @@ QDeclarativeGeoMap::QDeclarativeGeoMap(QQuickItem *parent)
m_componentCompleted(false),
m_mappingManagerInitialized(false),
m_color(QColor::fromRgbF(0.9, 0.9, 0.9)),
- m_pendingFitViewport(false)
+ m_pendingFitViewport(false),
+ m_validRegion(false)
{
setAcceptHoverEvents(false);
setAcceptedMouseButtons(Qt::LeftButton);
@@ -503,7 +504,7 @@ void QDeclarativeGeoMap::mappingManagerInitialized()
connect(m_map->mapController(),
SIGNAL(centerChanged(QGeoCoordinate)),
this,
- SIGNAL(centerChanged(QGeoCoordinate)));
+ SLOT(mapCenterChanged(QGeoCoordinate)));
connect(m_map->mapController(),
SIGNAL(zoomChanged(qreal)),
this,
@@ -646,6 +647,8 @@ void QDeclarativeGeoMap::setZoomLevel(qreal zoomLevel)
return;
m_zoomLevel = zoomLevel;
+ m_validRegion = false;
+
if (m_mappingManagerInitialized)
m_map->mapController()->setZoom(m_zoomLevel);
emit zoomLevelChanged(zoomLevel);
@@ -676,6 +679,7 @@ void QDeclarativeGeoMap::setCenter(const QGeoCoordinate &center)
return;
m_center = center;
+ m_validRegion = false;
if (m_center.isValid() && m_mappingManagerInitialized) {
m_map->mapController()->setCenter(m_center);
@@ -714,7 +718,7 @@ QGeoCoordinate QDeclarativeGeoMap::center() const
*/
void QDeclarativeGeoMap::setVisibleRegion(const QGeoShape &shape)
{
- if (shape == m_region)
+ if (shape == m_region && m_validRegion)
return;
m_region = shape;
@@ -822,6 +826,8 @@ void QDeclarativeGeoMap::fitViewportToGeoShape()
newZoom = std::floor(qMax(minimumZoomLevel(), (m_map->mapController()->zoom() + newZoom)));
setProperty("zoomLevel", QVariant::fromValue(newZoom));
+
+ m_validRegion = true;
}
/*!
@@ -832,9 +838,16 @@ void QDeclarativeGeoMap::mapZoomLevelChanged(qreal zoom)
if (zoom == m_zoomLevel)
return;
m_zoomLevel = zoom;
+ m_validRegion = false;
emit zoomLevelChanged(m_zoomLevel);
}
+void QDeclarativeGeoMap::mapCenterChanged(const QGeoCoordinate &center)
+{
+ m_validRegion = false;
+ emit centerChanged(center);
+}
+
/*!
\qmlproperty list<MapType> QtLocation::Map::supportedMapTypes
diff --git a/src/imports/location/qdeclarativegeomap_p.h b/src/imports/location/qdeclarativegeomap_p.h
index fb36104a..ca1b7a62 100644
--- a/src/imports/location/qdeclarativegeomap_p.h
+++ b/src/imports/location/qdeclarativegeomap_p.h
@@ -167,6 +167,7 @@ protected:
private Q_SLOTS:
void mappingManagerInitialized();
void mapZoomLevelChanged(qreal zoom);
+ void mapCenterChanged(const QGeoCoordinate &center);
void pluginReady();
void onMapChildrenChanged();
@@ -198,6 +199,7 @@ private:
QGeoShape m_region;
QColor m_color;
bool m_pendingFitViewport;
+ bool m_validRegion;
friend class QDeclarativeGeoMapItem;
friend class QDeclarativeGeoMapItemView;
diff --git a/tests/auto/declarative_ui/tst_map_item_fit_viewport.qml b/tests/auto/declarative_ui/tst_map_item_fit_viewport.qml
index 8671d05d..4cbef945 100644
--- a/tests/auto/declarative_ui/tst_map_item_fit_viewport.qml
+++ b/tests/auto/declarative_ui/tst_map_item_fit_viewport.qml
@@ -357,6 +357,27 @@ Item {
verify(!is_coord_on_screen(fitCircleBottomRight))
verify(is_coord_on_screen(fitEmptyRect.topLeft))
verify(is_coord_on_screen(fitEmptyRect.bottomRight))
+
+ // Test if this can be reset
+ map.visibleRegion = fitRect
+ verify(is_coord_on_screen(fitRect.topLeft))
+ verify(is_coord_on_screen(fitRect.bottomRight))
+ // move map
+ map.center = QtPositioning.coordinate(0,0)
+ verify(!is_coord_on_screen(fitRect.topLeft))
+ verify(!is_coord_on_screen(fitRect.bottomRight))
+ // recheck
+ map.visibleRegion = fitRect
+ verify(is_coord_on_screen(fitRect.topLeft))
+ verify(is_coord_on_screen(fitRect.bottomRight))
+ //zoom map
+ map.zoomLevel++;
+ verify(!is_coord_on_screen(fitRect.topLeft))
+ verify(!is_coord_on_screen(fitRect.bottomRight))
+ // recheck
+ map.visibleRegion = fitRect
+ verify(is_coord_on_screen(fitRect.topLeft))
+ verify(is_coord_on_screen(fitRect.bottomRight))
}
/*function test_ad_visible_items_move() {