From fcee1ba3a93de83b94c3467e82684890812558d1 Mon Sep 17 00:00:00 2001 From: Paolo Angelelli Date: Fri, 1 Jul 2016 22:49:47 +0200 Subject: 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 Reviewed-by: Alex Blasche --- src/location/maps/qgeofiletilecache.cpp | 82 +++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 35 deletions(-) (limited to 'src/location/maps/qgeofiletilecache.cpp') 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 QGeoFileTileCache::get(const QGeoTileSpec &spec) { - QSharedPointer tt = textureCache_.object(spec); + QSharedPointer tt = getFromMemory(spec); if (tt) return tt; - - QSharedPointer tm = memoryCache_.object(spec); - if (tm) { - QImage image; - if (!image.loadFromData(tm->bytes)) { - handleError(spec, QLatin1String("Problem with tile image")); - return QSharedPointer(0); - } - QSharedPointer tt = addToTextureCache(spec, image); - if (tt) - return tt; - } - - QSharedPointer 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(0); - } - - addToMemoryCache(spec, bytes, format); - QSharedPointer tt = addToTextureCache(td->spec, image); - if (tt) - return tt; - } - - return QSharedPointer(); + return getFromDisk(spec); } void QGeoFileTileCache::insert(const QGeoTileSpec &spec, @@ -394,6 +361,51 @@ QSharedPointer QGeoFileTileCache::addToTextureCache(const QGeoT return tt; } +QSharedPointer QGeoFileTileCache::getFromMemory(const QGeoTileSpec &spec) +{ + QSharedPointer tt = textureCache_.object(spec); + if (tt) + return tt; + + QSharedPointer tm = memoryCache_.object(spec); + if (tm) { + QImage image; + if (!image.loadFromData(tm->bytes)) { + handleError(spec, QLatin1String("Problem with tile image")); + return QSharedPointer(0); + } + QSharedPointer tt = addToTextureCache(spec, image); + if (tt) + return tt; + } + return QSharedPointer(); +} + +QSharedPointer QGeoFileTileCache::getFromDisk(const QGeoTileSpec &spec) +{ + QSharedPointer 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(0); + } + + addToMemoryCache(spec, bytes, format); + QSharedPointer tt = addToTextureCache(td->spec, image); + if (tt) + return tt; + } + + return QSharedPointer(); +} + QString QGeoFileTileCache::tileSpecToFilename(const QGeoTileSpec &spec, const QString &format, const QString &directory) const { QString filename = spec.plugin(); -- cgit v1.2.1