From 211fd58142a03387b8a693f20a6054a8578e9f8a Mon Sep 17 00:00:00 2001 From: Harald Meyer Date: Sat, 10 Oct 2015 17:01:07 +0200 Subject: Split QGeoTileCache for easier customization of the tile cache. The QGeoTileCache is split into two classes: The abstract class QAbstractGeoTileCache offers interfaces for inserting and getting tiles, as well as getting cache status information such as used texture memory. The new class QGeoFileTileCache implements QAbstractGeoTileCache and offers a file based caching implementation (the implementation is the same as before splitting the class). Change-Id: I2eab7491d489ac5b251c1296b67688901f5cc7d7 Reviewed-by: Laszlo Agocs --- src/location/maps/maps.pri | 6 +- src/location/maps/qabstractgeotilecache.cpp | 147 ++++++ src/location/maps/qabstractgeotilecache_p.h | 123 +++++ src/location/maps/qgeofiletilecache.cpp | 447 ++++++++++++++++++ src/location/maps/qgeofiletilecache_p.h | 155 +++++++ src/location/maps/qgeomapscene.cpp | 2 +- src/location/maps/qgeotilecache.cpp | 499 --------------------- src/location/maps/qgeotilecache_p.h | 170 ------- src/location/maps/qgeotiledmap.cpp | 4 +- src/location/maps/qgeotiledmap_p.h | 4 +- src/location/maps/qgeotiledmap_p_p.h | 4 +- .../maps/qgeotiledmappingmanagerengine.cpp | 12 +- .../maps/qgeotiledmappingmanagerengine_p.h | 6 +- .../maps/qgeotiledmappingmanagerengine_p_p.h | 4 +- src/location/maps/qgeotilefetcher_p_p.h | 1 - src/location/maps/qgeotilerequestmanager.cpp | 2 +- src/location/maps/qgeotilerequestmanager_p.h | 1 - 17 files changed, 895 insertions(+), 692 deletions(-) create mode 100644 src/location/maps/qabstractgeotilecache.cpp create mode 100644 src/location/maps/qabstractgeotilecache_p.h create mode 100644 src/location/maps/qgeofiletilecache.cpp create mode 100644 src/location/maps/qgeofiletilecache_p.h delete mode 100644 src/location/maps/qgeotilecache.cpp delete mode 100644 src/location/maps/qgeotilecache_p.h (limited to 'src/location') diff --git a/src/location/maps/maps.pri b/src/location/maps/maps.pri index 43e0f747..93af4f4d 100644 --- a/src/location/maps/maps.pri +++ b/src/location/maps/maps.pri @@ -49,7 +49,8 @@ PRIVATE_HEADERS += \ maps/qgeoroutingmanagerengine_p.h \ maps/qgeoroutingmanager_p.h \ maps/qgeoserviceprovider_p.h \ - maps/qgeotilecache_p.h \ + maps/qabstractgeotilecache_p.h \ + maps/qgeofiletilecache_p.h \ maps/qgeotiledmapreply_p.h \ maps/qgeotiledmapreply_p_p.h \ maps/qgeotilespec_p.h \ @@ -81,7 +82,8 @@ SOURCES += \ maps/qgeoroutingmanagerengine.cpp \ maps/qgeoserviceprovider.cpp \ maps/qgeoserviceproviderfactory.cpp \ - maps/qgeotilecache.cpp \ + maps/qabstractgeotilecache.cpp \ + maps/qgeofiletilecache.cpp \ maps/qgeotiledmapreply.cpp \ maps/qgeotilespec.cpp \ maps/qgeotiledmap.cpp diff --git a/src/location/maps/qabstractgeotilecache.cpp b/src/location/maps/qabstractgeotilecache.cpp new file mode 100644 index 00000000..739123db --- /dev/null +++ b/src/location/maps/qabstractgeotilecache.cpp @@ -0,0 +1,147 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qabstractgeotilecache_p.h" + +#include "qgeotilespec_p.h" + +#include "qgeomappingmanager_p.h" + +#include +#include +#include +#include +#include + +Q_DECLARE_METATYPE(QList) +Q_DECLARE_METATYPE(QSet) + +QT_BEGIN_NAMESPACE + +QGeoTileTexture::QGeoTileTexture() + : textureBound(false) {} + +QGeoTileTexture::~QGeoTileTexture() +{ +} + +QAbstractGeoTileCache::QAbstractGeoTileCache(QObject *parent) + : QObject(parent) +{ + qRegisterMetaType(); + qRegisterMetaType >(); + qRegisterMetaType >(); +} + +QAbstractGeoTileCache::~QAbstractGeoTileCache() +{ +} + +void QAbstractGeoTileCache::printStats() +{ +} + +void QAbstractGeoTileCache::handleError(const QGeoTileSpec &, const QString &error) +{ + qWarning() << "tile request error " << error; +} + +void QAbstractGeoTileCache::setMaxDiskUsage(int diskUsage) +{ + Q_UNUSED(diskUsage); +} + +int QAbstractGeoTileCache::maxDiskUsage() const +{ + return 0; +} + +int QAbstractGeoTileCache::diskUsage() const +{ + return 0; +} + +void QAbstractGeoTileCache::setMaxMemoryUsage(int memoryUsage) +{ + Q_UNUSED(memoryUsage); +} + +int QAbstractGeoTileCache::maxMemoryUsage() const +{ + return 0; +} + +int QAbstractGeoTileCache::memoryUsage() const +{ + return 0; +} + +QString QAbstractGeoTileCache::baseCacheDirectory() +{ + QString dir; + + // Try the shared cache first and use a specific directory. (e.g. ~/.cache/QtLocation) + // If this is not supported by the platform, use the application-specific cache + // location. (e.g. ~/.cache//QtLocation) + dir = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation); + + if (!dir.isEmpty()) { + // The shared cache may not be writable when application isolation is enforced. + static bool writable = false; + static bool writableChecked = false; + if (!writableChecked) { + writableChecked = true; + QDir::root().mkpath(dir); + QFile writeTestFile(QDir(dir).filePath(QStringLiteral("qt_cache_check"))); + writable = writeTestFile.open(QIODevice::WriteOnly); + if (writable) + writeTestFile.remove(); + } + if (!writable) + dir = QString(); + } + + if (dir.isEmpty()) + dir = QStandardPaths::writableLocation(QStandardPaths::CacheLocation); + + if (!dir.endsWith(QLatin1Char('/'))) + dir += QLatin1Char('/'); + + dir += QLatin1String("QtLocation/"); + + return dir; +} + +QT_END_NAMESPACE diff --git a/src/location/maps/qabstractgeotilecache_p.h b/src/location/maps/qabstractgeotilecache_p.h new file mode 100644 index 00000000..a679b430 --- /dev/null +++ b/src/location/maps/qabstractgeotilecache_p.h @@ -0,0 +1,123 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QABSTRACTGEOTILECACHE_P_H +#define QABSTRACTGEOTILECACHE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include + +#include +#include +#include "qcache3q_p.h" +#include +#include +#include + +#include "qgeotilespec_p.h" +#include "qgeotiledmappingmanagerengine_p.h" + +#include + +QT_BEGIN_NAMESPACE + +class QGeoMappingManager; + +class QGeoTile; +class QAbstractGeoTileCache; + +class QThread; + +/* This is also used in the mapgeometry */ +class Q_LOCATION_EXPORT QGeoTileTexture +{ +public: + + QGeoTileTexture(); + ~QGeoTileTexture(); + + QGeoTileSpec spec; + QImage image; + bool textureBound; +}; + +class Q_LOCATION_EXPORT QAbstractGeoTileCache : public QObject +{ + Q_OBJECT +public: + QAbstractGeoTileCache(QObject *parent = 0); + virtual ~QAbstractGeoTileCache(); + + virtual void setMaxDiskUsage(int diskUsage); + virtual int maxDiskUsage() const; + virtual int diskUsage() const; + + virtual void setMaxMemoryUsage(int memoryUsage); + virtual int maxMemoryUsage() const; + virtual int memoryUsage() const; + + virtual void setMinTextureUsage(int textureUsage) = 0; + virtual void setExtraTextureUsage(int textureUsage) = 0; + virtual int maxTextureUsage() const = 0; + virtual int minTextureUsage() const = 0; + virtual int textureUsage() const = 0; + + virtual QSharedPointer get(const QGeoTileSpec &spec) = 0; + + virtual void insert(const QGeoTileSpec &spec, + const QByteArray &bytes, + const QString &format, + QGeoTiledMappingManagerEngine::CacheAreas areas = QGeoTiledMappingManagerEngine::AllCaches) = 0; + virtual void handleError(const QGeoTileSpec &spec, const QString &errorString); + + static QString baseCacheDirectory(); + +protected: + virtual void printStats() = 0; +}; + +QT_END_NAMESPACE + +#endif // QABSTRACTGEOTILECACHE_P_H diff --git a/src/location/maps/qgeofiletilecache.cpp b/src/location/maps/qgeofiletilecache.cpp new file mode 100644 index 00000000..4efe9696 --- /dev/null +++ b/src/location/maps/qgeofiletilecache.cpp @@ -0,0 +1,447 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qgeofiletilecache_p.h" + +#include "qgeotilespec_p.h" + +#include "qgeomappingmanager_p.h" + +#include +#include +#include +#include +#include + +Q_DECLARE_METATYPE(QList) +Q_DECLARE_METATYPE(QSet) + +QT_BEGIN_NAMESPACE + +class QGeoCachedTileMemory +{ +public: + ~QGeoCachedTileMemory() + { + if (cache) + cache->evictFromMemoryCache(this); + } + + QGeoTileSpec spec; + QGeoFileTileCache *cache; + QByteArray bytes; + QString format; +}; + +void QCache3QTileEvictionPolicy::aboutToBeRemoved(const QGeoTileSpec &key, QSharedPointer obj) +{ + Q_UNUSED(key); + // set the cache pointer to zero so we can't call evictFromDiskCache + obj->cache = 0; +} + +void QCache3QTileEvictionPolicy::aboutToBeEvicted(const QGeoTileSpec &key, QSharedPointer obj) +{ + Q_UNUSED(key); + Q_UNUSED(obj); + // leave the pointer set if it's a real eviction +} + +QGeoCachedTileDisk::~QGeoCachedTileDisk() +{ + if (cache) + cache->evictFromDiskCache(this); +} + +QGeoFileTileCache::QGeoFileTileCache(const QString &directory, QObject *parent) + : QAbstractGeoTileCache(parent), directory_(directory), + minTextureUsage_(0), extraTextureUsage_(0) +{ + const QString basePath = baseCacheDirectory(); + + // delete old tiles from QtLocation 5.4 or prior + // Newer version use plugin-specific subdirectories so those are not affected. + // TODO Remove cache cleanup in Qt 6 + QDir baseDir(basePath); + if (baseDir.exists()) { + const QStringList oldCacheFiles = baseDir.entryList(QDir::Files); + foreach (const QString& file, oldCacheFiles) + baseDir.remove(file); + } + + if (directory_.isEmpty()) { + directory_ = basePath; + qWarning() << "Plugin uses uninitialized QGeoFileTileCache directory which was deleted during startup"; + } + + QDir::root().mkpath(directory_); + + // default values + setMaxDiskUsage(20 * 1024 * 1024); + setMaxMemoryUsage(3 * 1024 * 1024); + setExtraTextureUsage(6 * 1024 * 1024); + + loadTiles(); +} + +void QGeoFileTileCache::loadTiles() +{ + QStringList formats; + formats << QLatin1String("*.*"); + + QDir dir(directory_); + QStringList files = dir.entryList(formats, QDir::Files); + + // Method: + // 1. read each queue file then, if each file exists, deserialize the data into the appropriate + // cache queue. + for (int i = 1; i<=4; i++) { + QString filename = dir.filePath(QString::fromLatin1("queue") + QString::number(i)); + QFile file(filename); + if (!file.open(QIODevice::ReadOnly)) + continue; + QList > queue; + QList specs; + QList costs; + while (!file.atEnd()) { + QByteArray line = file.readLine().trimmed(); + QString filename = QString::fromLatin1(line.constData(), line.length()); + if (dir.exists(filename)){ + files.removeOne(filename); + QGeoTileSpec spec = filenameToTileSpec(filename); + if (spec.zoom() == -1) + continue; + QSharedPointer tileDisk(new QGeoCachedTileDisk); + tileDisk->filename = dir.filePath(filename); + tileDisk->cache = this; + tileDisk->spec = spec; + QFileInfo fi(tileDisk->filename); + specs.append(spec); + queue.append(tileDisk); + costs.append(fi.size()); + } + } + + diskCache_.deserializeQueue(i, specs, queue, costs); + file.close(); + } + + // 2. remaining tiles that aren't registered in a queue get pushed into cache here + // this is a backup, in case the queue manifest files get deleted or out of sync due to + // the application not closing down properly + for (int i = 0; i < files.size(); ++i) { + QGeoTileSpec spec = filenameToTileSpec(files.at(i)); + if (spec.zoom() == -1) + continue; + QString filename = dir.filePath(files.at(i)); + addToDiskCache(spec, filename); + } +} + +QGeoFileTileCache::~QGeoFileTileCache() +{ + // write disk cache queues to disk + QDir dir(directory_); + for (int i = 1; i<=4; i++) { + QString filename = dir.filePath(QString::fromLatin1("queue") + QString::number(i)); + QFile file(filename); + if (!file.open(QIODevice::WriteOnly)){ + qWarning() << "Unable to write tile cache file " << filename; + continue; + } + QList > queue; + diskCache_.serializeQueue(i, queue); + foreach (const QSharedPointer &tile, queue) { + if (tile.isNull()) + continue; + + // we just want the filename here, not the full path + int index = tile->filename.lastIndexOf(QLatin1Char('/')); + QByteArray filename = tile->filename.mid(index + 1).toLatin1() + '\n'; + file.write(filename); + } + file.close(); + } +} + +void QGeoFileTileCache::printStats() +{ + textureCache_.printStats(); + memoryCache_.printStats(); + diskCache_.printStats(); +} + +void QGeoFileTileCache::setMaxDiskUsage(int diskUsage) +{ + diskCache_.setMaxCost(diskUsage); +} + +int QGeoFileTileCache::maxDiskUsage() const +{ + return diskCache_.maxCost(); +} + +int QGeoFileTileCache::diskUsage() const +{ + return diskCache_.totalCost(); +} + +void QGeoFileTileCache::setMaxMemoryUsage(int memoryUsage) +{ + memoryCache_.setMaxCost(memoryUsage); +} + +int QGeoFileTileCache::maxMemoryUsage() const +{ + return memoryCache_.maxCost(); +} + +int QGeoFileTileCache::memoryUsage() const +{ + return memoryCache_.totalCost(); +} + +void QGeoFileTileCache::setExtraTextureUsage(int textureUsage) +{ + extraTextureUsage_ = textureUsage; + textureCache_.setMaxCost(minTextureUsage_ + extraTextureUsage_); +} + +void QGeoFileTileCache::setMinTextureUsage(int textureUsage) +{ + minTextureUsage_ = textureUsage; + textureCache_.setMaxCost(minTextureUsage_ + extraTextureUsage_); +} + +int QGeoFileTileCache::maxTextureUsage() const +{ + return textureCache_.maxCost(); +} + +int QGeoFileTileCache::minTextureUsage() const +{ + return minTextureUsage_; +} + + +int QGeoFileTileCache::textureUsage() const +{ + return textureCache_.totalCost(); +} + +QSharedPointer QGeoFileTileCache::get(const QGeoTileSpec &spec) +{ + QSharedPointer tt = textureCache_.object(spec); + if (tt) + return tt; + + QSharedPointer tm = memoryCache_.object(spec); + if (tm) { + QPixmap pixmap; + if (!pixmap.loadFromData(tm->bytes)) { + handleError(spec, QLatin1String("Problem with tile image")); + return QSharedPointer(0); + } + QSharedPointer tt = addToTextureCache(spec, pixmap); + 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(); + + QPixmap pixmap; + if (!pixmap.loadFromData(bytes)) { + handleError(spec, QLatin1String("Problem with tile image")); + return QSharedPointer(0); + } + + addToMemoryCache(spec, bytes, format); + QSharedPointer tt = addToTextureCache(td->spec, pixmap); + if (tt) + return tt; + } + + return QSharedPointer(); +} + +void QGeoFileTileCache::insert(const QGeoTileSpec &spec, + const QByteArray &bytes, + const QString &format, + QGeoTiledMappingManagerEngine::CacheAreas areas) +{ + if (areas & QGeoTiledMappingManagerEngine::DiskCache) { + QString filename = tileSpecToFilename(spec, format, directory_); + QFile file(filename); + file.open(QIODevice::WriteOnly); + file.write(bytes); + file.close(); + + addToDiskCache(spec, filename); + } + + if (areas & QGeoTiledMappingManagerEngine::MemoryCache) { + addToMemoryCache(spec, bytes, format); + } + + /* inserts do not hit the texture cache -- this actually reduces overall + * cache hit rates because many tiles come too late to be useful + * and act as a poison */ +} + +void QGeoFileTileCache::evictFromDiskCache(QGeoCachedTileDisk *td) +{ + QFile::remove(td->filename); +} + +void QGeoFileTileCache::evictFromMemoryCache(QGeoCachedTileMemory * /* tm */) +{ +} + +QSharedPointer QGeoFileTileCache::addToDiskCache(const QGeoTileSpec &spec, const QString &filename) +{ + QSharedPointer td(new QGeoCachedTileDisk); + td->spec = spec; + td->filename = filename; + td->cache = this; + + QFileInfo fi(filename); + int diskCost = fi.size(); + diskCache_.insert(spec, td, diskCost); + return td; +} + +QSharedPointer QGeoFileTileCache::addToMemoryCache(const QGeoTileSpec &spec, const QByteArray &bytes, const QString &format) +{ + QSharedPointer tm(new QGeoCachedTileMemory); + tm->spec = spec; + tm->cache = this; + tm->bytes = bytes; + tm->format = format; + + int cost = bytes.size(); + memoryCache_.insert(spec, tm, cost); + + return tm; +} + +QSharedPointer QGeoFileTileCache::addToTextureCache(const QGeoTileSpec &spec, const QPixmap &pixmap) +{ + QSharedPointer tt(new QGeoTileTexture); + tt->spec = spec; + tt->image = pixmap.toImage(); + + int textureCost = tt->image.width() * tt->image.height() * tt->image.depth() / 8; + textureCache_.insert(spec, tt, textureCost); + + return tt; +} + +QString QGeoFileTileCache::tileSpecToFilename(const QGeoTileSpec &spec, const QString &format, const QString &directory) +{ + QString filename = spec.plugin(); + filename += QLatin1String("-"); + filename += QString::number(spec.mapId()); + filename += QLatin1String("-"); + filename += QString::number(spec.zoom()); + filename += QLatin1String("-"); + filename += QString::number(spec.x()); + filename += QLatin1String("-"); + filename += QString::number(spec.y()); + + //Append version if real version number to ensure backwards compatibility and eviction of old tiles + if (spec.version() != -1) { + filename += QLatin1String("-"); + filename += QString::number(spec.version()); + } + + filename += QLatin1String("."); + filename += format; + + QDir dir = QDir(directory); + + return dir.filePath(filename); +} + +QGeoTileSpec QGeoFileTileCache::filenameToTileSpec(const QString &filename) +{ + QGeoTileSpec emptySpec; + + QStringList parts = filename.split('.'); + + if (parts.length() != 2) + return emptySpec; + + QString name = parts.at(0); + QStringList fields = name.split('-'); + + int length = fields.length(); + if (length != 5 && length != 6) + return emptySpec; + + QList numbers; + + bool ok = false; + for (int i = 1; i < length; ++i) { + ok = false; + int value = fields.at(i).toInt(&ok); + if (!ok) + return emptySpec; + numbers.append(value); + } + + //File name without version, append default + if (numbers.length() < 5) + numbers.append(-1); + + return QGeoTileSpec(fields.at(0), + numbers.at(0), + numbers.at(1), + numbers.at(2), + numbers.at(3), + numbers.at(4)); +} + +QString QGeoFileTileCache::directory() const +{ + return directory_; +} + +QT_END_NAMESPACE diff --git a/src/location/maps/qgeofiletilecache_p.h b/src/location/maps/qgeofiletilecache_p.h new file mode 100644 index 00000000..1ed2aabc --- /dev/null +++ b/src/location/maps/qgeofiletilecache_p.h @@ -0,0 +1,155 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QGEOFILETILECACHE_P_H +#define QGEOFILETILECACHE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include + +#include +#include +#include "qcache3q_p.h" +#include +#include +#include + +#include "qgeotilespec_p.h" +#include "qgeotiledmappingmanagerengine_p.h" +#include "qabstractgeotilecache_p.h" + +#include + +QT_BEGIN_NAMESPACE + +class QGeoMappingManager; + +class QGeoTile; +class QGeoCachedTileMemory; +class QGeoFileTileCache; + +class QPixmap; +class QThread; + +/* This would be internal to qgeofiletilecache.cpp except that the eviction + * policy can't be defined without it being concrete here */ +class QGeoCachedTileDisk +{ +public: + ~QGeoCachedTileDisk(); + + QGeoTileSpec spec; + QString filename; + QString format; + QGeoFileTileCache *cache; +}; + +/* Custom eviction policy for the disk cache, to avoid deleting all the files + * when the application closes */ +class QCache3QTileEvictionPolicy : public QCache3QDefaultEvictionPolicy +{ +protected: + void aboutToBeRemoved(const QGeoTileSpec &key, QSharedPointer obj); + void aboutToBeEvicted(const QGeoTileSpec &key, QSharedPointer obj); +}; + +class Q_LOCATION_EXPORT QGeoFileTileCache : public QAbstractGeoTileCache +{ + Q_OBJECT +public: + QGeoFileTileCache(const QString &directory = QString(), QObject *parent = 0); + ~QGeoFileTileCache(); + + void setMaxDiskUsage(int diskUsage); + int maxDiskUsage() const; + int diskUsage() const; + + void setMaxMemoryUsage(int memoryUsage); + int maxMemoryUsage() const; + int memoryUsage() const; + + void setMinTextureUsage(int textureUsage); + void setExtraTextureUsage(int textureUsage); + int maxTextureUsage() const; + int minTextureUsage() const; + int textureUsage() const; + + QSharedPointer get(const QGeoTileSpec &spec); + + // can be called without a specific tileCache pointer + static void evictFromDiskCache(QGeoCachedTileDisk *td); + static void evictFromMemoryCache(QGeoCachedTileMemory *tm); + + void insert(const QGeoTileSpec &spec, + const QByteArray &bytes, + const QString &format, + QGeoTiledMappingManagerEngine::CacheAreas areas = QGeoTiledMappingManagerEngine::AllCaches); + +private: + void printStats(); + void loadTiles(); + + QString directory() const; + + QSharedPointer addToDiskCache(const QGeoTileSpec &spec, const QString &filename); + QSharedPointer addToMemoryCache(const QGeoTileSpec &spec, const QByteArray &bytes, const QString &format); + QSharedPointer addToTextureCache(const QGeoTileSpec &spec, const QPixmap &pixmap); + + static QString tileSpecToFilename(const QGeoTileSpec &spec, const QString &format, const QString &directory); + static QGeoTileSpec filenameToTileSpec(const QString &filename); + + QCache3Q diskCache_; + QCache3Q memoryCache_; + QCache3Q textureCache_; + + int minTextureUsage_; + int extraTextureUsage_; + + QString directory_; +}; + +QT_END_NAMESPACE + +#endif // QGEOFILETILECACHE_P_H diff --git a/src/location/maps/qgeomapscene.cpp b/src/location/maps/qgeomapscene.cpp index a25405ec..4a457005 100644 --- a/src/location/maps/qgeomapscene.cpp +++ b/src/location/maps/qgeomapscene.cpp @@ -36,7 +36,7 @@ ****************************************************************************/ #include "qgeomapscene_p.h" #include "qgeocameradata_p.h" -#include "qgeotilecache_p.h" +#include "qabstractgeotilecache_p.h" #include "qgeotilespec_p.h" #include #include diff --git a/src/location/maps/qgeotilecache.cpp b/src/location/maps/qgeotilecache.cpp deleted file mode 100644 index 01cfcba4..00000000 --- a/src/location/maps/qgeotilecache.cpp +++ /dev/null @@ -1,499 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include "qgeotilecache_p.h" - -#include "qgeotilespec_p.h" - -#include "qgeomappingmanager_p.h" - -#include -#include -#include -#include -#include - -Q_DECLARE_METATYPE(QList) -Q_DECLARE_METATYPE(QSet) - -QT_BEGIN_NAMESPACE - -class QGeoCachedTileMemory -{ -public: - ~QGeoCachedTileMemory() - { - if (cache) - cache->evictFromMemoryCache(this); - } - - QGeoTileSpec spec; - QGeoTileCache *cache; - QByteArray bytes; - QString format; -}; - -QGeoTileTexture::QGeoTileTexture() - : textureBound(false) {} - -void QCache3QTileEvictionPolicy::aboutToBeRemoved(const QGeoTileSpec &key, QSharedPointer obj) -{ - Q_UNUSED(key); - // set the cache pointer to zero so we can't call evictFromDiskCache - obj->cache = 0; -} - -void QCache3QTileEvictionPolicy::aboutToBeEvicted(const QGeoTileSpec &key, QSharedPointer obj) -{ - Q_UNUSED(key); - Q_UNUSED(obj); - // leave the pointer set if it's a real eviction -} - -QGeoCachedTileDisk::~QGeoCachedTileDisk() -{ - if (cache) - cache->evictFromDiskCache(this); -} - -QGeoTileTexture::~QGeoTileTexture() -{ -} - -QGeoTileCache::QGeoTileCache(const QString &directory, QObject *parent) - : QObject(parent), directory_(directory), - minTextureUsage_(0), extraTextureUsage_(0) -{ - qRegisterMetaType(); - qRegisterMetaType >(); - qRegisterMetaType >(); - - const QString basePath = baseCacheDirectory(); - - // delete old tiles from QtLocation 5.4 or prior - // Newer version use plugin-specific subdirectories so those are not affected. - // TODO Remove cache cleanup in Qt 6 - QDir baseDir(basePath); - if (baseDir.exists()) { - const QStringList oldCacheFiles = baseDir.entryList(QDir::Files); - foreach (const QString& file, oldCacheFiles) - baseDir.remove(file); - } - - if (directory_.isEmpty()) { - directory_ = basePath; - qWarning() << "Plugin uses uninitialized QGeoTileCache directory which was deleted during startup"; - } - - QDir::root().mkpath(directory_); - - // default values - setMaxDiskUsage(20 * 1024 * 1024); - setMaxMemoryUsage(3 * 1024 * 1024); - setExtraTextureUsage(6 * 1024 * 1024); - - loadTiles(); -} - -void QGeoTileCache::loadTiles() -{ - QStringList formats; - formats << QLatin1String("*.*"); - - QDir dir(directory_); - QStringList files = dir.entryList(formats, QDir::Files); - - // Method: - // 1. read each queue file then, if each file exists, deserialize the data into the appropriate - // cache queue. - for (int i = 1; i<=4; i++) { - QString filename = dir.filePath(QString::fromLatin1("queue") + QString::number(i)); - QFile file(filename); - if (!file.open(QIODevice::ReadOnly)) - continue; - QList > queue; - QList specs; - QList costs; - while (!file.atEnd()) { - QByteArray line = file.readLine().trimmed(); - QString filename = QString::fromLatin1(line.constData(), line.length()); - if (dir.exists(filename)){ - files.removeOne(filename); - QGeoTileSpec spec = filenameToTileSpec(filename); - if (spec.zoom() == -1) - continue; - QSharedPointer tileDisk(new QGeoCachedTileDisk); - tileDisk->filename = dir.filePath(filename); - tileDisk->cache = this; - tileDisk->spec = spec; - QFileInfo fi(tileDisk->filename); - specs.append(spec); - queue.append(tileDisk); - costs.append(fi.size()); - } - } - - diskCache_.deserializeQueue(i, specs, queue, costs); - file.close(); - } - - // 2. remaining tiles that aren't registered in a queue get pushed into cache here - // this is a backup, in case the queue manifest files get deleted or out of sync due to - // the application not closing down properly - for (int i = 0; i < files.size(); ++i) { - QGeoTileSpec spec = filenameToTileSpec(files.at(i)); - if (spec.zoom() == -1) - continue; - QString filename = dir.filePath(files.at(i)); - addToDiskCache(spec, filename); - } -} - -QGeoTileCache::~QGeoTileCache() -{ - // write disk cache queues to disk - QDir dir(directory_); - for (int i = 1; i<=4; i++) { - QString filename = dir.filePath(QString::fromLatin1("queue") + QString::number(i)); - QFile file(filename); - if (!file.open(QIODevice::WriteOnly)){ - qWarning() << "Unable to write tile cache file " << filename; - continue; - } - QList > queue; - diskCache_.serializeQueue(i, queue); - foreach (const QSharedPointer &tile, queue) { - if (tile.isNull()) - continue; - - // we just want the filename here, not the full path - int index = tile->filename.lastIndexOf(QLatin1Char('/')); - QByteArray filename = tile->filename.mid(index + 1).toLatin1() + '\n'; - file.write(filename); - } - file.close(); - } -} - -void QGeoTileCache::printStats() -{ - textureCache_.printStats(); - memoryCache_.printStats(); - diskCache_.printStats(); -} - -void QGeoTileCache::setMaxDiskUsage(int diskUsage) -{ - diskCache_.setMaxCost(diskUsage); -} - -int QGeoTileCache::maxDiskUsage() const -{ - return diskCache_.maxCost(); -} - -int QGeoTileCache::diskUsage() const -{ - return diskCache_.totalCost(); -} - -void QGeoTileCache::setMaxMemoryUsage(int memoryUsage) -{ - memoryCache_.setMaxCost(memoryUsage); -} - -int QGeoTileCache::maxMemoryUsage() const -{ - return memoryCache_.maxCost(); -} - -int QGeoTileCache::memoryUsage() const -{ - return memoryCache_.totalCost(); -} - -void QGeoTileCache::setExtraTextureUsage(int textureUsage) -{ - extraTextureUsage_ = textureUsage; - textureCache_.setMaxCost(minTextureUsage_ + extraTextureUsage_); -} - -void QGeoTileCache::setMinTextureUsage(int textureUsage) -{ - minTextureUsage_ = textureUsage; - textureCache_.setMaxCost(minTextureUsage_ + extraTextureUsage_); -} - -int QGeoTileCache::maxTextureUsage() const -{ - return textureCache_.maxCost(); -} - -int QGeoTileCache::minTextureUsage() const -{ - return minTextureUsage_; -} - - -int QGeoTileCache::textureUsage() const -{ - return textureCache_.totalCost(); -} - -QSharedPointer QGeoTileCache::get(const QGeoTileSpec &spec) -{ - QSharedPointer tt = textureCache_.object(spec); - if (tt) - return tt; - - QSharedPointer tm = memoryCache_.object(spec); - if (tm) { - QPixmap pixmap; - if (!pixmap.loadFromData(tm->bytes)) { - handleError(spec, QLatin1String("Problem with tile image")); - return QSharedPointer(0); - } - QSharedPointer tt = addToTextureCache(spec, pixmap); - 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(); - - QPixmap pixmap; - if (!pixmap.loadFromData(bytes)) { - handleError(spec, QLatin1String("Problem with tile image")); - return QSharedPointer(0); - } - - addToMemoryCache(spec, bytes, format); - QSharedPointer tt = addToTextureCache(td->spec, pixmap); - if (tt) - return tt; - } - - return QSharedPointer(); -} - -QString QGeoTileCache::directory() const -{ - return directory_; -} - -void QGeoTileCache::insert(const QGeoTileSpec &spec, - const QByteArray &bytes, - const QString &format, - QGeoTiledMappingManagerEngine::CacheAreas areas) -{ - if (areas & QGeoTiledMappingManagerEngine::DiskCache) { - QString filename = tileSpecToFilename(spec, format, directory_); - QFile file(filename); - file.open(QIODevice::WriteOnly); - file.write(bytes); - file.close(); - - addToDiskCache(spec, filename); - } - - if (areas & QGeoTiledMappingManagerEngine::MemoryCache) { - addToMemoryCache(spec, bytes, format); - } - - /* inserts do not hit the texture cache -- this actually reduces overall - * cache hit rates because many tiles come too late to be useful - * and act as a poison */ -} - -void QGeoTileCache::evictFromDiskCache(QGeoCachedTileDisk *td) -{ - QFile::remove(td->filename); -} - -void QGeoTileCache::evictFromMemoryCache(QGeoCachedTileMemory * /* tm */) -{ -} - -QSharedPointer QGeoTileCache::addToDiskCache(const QGeoTileSpec &spec, const QString &filename) -{ - QSharedPointer td(new QGeoCachedTileDisk); - td->spec = spec; - td->filename = filename; - td->cache = this; - - QFileInfo fi(filename); - int diskCost = fi.size(); - diskCache_.insert(spec, td, diskCost); - return td; -} - -QSharedPointer QGeoTileCache::addToMemoryCache(const QGeoTileSpec &spec, const QByteArray &bytes, const QString &format) -{ - QSharedPointer tm(new QGeoCachedTileMemory); - tm->spec = spec; - tm->cache = this; - tm->bytes = bytes; - tm->format = format; - - int cost = bytes.size(); - memoryCache_.insert(spec, tm, cost); - - return tm; -} - -QSharedPointer QGeoTileCache::addToTextureCache(const QGeoTileSpec &spec, const QPixmap &pixmap) -{ - QSharedPointer tt(new QGeoTileTexture); - tt->spec = spec; - tt->image = pixmap.toImage(); - - int textureCost = tt->image.width() * tt->image.height() * tt->image.depth() / 8; - textureCache_.insert(spec, tt, textureCost); - - return tt; -} - -void QGeoTileCache::handleError(const QGeoTileSpec &, const QString &error) -{ - qWarning() << "tile request error " << error; -} - -QString QGeoTileCache::tileSpecToFilename(const QGeoTileSpec &spec, const QString &format, const QString &directory) -{ - QString filename = spec.plugin(); - filename += QLatin1String("-"); - filename += QString::number(spec.mapId()); - filename += QLatin1String("-"); - filename += QString::number(spec.zoom()); - filename += QLatin1String("-"); - filename += QString::number(spec.x()); - filename += QLatin1String("-"); - filename += QString::number(spec.y()); - - //Append version if real version number to ensure backwards compatibility and eviction of old tiles - if (spec.version() != -1) { - filename += QLatin1String("-"); - filename += QString::number(spec.version()); - } - - filename += QLatin1String("."); - filename += format; - - QDir dir = QDir(directory); - - return dir.filePath(filename); -} - -QGeoTileSpec QGeoTileCache::filenameToTileSpec(const QString &filename) -{ - QGeoTileSpec emptySpec; - - QStringList parts = filename.split('.'); - - if (parts.length() != 2) - return emptySpec; - - QString name = parts.at(0); - QStringList fields = name.split('-'); - - int length = fields.length(); - if (length != 5 && length != 6) - return emptySpec; - - QList numbers; - - bool ok = false; - for (int i = 1; i < length; ++i) { - ok = false; - int value = fields.at(i).toInt(&ok); - if (!ok) - return emptySpec; - numbers.append(value); - } - - //File name without version, append default - if (numbers.length() < 5) - numbers.append(-1); - - return QGeoTileSpec(fields.at(0), - numbers.at(0), - numbers.at(1), - numbers.at(2), - numbers.at(3), - numbers.at(4)); -} - -QString QGeoTileCache::baseCacheDirectory() -{ - QString dir; - - // Try the shared cache first and use a specific directory. (e.g. ~/.cache/QtLocation) - // If this is not supported by the platform, use the application-specific cache - // location. (e.g. ~/.cache//QtLocation) - dir = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation); - - if (!dir.isEmpty()) { - // The shared cache may not be writable when application isolation is enforced. - static bool writable = false; - static bool writableChecked = false; - if (!writableChecked) { - writableChecked = true; - QDir::root().mkpath(dir); - QFile writeTestFile(QDir(dir).filePath(QStringLiteral("qt_cache_check"))); - writable = writeTestFile.open(QIODevice::WriteOnly); - if (writable) - writeTestFile.remove(); - } - if (!writable) - dir = QString(); - } - - if (dir.isEmpty()) - dir = QStandardPaths::writableLocation(QStandardPaths::CacheLocation); - - if (!dir.endsWith(QLatin1Char('/'))) - dir += QLatin1Char('/'); - - dir += QLatin1String("QtLocation/"); - - return dir; -} - -QT_END_NAMESPACE diff --git a/src/location/maps/qgeotilecache_p.h b/src/location/maps/qgeotilecache_p.h deleted file mode 100644 index d9f7bce9..00000000 --- a/src/location/maps/qgeotilecache_p.h +++ /dev/null @@ -1,170 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the QtLocation module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef QGEOTILECACHE_P_H -#define QGEOTILECACHE_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include - -#include -#include -#include "qcache3q_p.h" -#include -#include -#include - -#include "qgeotilespec_p.h" -#include "qgeotiledmappingmanagerengine_p.h" - -#include - -QT_BEGIN_NAMESPACE - -class QGeoMappingManager; - -class QGeoTile; -class QGeoCachedTileMemory; -class QGeoTileCache; - -class QPixmap; -class QThread; - -/* This would be internal to qgeotilecache.cpp except that the eviction - * policy can't be defined without it being concrete here */ -class QGeoCachedTileDisk -{ -public: - ~QGeoCachedTileDisk(); - - QGeoTileSpec spec; - QString filename; - QString format; - QGeoTileCache *cache; -}; - -/* This is also used in the mapgeometry */ -class Q_LOCATION_EXPORT QGeoTileTexture -{ -public: - - QGeoTileTexture(); - ~QGeoTileTexture(); - - QGeoTileSpec spec; - QImage image; - bool textureBound; -}; - -/* Custom eviction policy for the disk cache, to avoid deleting all the files - * when the application closes */ -class QCache3QTileEvictionPolicy : public QCache3QDefaultEvictionPolicy -{ -protected: - void aboutToBeRemoved(const QGeoTileSpec &key, QSharedPointer obj); - void aboutToBeEvicted(const QGeoTileSpec &key, QSharedPointer obj); -}; - -class Q_LOCATION_EXPORT QGeoTileCache : public QObject -{ - Q_OBJECT -public: - QGeoTileCache(const QString &directory = QString(), QObject *parent = 0); - ~QGeoTileCache(); - - void setMaxDiskUsage(int diskUsage); - int maxDiskUsage() const; - int diskUsage() const; - - void setMaxMemoryUsage(int memoryUsage); - int maxMemoryUsage() const; - int memoryUsage() const; - - void setMinTextureUsage(int textureUsage); - void setExtraTextureUsage(int textureUsage); - int maxTextureUsage() const; - int minTextureUsage() const; - int textureUsage() const; - - QSharedPointer get(const QGeoTileSpec &spec); - QString directory() const; - - // can be called without a specific tileCache pointer - static void evictFromDiskCache(QGeoCachedTileDisk *td); - static void evictFromMemoryCache(QGeoCachedTileMemory *tm); - - void insert(const QGeoTileSpec &spec, - const QByteArray &bytes, - const QString &format, - QGeoTiledMappingManagerEngine::CacheAreas areas = QGeoTiledMappingManagerEngine::AllCaches); - void handleError(const QGeoTileSpec &spec, const QString &errorString); - - static QString baseCacheDirectory(); - -public Q_SLOTS: - void printStats(); - -private: - void loadTiles(); - - QSharedPointer addToDiskCache(const QGeoTileSpec &spec, const QString &filename); - QSharedPointer addToMemoryCache(const QGeoTileSpec &spec, const QByteArray &bytes, const QString &format); - QSharedPointer addToTextureCache(const QGeoTileSpec &spec, const QPixmap &pixmap); - - static QString tileSpecToFilename(const QGeoTileSpec &spec, const QString &format, const QString &directory); - static QGeoTileSpec filenameToTileSpec(const QString &filename); - - QString directory_; - QCache3Q diskCache_; - QCache3Q memoryCache_; - QCache3Q textureCache_; - - int minTextureUsage_; - int extraTextureUsage_; -}; - -QT_END_NAMESPACE - -#endif // QGEOTILECACHE_P_H diff --git a/src/location/maps/qgeotiledmap.cpp b/src/location/maps/qgeotiledmap.cpp index 06f5a5e8..d561c011 100644 --- a/src/location/maps/qgeotiledmap.cpp +++ b/src/location/maps/qgeotiledmap.cpp @@ -37,7 +37,7 @@ #include "qgeotiledmap_p_p.h" #include "qgeotiledmappingmanagerengine_p.h" -#include "qgeotilecache_p.h" +#include "qabstractgeotilecache_p.h" #include "qgeotilespec_p.h" #include "qgeocameratiles_p.h" @@ -85,7 +85,7 @@ void QGeoTiledMap::updateTile(const QGeoTileSpec &spec) d->updateTile(spec); } -QGeoTileCache *QGeoTiledMap::tileCache() +QAbstractGeoTileCache *QGeoTiledMap::tileCache() { Q_D(QGeoTiledMap); return d->m_cache; diff --git a/src/location/maps/qgeotiledmap_p.h b/src/location/maps/qgeotiledmap_p.h index 2afbc5c9..111056d2 100644 --- a/src/location/maps/qgeotiledmap_p.h +++ b/src/location/maps/qgeotiledmap_p.h @@ -60,7 +60,7 @@ QT_BEGIN_NAMESPACE class QGeoTileSpec; class QGeoTileTexture; -class QGeoTileCache; +class QAbstractGeoTileCache; class QGeoTiledMapPrivate; class QGeoTiledMappingManagerEngine; class QGeoTileRequestManager; @@ -79,7 +79,7 @@ public: QGeoTiledMap(QGeoTiledMappingManagerEngine *engine, QObject *parent); virtual ~QGeoTiledMap(); - QGeoTileCache *tileCache(); + QAbstractGeoTileCache *tileCache(); QGeoTileRequestManager *requestManager(); void updateTile(const QGeoTileSpec &spec); diff --git a/src/location/maps/qgeotiledmap_p_p.h b/src/location/maps/qgeotiledmap_p_p.h index 95a61a2b..2e93a006 100644 --- a/src/location/maps/qgeotiledmap_p_p.h +++ b/src/location/maps/qgeotiledmap_p_p.h @@ -58,7 +58,7 @@ QT_BEGIN_NAMESPACE class QGeoCameraTiles; class QGeoMapScene; -class QGeoTileCache; +class QAbstractGeoTileCache; class QGeoTiledMappingManagerEngine; class QGeoTiledMap; class QGeoTileRequestManager; @@ -92,7 +92,7 @@ private: void updateScene(); private: - QGeoTileCache *m_cache; + QAbstractGeoTileCache *m_cache; QGeoCameraTiles *m_cameraTiles; QGeoMapScene *m_mapScene; QGeoTileRequestManager *m_tileRequests; diff --git a/src/location/maps/qgeotiledmappingmanagerengine.cpp b/src/location/maps/qgeotiledmappingmanagerengine.cpp index 43f56872..1c61305b 100644 --- a/src/location/maps/qgeotiledmappingmanagerengine.cpp +++ b/src/location/maps/qgeotiledmappingmanagerengine.cpp @@ -41,7 +41,7 @@ #include "qgeotiledmap_p.h" #include "qgeotilerequestmanager_p.h" -#include "qgeotilecache_p.h" +#include "qgeofiletilecache_p.h" #include "qgeotilespec_p.h" #include @@ -275,22 +275,22 @@ void QGeoTiledMappingManagerEngine::setCacheHint(QGeoTiledMappingManagerEngine:: d->cacheHint_ = cacheHint; } -QGeoTileCache *QGeoTiledMappingManagerEngine::createTileCacheWithDir(const QString &cacheDirectory) +QAbstractGeoTileCache *QGeoTiledMappingManagerEngine::createTileCacheWithDir(const QString &cacheDirectory) { Q_D(QGeoTiledMappingManagerEngine); Q_ASSERT_X(!d->tileCache_, Q_FUNC_INFO, "This should be called only once"); - d->tileCache_ = new QGeoTileCache(cacheDirectory); + d->tileCache_ = new QGeoFileTileCache(cacheDirectory); return d->tileCache_; } -QGeoTileCache *QGeoTiledMappingManagerEngine::tileCache() +QAbstractGeoTileCache *QGeoTiledMappingManagerEngine::tileCache() { Q_D(QGeoTiledMappingManagerEngine); if (!d->tileCache_) { QString cacheDirectory; if (!managerName().isEmpty()) - cacheDirectory = QGeoTileCache::baseCacheDirectory() + managerName(); - d->tileCache_ = new QGeoTileCache(cacheDirectory); + cacheDirectory = QAbstractGeoTileCache::baseCacheDirectory() + managerName(); + d->tileCache_ = new QGeoFileTileCache(cacheDirectory); } return d->tileCache_; } diff --git a/src/location/maps/qgeotiledmappingmanagerengine_p.h b/src/location/maps/qgeotiledmappingmanagerengine_p.h index 12b43c40..b4ce173b 100644 --- a/src/location/maps/qgeotiledmappingmanagerengine_p.h +++ b/src/location/maps/qgeotiledmappingmanagerengine_p.h @@ -64,7 +64,7 @@ class QGeoTileTexture; class QGeoTileSpec; class QGeoTiledMap; -class QGeoTileCache; +class QAbstractGeoTileCache; class Q_LOCATION_EXPORT QGeoTiledMappingManagerEngine : public QGeoMappingManagerEngine { @@ -93,7 +93,7 @@ public: const QSet &tilesAdded, const QSet &tilesRemoved); - QGeoTileCache *tileCache(); // TODO: check this is still used + QAbstractGeoTileCache *tileCache(); // TODO: check this is still used QSharedPointer getTileTexture(const QGeoTileSpec &spec); @@ -113,7 +113,7 @@ protected: void setTileVersion(int version); void setCacheHint(QGeoTiledMappingManagerEngine::CacheAreas cacheHint); - QGeoTileCache *createTileCacheWithDir(const QString &cacheDirectory); + QAbstractGeoTileCache *createTileCacheWithDir(const QString &cacheDirectory); private: QGeoTiledMappingManagerEnginePrivate *d_ptr; diff --git a/src/location/maps/qgeotiledmappingmanagerengine_p_p.h b/src/location/maps/qgeotiledmappingmanagerengine_p_p.h index 7fb08e75..86ad0f08 100644 --- a/src/location/maps/qgeotiledmappingmanagerengine_p_p.h +++ b/src/location/maps/qgeotiledmappingmanagerengine_p_p.h @@ -57,7 +57,7 @@ QT_BEGIN_NAMESPACE class QGeoTiledMap; -class QGeoTileCache; +class QAbstractGeoTileCache; class QGeoTileSpec; class QGeoTileFetcher; @@ -72,7 +72,7 @@ public: QHash > mapHash_; QHash > tileHash_; QGeoTiledMappingManagerEngine::CacheAreas cacheHint_; - QGeoTileCache *tileCache_; + QAbstractGeoTileCache *tileCache_; QGeoTileFetcher *fetcher_; private: diff --git a/src/location/maps/qgeotilefetcher_p_p.h b/src/location/maps/qgeotilefetcher_p_p.h index ce2a5481..acd7288e 100644 --- a/src/location/maps/qgeotilefetcher_p_p.h +++ b/src/location/maps/qgeotilefetcher_p_p.h @@ -62,7 +62,6 @@ QT_BEGIN_NAMESPACE class QGeoTileSpec; class QGeoTiledMapReply; -class QGeoTileCache; class QGeoTiledMappingManagerEngine; class QGeoTileFetcherPrivate diff --git a/src/location/maps/qgeotilerequestmanager.cpp b/src/location/maps/qgeotilerequestmanager.cpp index 8857671d..1409856a 100644 --- a/src/location/maps/qgeotilerequestmanager.cpp +++ b/src/location/maps/qgeotilerequestmanager.cpp @@ -37,7 +37,7 @@ #include "qgeotilespec_p.h" #include "qgeotiledmap_p.h" #include "qgeotiledmappingmanagerengine_p.h" -#include "qgeotilecache_p.h" +#include "qabstractgeotilecache_p.h" #include QT_BEGIN_NAMESPACE diff --git a/src/location/maps/qgeotilerequestmanager_p.h b/src/location/maps/qgeotilerequestmanager_p.h index 8ae7360a..66d2251e 100644 --- a/src/location/maps/qgeotilerequestmanager_p.h +++ b/src/location/maps/qgeotilerequestmanager_p.h @@ -54,7 +54,6 @@ QT_BEGIN_NAMESPACE class QGeoTiledMap; class QGeoTiledMappingManagerEngine; class QGeoTileSpec; -class QGeoTileCache; class QGeoTileTexture; class QGeoTileRequestManagerPrivate; -- cgit v1.2.1