diff options
author | Paolo Angelelli <paolo.angelelli@qt.io> | 2017-01-31 17:12:22 +0100 |
---|---|---|
committer | Paolo Angelelli <paolo.angelelli@qt.io> | 2017-01-31 18:29:12 +0000 |
commit | 7d1660289bc83856f3cb79685415cb291f12b4f9 (patch) | |
tree | 961b5ff8e0ec78028fbe386bee006de5abbfe235 /src/location/declarativemaps/qdeclarativegeomap.cpp | |
parent | 0f035d991b2f94cf9bb3c592fb38e56f6bd058ee (diff) | |
download | qtlocation-7d1660289bc83856f3cb79685415cb291f12b4f9.tar.gz |
Add QDeclarativeGeoMap::fitViewportToVisibleMapItems
As per request, this additional method behaves like
fitViewportToMapItems except that only items that are visible
are considered
Task-number: QTBUG-57912
Change-Id: Ic334ad0a5a2899b2990a03d4ba655d03c39c1227
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
Diffstat (limited to 'src/location/declarativemaps/qdeclarativegeomap.cpp')
-rw-r--r-- | src/location/declarativemaps/qdeclarativegeomap.cpp | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/src/location/declarativemaps/qdeclarativegeomap.cpp b/src/location/declarativemaps/qdeclarativegeomap.cpp index 00be6376..b7ec31ca 100644 --- a/src/location/declarativemaps/qdeclarativegeomap.cpp +++ b/src/location/declarativemaps/qdeclarativegeomap.cpp @@ -1744,18 +1744,33 @@ void QDeclarativeGeoMap::geometryChanged(const QRectF &newGeometry, const QRectF Fits the current viewport to the boundary of all map items. The camera is positioned in the center of the map items, and at the largest integral zoom level possible which - allows all map items to be visible on screen + allows all map items to be visible on screen. + \sa fitViewportToVisibleMapItems */ void QDeclarativeGeoMap::fitViewportToMapItems() { - fitViewportToMapItemsRefine(true); + fitViewportToMapItemsRefine(true, false); +} + +/*! + \qmlmethod void QtLocation::Map::fitViewportToVisibleMapItems() + + Fits the current viewport to the boundary of all \b visible map items. + The camera is positioned in the center of the map items, and at the largest integral + zoom level possible which allows all map items to be visible on screen. + + \sa fitViewportToMapItems +*/ +void QDeclarativeGeoMap::fitViewportToVisibleMapItems() +{ + fitViewportToMapItemsRefine(true, true); } /*! \internal */ -void QDeclarativeGeoMap::fitViewportToMapItemsRefine(bool refine) +void QDeclarativeGeoMap::fitViewportToMapItemsRefine(bool refine, bool onlyVisible) { if (!m_map) return; @@ -1779,7 +1794,7 @@ void QDeclarativeGeoMap::fitViewportToMapItemsRefine(bool refine) if (!m_mapItems.at(i)) continue; QDeclarativeGeoMapItemBase *item = m_mapItems.at(i).data(); - if (!item) + if (!item || (onlyVisible && (!item->isVisible() || item->mapItemOpacity() <= 0.0))) continue; // skip quick items in the first pass and refine the fit later @@ -1821,7 +1836,7 @@ void QDeclarativeGeoMap::fitViewportToMapItemsRefine(bool refine) if (itemCount == 0) { if (haveQuickItem) - fitViewportToMapItemsRefine(false); + fitViewportToMapItemsRefine(false, onlyVisible); return; } double bboxWidth = maxX - minX; @@ -1851,7 +1866,7 @@ void QDeclarativeGeoMap::fitViewportToMapItemsRefine(bool refine) // as map quick items retain the same screen size after the camera zooms in/out // we refine the viewport again to achieve better results if (refine) - fitViewportToMapItemsRefine(false); + fitViewportToMapItemsRefine(false, onlyVisible); } bool QDeclarativeGeoMap::sendMouseEvent(QMouseEvent *event) |