summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaolo Angelelli <paolo.angelelli@theqtcompany.com>2016-08-01 19:44:41 +0200
committerPaolo Angelelli <paolo.angelelli@theqtcompany.com>2016-08-04 10:07:41 +0000
commit6f34c2ac75bdbfb679b5f4767006ad6a373cabb1 (patch)
tree7138df39343d265f07c5bc7c013986a7410b3652
parentd031c0f7b13bb07227210632f66adceef71dc5bb (diff)
Version tile cache with qt version and evict obsolete data on init()
This patch changes the base cache directory to a new scheme containing the qt version. At the time of commit, this would be "QtLocation/5.8/tiles/" This versioning does not have to change at every release, but when there are changes in the caching scheme. The reason for this is that, otherwise, it becomes difficult to clean up old cache data. QGeoFileTileCache::init already clean up old tile cache from 5.4 or older, where the cache data wasn't organized under a directory for each plugin. In 5.8 different naming scheme are introduced for mapbox tiles (with @1x,@2x) , here maps (with ppi), and soon for OSM too (with an identifier for the actual provider, not only the mapId). With this patch it will become easier and cleaner to upgrade the cache data without leaving residues. Change-Id: I89aeac0aaf1408d119cde5792fc69a64d5d89c3a Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
-rw-r--r--src/location/maps/qabstractgeotilecache.cpp10
-rw-r--r--src/location/maps/qabstractgeotilecache_p.h1
-rw-r--r--src/location/maps/qgeofiletilecache.cpp14
-rw-r--r--src/location/maps/qgeotiledmappingmanagerengine.cpp2
-rw-r--r--src/plugins/geoservices/mapbox/qgeotiledmappingmanagerenginemapbox.cpp2
-rw-r--r--src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.cpp2
-rw-r--r--src/plugins/geoservices/osm/qgeotiledmappingmanagerengineosm.cpp2
7 files changed, 23 insertions, 10 deletions
diff --git a/src/location/maps/qabstractgeotilecache.cpp b/src/location/maps/qabstractgeotilecache.cpp
index 739123db..395206c8 100644
--- a/src/location/maps/qabstractgeotilecache.cpp
+++ b/src/location/maps/qabstractgeotilecache.cpp
@@ -139,9 +139,15 @@ QString QAbstractGeoTileCache::baseCacheDirectory()
if (!dir.endsWith(QLatin1Char('/')))
dir += QLatin1Char('/');
- dir += QLatin1String("QtLocation/");
-
return dir;
}
+QString QAbstractGeoTileCache::baseLocationCacheDirectory()
+{
+ // This scheme allows to have the "tiles" prefix hardcoded here
+ // NOTE: changing the Qt version here requires changing it also in QGeoFileTileCache::init,
+ // in the code that remove old version tiles !
+ return baseCacheDirectory() + QLatin1String("QtLocation/5.8/tiles/");
+}
+
QT_END_NAMESPACE
diff --git a/src/location/maps/qabstractgeotilecache_p.h b/src/location/maps/qabstractgeotilecache_p.h
index bf1e56b9..8cd303ee 100644
--- a/src/location/maps/qabstractgeotilecache_p.h
+++ b/src/location/maps/qabstractgeotilecache_p.h
@@ -113,6 +113,7 @@ public:
virtual void handleError(const QGeoTileSpec &spec, const QString &errorString);
static QString baseCacheDirectory();
+ static QString baseLocationCacheDirectory();
protected:
QAbstractGeoTileCache(QObject *parent = 0);
diff --git a/src/location/maps/qgeofiletilecache.cpp b/src/location/maps/qgeofiletilecache.cpp
index fd6bbc38..6e8fa856 100644
--- a/src/location/maps/qgeofiletilecache.cpp
+++ b/src/location/maps/qgeofiletilecache.cpp
@@ -93,20 +93,26 @@ QGeoFileTileCache::QGeoFileTileCache(const QString &directory, QObject *parent)
void QGeoFileTileCache::init()
{
- const QString basePath = baseCacheDirectory();
+ const QString basePath = baseCacheDirectory() + QLatin1String("QtLocation/");
- // delete old tiles from QtLocation 5.4 or prior
- // Newer version use plugin-specific subdirectories so those are not affected.
+ // delete old tiles from QtLocation 5.7 or prior
+ // Newer version use plugin-specific subdirectories, versioned with qt version so those are not affected.
// TODO Remove cache cleanup in Qt 6
QDir baseDir(basePath);
if (baseDir.exists()) {
const QStringList oldCacheFiles = baseDir.entryList(QDir::Files);
foreach (const QString& file, oldCacheFiles)
baseDir.remove(file);
+ const QStringList oldCacheDirs = { QStringLiteral("osm"), QStringLiteral("mapbox"), QStringLiteral("here") };
+ foreach (const QString& d, oldCacheDirs) {
+ QDir oldCacheDir(basePath + QLatin1Char('/') + d);
+ if (oldCacheDir.exists())
+ oldCacheDir.removeRecursively();
+ }
}
if (directory_.isEmpty()) {
- directory_ = basePath;
+ directory_ = baseLocationCacheDirectory();
qWarning() << "Plugin uses uninitialized QGeoFileTileCache directory which was deleted during startup";
}
diff --git a/src/location/maps/qgeotiledmappingmanagerengine.cpp b/src/location/maps/qgeotiledmappingmanagerengine.cpp
index 1aaae4c6..0ad37a1d 100644
--- a/src/location/maps/qgeotiledmappingmanagerengine.cpp
+++ b/src/location/maps/qgeotiledmappingmanagerengine.cpp
@@ -298,7 +298,7 @@ QAbstractGeoTileCache *QGeoTiledMappingManagerEngine::tileCache()
if (!d->tileCache_) {
QString cacheDirectory;
if (!managerName().isEmpty())
- cacheDirectory = QAbstractGeoTileCache::baseCacheDirectory() + managerName();
+ cacheDirectory = QAbstractGeoTileCache::baseLocationCacheDirectory() + managerName();
d->tileCache_ = new QGeoFileTileCache(cacheDirectory);
d->tileCache_->init();
}
diff --git a/src/plugins/geoservices/mapbox/qgeotiledmappingmanagerenginemapbox.cpp b/src/plugins/geoservices/mapbox/qgeotiledmappingmanagerenginemapbox.cpp
index 2bf756fc..78c76b40 100644
--- a/src/plugins/geoservices/mapbox/qgeotiledmappingmanagerenginemapbox.cpp
+++ b/src/plugins/geoservices/mapbox/qgeotiledmappingmanagerenginemapbox.cpp
@@ -126,7 +126,7 @@ QGeoTiledMappingManagerEngineMapbox::QGeoTiledMappingManagerEngineMapbox(const Q
m_cacheDirectory = parameters.value(QStringLiteral("mapbox.cache.directory")).toString();
} else {
// managerName() is not yet set, we have to hardcode the plugin name below
- m_cacheDirectory = QAbstractGeoTileCache::baseCacheDirectory() + QLatin1String("mapbox");
+ m_cacheDirectory = QAbstractGeoTileCache::baseLocationCacheDirectory() + QLatin1String("mapbox");
}
// The Mapbox free plan allows for 6000 tiles to be stored for offline uses
diff --git a/src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.cpp b/src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.cpp
index e823c7e8..2ca5d7f1 100644
--- a/src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.cpp
+++ b/src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.cpp
@@ -112,7 +112,7 @@ QGeoTiledMappingManagerEngineNokia::QGeoTiledMappingManagerEngineNokia(
m_cacheDirectory = parameters.value(QStringLiteral("here.mapping.cache.directory")).toString();
} else {
// managerName() is not yet set, we have to hardcode the plugin name below
- m_cacheDirectory = QAbstractGeoTileCache::baseCacheDirectory() + QLatin1String("here");
+ m_cacheDirectory = QAbstractGeoTileCache::baseLocationCacheDirectory() + QLatin1String("here");
}
QGeoFileTileCache *tileCache = new QGeoFileTileCacheNokia(ppi, m_cacheDirectory);
diff --git a/src/plugins/geoservices/osm/qgeotiledmappingmanagerengineosm.cpp b/src/plugins/geoservices/osm/qgeotiledmappingmanagerengineosm.cpp
index 2b562e62..b87c4020 100644
--- a/src/plugins/geoservices/osm/qgeotiledmappingmanagerengineosm.cpp
+++ b/src/plugins/geoservices/osm/qgeotiledmappingmanagerengineosm.cpp
@@ -195,7 +195,7 @@ QGeoTiledMappingManagerEngineOsm::QGeoTiledMappingManagerEngineOsm(const QVarian
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::baseCacheDirectory() + QLatin1String("osm");
+ m_cacheDirectory = QAbstractGeoTileCache::baseLocationCacheDirectory() + QLatin1String("osm");
}
if (parameters.contains(QStringLiteral("osm.mapping.offline.directory")))
m_offlineDirectory = parameters.value(QStringLiteral("osm.mapping.offline.directory")).toString();