summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2016-08-01 09:53:55 +0200
committerLiang Qi <liang.qi@qt.io>2016-08-01 09:54:08 +0200
commit19642842cea91a4588828362eba023c5da5ab57b (patch)
tree10366b074ae32e280300eb5f6fbcd5111ad4c82b
parent1a1d2e3fff5856dc9d1283b510a9f325c6fb8a93 (diff)
parente7099f14c8faea4fb7c89877973b7cec75044cb3 (diff)
Merge remote-tracking branch 'origin/5.6' into 5.7
-rw-r--r--src/imports/location/qdeclarativegeomap.cpp38
-rw-r--r--src/imports/location/qdeclarativegeomap_p.h1
-rw-r--r--src/location/doc/src/plugins/osm.qdoc9
-rw-r--r--src/location/maps/qgeomappingmanager.cpp6
-rw-r--r--src/location/maps/qgeomappingmanager_p.h1
-rw-r--r--src/location/maps/qgeomappingmanagerengine.cpp1
-rw-r--r--src/location/maps/qgeomappingmanagerengine_p.h1
-rw-r--r--src/plugins/geoservices/osm/qgeotiledmappingmanagerengineosm.cpp46
-rw-r--r--src/plugins/geoservices/osm/qgeotiledmappingmanagerengineosm.h7
-rw-r--r--src/plugins/geoservices/osm/qgeotilefetcherosm.cpp5
10 files changed, 103 insertions, 12 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();
diff --git a/src/imports/location/qdeclarativegeomap_p.h b/src/imports/location/qdeclarativegeomap_p.h
index 31723490..d1d69656 100644
--- a/src/imports/location/qdeclarativegeomap_p.h
+++ b/src/imports/location/qdeclarativegeomap_p.h
@@ -173,6 +173,7 @@ private Q_SLOTS:
void mappingManagerInitialized();
void pluginReady();
void onMapChildrenChanged();
+ void onSupportedMapTypesChanged();
private:
void setupMapView(QDeclarativeGeoMapItemView *view);
diff --git a/src/location/doc/src/plugins/osm.qdoc b/src/location/doc/src/plugins/osm.qdoc
index 2fd9e7c4..75ac104d 100644
--- a/src/location/doc/src/plugins/osm.qdoc
+++ b/src/location/doc/src/plugins/osm.qdoc
@@ -37,12 +37,17 @@
This geo services plugin allows applications to access
\l {http://openstreetmap.org}{Open Street Map} location based services using the Qt Location API.
-Data, imagery and map information provided by \l {http://www.mapquest.com}{MapQuest},
+Data, imagery and map information provided by \l {http://korona.geog.uni-heidelberg.de/}{OpenMapSurfer},
\l {http://www.thunderforest.com/}{ThunderForest}, OpenStreetMap and contributors. The data is
available under the \l {http://www.opendatacommons.org/licenses/odbl}{Open Database License}.
The Open Street Map geo services plugin can be loaded by using the plugin key "osm".
+\note Since Qt 5.6.2, the available map types offered by this plugin may change without notice depending on the
+actual availability of each provider. To prevent these changes, either a different geo service plugin should be used, or the plugin
+parameter \e osm.mapping.providersrepository.address should be set to a user-specified repository, in order to take full control over
+(and accept \b responsibility for) selecting the provider that is used for each map type.
+
\section1 Parameters
\section2 Optional parameters
@@ -78,7 +83,7 @@ a prefix.
\li The OpenStreetMap plugin retrieves the provider's information from a remote repository. This is done to prevent using hardcoded
servers by default, which may become unavailable. By default this information is fetched from \l {http://maps-redirect.qt.io} {maps-redirect.qt.io}.
Setting this parameter changes the provider repository address to a user-specified one, which must contain the files
- \tt{street}, \tt{satellite}, \tt{cycle}, \tt{transit}, \tt{night-transit}, \tt{terrain} and \tt{hiking}.
+ \tt{street}, \tt{satellite}, \tt{cycle}, \tt{transit}, \tt{night-transit}, \tt{terrain} and \tt{hiking}, each of which must contain valid provider information.
\row
\li osm.mapping.providersrepository.disabled
\li By default, the OpenStreetMap plugin retrieves the provider's information from a remote repository to avoid a loss of service due to unavailability of hardcoded services.
diff --git a/src/location/maps/qgeomappingmanager.cpp b/src/location/maps/qgeomappingmanager.cpp
index 5e9531ca..12e61c71 100644
--- a/src/location/maps/qgeomappingmanager.cpp
+++ b/src/location/maps/qgeomappingmanager.cpp
@@ -81,6 +81,12 @@ QGeoMappingManager::QGeoMappingManager(QGeoMappingManagerEngine *engine, QObject
this,
SIGNAL(initialized()),
Qt::QueuedConnection);
+
+ connect(d_ptr->engine,
+ SIGNAL(supportedMapTypesChanged()),
+ this,
+ SIGNAL(supportedMapTypesChanged()),
+ Qt::QueuedConnection);
}
/*!
diff --git a/src/location/maps/qgeomappingmanager_p.h b/src/location/maps/qgeomappingmanager_p.h
index 043ebd8f..2ec1e8b5 100644
--- a/src/location/maps/qgeomappingmanager_p.h
+++ b/src/location/maps/qgeomappingmanager_p.h
@@ -89,6 +89,7 @@ public:
Q_SIGNALS:
void initialized();
+ void supportedMapTypesChanged();
protected:
QGeoMappingManager(QGeoMappingManagerEngine *engine, QObject *parent = 0);
diff --git a/src/location/maps/qgeomappingmanagerengine.cpp b/src/location/maps/qgeomappingmanagerengine.cpp
index 91eecf39..0eeadf71 100644
--- a/src/location/maps/qgeomappingmanagerengine.cpp
+++ b/src/location/maps/qgeomappingmanagerengine.cpp
@@ -147,6 +147,7 @@ void QGeoMappingManagerEngine::setSupportedMapTypes(const QList<QGeoMapType> &su
{
Q_D(QGeoMappingManagerEngine);
d->supportedMapTypes = supportedMapTypes;
+ emit supportedMapTypesChanged();
}
QGeoCameraCapabilities QGeoMappingManagerEngine::cameraCapabilities() const
diff --git a/src/location/maps/qgeomappingmanagerengine_p.h b/src/location/maps/qgeomappingmanagerengine_p.h
index 4496e7bd..fd48d44c 100644
--- a/src/location/maps/qgeomappingmanagerengine_p.h
+++ b/src/location/maps/qgeomappingmanagerengine_p.h
@@ -98,6 +98,7 @@ public:
Q_SIGNALS:
void initialized();
+ void supportedMapTypesChanged();
protected:
void setSupportedMapTypes(const QList<QGeoMapType> &supportedMapTypes);
diff --git a/src/plugins/geoservices/osm/qgeotiledmappingmanagerengineosm.cpp b/src/plugins/geoservices/osm/qgeotiledmappingmanagerengineosm.cpp
index 920b0148..fba177f4 100644
--- a/src/plugins/geoservices/osm/qgeotiledmappingmanagerengineosm.cpp
+++ b/src/plugins/geoservices/osm/qgeotiledmappingmanagerengineosm.cpp
@@ -86,11 +86,8 @@ QGeoTiledMappingManagerEngineOsm::QGeoTiledMappingManagerEngineOsm(const QVarian
new QGeoTileProviderOsm(domain + "satellite",
nm,
QGeoMapType(QGeoMapType::SatelliteMapDay, tr("Satellite Map"), tr("Satellite map view in daylight mode"), false, false, 2),
- QGeoTileProviderOsm::TileProvider(QStringLiteral("http://basemap.nationalmap.gov/arcgis/rest/services/USGSImageryOnly/MapServer/tile/%z/%y/%x"),
- QStringLiteral("jpg"),
- QStringLiteral("<a href='http://basemap.nationalmap.gov/arcgis/rest/services/USGSImageryOnly/MapServer'>USGS The National Map: Orthoimagery</a>"),
- QStringLiteral("<a href='http://landsat.gsfc.nasa.gov/?page_id=2339'>USGS/NASA Landsat</a>")
- )));
+ QGeoTileProviderOsm::TileProvider()
+ ));
m_providers.push_back(
new QGeoTileProviderOsm(domain + "cycle",
nm,
@@ -173,15 +170,17 @@ QGeoTiledMappingManagerEngineOsm::QGeoTiledMappingManagerEngineOsm(const QVarian
if (parameters.contains(QStringLiteral("osm.mapping.providersrepository.disabled")))
disableRedirection = parameters.value(QStringLiteral("osm.mapping.providersrepository.disabled")).toBool();
- QList<QGeoMapType> mapTypes;
foreach (QGeoTileProviderOsm * provider, m_providers) {
provider->setParent(this);
if (disableRedirection)
provider->disableRedirection();
- mapTypes << provider->mapType();
+
+ connect(provider, &QGeoTileProviderOsm::resolutionFinished,
+ this, &QGeoTiledMappingManagerEngineOsm::onProviderResolutionFinished);
+ connect(provider, &QGeoTileProviderOsm::resolutionError,
+ this, &QGeoTiledMappingManagerEngineOsm::onProviderResolutionError);
}
- // See map type implementations in QGeoTiledMapOsm and QGeoTileFetcherOsm.
- setSupportedMapTypes(mapTypes);
+ updateMapTypes();
QGeoTileFetcherOsm *tileFetcher = new QGeoTileFetcherOsm(m_providers, nm, this);
if (parameters.contains(QStringLiteral("osm.useragent"))) {
@@ -220,4 +219,33 @@ QString QGeoTiledMappingManagerEngineOsm::customCopyright() const
return m_customCopyright;
}
+void QGeoTiledMappingManagerEngineOsm::onProviderResolutionFinished(const QGeoTileProviderOsm *provider)
+{
+ if (!provider->isResolved())
+ return;
+ updateMapTypes();
+}
+
+void QGeoTiledMappingManagerEngineOsm::onProviderResolutionError(const QGeoTileProviderOsm *provider, QNetworkReply::NetworkError error)
+{
+ Q_UNUSED(error)
+ if (!provider->isResolved())
+ return;
+ updateMapTypes();
+}
+
+void QGeoTiledMappingManagerEngineOsm::updateMapTypes()
+{
+ QList<QGeoMapType> mapTypes;
+ foreach (QGeoTileProviderOsm * provider, m_providers) {
+ // assume provider are ok until they have been resolved invalid
+ if (!provider->isResolved() || provider->isValid())
+ mapTypes << provider->mapType();
+ }
+ const QList<QGeoMapType> currentlySupportedMapTypes = supportedMapTypes();
+ if (currentlySupportedMapTypes != mapTypes)
+ // See map type implementations in QGeoTiledMapOsm and QGeoTileFetcherOsm.
+ setSupportedMapTypes(mapTypes);
+}
+
QT_END_NAMESPACE
diff --git a/src/plugins/geoservices/osm/qgeotiledmappingmanagerengineosm.h b/src/plugins/geoservices/osm/qgeotiledmappingmanagerengineosm.h
index 2ceebc74..247e4377 100644
--- a/src/plugins/geoservices/osm/qgeotiledmappingmanagerengineosm.h
+++ b/src/plugins/geoservices/osm/qgeotiledmappingmanagerengineosm.h
@@ -63,6 +63,13 @@ public:
const QVector<QGeoTileProviderOsm *> &providers();
QString customCopyright() const;
+protected Q_SLOTS:
+ void onProviderResolutionFinished(const QGeoTileProviderOsm *provider);
+ void onProviderResolutionError(const QGeoTileProviderOsm *provider, QNetworkReply::NetworkError error);
+
+protected:
+ void updateMapTypes();
+
private:
QVector<QGeoTileProviderOsm *> m_providers;
QString m_customCopyright;
diff --git a/src/plugins/geoservices/osm/qgeotilefetcherosm.cpp b/src/plugins/geoservices/osm/qgeotilefetcherosm.cpp
index 730b5379..98621411 100644
--- a/src/plugins/geoservices/osm/qgeotilefetcherosm.cpp
+++ b/src/plugins/geoservices/osm/qgeotilefetcherosm.cpp
@@ -115,7 +115,10 @@ QGeoTiledMapReply *QGeoTileFetcherOsm::getTileImage(const QGeoTileSpec &spec)
int id = spec.mapId();
if (id < 1 || id > m_providers.size()) {
qWarning("Unknown map id %d\n", spec.mapId());
- id = 0;
+ if (m_providers.isEmpty())
+ return Q_NULLPTR;
+ else
+ id = 1;
}
id -= 1; // TODO: make OSM map ids start from 0.