summaryrefslogtreecommitdiff
path: root/src/location/maps
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 /src/location/maps
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>
Diffstat (limited to 'src/location/maps')
-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
3 files changed, 54 insertions, 18 deletions
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