diff options
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(); |