summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Angelelli <paolo.angelelli@qt.io>2016-10-19 17:14:22 +0200
committerPaolo Angelelli <paolo.angelelli@qt.io>2016-11-23 11:40:26 +0000
commitf52d84f4c750dfdaba8f4f0c241994b7364ec5fc (patch)
treefe04ea8bce5c5e48fea10099c042544324218b3d
parent3a6fb42cb2bb72f51f9fc05c5f6651a659cb9c8b (diff)
downloadqtlocation-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>
-rw-r--r--src/location/doc/src/plugins/mapbox.qdoc25
-rw-r--r--src/location/maps/qabstractgeotilecache_p.h8
-rw-r--r--src/location/maps/qgeofiletilecache.cpp52
-rw-r--r--src/location/maps/qgeofiletilecache_p.h12
-rw-r--r--src/plugins/geoservices/mapbox/qgeotiledmappingmanagerenginemapbox.cpp51
5 files changed, 112 insertions, 36 deletions
diff --git a/src/location/doc/src/plugins/mapbox.qdoc b/src/location/doc/src/plugins/mapbox.qdoc
index 617be5cf..dfa83713 100644
--- a/src/location/doc/src/plugins/mapbox.qdoc
+++ b/src/location/doc/src/plugins/mapbox.qdoc
@@ -92,14 +92,13 @@ The following table lists optional parameters that can be passed to the Mapbox p
The default place for the cache is \c{QtLocation/mapbox} directory in \l {QStandardPaths::writableLocation()} {QStandardPaths::writableLocation}(\l{QStandardPaths::GenericCacheLocation}).
On systems that have no concept of a shared cache, the application-specific \l{QStandardPaths::CacheLocation} is used instead.
\row
- \li mapbox.mapping.cache.cost_strategy
- \li The cost strategy to use to cache map tiles.
+ \li mapbox.mapping.cache.disk.cost_strategy
+ \li The cost strategy to use to cache map tiles on disk.
Valid values are \b bytesize and \b unitary.
- Using \b bytesize, the size parameters (\b mapbox.mapping.cache.disk.size,
- \b mapbox.mapping.cache.memory.size and \b mapbox.mapping.cache.texture.size) will
+ Using \b bytesize, the related size parameter (\b mapbox.mapping.cache.disk.size) will
be interpreted as bytes.
Using \b unitary, they will be interpreted as number of tiles.
- The default value is \b unitary.
+ The default value for this parameter is \b unitary.
\row
\li mapbox.mapping.cache.disk.size
\li Disk cache size for map tiles.
@@ -108,11 +107,27 @@ The following table lists optional parameters that can be passed to the Mapbox p
Note that 6000 is the maximum amount of tiles that the Mapbox free plan allows to cache.
Make sure to comply with Mapbox Terms of Service before increasing this value.
\row
+ \li mapbox.mapping.cache.memory.cost_strategy
+ \li The cost strategy to use to cache map tiles in memory.
+ Valid values are \b bytesize and \b unitary.
+ Using \b bytesize, the related size parameter (\b mapbox.mapping.cache.memory.size) will
+ be interpreted as bytes.
+ Using \b unitary, they will be interpreted as number of tiles.
+ The default value for this parameter is \b bytesize.
+\row
\li mapbox.mapping.cache.memory.size
\li Memory cache size for map tiles.
The Default size of this cache is 100 if \b unitary is used as cost strategy, or
3 MiB, if \b bytesize is used as cost strategy.
\row
+ \li mapbox.mapping.cache.texture.cost_strategy
+ \li The cost strategy to use to cache decompressed map tiles in memory.
+ Valid values are \b bytesize and \b unitary.
+ Using \b bytesize, the related size parameter (\b mapbox.mapping.cache.texture.size) will
+ be interpreted as bytes.
+ Using \b unitary, they will be interpreted as number of tiles.
+ The default value for this parameter is \b bytesize.
+\row
\li mapbox.mapping.cache.texture.size
\li Texture cache size for map tiles.
The Default size of this cache is 30 if \b unitary is used as cost strategy, or
diff --git a/src/location/maps/qabstractgeotilecache_p.h b/src/location/maps/qabstractgeotilecache_p.h
index 6660d13a..484bb8a5 100644
--- a/src/location/maps/qabstractgeotilecache_p.h
+++ b/src/location/maps/qabstractgeotilecache_p.h
@@ -107,8 +107,12 @@ public:
virtual int minTextureUsage() const = 0;
virtual int textureUsage() const = 0;
virtual void clearAll() = 0;
- virtual void setCostStrategy(CostStrategy costStrategy) = 0;
- virtual CostStrategy costStrategy() = 0;
+ virtual void setCostStrategyDisk(CostStrategy costStrategy) = 0;
+ virtual CostStrategy costStrategyDisk() const = 0;
+ virtual void setCostStrategyMemory(CostStrategy costStrategy) = 0;
+ virtual CostStrategy costStrategyMemory() const = 0;
+ virtual void setCostStrategyTexture(CostStrategy costStrategy) = 0;
+ virtual CostStrategy costStrategyTexture() const = 0;
virtual QSharedPointer<QGeoTileTexture> get(const QGeoTileSpec &spec) = 0;
diff --git a/src/location/maps/qgeofiletilecache.cpp b/src/location/maps/qgeofiletilecache.cpp
index fee31dbd..911e9865 100644
--- a/src/location/maps/qgeofiletilecache.cpp
+++ b/src/location/maps/qgeofiletilecache.cpp
@@ -86,7 +86,8 @@ QGeoCachedTileDisk::~QGeoCachedTileDisk()
}
QGeoFileTileCache::QGeoFileTileCache(const QString &directory, QObject *parent)
- : QAbstractGeoTileCache(parent), directory_(directory), minTextureUsage_(0), extraTextureUsage_(0), costStrategy_(ByteSize)
+ : QAbstractGeoTileCache(parent), directory_(directory), minTextureUsage_(0), extraTextureUsage_(0)
+ ,costStrategyDisk_(ByteSize), costStrategyMemory_(ByteSize), costStrategyTexture_(ByteSize)
{
}
@@ -119,15 +120,20 @@ void QGeoFileTileCache::init()
QDir::root().mkpath(directory_);
// default values
- if (costStrategy_ == ByteSize) {
+ if (costStrategyDisk_ == ByteSize)
setMaxDiskUsage(50 * 1024 * 1024);
- setMaxMemoryUsage(3 * 1024 * 1024);
- setExtraTextureUsage(6 * 1024 * 1024);
- } else {
+ else
setMaxDiskUsage(1000);
+
+ if (costStrategyMemory_ == ByteSize)
+ setMaxMemoryUsage(3 * 1024 * 1024);
+ else
setMaxMemoryUsage(100);
+
+ if (costStrategyTexture_ == ByteSize)
+ setExtraTextureUsage(6 * 1024 * 1024);
+ else
setExtraTextureUsage(30); // byte size of texture is >> compressed image, hence unitary cost should be lower
- }
loadTiles();
}
@@ -318,14 +324,34 @@ void QGeoFileTileCache::clearMapId(const int mapId)
}
}
-void QGeoFileTileCache::setCostStrategy(QAbstractGeoTileCache::CostStrategy costStrategy)
+void QGeoFileTileCache::setCostStrategyDisk(QAbstractGeoTileCache::CostStrategy costStrategy)
+{
+ costStrategyDisk_ = costStrategy;
+}
+
+QAbstractGeoTileCache::CostStrategy QGeoFileTileCache::costStrategyDisk() const
+{
+ return costStrategyDisk_;
+}
+
+void QGeoFileTileCache::setCostStrategyMemory(QAbstractGeoTileCache::CostStrategy costStrategy)
+{
+ costStrategyMemory_ = costStrategy;
+}
+
+QAbstractGeoTileCache::CostStrategy QGeoFileTileCache::costStrategyMemory() const
+{
+ return costStrategyMemory_;
+}
+
+void QGeoFileTileCache::setCostStrategyTexture(QAbstractGeoTileCache::CostStrategy costStrategy)
{
- costStrategy_ = costStrategy;
+ costStrategyTexture_ = costStrategy;
}
-QAbstractGeoTileCache::CostStrategy QGeoFileTileCache::costStrategy()
+QAbstractGeoTileCache::CostStrategy QGeoFileTileCache::costStrategyTexture() const
{
- return costStrategy_;
+ return costStrategyTexture_;
}
QSharedPointer<QGeoTileTexture> QGeoFileTileCache::get(const QGeoTileSpec &spec)
@@ -380,7 +406,7 @@ QSharedPointer<QGeoCachedTileDisk> QGeoFileTileCache::addToDiskCache(const QGeoT
td->cache = this;
int cost = 1;
- if (costStrategy_ == ByteSize) {
+ if (costStrategyDisk_ == ByteSize) {
QFileInfo fi(filename);
cost = fi.size();
}
@@ -397,7 +423,7 @@ QSharedPointer<QGeoCachedTileMemory> QGeoFileTileCache::addToMemoryCache(const Q
tm->format = format;
int cost = 1;
- if (costStrategy_ == ByteSize)
+ if (costStrategyMemory_ == ByteSize)
cost = bytes.size();
memoryCache_.insert(spec, tm, cost);
@@ -411,7 +437,7 @@ QSharedPointer<QGeoTileTexture> QGeoFileTileCache::addToTextureCache(const QGeoT
tt->image = image;
int cost = 1;
- if (costStrategy_ == ByteSize)
+ if (costStrategyTexture_ == ByteSize)
cost = image.width() * image.height() * image.depth() / 8;
textureCache_.insert(spec, tt, cost);
diff --git a/src/location/maps/qgeofiletilecache_p.h b/src/location/maps/qgeofiletilecache_p.h
index 96fcf1ee..7d6df9fd 100644
--- a/src/location/maps/qgeofiletilecache_p.h
+++ b/src/location/maps/qgeofiletilecache_p.h
@@ -118,8 +118,12 @@ public:
int textureUsage() const Q_DECL_OVERRIDE;
void clearAll() Q_DECL_OVERRIDE;
void clearMapId(const int mapId);
- void setCostStrategy(CostStrategy costStrategy) Q_DECL_OVERRIDE;
- CostStrategy costStrategy() Q_DECL_OVERRIDE;
+ void setCostStrategyDisk(CostStrategy costStrategy) Q_DECL_OVERRIDE;
+ CostStrategy costStrategyDisk() const Q_DECL_OVERRIDE;
+ void setCostStrategyMemory(CostStrategy costStrategy) Q_DECL_OVERRIDE;
+ CostStrategy costStrategyMemory() const Q_DECL_OVERRIDE;
+ void setCostStrategyTexture(CostStrategy costStrategy) Q_DECL_OVERRIDE;
+ CostStrategy costStrategyTexture() const Q_DECL_OVERRIDE;
QSharedPointer<QGeoTileTexture> get(const QGeoTileSpec &spec) Q_DECL_OVERRIDE;
@@ -157,7 +161,9 @@ protected:
int minTextureUsage_;
int extraTextureUsage_;
- CostStrategy costStrategy_;
+ CostStrategy costStrategyDisk_;
+ CostStrategy costStrategyMemory_;
+ CostStrategy costStrategyTexture_;
};
QT_END_NAMESPACE
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;