summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaolo Angelelli <paolo.angelelli@theqtcompany.com>2016-07-06 20:01:59 +0200
committerPaolo Angelelli <paolo.angelelli@theqtcompany.com>2016-07-19 12:16:31 +0000
commit10b708e419c672411507feceb4c7869a5024df1e (patch)
treef08b8290bc6d9e2487930a285b58a4ffc678358c /src
parent208c822225fe2a7a7e214dfb04acc48de5a7d001 (diff)
downloadqtlocation-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')
-rw-r--r--src/plugins/geoservices/mapbox/qgeofiletilecachemapbox.cpp19
-rw-r--r--src/plugins/geoservices/mapbox/qgeofiletilecachemapbox.h3
-rw-r--r--src/plugins/geoservices/mapbox/qgeotiledmappingmanagerenginemapbox.cpp9
-rw-r--r--src/plugins/geoservices/mapbox/qgeotilefetchermapbox.cpp9
-rw-r--r--src/plugins/geoservices/mapbox/qgeotilefetchermapbox.h4
-rw-r--r--src/plugins/geoservices/nokia/nokia.pro6
-rw-r--r--src/plugins/geoservices/nokia/qgeofiletilecachenokia.cpp124
-rw-r--r--src/plugins/geoservices/nokia/qgeofiletilecachenokia.h60
-rw-r--r--src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.cpp4
9 files changed, 220 insertions, 18 deletions
diff --git a/src/plugins/geoservices/mapbox/qgeofiletilecachemapbox.cpp b/src/plugins/geoservices/mapbox/qgeofiletilecachemapbox.cpp
index 4057568d..6ce41a2b 100644
--- a/src/plugins/geoservices/mapbox/qgeofiletilecachemapbox.cpp
+++ b/src/plugins/geoservices/mapbox/qgeofiletilecachemapbox.cpp
@@ -40,9 +40,10 @@
QT_BEGIN_NAMESPACE
-QGeoFileTileCacheMapbox::QGeoFileTileCacheMapbox(const QList<QGeoMapType> &mapTypes, const QString &directory, QObject *parent)
+QGeoFileTileCacheMapbox::QGeoFileTileCacheMapbox(const QList<QGeoMapType> &mapTypes, int scaleFactor, const QString &directory, QObject *parent)
:QGeoFileTileCache(directory, parent), m_mapTypes(mapTypes)
{
+ m_scaleFactor = qBound(1, scaleFactor, 2);
for (int i=0; i < mapTypes.size(); i++)
m_mapNameToId.insert(mapTypes[i].name(), i);
}
@@ -70,6 +71,10 @@ QString QGeoFileTileCacheMapbox::tileSpecToFilename(const QGeoTileSpec &spec, co
filename += QString::number(spec.version());
}
+ filename += QLatin1String("-@");
+ filename += QString::number(m_scaleFactor);
+ filename += QLatin1Char('x');
+
filename += QLatin1String(".");
filename += format;
@@ -89,13 +94,21 @@ QGeoTileSpec QGeoFileTileCacheMapbox::filenameToTileSpec(const QString &filename
QStringList fields = name.split('-');
int length = fields.length();
- if (length != 5 && length != 6)
+ if (length != 6 && length != 7) {
return QGeoTileSpec();
+ } else {
+ int scaleIdx = fields.last().indexOf("@");
+ if (scaleIdx < 0 || fields.last().size() <= (scaleIdx + 2))
+ return QGeoTileSpec();
+ int scaleFactor = fields.last()[scaleIdx + 1].digitValue();
+ if (scaleFactor != m_scaleFactor)
+ return QGeoTileSpec();
+ }
QList<int> numbers;
bool ok = false;
- for (int i = 2; i < length; ++i) {
+ for (int i = 2; i < length-1; ++i) { // skipping -@_X
ok = false;
int value = fields.at(i).toInt(&ok);
if (!ok)
diff --git a/src/plugins/geoservices/mapbox/qgeofiletilecachemapbox.h b/src/plugins/geoservices/mapbox/qgeofiletilecachemapbox.h
index e96e5ab0..faf9b2bf 100644
--- a/src/plugins/geoservices/mapbox/qgeofiletilecachemapbox.h
+++ b/src/plugins/geoservices/mapbox/qgeofiletilecachemapbox.h
@@ -46,7 +46,7 @@ class QGeoFileTileCacheMapbox : public QGeoFileTileCache
{
Q_OBJECT
public:
- QGeoFileTileCacheMapbox(const QList<QGeoMapType> &mapTypes, const QString &directory = QString(), QObject *parent = 0);
+ QGeoFileTileCacheMapbox(const QList<QGeoMapType> &mapTypes, int scaleFactor, const QString &directory = QString(), QObject *parent = 0);
~QGeoFileTileCacheMapbox();
protected:
@@ -55,6 +55,7 @@ protected:
QList<QGeoMapType> m_mapTypes;
QMap<QString, int> m_mapNameToId;
+ int m_scaleFactor;
};
QT_END_NAMESPACE
diff --git a/src/plugins/geoservices/mapbox/qgeotiledmappingmanagerenginemapbox.cpp b/src/plugins/geoservices/mapbox/qgeotiledmappingmanagerenginemapbox.cpp
index de7eb4cf..30e5179e 100644
--- a/src/plugins/geoservices/mapbox/qgeotiledmappingmanagerenginemapbox.cpp
+++ b/src/plugins/geoservices/mapbox/qgeotiledmappingmanagerenginemapbox.cpp
@@ -116,13 +116,14 @@ QGeoTiledMappingManagerEngineMapbox::QGeoTiledMappingManagerEngineMapbox(const Q
setSupportedMapTypes(mapTypes);
- bool doubleRes = true;
+ int scaleFactor = 2;
if (parameters.contains(QStringLiteral("mapbox.highdpi_tiles"))) {
const QString param = parameters.value(QStringLiteral("mapbox.highdpi_tiles")).toString().toLower();
if (param == "false")
- doubleRes = false;
+ scaleFactor = 1;
}
- QGeoTileFetcherMapbox *tileFetcher = new QGeoTileFetcherMapbox(this, doubleRes);
+
+ QGeoTileFetcherMapbox *tileFetcher = new QGeoTileFetcherMapbox(scaleFactor, this);
tileFetcher->setMapIds(mapIds);
if (parameters.contains(QStringLiteral("useragent"))) {
@@ -159,7 +160,7 @@ QGeoTiledMappingManagerEngineMapbox::QGeoTiledMappingManagerEngineMapbox(const Q
// It is illegal to violate Mapbox Terms of Service, setting a limit that exceeds
// what the plan the token belongs to allows.
- QAbstractGeoTileCache *tileCache = new QGeoFileTileCacheMapbox(mapTypes, m_cacheDirectory);
+ QGeoFileTileCache *tileCache = new QGeoFileTileCacheMapbox(mapTypes, scaleFactor, m_cacheDirectory);
if (parameters.contains(QStringLiteral("mapbox.cache.disk.size"))) {
bool ok = false;
diff --git a/src/plugins/geoservices/mapbox/qgeotilefetchermapbox.cpp b/src/plugins/geoservices/mapbox/qgeotilefetchermapbox.cpp
index 6b7fc06b..062b4f89 100644
--- a/src/plugins/geoservices/mapbox/qgeotilefetchermapbox.cpp
+++ b/src/plugins/geoservices/mapbox/qgeotilefetchermapbox.cpp
@@ -44,14 +44,14 @@
QT_BEGIN_NAMESPACE
-QGeoTileFetcherMapbox::QGeoTileFetcherMapbox(QObject *parent, bool highDpiTiles)
+QGeoTileFetcherMapbox::QGeoTileFetcherMapbox(int scaleFactor, QObject *parent)
: QGeoTileFetcher(parent), m_networkManager(new QNetworkAccessManager(this)),
m_userAgent("Qt Location based application"),
m_format("png"),
m_replyFormat("png"),
- m_accessToken(""),
- m_highDpiTiles(highDpiTiles)
+ m_accessToken("")
{
+ m_scaleFactor = qBound(1, scaleFactor, 2);
}
void QGeoTileFetcherMapbox::setUserAgent(const QByteArray &userAgent)
@@ -90,7 +90,8 @@ QGeoTiledMapReply *QGeoTileFetcherMapbox::getTileImage(const QGeoTileSpec &spec)
((spec.mapId() >= m_mapIds.size()) ? QStringLiteral("mapbox.streets") : m_mapIds[spec.mapId()]) + QLatin1Char('/') +
QString::number(spec.zoom()) + QLatin1Char('/') +
QString::number(spec.x()) + QLatin1Char('/') +
- QString::number(spec.y()) + ((m_highDpiTiles) ? QStringLiteral("@2x.") : QStringLiteral(".")) +
+ QString::number(spec.y()) +
+ ((m_scaleFactor > 1) ? (QLatin1Char('@') + QString::number(m_scaleFactor) + QLatin1String("x.")) : QLatin1String(".")) +
m_format + QLatin1Char('?') +
QStringLiteral("access_token=") + m_accessToken));
diff --git a/src/plugins/geoservices/mapbox/qgeotilefetchermapbox.h b/src/plugins/geoservices/mapbox/qgeotilefetchermapbox.h
index 1263b237..e52651e1 100644
--- a/src/plugins/geoservices/mapbox/qgeotilefetchermapbox.h
+++ b/src/plugins/geoservices/mapbox/qgeotilefetchermapbox.h
@@ -50,7 +50,7 @@ class QGeoTileFetcherMapbox : public QGeoTileFetcher
Q_OBJECT
public:
- QGeoTileFetcherMapbox(QObject *parent = 0, bool highDpiTiles = true);
+ QGeoTileFetcherMapbox(int scaleFactor = 2, QObject *parent = 0);
void setUserAgent(const QByteArray &userAgent);
void setMapIds(const QVector<QString> &mapIds);
@@ -66,7 +66,7 @@ private:
QString m_replyFormat;
QString m_accessToken;
QVector<QString> m_mapIds;
- bool m_highDpiTiles;
+ int m_scaleFactor;
};
QT_END_NAMESPACE
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"))) {