From e7099f14c8faea4fb7c89877973b7cec75044cb3 Mon Sep 17 00:00:00 2001 From: Paolo Angelelli Date: Tue, 26 Jul 2016 16:45:37 +0200 Subject: Enable dynamic addition/removal of map types by the mapping manager Map types are currently fixed in the constructor, regardless of whether they were available, or, now, whether they are enabled or not. This patch makes the geomappingmanager notify (e.g., emit a signal) when the available map types change at runtime. This is used in the OSM mappingmanagerengine, which can now disable map types if provider records turn out to be invalid or disabled after they have been fetched. Change-Id: I8e0e75504c882609f91c6d1ceb88424eee656f26 Reviewed-by: Leena Miettinen Reviewed-by: Alex Blasche --- src/imports/location/qdeclarativegeomap.cpp | 38 +++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'src/imports/location/qdeclarativegeomap.cpp') diff --git a/src/imports/location/qdeclarativegeomap.cpp b/src/imports/location/qdeclarativegeomap.cpp index b220c899..ad2b78da 100644 --- a/src/imports/location/qdeclarativegeomap.cpp +++ b/src/imports/location/qdeclarativegeomap.cpp @@ -249,6 +249,43 @@ void QDeclarativeGeoMap::onMapChildrenChanged() copyrights->setCopyrightsZ(maxChildZ + 1); } +static QDeclarativeGeoMapType *findMapType(const QList &types, const QGeoMapType &type) +{ + for (int i = 0; i < types.size(); ++i) + if (types[i]->mapType() == type) + return types[i]; + return Q_NULLPTR; +} + +void QDeclarativeGeoMap::onSupportedMapTypesChanged() +{ + QList supportedMapTypes; + QList types = m_mappingManager->supportedMapTypes(); + for (int i = 0; i < types.size(); ++i) { + // types that are present and get removed will be deleted at QObject destruction + QDeclarativeGeoMapType *type = findMapType(m_supportedMapTypes, types[i]); + if (!type) + type = new QDeclarativeGeoMapType(types[i], this); + supportedMapTypes.append(type); + } + m_supportedMapTypes.swap(supportedMapTypes); + if (m_supportedMapTypes.isEmpty()) { + m_map->setActiveMapType(QGeoMapType()); // no supported map types: setting an invalid one + } else { + bool hasMapType = false; + foreach (QDeclarativeGeoMapType *declarativeType, m_supportedMapTypes) { + if (declarativeType->mapType() == m_map->activeMapType()) + hasMapType = true; + } + if (!hasMapType) { + QDeclarativeGeoMapType *type = m_supportedMapTypes.at(0); + m_activeMapType = type; + m_map->setActiveMapType(type->mapType()); + } + } + + emit supportedMapTypesChanged(); +} void QDeclarativeGeoMap::setError(QGeoServiceProvider::Error error, const QString &errorString) { @@ -518,6 +555,7 @@ void QDeclarativeGeoMap::mappingManagerInitialized() m_map->prefetchData(); m_map->update(); + connect(m_mappingManager, SIGNAL(supportedMapTypesChanged()), this, SLOT(onSupportedMapTypesChanged())); emit minimumZoomLevelChanged(); emit maximumZoomLevelChanged(); emit supportedMapTypesChanged(); -- cgit v1.2.1