summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Angelelli <paolo.angelelli@qt.io>2019-08-21 13:42:06 +0200
committerAlex Blasche <alexander.blasche@qt.io>2019-09-26 08:18:44 +0000
commitefdf3c266dce8791b78d1a851b16d2f4dbe8534e (patch)
tree052c3278fb70161f9f9afdef652244729d56d81f
parent7bc06b5d57be39e47550e1d3d1082e405e666a24 (diff)
downloadqtlocation-efdf3c266dce8791b78d1a851b16d2f4dbe8534e.tar.gz
Add optional argument to Map.fitViewportToMapItems
So that a user-specified list of items can be fitted without requiring complex computations in JS to deduct the enclosing geo rectangle. Change-Id: I4a36fe72a49d5fc3566ba0b9fe1db930c4008885 Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
-rw-r--r--src/location/declarativemaps/qdeclarativegeomap.cpp44
-rw-r--r--src/location/declarativemaps/qdeclarativegeomap_p.h4
2 files changed, 32 insertions, 16 deletions
diff --git a/src/location/declarativemaps/qdeclarativegeomap.cpp b/src/location/declarativemaps/qdeclarativegeomap.cpp
index 4704dc3e..4f7c3945 100644
--- a/src/location/declarativemaps/qdeclarativegeomap.cpp
+++ b/src/location/declarativemaps/qdeclarativegeomap.cpp
@@ -2261,17 +2261,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);
+ }
}
/*!
@@ -2285,18 +2299,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();
@@ -2311,10 +2327,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;
@@ -2365,7 +2381,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;
@@ -2395,7 +2411,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);