diff options
author | Paolo Angelelli <paolo.angelelli@theqtcompany.com> | 2016-07-06 20:01:59 +0200 |
---|---|---|
committer | Paolo Angelelli <paolo.angelelli@theqtcompany.com> | 2016-07-19 12:16:31 +0000 |
commit | 10b708e419c672411507feceb4c7869a5024df1e (patch) | |
tree | f08b8290bc6d9e2487930a285b58a4ffc678358c /src/plugins/geoservices/nokia | |
parent | 208c822225fe2a7a7e214dfb04acc48de5a7d001 (diff) | |
download | qtlocation-10b708e419c672411507feceb4c7869a5024df1e.tar.gz |
Differentiate cached tiles by dpi
This patch uses separate filenames for tiles
downloaded at different resolutions/dpi.
For the HERE plugin, the dpi is appeneded
to the filename.
For the mapbox plugin, @1x or @2x is used
due to the different approach to High DPI
tiles.
Change-Id: I0dcda088dae84e98c0e73bdc24435d7e2a3f43f7
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src/plugins/geoservices/nokia')
4 files changed, 190 insertions, 4 deletions
diff --git a/src/plugins/geoservices/nokia/nokia.pro b/src/plugins/geoservices/nokia/nokia.pro index cd340f50..a063aaf2 100644 --- a/src/plugins/geoservices/nokia/nokia.pro +++ b/src/plugins/geoservices/nokia/nokia.pro @@ -26,7 +26,8 @@ HEADERS += \ uri_constants.h \ qgeoerror_messages.h \ qgeomapversion.h \ - qgeotiledmap_nokia.h + qgeotiledmap_nokia.h \ + qgeofiletilecachenokia.h SOURCES += \ @@ -45,7 +46,8 @@ SOURCES += \ uri_constants.cpp \ qgeoerror_messages.cpp \ qgeomapversion.cpp \ - qgeotiledmap_nokia.cpp + qgeotiledmap_nokia.cpp \ + qgeofiletilecachenokia.cpp include(placesv2/placesv2.pri) diff --git a/src/plugins/geoservices/nokia/qgeofiletilecachenokia.cpp b/src/plugins/geoservices/nokia/qgeofiletilecachenokia.cpp new file mode 100644 index 00000000..8b795325 --- /dev/null +++ b/src/plugins/geoservices/nokia/qgeofiletilecachenokia.cpp @@ -0,0 +1,124 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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 "qgeofiletilecachenokia.h" +#include <QtLocation/private/qgeotilespec_p.h> +#include <QDir> + +QT_BEGIN_NAMESPACE + +QGeoFileTileCacheNokia::QGeoFileTileCacheNokia(int ppi, const QString &directory, QObject *parent) + :QGeoFileTileCache(directory, parent) +{ + m_ppi = QString::number(ppi) + QLatin1String("p"); +} + +QGeoFileTileCacheNokia::~QGeoFileTileCacheNokia() +{ + +} + +QString QGeoFileTileCacheNokia::tileSpecToFilename(const QGeoTileSpec &spec, const QString &format, const QString &directory) const +{ + 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 += m_ppi; + + filename += QLatin1String("."); + filename += format; + + QDir dir = QDir(directory); + + return dir.filePath(filename); +} + +QGeoTileSpec QGeoFileTileCacheNokia::filenameToTileSpec(const QString &filename) const +{ + 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 != 6 && length != 7) + return emptySpec; + else if (fields.last() != m_ppi) + return QGeoTileSpec(); + + QList<int> numbers; + + bool ok = false; + for (int i = 1; i < length-1; ++i) { // skipping -<ppi> + 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)); +} + +QT_END_NAMESPACE diff --git a/src/plugins/geoservices/nokia/qgeofiletilecachenokia.h b/src/plugins/geoservices/nokia/qgeofiletilecachenokia.h new file mode 100644 index 00000000..aba232f5 --- /dev/null +++ b/src/plugins/geoservices/nokia/qgeofiletilecachenokia.h @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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 QGEOFILETILECACHENOKIA_H +#define QGEOFILETILECACHENOKIA_H + +#include <QtLocation/private/qgeofiletilecache_p.h> + +QT_BEGIN_NAMESPACE + +class QGeoFileTileCacheNokia : public QGeoFileTileCache +{ + Q_OBJECT +public: + QGeoFileTileCacheNokia(int ppi, const QString &directory = QString(), QObject *parent = 0); + ~QGeoFileTileCacheNokia(); + +protected: + virtual QString tileSpecToFilename(const QGeoTileSpec &spec, const QString &format, const QString &directory) const Q_DECL_OVERRIDE; + virtual QGeoTileSpec filenameToTileSpec(const QString &filename) const Q_DECL_OVERRIDE; + + QString m_ppi; +}; + +QT_END_NAMESPACE + +#endif // QGEOFILETILECACHENOKIA_H diff --git a/src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.cpp b/src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.cpp index 5acbfed5..e823c7e8 100644 --- a/src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.cpp +++ b/src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.cpp @@ -39,7 +39,7 @@ #include "qgeotiledmap_nokia.h" #include "qgeotilefetcher_nokia.h" #include "qgeotilespec_p.h" -#include "qgeofiletilecache_p.h" +#include "qgeofiletilecachenokia.h" #include <QDebug> #include <QDir> @@ -115,7 +115,7 @@ QGeoTiledMappingManagerEngineNokia::QGeoTiledMappingManagerEngineNokia( m_cacheDirectory = QAbstractGeoTileCache::baseCacheDirectory() + QLatin1String("here"); } - QGeoFileTileCache *tileCache = new QGeoFileTileCache(m_cacheDirectory); + QGeoFileTileCache *tileCache = new QGeoFileTileCacheNokia(ppi, m_cacheDirectory); setTileCache(tileCache); if (parameters.contains(QStringLiteral("here.mapping.cache.disk.size"))) { |