diff options
author | Paolo Angelelli <paolo.angelelli@qt.io> | 2016-10-19 17:14:22 +0200 |
---|---|---|
committer | Paolo Angelelli <paolo.angelelli@qt.io> | 2016-11-23 11:40:26 +0000 |
commit | f52d84f4c750dfdaba8f4f0c241994b7364ec5fc (patch) | |
tree | fe04ea8bce5c5e48fea10099c042544324218b3d /src/plugins/geoservices/mapbox | |
parent | 3a6fb42cb2bb72f51f9fc05c5f6651a659cb9c8b (diff) | |
download | qtlocation-f52d84f4c750dfdaba8f4f0c241994b7364ec5fc.tar.gz |
Improve support for unitary tile cost in QGeoFileTileCache
This patch adds support for separate caching mode for each of the
three caches, disk, memory and texture.
It also adds separate plugin parameters to the mapbox plugin to
control the functioning of each of these cache.
By default it only sets the disk cache to unitary, to comply with
mapbox TOS, and leaves the other two caches to bytesize behavior
(old beavior).
Change-Id: I665d40568f4e69a836d7489e1daa2d8dcb8987af
Reviewed-by: Paolo Angelelli <paolo.angelelli@qt.io>
Diffstat (limited to 'src/plugins/geoservices/mapbox')
-rw-r--r-- | src/plugins/geoservices/mapbox/qgeotiledmappingmanagerenginemapbox.cpp | 51 |
1 files changed, 38 insertions, 13 deletions
diff --git a/src/plugins/geoservices/mapbox/qgeotiledmappingmanagerenginemapbox.cpp b/src/plugins/geoservices/mapbox/qgeotiledmappingmanagerenginemapbox.cpp index 1fbda8e0..5404eb30 100644 --- a/src/plugins/geoservices/mapbox/qgeotiledmappingmanagerenginemapbox.cpp +++ b/src/plugins/geoservices/mapbox/qgeotiledmappingmanagerenginemapbox.cpp @@ -151,32 +151,44 @@ QGeoTiledMappingManagerEngineMapbox::QGeoTiledMappingManagerEngineMapbox(const Q QGeoFileTileCache *tileCache = new QGeoFileTileCacheMapbox(mapTypes, scaleFactor, m_cacheDirectory); - // The Mapbox free plan allows for 6000 tiles to be stored for offline uses, - // As of 2016.06.15, according to https://www.mapbox.com/help/mobile-offline/ . - // Thus defaulting to Unitary strategy, and setting 6000 tiles as default cache disk size - if (parameters.contains(QStringLiteral("mapbox.mapping.cache.cost_strategy"))) { - QString cacheStrategy = parameters.value(QStringLiteral("mapbox.mapping.cache.cost_strategy")).toString().toLower(); + /* + * Disk cache setup -- defaults to Unitary since: + * + * The Mapbox free plan allows for 6000 tiles to be stored for offline uses, + * As of 2016.06.15, according to https://www.mapbox.com/help/mobile-offline/ . + * Thus defaulting to Unitary strategy, and setting 6000 tiles as default cache disk size + */ + if (parameters.contains(QStringLiteral("mapbox.mapping.cache.disk.cost_strategy"))) { + QString cacheStrategy = parameters.value(QStringLiteral("mapbox.mapping.cache.disk.cost_strategy")).toString().toLower(); if (cacheStrategy == QLatin1String("bytesize")) - tileCache->setCostStrategy(QGeoFileTileCache::ByteSize); + tileCache->setCostStrategyDisk(QGeoFileTileCache::ByteSize); else - tileCache->setCostStrategy(QGeoFileTileCache::Unitary); + tileCache->setCostStrategyDisk(QGeoFileTileCache::Unitary); } else { - // Default to unitary - tileCache->setCostStrategy(QGeoFileTileCache::Unitary); + tileCache->setCostStrategyDisk(QGeoFileTileCache::Unitary); } - - - if (parameters.contains(QStringLiteral("mapbox.mapping.cache.disk.size"))) { bool ok = false; int cacheSize = parameters.value(QStringLiteral("mapbox.mapping.cache.disk.size")).toString().toInt(&ok); if (ok) tileCache->setMaxDiskUsage(cacheSize); } else { - if (tileCache->costStrategy() == QGeoFileTileCache::Unitary) + if (tileCache->costStrategyDisk() == QGeoFileTileCache::Unitary) tileCache->setMaxDiskUsage(6000); // The maximum allowed with the free tier } + /* + * Memory cache setup -- defaults to ByteSize (old behavior) + */ + if (parameters.contains(QStringLiteral("mapbox.mapping.cache.memory.cost_strategy"))) { + QString cacheStrategy = parameters.value(QStringLiteral("mapbox.mapping.cache.memory.cost_strategy")).toString().toLower(); + if (cacheStrategy == QLatin1String("bytesize")) + tileCache->setCostStrategyMemory(QGeoFileTileCache::ByteSize); + else + tileCache->setCostStrategyMemory(QGeoFileTileCache::Unitary); + } else { + tileCache->setCostStrategyMemory(QGeoFileTileCache::ByteSize); + } if (parameters.contains(QStringLiteral("mapbox.mapping.cache.memory.size"))) { bool ok = false; int cacheSize = parameters.value(QStringLiteral("mapbox.mapping.cache.memory.size")).toString().toInt(&ok); @@ -184,6 +196,18 @@ QGeoTiledMappingManagerEngineMapbox::QGeoTiledMappingManagerEngineMapbox(const Q tileCache->setMaxMemoryUsage(cacheSize); } + /* + * Texture cache setup -- defaults to ByteSize (old behavior) + */ + if (parameters.contains(QStringLiteral("mapbox.mapping.cache.texture.cost_strategy"))) { + QString cacheStrategy = parameters.value(QStringLiteral("mapbox.mapping.cache.texture.cost_strategy")).toString().toLower(); + if (cacheStrategy == QLatin1String("bytesize")) + tileCache->setCostStrategyTexture(QGeoFileTileCache::ByteSize); + else + tileCache->setCostStrategyTexture(QGeoFileTileCache::Unitary); + } else { + tileCache->setCostStrategyTexture(QGeoFileTileCache::ByteSize); + } if (parameters.contains(QStringLiteral("mapbox.mapping.cache.texture.size"))) { bool ok = false; int cacheSize = parameters.value(QStringLiteral("mapbox.mapping.cache.texture.size")).toString().toInt(&ok); @@ -191,6 +215,7 @@ QGeoTiledMappingManagerEngineMapbox::QGeoTiledMappingManagerEngineMapbox(const Q tileCache->setExtraTextureUsage(cacheSize); } + setTileCache(tileCache); *error = QGeoServiceProvider::NoError; |