summaryrefslogtreecommitdiff
path: root/src/location/maps/qgeofiletilecache.cpp
diff options
context:
space:
mode:
authorPaolo Angelelli <paolo.angelelli@theqtcompany.com>2016-07-01 22:49:47 +0200
committerPaolo Angelelli <paolo.angelelli@theqtcompany.com>2016-07-21 14:44:53 +0000
commitfcee1ba3a93de83b94c3467e82684890812558d1 (patch)
tree2caac58f3f420c88dabd90ad52f15b339b3ed3ae /src/location/maps/qgeofiletilecache.cpp
parentd7c02e9dace021a013cae7a6878378d5a63a62eb (diff)
downloadqtlocation-fcee1ba3a93de83b94c3467e82684890812558d1.tar.gz
OSM Geoservice plugin improvements, including offline data support
This patch contains improvements for the OSM geoservice plugin, in form of property-controllable disk cache, and the support for a directory containing an offline dataset. The offline directory can contain subdirectories also in form of symlinks. If duplicate tiles are present, the newest is used. The population of the offline tiles registry is offloaded to a thread to prevent blocking the startup of the application. No synchronization is used (except on cache destruction), so that, as the tiles are being indexed, they can be used in the application. For the time being, no support is given to populate such directory (mostly due to current API limitations), but tiles can be placed manually, for example copying them from the disk cache directory. Task-number: QTBUG-45284 Change-Id: I518980669a3ee474545025adf05adc69cdd29781 Reviewed-by: Paolo Angelelli <paolo.angelelli@theqtcompany.com> Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src/location/maps/qgeofiletilecache.cpp')
-rw-r--r--src/location/maps/qgeofiletilecache.cpp82
1 files changed, 47 insertions, 35 deletions
diff --git a/src/location/maps/qgeofiletilecache.cpp b/src/location/maps/qgeofiletilecache.cpp
index 520649ea..fd6bbc38 100644
--- a/src/location/maps/qgeofiletilecache.cpp
+++ b/src/location/maps/qgeofiletilecache.cpp
@@ -280,43 +280,10 @@ void QGeoFileTileCache::clearAll()
QSharedPointer<QGeoTileTexture> QGeoFileTileCache::get(const QGeoTileSpec &spec)
{
- QSharedPointer<QGeoTileTexture> tt = textureCache_.object(spec);
+ QSharedPointer<QGeoTileTexture> tt = getFromMemory(spec);
if (tt)
return tt;
-
- QSharedPointer<QGeoCachedTileMemory> tm = memoryCache_.object(spec);
- if (tm) {
- QImage image;
- if (!image.loadFromData(tm->bytes)) {
- handleError(spec, QLatin1String("Problem with tile image"));
- return QSharedPointer<QGeoTileTexture>(0);
- }
- QSharedPointer<QGeoTileTexture> tt = addToTextureCache(spec, image);
- if (tt)
- return tt;
- }
-
- QSharedPointer<QGeoCachedTileDisk> td = diskCache_.object(spec);
- if (td) {
- const QString format = QFileInfo(td->filename).suffix();
- QFile file(td->filename);
- file.open(QIODevice::ReadOnly);
- QByteArray bytes = file.readAll();
- file.close();
-
- QImage image;
- if (!image.loadFromData(bytes)) {
- handleError(spec, QLatin1String("Problem with tile image"));
- return QSharedPointer<QGeoTileTexture>(0);
- }
-
- addToMemoryCache(spec, bytes, format);
- QSharedPointer<QGeoTileTexture> tt = addToTextureCache(td->spec, image);
- if (tt)
- return tt;
- }
-
- return QSharedPointer<QGeoTileTexture>();
+ return getFromDisk(spec);
}
void QGeoFileTileCache::insert(const QGeoTileSpec &spec,
@@ -394,6 +361,51 @@ QSharedPointer<QGeoTileTexture> QGeoFileTileCache::addToTextureCache(const QGeoT
return tt;
}
+QSharedPointer<QGeoTileTexture> QGeoFileTileCache::getFromMemory(const QGeoTileSpec &spec)
+{
+ QSharedPointer<QGeoTileTexture> tt = textureCache_.object(spec);
+ if (tt)
+ return tt;
+
+ QSharedPointer<QGeoCachedTileMemory> tm = memoryCache_.object(spec);
+ if (tm) {
+ QImage image;
+ if (!image.loadFromData(tm->bytes)) {
+ handleError(spec, QLatin1String("Problem with tile image"));
+ return QSharedPointer<QGeoTileTexture>(0);
+ }
+ QSharedPointer<QGeoTileTexture> tt = addToTextureCache(spec, image);
+ if (tt)
+ return tt;
+ }
+ return QSharedPointer<QGeoTileTexture>();
+}
+
+QSharedPointer<QGeoTileTexture> QGeoFileTileCache::getFromDisk(const QGeoTileSpec &spec)
+{
+ QSharedPointer<QGeoCachedTileDisk> td = diskCache_.object(spec);
+ if (td) {
+ const QString format = QFileInfo(td->filename).suffix();
+ QFile file(td->filename);
+ file.open(QIODevice::ReadOnly);
+ QByteArray bytes = file.readAll();
+ file.close();
+
+ QImage image;
+ if (!image.loadFromData(bytes)) {
+ handleError(spec, QLatin1String("Problem with tile image"));
+ return QSharedPointer<QGeoTileTexture>(0);
+ }
+
+ addToMemoryCache(spec, bytes, format);
+ QSharedPointer<QGeoTileTexture> tt = addToTextureCache(td->spec, image);
+ if (tt)
+ return tt;
+ }
+
+ return QSharedPointer<QGeoTileTexture>();
+}
+
QString QGeoFileTileCache::tileSpecToFilename(const QGeoTileSpec &spec, const QString &format, const QString &directory) const
{
QString filename = spec.plugin();