summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2019-05-07 03:01:37 +0200
committerQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2019-05-07 03:01:38 +0200
commitca339bc55d6fc617c63e723c43150445fc8ac050 (patch)
tree94988fd2e0ce421075946c569e4379568add75e2
parenta6ac8739a23c4101a3c582aa89281aa90027128f (diff)
parent4d3183c6ca22203a75e29af601b4c407231eaab4 (diff)
downloadqtlocation-ca339bc55d6fc617c63e723c43150445fc8ac050.tar.gz
Merge remote-tracking branch 'origin/5.12' into 5.13v5.13.0-beta4
Change-Id: I28b2db32a10b2f70d8c3626d645d279cfedb49f5
-rw-r--r--src/plugins/geoservices/osm/qgeotiledmappingmanagerengineosm.cpp39
-rw-r--r--src/plugins/geoservices/osm/qgeotileproviderosm.cpp1
2 files changed, 24 insertions, 16 deletions
diff --git a/src/plugins/geoservices/osm/qgeotiledmappingmanagerengineosm.cpp b/src/plugins/geoservices/osm/qgeotiledmappingmanagerengineosm.cpp
index 9174ad62..22c32342 100644
--- a/src/plugins/geoservices/osm/qgeotiledmappingmanagerengineosm.cpp
+++ b/src/plugins/geoservices/osm/qgeotiledmappingmanagerengineosm.cpp
@@ -48,6 +48,7 @@
#include <QtLocation/private/qgeofiletilecache_p.h>
#include <QtNetwork/QNetworkAccessManager>
+#include <QtNetwork/QNetworkDiskCache>
QT_BEGIN_NAMESPACE
@@ -68,7 +69,20 @@ QGeoTiledMappingManagerEngineOsm::QGeoTiledMappingManagerEngineOsm(const QVarian
setTileSize(QSize(256, 256));
- QNetworkAccessManager *nm = new QNetworkAccessManager();
+ const QByteArray pluginName = "osm";
+ if (parameters.contains(QStringLiteral("osm.mapping.cache.directory"))) {
+ m_cacheDirectory = parameters.value(QStringLiteral("osm.mapping.cache.directory")).toString();
+ } else {
+ // managerName() is not yet set, we have to hardcode the plugin name below
+ m_cacheDirectory = QAbstractGeoTileCache::baseLocationCacheDirectory() + QLatin1String(pluginName);
+ }
+ QNetworkAccessManager *nmCached = new QNetworkAccessManager(this);
+ QNetworkDiskCache *diskCache = new QNetworkDiskCache(this);
+ diskCache->setCacheDirectory(m_cacheDirectory + QLatin1String("/providers"));
+ diskCache->setMaximumCacheSize(100000000000); // enough to prevent diskCache to fiddle with tile cache. it's anyway used only for providers.
+ nmCached->setCache(diskCache);
+
+ QNetworkAccessManager *nm = new QNetworkAccessManager(); // Gets owned by QGeoTileFetcherOsm
QString domain = QStringLiteral("http://maps-redirect.qt.io/osm/5.8/");
if (parameters.contains(QStringLiteral("osm.mapping.providersrepository.address"))) {
QString customAddress = parameters.value(QStringLiteral("osm.mapping.providersrepository.address")).toString();
@@ -162,26 +176,25 @@ QGeoTiledMappingManagerEngineOsm::QGeoTiledMappingManagerEngineOsm(const QVarian
/* QGeoTileProviderOsms setup */
- const QByteArray pluginName = "osm";
- m_providers.push_back( new QGeoTileProviderOsm( nm,
+ m_providers.push_back( new QGeoTileProviderOsm( nmCached,
QGeoMapType(QGeoMapType::StreetMap, tr("Street Map"), tr("Street map view in daylight mode"), false, false, 1, pluginName, cameraCaps),
providers_street, cameraCaps ));
- m_providers.push_back( new QGeoTileProviderOsm( nm,
+ m_providers.push_back( new QGeoTileProviderOsm( nmCached,
QGeoMapType(QGeoMapType::SatelliteMapDay, tr("Satellite Map"), tr("Satellite map view in daylight mode"), false, false, 2, pluginName, cameraCaps),
providers_satellite, cameraCaps ));
- m_providers.push_back( new QGeoTileProviderOsm( nm,
+ m_providers.push_back( new QGeoTileProviderOsm( nmCached,
QGeoMapType(QGeoMapType::CycleMap, tr("Cycle Map"), tr("Cycle map view in daylight mode"), false, false, 3, pluginName, cameraCaps),
providers_cycle, cameraCaps ));
- m_providers.push_back( new QGeoTileProviderOsm( nm,
+ m_providers.push_back( new QGeoTileProviderOsm( nmCached,
QGeoMapType(QGeoMapType::TransitMap, tr("Transit Map"), tr("Public transit map view in daylight mode"), false, false, 4, pluginName, cameraCaps),
providers_transit, cameraCaps ));
- m_providers.push_back( new QGeoTileProviderOsm( nm,
+ m_providers.push_back( new QGeoTileProviderOsm( nmCached,
QGeoMapType(QGeoMapType::TransitMap, tr("Night Transit Map"), tr("Public transit map view in night mode"), false, true, 5, pluginName, cameraCaps),
providers_nighttransit, cameraCaps ));
- m_providers.push_back( new QGeoTileProviderOsm( nm,
+ m_providers.push_back( new QGeoTileProviderOsm( nmCached,
QGeoMapType(QGeoMapType::TerrainMap, tr("Terrain Map"), tr("Terrain map view"), false, false, 6, pluginName, cameraCaps),
providers_terrain, cameraCaps ));
- m_providers.push_back( new QGeoTileProviderOsm( nm,
+ m_providers.push_back( new QGeoTileProviderOsm( nmCached,
QGeoMapType(QGeoMapType::PedestrianMap, tr("Hiking Map"), tr("Hiking map view"), false, false, 7, pluginName, cameraCaps),
providers_hiking, cameraCaps ));
@@ -205,7 +218,7 @@ QGeoTiledMappingManagerEngineOsm::QGeoTiledMappingManagerEngineOsm(const QVarian
m_customCopyright = parameters.value(QStringLiteral("osm.mapping.copyright")).toString();
m_providers.push_back(
- new QGeoTileProviderOsm( nm,
+ new QGeoTileProviderOsm( nmCached,
QGeoMapType(QGeoMapType::CustomMap, tr("Custom URL Map"), tr("Custom url map view set via urlprefix parameter"), false, false, 8, pluginName, cameraCaps),
{ new TileProvider(tmsServer + QStringLiteral("%z/%x/%y.png"),
QStringLiteral("png"),
@@ -235,12 +248,6 @@ QGeoTiledMappingManagerEngineOsm::QGeoTiledMappingManagerEngineOsm(const QVarian
/* TILE CACHE */
- if (parameters.contains(QStringLiteral("osm.mapping.cache.directory"))) {
- m_cacheDirectory = parameters.value(QStringLiteral("osm.mapping.cache.directory")).toString();
- } else {
- // managerName() is not yet set, we have to hardcode the plugin name below
- m_cacheDirectory = QAbstractGeoTileCache::baseLocationCacheDirectory() + QLatin1String(pluginName);
- }
if (parameters.contains(QStringLiteral("osm.mapping.offline.directory")))
m_offlineDirectory = parameters.value(QStringLiteral("osm.mapping.offline.directory")).toString();
QGeoFileTileCacheOsm *tileCache = new QGeoFileTileCacheOsm(m_providers, m_offlineDirectory, m_cacheDirectory);
diff --git a/src/plugins/geoservices/osm/qgeotileproviderosm.cpp b/src/plugins/geoservices/osm/qgeotileproviderosm.cpp
index f52968b0..1eedddb1 100644
--- a/src/plugins/geoservices/osm/qgeotileproviderosm.cpp
+++ b/src/plugins/geoservices/osm/qgeotileproviderosm.cpp
@@ -336,6 +336,7 @@ void TileProvider::resolveProvider()
request.setHeader(QNetworkRequest::UserAgentHeader, QByteArrayLiteral("QGeoTileFetcherOsm"));
request.setUrl(m_urlRedirector);
request.setAttribute(QNetworkRequest::BackgroundRequestAttribute, true);
+ request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferNetwork);
QNetworkReply *reply = m_nm->get(request);
connect(reply, SIGNAL(finished()), this, SLOT(onNetworkReplyFinished()) );
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onNetworkReplyError(QNetworkReply::NetworkError)));