diff options
author | Paolo Angelelli <paolo.angelelli@qt.io> | 2019-07-23 11:51:41 +0200 |
---|---|---|
committer | paolo <paolo.angelelli@qt.io> | 2019-10-31 11:17:30 +0100 |
commit | 60925ff5d4aaf211090b246618b492cf177cf21d (patch) | |
tree | 4d08471475884d10bfbd5fb057c9f4a6104ae1c5 /src/location/declarativemaps/qdeclarativegeomap.cpp | |
parent | 769de139fa137d9845b156ac96afb8bec16ff307 (diff) | |
download | qtlocation-60925ff5d4aaf211090b246618b492cf177cf21d.tar.gz |
Fix slow Map.removeMapItem
This removes connections in map items to react on map changes.
A further improvement could be replacing item lists with QSets.
This might however have implications with plugins which
might expect ordered items.
Change-Id: I52dbd64ed22762b1e2d51d1bc38f496346e7a664
Fixes: QTBUG-76950
(cherry picked from commit 2bb07804f32e0c9cc7948a5cff0bcef81ae9d8c9)
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src/location/declarativemaps/qdeclarativegeomap.cpp')
-rw-r--r-- | src/location/declarativemaps/qdeclarativegeomap.cpp | 39 |
1 files changed, 29 insertions, 10 deletions
diff --git a/src/location/declarativemaps/qdeclarativegeomap.cpp b/src/location/declarativemaps/qdeclarativegeomap.cpp index 5997bd3e..ad1dc1f3 100644 --- a/src/location/declarativemaps/qdeclarativegeomap.cpp +++ b/src/location/declarativemaps/qdeclarativegeomap.cpp @@ -623,6 +623,15 @@ void QDeclarativeGeoMap::mappingManagerInitialized() if (!m_map) return; + // Any map items that were added before the plugin was ready + // need to have setMap called again + for (const QPointer<QDeclarativeGeoMapItemBase> &item : qAsConst(m_mapItems)) { + if (item) { + item->setMap(this, m_map); + m_map->addMapItem(item.data()); // m_map filters out what is not supported. + } + } + /* COPY NOTICE SETUP */ m_copyrights = new QDeclarativeGeoMapCopyrightNotice(this); m_copyrights->setCopyrightsZ(m_maxChildZ + 1); @@ -706,15 +715,6 @@ void QDeclarativeGeoMap::mappingManagerInitialized() emit supportedMapTypesChanged(); emit activeMapTypeChanged(); - // Any map items that were added before the plugin was ready - // need to have setMap called again - for (const QPointer<QDeclarativeGeoMapItemBase> &item : qAsConst(m_mapItems)) { - if (item) { - item->setMap(this, m_map); - m_map->addMapItem(item.data()); // m_map filters out what is not supported. - } - } - // Any map item groups that were added before the plugin was ready // DO NOT need to have setMap called again on their children map items // because they have been added to m_mapItems, which is processed right above. @@ -1423,6 +1423,14 @@ void QDeclarativeGeoMap::setVisibleArea(const QRectF &visibleArea) if (m_initialized) { m_map->setVisibleArea(visibleArea); + const QRectF newVisibleArea = QDeclarativeGeoMap::visibleArea(); + if (newVisibleArea != oldVisibleArea) { + // polish map items + for (const QPointer<QDeclarativeGeoMapItemBase> &i: qAsConst(m_mapItems)) { + if (i) + i->visibleAreaChanged(); + } + } } else { m_visibleArea = visibleArea; const QRectF newVisibleArea = QDeclarativeGeoMap::visibleArea(); @@ -1744,6 +1752,11 @@ void QDeclarativeGeoMap::onCameraDataChanged(const QGeoCameraData &cameraData) bool zoomHasChanged = cameraData.zoomLevel() != m_cameraData.zoomLevel(); m_cameraData = cameraData; + // polish map items + for (const QPointer<QDeclarativeGeoMapItemBase> &i: qAsConst(m_mapItems)) { + if (i) + i->baseCameraDataChanged(m_cameraData); // Consider optimizing this further, removing the contained duplicate if conditions. + } if (centerHasChanged) emit centerChanged(m_cameraData.center()); @@ -2225,7 +2238,13 @@ void QDeclarativeGeoMap::geometryChanged(const QRectF &newGeometry, const QRectF QGeoCoordinate coord = cameraData.center(); coord.setLatitude(qBound(m_minimumViewportLatitude, coord.latitude(), m_maximumViewportLatitude)); cameraData.setCenter(coord); - m_map->setCameraData(cameraData); + m_map->setCameraData(cameraData); // this polishes map items + } else if (oldGeometry.size() != newGeometry.size()) { + // polish map items + for (const QPointer<QDeclarativeGeoMapItemBase> &i: qAsConst(m_mapItems)) { + if (i) + i->polishAndUpdate(); + } } } |