diff options
author | Liang Qi <liang.qi@qt.io> | 2016-08-01 09:53:55 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2016-08-01 09:54:08 +0200 |
commit | 19642842cea91a4588828362eba023c5da5ab57b (patch) | |
tree | 10366b074ae32e280300eb5f6fbcd5111ad4c82b /src/imports/location/qdeclarativegeomap.cpp | |
parent | 1a1d2e3fff5856dc9d1283b510a9f325c6fb8a93 (diff) | |
parent | e7099f14c8faea4fb7c89877973b7cec75044cb3 (diff) | |
download | qtlocation-19642842cea91a4588828362eba023c5da5ab57b.tar.gz |
Merge remote-tracking branch 'origin/5.6' into 5.7
Change-Id: I4f29307985225a723304783e00a6844a1b9ee825
Diffstat (limited to 'src/imports/location/qdeclarativegeomap.cpp')
-rw-r--r-- | src/imports/location/qdeclarativegeomap.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/imports/location/qdeclarativegeomap.cpp b/src/imports/location/qdeclarativegeomap.cpp index 75f81e1c..9b5c658f 100644 --- a/src/imports/location/qdeclarativegeomap.cpp +++ b/src/imports/location/qdeclarativegeomap.cpp @@ -254,6 +254,43 @@ void QDeclarativeGeoMap::onMapChildrenChanged() copyrights->setCopyrightsZ(maxChildZ + 1); } +static QDeclarativeGeoMapType *findMapType(const QList<QDeclarativeGeoMapType *> &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<QDeclarativeGeoMapType *> supportedMapTypes; + QList<QGeoMapType> 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) { @@ -542,6 +579,7 @@ void QDeclarativeGeoMap::mappingManagerInitialized() // This prefetches a buffer around the map m_map->prefetchData(); + connect(m_mappingManager, SIGNAL(supportedMapTypesChanged()), this, SLOT(onSupportedMapTypesChanged())); emit minimumZoomLevelChanged(); emit maximumZoomLevelChanged(); emit supportedMapTypesChanged(); |