diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/location/declarativemaps/qdeclarativegeomap.cpp | 44 | ||||
-rw-r--r-- | src/location/declarativemaps/qdeclarativegeomap_p.h | 4 |
2 files changed, 32 insertions, 16 deletions
diff --git a/src/location/declarativemaps/qdeclarativegeomap.cpp b/src/location/declarativemaps/qdeclarativegeomap.cpp index 7fd5f78a..6a2d82e8 100644 --- a/src/location/declarativemaps/qdeclarativegeomap.cpp +++ b/src/location/declarativemaps/qdeclarativegeomap.cpp @@ -2289,17 +2289,31 @@ void QDeclarativeGeoMap::geometryChanged(const QRectF &newGeometry, const QRectF } /*! - \qmlmethod void QtLocation::Map::fitViewportToMapItems() + \qmlmethod void QtLocation::Map::fitViewportToMapItems(list<MapItems> items = {}) - 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. + If no argument is provided, 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. + If \a items is provided, fits the current viewport to the boundary of the specified map items only. + + \note This method gained the optional \a items argument since Qt 5.15. + In previous releases, this method fitted the map to all map items. \sa fitViewportToVisibleMapItems */ -void QDeclarativeGeoMap::fitViewportToMapItems() +void QDeclarativeGeoMap::fitViewportToMapItems(const QVariantList &items) { - fitViewportToMapItemsRefine(true, false); + if (items.size()) { + QList<QPointer<QDeclarativeGeoMapItemBase> > itms; + for (const QVariant &i: items) { + QDeclarativeGeoMapItemBase *itm = qobject_cast<QDeclarativeGeoMapItemBase *>(i.value<QObject *>()); + if (itm) + itms.append(itm); + } + fitViewportToMapItemsRefine(itms, true, false); + } else { + fitViewportToMapItemsRefine(m_mapItems, true, false); + } } /*! @@ -2313,18 +2327,20 @@ void QDeclarativeGeoMap::fitViewportToMapItems() */ void QDeclarativeGeoMap::fitViewportToVisibleMapItems() { - fitViewportToMapItemsRefine(true, true); + fitViewportToMapItemsRefine(m_mapItems, true, true); } /*! \internal */ -void QDeclarativeGeoMap::fitViewportToMapItemsRefine(bool refine, bool onlyVisible) +void QDeclarativeGeoMap::fitViewportToMapItemsRefine(const QList<QPointer<QDeclarativeGeoMapItemBase> > &mapItems, + bool refine, + bool onlyVisible) { if (!m_map) return; - if (m_mapItems.size() == 0) + if (mapItems.size() == 0) return; double minX = qInf(); @@ -2339,10 +2355,10 @@ void QDeclarativeGeoMap::fitViewportToMapItemsRefine(bool refine, bool onlyVisib // find bounds of all map items int itemCount = 0; - for (int i = 0; i < m_mapItems.count(); ++i) { - if (!m_mapItems.at(i)) + for (int i = 0; i < mapItems.count(); ++i) { + if (!mapItems.at(i)) continue; - QDeclarativeGeoMapItemBase *item = m_mapItems.at(i).data(); + QDeclarativeGeoMapItemBase *item = mapItems.at(i).data(); if (!item || (onlyVisible && (!item->isVisible() || item->mapItemOpacity() <= 0.0))) continue; @@ -2393,7 +2409,7 @@ void QDeclarativeGeoMap::fitViewportToMapItemsRefine(bool refine, bool onlyVisib if (itemCount == 0) { if (haveQuickItem) - fitViewportToMapItemsRefine(false, onlyVisible); + fitViewportToMapItemsRefine(mapItems, false, onlyVisible); return; } double bboxWidth = maxX - minX; @@ -2423,7 +2439,7 @@ void QDeclarativeGeoMap::fitViewportToMapItemsRefine(bool refine, bool onlyVisib // 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, onlyVisible); + fitViewportToMapItemsRefine(mapItems, false, onlyVisible); } /*! diff --git a/src/location/declarativemaps/qdeclarativegeomap_p.h b/src/location/declarativemaps/qdeclarativegeomap_p.h index c97c3622..ee9f8ec2 100644 --- a/src/location/declarativemaps/qdeclarativegeomap_p.h +++ b/src/location/declarativemaps/qdeclarativegeomap_p.h @@ -193,7 +193,7 @@ public: QQuickGeoMapGestureArea *gesture(); - Q_INVOKABLE void fitViewportToMapItems(); + Q_INVOKABLE void fitViewportToMapItems(const QVariantList &items = {}); Q_INVOKABLE void fitViewportToVisibleMapItems(); Q_INVOKABLE void pan(int dx, int dy); Q_INVOKABLE void prefetchData(); // optional hint for prefetch @@ -280,7 +280,7 @@ private: void setupMapView(QDeclarativeGeoMapItemView *view); void populateMap(); void populateParameters(); - void fitViewportToMapItemsRefine(bool refine, bool onlyVisible); + void fitViewportToMapItemsRefine(const QList<QPointer<QDeclarativeGeoMapItemBase> > &mapItems, bool refine, bool onlyVisible); bool isInteractive(); void attachCopyrightNotice(bool initialVisibility); void detachCopyrightNotice(bool currentVisibility); |