summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/location/maps/qgeocameratiles.cpp19
-rw-r--r--src/location/maps/qgeocameratiles_p.h1
-rw-r--r--src/location/maps/qgeotilecache.cpp24
-rw-r--r--src/location/maps/qgeotilecache_p.h1
-rw-r--r--src/location/maps/qgeotiledmapdata.cpp22
-rw-r--r--src/location/maps/qgeotiledmapdata_p.h4
-rw-r--r--src/location/maps/qgeotiledmapdata_p_p.h1
-rw-r--r--src/location/maps/qgeotiledmappingmanagerengine_p.h1
-rw-r--r--src/location/maps/qgeotilespec.cpp39
-rw-r--r--src/location/maps/qgeotilespec_p.h5
-rw-r--r--src/location/maps/qgeotilespec_p_p.h3
-rw-r--r--src/plugins/geoservices/nokia/nokia.pro6
-rw-r--r--src/plugins/geoservices/nokia/qgeomapversion.cpp91
-rw-r--r--src/plugins/geoservices/nokia/qgeomapversion.h75
-rw-r--r--src/plugins/geoservices/nokia/qgeotiledmapdata_nokia.cpp6
-rw-r--r--src/plugins/geoservices/nokia/qgeotiledmapdata_nokia.h2
-rw-r--r--src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.cpp76
-rw-r--r--src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.h7
-rw-r--r--src/plugins/geoservices/nokia/qgeotilefetcher_nokia.cpp56
-rw-r--r--src/plugins/geoservices/nokia/qgeotilefetcher_nokia.h3
20 files changed, 419 insertions, 23 deletions
diff --git a/src/location/maps/qgeocameratiles.cpp b/src/location/maps/qgeocameratiles.cpp
index 32bbae36..0d5a5626 100644
--- a/src/location/maps/qgeocameratiles.cpp
+++ b/src/location/maps/qgeocameratiles.cpp
@@ -85,6 +85,7 @@ public:
QString pluginString_;
QGeoMapType mapType_;
+ int mapVersion_;
QGeoCameraData camera_;
QSize screenSize_;
int tileSize_;
@@ -245,6 +246,17 @@ void QGeoCameraTiles::setMapType(const QGeoMapType &mapType)
d->updateMetadata();
}
+void QGeoCameraTiles::setMapVersion(const int mapVersion)
+{
+ Q_D(QGeoCameraTiles);
+
+ if (d->mapVersion_ == mapVersion)
+ return;
+
+ d->mapVersion_ = mapVersion;
+ d->updateMetadata();
+}
+
void QGeoCameraTiles::setTileSize(int tileSize)
{
Q_D(QGeoCameraTiles);
@@ -285,7 +297,8 @@ QGeoCameraTilesPrivate::QGeoCameraTilesPrivate()
: tileSize_(0),
maxZoom_(0),
intZoomLevel_(0),
- sideLength_(0) {}
+ sideLength_(0),
+ mapVersion_(-1) {}
QGeoCameraTilesPrivate::~QGeoCameraTilesPrivate() {}
@@ -300,7 +313,7 @@ void QGeoCameraTilesPrivate::updateMetadata()
for (; i != end; ++i) {
QGeoTileSpec tile = *i;
- newTiles.insert(QGeoTileSpec(pluginString_, mapType_.mapId(), tile.zoom(), tile.x(), tile.y()));
+ newTiles.insert(QGeoTileSpec(pluginString_, mapType_.mapId(), tile.zoom(), tile.x(), tile.y(), mapVersion_));
}
tiles_ = newTiles;
@@ -988,7 +1001,7 @@ QSet<QGeoTileSpec> QGeoCameraTilesPrivate::tilesFromPolygon(const Polygon &polyg
int minX = i->first;
int maxX = i->second;
for (int x = minX; x <= maxX; ++x) {
- results.insert(QGeoTileSpec(pluginString_, mapType_.mapId(), z, x, y));
+ results.insert(QGeoTileSpec(pluginString_, mapType_.mapId(), z, x, y, mapVersion_));
}
}
diff --git a/src/location/maps/qgeocameratiles_p.h b/src/location/maps/qgeocameratiles_p.h
index 29cae47f..efaace75 100644
--- a/src/location/maps/qgeocameratiles_p.h
+++ b/src/location/maps/qgeocameratiles_p.h
@@ -80,6 +80,7 @@ public:
void setPluginString(const QString &pluginString);
void setMapType(const QGeoMapType &mapType);
+ void setMapVersion(int mapVersion);
QSet<QGeoTileSpec> tiles() const;
void findPrefetchTiles();
diff --git a/src/location/maps/qgeotilecache.cpp b/src/location/maps/qgeotilecache.cpp
index 54a850cd..3bcb2275 100644
--- a/src/location/maps/qgeotilecache.cpp
+++ b/src/location/maps/qgeotilecache.cpp
@@ -334,6 +334,11 @@ QSharedPointer<QGeoTileTexture> QGeoTileCache::get(const QGeoTileSpec &spec)
return QSharedPointer<QGeoTileTexture>();
}
+QString QGeoTileCache::directory() const
+{
+ return directory_;
+}
+
void QGeoTileCache::insert(const QGeoTileSpec &spec,
const QByteArray &bytes,
const QString &format,
@@ -434,6 +439,13 @@ QString QGeoTileCache::tileSpecToFilename(const QGeoTileSpec &spec, const QStrin
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;
@@ -454,13 +466,14 @@ QGeoTileSpec QGeoTileCache::filenameToTileSpec(const QString &filename)
QString name = parts.at(0);
QStringList fields = name.split('-');
- if (fields.length() != 5)
+ int length = fields.length();
+ if (length != 5 && length != 6)
return emptySpec;
QList<int> numbers;
bool ok = false;
- for (int i = 1; i < 5; ++i) {
+ for (int i = 1; i < length; ++i) {
ok = false;
int value = fields.at(i).toInt(&ok);
if (!ok)
@@ -468,11 +481,16 @@ QGeoTileSpec QGeoTileCache::filenameToTileSpec(const QString &filename)
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(3),
+ numbers.at(4));
}
QT_END_NAMESPACE
diff --git a/src/location/maps/qgeotilecache_p.h b/src/location/maps/qgeotilecache_p.h
index 6fecfa8f..eee09de3 100644
--- a/src/location/maps/qgeotilecache_p.h
+++ b/src/location/maps/qgeotilecache_p.h
@@ -135,6 +135,7 @@ public:
void GLContextAvailable();
QSharedPointer<QGeoTileTexture> get(const QGeoTileSpec &spec);
+ QString directory() const;
// can be called without a specific tileCache pointer
static void evictFromDiskCache(QGeoCachedTileDisk *td);
diff --git a/src/location/maps/qgeotiledmapdata.cpp b/src/location/maps/qgeotiledmapdata.cpp
index dd64917a..204414f8 100644
--- a/src/location/maps/qgeotiledmapdata.cpp
+++ b/src/location/maps/qgeotiledmapdata.cpp
@@ -77,6 +77,12 @@ QGeoTiledMapData::QGeoTiledMapData(QGeoTiledMappingManagerEngine *engine, QObjec
{
d_ptr = new QGeoTiledMapDataPrivate(this, engine);
engine->registerMap(this);
+
+ connect(engine,
+ SIGNAL(mapVersionChanged()),
+ this,
+ SLOT(updateMapVersion()));
+ QMetaObject::invokeMethod(this, "updateMapVersion", Qt::QueuedConnection);
}
QGeoTiledMapData::~QGeoTiledMapData()
@@ -134,6 +140,17 @@ void QGeoTiledMapData::changeActiveMapType(const QGeoMapType mapType)
d->changeActiveMapType(mapType);
}
+int QGeoTiledMapData::mapVersion()
+{
+ return -1;
+}
+
+void QGeoTiledMapData::updateMapVersion()
+{
+ Q_D(QGeoTiledMapData);
+ d->changeMapVersion(mapVersion());
+}
+
void QGeoTiledMapData::evaluateCopyrights(const QSet<QGeoTileSpec> &visibleTiles)
{
Q_UNUSED(visibleTiles);
@@ -267,6 +284,11 @@ void QGeoTiledMapDataPrivate::changeActiveMapType(const QGeoMapType mapType)
cameraTiles_->setMapType(mapType);
}
+void QGeoTiledMapDataPrivate::changeMapVersion(int mapVersion)
+{
+ cameraTiles_->setMapVersion(mapVersion);
+}
+
void QGeoTiledMapDataPrivate::resized(int width, int height)
{
if (cameraTiles_)
diff --git a/src/location/maps/qgeotiledmapdata_p.h b/src/location/maps/qgeotiledmapdata_p.h
index 126454e4..5a282a8c 100644
--- a/src/location/maps/qgeotiledmapdata_p.h
+++ b/src/location/maps/qgeotiledmapdata_p.h
@@ -93,6 +93,9 @@ public:
// Alternative to exposing this is to make tileFetched a slot, but then requestManager would
// need to be a QObject
QGeoTileRequestManager *getRequestManager();
+
+ virtual int mapVersion();
+
protected:
void mapResized(int width, int height);
void changeCameraData(const QGeoCameraData &oldCameraData);
@@ -101,6 +104,7 @@ protected:
protected Q_SLOTS:
virtual void evaluateCopyrights(const QSet<QGeoTileSpec> &visibleTiles);
+ void updateMapVersion();
private:
QGeoTiledMapDataPrivate *d_ptr;
diff --git a/src/location/maps/qgeotiledmapdata_p_p.h b/src/location/maps/qgeotiledmapdata_p_p.h
index 67ad5cc1..446b2872 100644
--- a/src/location/maps/qgeotiledmapdata_p_p.h
+++ b/src/location/maps/qgeotiledmapdata_p_p.h
@@ -97,6 +97,7 @@ public:
void changeCameraData(const QGeoCameraData &oldCameraData);
void changeActiveMapType(const QGeoMapType mapType);
+ void changeMapVersion(int mapVersion);
void resized(int width, int height);
QGeoCoordinate screenPositionToCoordinate(const QDoubleVector2D &pos) const;
diff --git a/src/location/maps/qgeotiledmappingmanagerengine_p.h b/src/location/maps/qgeotiledmappingmanagerengine_p.h
index 22e8b867..c9d549ff 100644
--- a/src/location/maps/qgeotiledmappingmanagerengine_p.h
+++ b/src/location/maps/qgeotiledmappingmanagerengine_p.h
@@ -107,6 +107,7 @@ private Q_SLOTS:
Q_SIGNALS:
void tileError(const QGeoTileSpec &spec, const QString &errorString);
+ void mapVersionChanged();
protected:
void setTileFetcher(QGeoTileFetcher *fetcher);
diff --git a/src/location/maps/qgeotilespec.cpp b/src/location/maps/qgeotilespec.cpp
index 63d22ea5..575f15b2 100644
--- a/src/location/maps/qgeotilespec.cpp
+++ b/src/location/maps/qgeotilespec.cpp
@@ -49,8 +49,8 @@ QT_BEGIN_NAMESPACE
QGeoTileSpec::QGeoTileSpec()
: d(QSharedDataPointer<QGeoTileSpecPrivate>(new QGeoTileSpecPrivate())) {}
-QGeoTileSpec::QGeoTileSpec(const QString &plugin, int mapId, int zoom, int x, int y)
- : d(QSharedDataPointer<QGeoTileSpecPrivate>(new QGeoTileSpecPrivate(plugin, mapId, zoom, x, y))) {}
+QGeoTileSpec::QGeoTileSpec(const QString &plugin, int mapId, int zoom, int x, int y, int version)
+ : d(QSharedDataPointer<QGeoTileSpecPrivate>(new QGeoTileSpecPrivate(plugin, mapId, zoom, x, y, version))) {}
QGeoTileSpec::QGeoTileSpec(const QGeoTileSpec &other)
: d(other.d) {}
@@ -112,6 +112,16 @@ int QGeoTileSpec::mapId() const
return d->mapId_;
}
+void QGeoTileSpec::setVersion(int version)
+{
+ d->version_ = version;
+}
+
+int QGeoTileSpec::version() const
+{
+ return d->version_;
+}
+
bool QGeoTileSpec::operator == (const QGeoTileSpec &rhs) const
{
return (*(d.constData()) == *(rhs.d.constData()));
@@ -129,12 +139,13 @@ unsigned int qHash(const QGeoTileSpec &spec)
result += ((spec.zoom() * 19) % 31) << 10;
result += ((spec.x() * 23) % 31) << 15;
result += ((spec.y() * 29) % 31) << 20;
+ result += (spec.version() % 3) << 25;
return result;
}
QDebug operator<< (QDebug dbg, const QGeoTileSpec &spec)
{
- dbg << spec.plugin() << spec.mapId() << spec.zoom() << spec.x() << spec.y();
+ dbg << spec.plugin() << spec.mapId() << spec.zoom() << spec.x() << spec.y() << spec.version();
return dbg;
}
@@ -142,7 +153,8 @@ QGeoTileSpecPrivate::QGeoTileSpecPrivate()
: mapId_(0),
zoom_(-1),
x_(-1),
- y_(-1) {}
+ y_(-1),
+ version_(-1) {}
QGeoTileSpecPrivate::QGeoTileSpecPrivate(const QGeoTileSpecPrivate &other)
: QSharedData(other),
@@ -150,14 +162,16 @@ QGeoTileSpecPrivate::QGeoTileSpecPrivate(const QGeoTileSpecPrivate &other)
mapId_(other.mapId_),
zoom_(other.zoom_),
x_(other.x_),
- y_(other.y_) {}
+ y_(other.y_),
+ version_(other.version_) {}
-QGeoTileSpecPrivate::QGeoTileSpecPrivate(const QString &plugin, int mapId, int zoom, int x, int y)
+QGeoTileSpecPrivate::QGeoTileSpecPrivate(const QString &plugin, int mapId, int zoom, int x, int y, int version)
: plugin_(plugin),
mapId_(mapId),
zoom_(zoom),
x_(x),
- y_(y) {}
+ y_(y),
+ version_(version) {}
QGeoTileSpecPrivate::~QGeoTileSpecPrivate() {}
@@ -171,6 +185,7 @@ QGeoTileSpecPrivate &QGeoTileSpecPrivate::operator = (const QGeoTileSpecPrivate
zoom_ = other.zoom_;
x_ = other.x_;
y_ = other.y_;
+ version_ = other.version_;
return *this;
}
@@ -192,6 +207,9 @@ bool QGeoTileSpecPrivate::operator == (const QGeoTileSpecPrivate &rhs) const
if (y_ != rhs.y_)
return false;
+ if (version_ != rhs.version_)
+ return false;
+
return true;
}
@@ -217,7 +235,12 @@ bool QGeoTileSpecPrivate::operator < (const QGeoTileSpecPrivate &rhs) const
if (x_ > rhs.x_)
return false;
- return (y_ < rhs.y_);
+ if (y_ < rhs.y_)
+ return true;
+ if (y_ > rhs.y_)
+ return false;
+
+ return (version_ < rhs.version_);
}
QT_END_NAMESPACE
diff --git a/src/location/maps/qgeotilespec_p.h b/src/location/maps/qgeotilespec_p.h
index ae2db7b6..e918b64b 100644
--- a/src/location/maps/qgeotilespec_p.h
+++ b/src/location/maps/qgeotilespec_p.h
@@ -68,7 +68,7 @@ class Q_LOCATION_EXPORT QGeoTileSpec
public:
QGeoTileSpec();
QGeoTileSpec(const QGeoTileSpec &other);
- QGeoTileSpec(const QString &plugin, int mapId, int zoom, int x, int y);
+ QGeoTileSpec(const QString &plugin, int mapId, int zoom, int x, int y, int version = -1);
~QGeoTileSpec();
QGeoTileSpec &operator = (const QGeoTileSpec &other);
@@ -87,6 +87,9 @@ public:
void setMapId(int mapId);
int mapId() const;
+ void setVersion(int version);
+ int version() const;
+
bool operator == (const QGeoTileSpec &rhs) const;
bool operator < (const QGeoTileSpec &rhs) const;
diff --git a/src/location/maps/qgeotilespec_p_p.h b/src/location/maps/qgeotilespec_p_p.h
index 80eaf8cb..ad50c13e 100644
--- a/src/location/maps/qgeotilespec_p_p.h
+++ b/src/location/maps/qgeotilespec_p_p.h
@@ -62,7 +62,7 @@ class QGeoTileSpecPrivate : public QSharedData
public:
QGeoTileSpecPrivate();
QGeoTileSpecPrivate(const QGeoTileSpecPrivate &other);
- QGeoTileSpecPrivate(const QString &plugin, int mapId, int zoom, int x, int y);
+ QGeoTileSpecPrivate(const QString &plugin, int mapId, int zoom, int x, int y, int version);
~QGeoTileSpecPrivate();
QGeoTileSpecPrivate &operator = (const QGeoTileSpecPrivate &other);
@@ -75,6 +75,7 @@ public:
int zoom_;
int x_;
int y_;
+ int version_;
};
QT_END_NAMESPACE
diff --git a/src/plugins/geoservices/nokia/nokia.pro b/src/plugins/geoservices/nokia/nokia.pro
index 597f8bae..647a0a4e 100644
--- a/src/plugins/geoservices/nokia/nokia.pro
+++ b/src/plugins/geoservices/nokia/nokia.pro
@@ -27,7 +27,8 @@ HEADERS += \
qgeointrinsicnetworkaccessmanager.h \
qgeouriprovider.h \
uri_constants.h \
- qgeoerror_messages.h
+ qgeoerror_messages.h \
+ qgeomapversion.h
SOURCES += \
@@ -45,7 +46,8 @@ SOURCES += \
qgeointrinsicnetworkaccessmanager.cpp \
qgeouriprovider.cpp \
uri_constants.cpp \
- qgeoerror_messages.cpp
+ qgeoerror_messages.cpp \
+ qgeomapversion.cpp
include(placesv2/placesv2.pri)
diff --git a/src/plugins/geoservices/nokia/qgeomapversion.cpp b/src/plugins/geoservices/nokia/qgeomapversion.cpp
new file mode 100644
index 00000000..c86b98a3
--- /dev/null
+++ b/src/plugins/geoservices/nokia/qgeomapversion.cpp
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Appello Systems AB.
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtLocation module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 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 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+** This file is part of the Nokia services plugin for the Maps and
+** Navigation API. The use of these services, whether by use of the
+** plugin or by other means, is governed by the terms and conditions
+** described by the file NOKIA_TERMS_AND_CONDITIONS.txt in
+** this package, located in the directory containing the Nokia services
+** plugin source code.
+**
+****************************************************************************/
+
+#include "qgeomapversion.h"
+
+#include <QJsonDocument>
+
+QT_BEGIN_NAMESPACE
+
+QGeoMapVersion::QGeoMapVersion()
+ : m_version(-1) {}
+
+bool QGeoMapVersion::isNewVersion(const QJsonObject &newVersionData)
+{
+ return m_versionData != newVersionData;
+}
+
+int QGeoMapVersion::version() const
+{
+ return m_version;
+}
+
+void QGeoMapVersion::setVersion(int version)
+{
+ m_version = version;
+}
+
+void QGeoMapVersion::setVersionData(const QJsonObject &versionData)
+{
+ m_versionData = versionData;
+}
+
+
+QByteArray QGeoMapVersion::toJson() const
+{
+
+ QJsonObject object;
+ object[QLatin1String("version")] = m_version;
+ object[QLatin1String("data")] = m_versionData;
+
+ QJsonDocument document(object);
+
+ return document.toJson();
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/geoservices/nokia/qgeomapversion.h b/src/plugins/geoservices/nokia/qgeomapversion.h
new file mode 100644
index 00000000..18a9f3a7
--- /dev/null
+++ b/src/plugins/geoservices/nokia/qgeomapversion.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Appello Systems AB.
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtLocation module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 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 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+** This file is part of the Nokia services plugin for the Maps and
+** Navigation API. The use of these services, whether by use of the
+** plugin or by other means, is governed by the terms and conditions
+** described by the file NOKIA_TERMS_AND_CONDITIONS.txt in
+** this package, located in the directory containing the Nokia services
+** plugin source code.
+**
+****************************************************************************/
+
+#ifndef QGEOMAPVERSION_H
+#define QGEOMAPVERSION_H
+
+#include <QByteArray>
+#include <QJsonObject>
+
+QT_BEGIN_NAMESPACE
+
+class QGeoMapVersion
+{
+
+public:
+ QGeoMapVersion();
+ bool isNewVersion(const QJsonObject &newVersionData);
+ int version() const;
+ void setVersion(const int);
+ void setVersionData(const QJsonObject &versionData);
+ QByteArray toJson() const;
+
+private:
+ int m_version;
+ QJsonObject m_versionData;
+};
+
+QT_END_NAMESPACE
+
+#endif // QGEOMAPVERSION_H
diff --git a/src/plugins/geoservices/nokia/qgeotiledmapdata_nokia.cpp b/src/plugins/geoservices/nokia/qgeotiledmapdata_nokia.cpp
index 506b3f70..563d8270 100644
--- a/src/plugins/geoservices/nokia/qgeotiledmapdata_nokia.cpp
+++ b/src/plugins/geoservices/nokia/qgeotiledmapdata_nokia.cpp
@@ -155,4 +155,10 @@ void QGeoTiledMapDataNokia::evaluateCopyrights(const QSet<QGeoTileSpec> &visible
}
}
+int QGeoTiledMapDataNokia::mapVersion()
+{
+ QGeoTiledMappingManagerEngineNokia *engineNokia = static_cast<QGeoTiledMappingManagerEngineNokia *>(engine());
+ return engineNokia->mapVersion();
+}
+
QT_END_NAMESPACE
diff --git a/src/plugins/geoservices/nokia/qgeotiledmapdata_nokia.h b/src/plugins/geoservices/nokia/qgeotiledmapdata_nokia.h
index 24e6b9c7..af87540d 100644
--- a/src/plugins/geoservices/nokia/qgeotiledmapdata_nokia.h
+++ b/src/plugins/geoservices/nokia/qgeotiledmapdata_nokia.h
@@ -66,6 +66,8 @@ public:
QString getViewCopyright();
void evaluateCopyrights(const QSet<QGeoTileSpec> &visibleTiles);
+ int mapVersion();
+
private:
Q_DISABLE_COPY(QGeoTiledMapDataNokia)
diff --git a/src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.cpp b/src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.cpp
index 0968b0b3..8c3cbe3b 100644
--- a/src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.cpp
+++ b/src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.cpp
@@ -138,7 +138,9 @@ QGeoTiledMappingManagerEngineNokia::QGeoTiledMappingManagerEngineNokia(
}
populateMapSchemes();
+ loadMapVersion();
QMetaObject::invokeMethod(fetcher, "fetchCopyrightsData", Qt::QueuedConnection);
+ QMetaObject::invokeMethod(fetcher, "fetchVersionData", Qt::QueuedConnection);
}
QGeoTiledMappingManagerEngineNokia::~QGeoTiledMappingManagerEngineNokia()
@@ -181,6 +183,11 @@ QString QGeoTiledMappingManagerEngineNokia::getBaseScheme(int mapId)
return fullScheme.section(QLatin1Char('.'), 0, 0);
}
+int QGeoTiledMappingManagerEngineNokia::mapVersion()
+{
+ return m_mapVersion.version();
+}
+
void QGeoTiledMappingManagerEngineNokia::loadCopyrightsDescriptorsFromJson(const QByteArray &jsonData)
{
QJsonDocument doc = QJsonDocument::fromJson(QByteArray(jsonData));
@@ -225,6 +232,75 @@ void QGeoTiledMappingManagerEngineNokia::loadCopyrightsDescriptorsFromJson(const
}
}
+void QGeoTiledMappingManagerEngineNokia::parseNewVersionInfo(const QByteArray &versionData)
+{
+ const QString versionString = QString::fromUtf8(versionData);
+
+ const QStringList versionLines = versionString.split(QLatin1Char('\n'));
+ QJsonObject newVersionData;
+ foreach (const QString &line, versionLines) {
+ const QStringList versionInfo = line.split(':');
+ if (versionInfo.size() > 1) {
+ const QString versionKey = versionInfo[0].trimmed();
+ const QString versionValue = versionInfo[1].trimmed();
+ if (!versionKey.isEmpty() && !versionValue.isEmpty()) {
+ newVersionData[versionKey] = versionValue;
+ }
+ }
+ }
+
+ updateVersion(newVersionData);
+}
+
+void QGeoTiledMappingManagerEngineNokia::updateVersion(const QJsonObject &newVersionData) {
+
+ if (m_mapVersion.isNewVersion(newVersionData)) {
+
+ m_mapVersion.setVersionData(newVersionData);
+ m_mapVersion.setVersion(m_mapVersion.version() + 1);
+
+ saveMapVersion();
+
+ emit mapVersionChanged();
+ }
+}
+
+void QGeoTiledMappingManagerEngineNokia::saveMapVersion()
+{
+ QDir saveDir(tileCache()->directory());
+ QFile saveFile(saveDir.filePath(QLatin1String("nokia_version")));
+
+ if (!saveFile.open(QIODevice::WriteOnly)) {
+ qWarning("Failed to write nokia map version.");
+ return;
+ }
+
+ saveFile.write(m_mapVersion.toJson());
+ saveFile.close();
+}
+
+void QGeoTiledMappingManagerEngineNokia::loadMapVersion()
+{
+
+ QDir saveDir(tileCache()->directory());
+ QFile loadFile(saveDir.filePath(QLatin1String("nokia_version")));
+
+ if (!loadFile.open(QIODevice::ReadOnly)) {
+ qWarning("Failed to read nokia map version.");
+ return;
+ }
+
+ QByteArray saveData = loadFile.readAll();
+ loadFile.close();
+
+ QJsonDocument doc(QJsonDocument::fromJson(saveData));
+
+ QJsonObject object = doc.object();
+
+ m_mapVersion.setVersion(object[QLatin1String("version")].toInt());
+ m_mapVersion.setVersionData(object[QLatin1String("data")].toObject());
+}
+
QString QGeoTiledMappingManagerEngineNokia::evaluateCopyrightsText(const QGeoMapType mapType,
const qreal zoomLevel,
const QSet<QGeoTileSpec> &tiles)
diff --git a/src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.h b/src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.h
index a30dcf69..0f2f5cb1 100644
--- a/src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.h
+++ b/src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.h
@@ -52,6 +52,7 @@
#include "qgeotiledmappingmanagerengine_p.h"
#include <QtPositioning/QGeoRectangle>
#include "qgeomaptype_p.h"
+#include "qgeomapversion.h"
#include <QGeoServiceProvider>
@@ -82,9 +83,11 @@ public:
const QSet<QGeoTileSpec> &tiles);
QString getScheme(int mapId);
QString getBaseScheme(int mapId);
+ int mapVersion();
public Q_SLOTS:
void loadCopyrightsDescriptorsFromJson(const QByteArray &jsonData);
+ void parseNewVersionInfo(const QByteArray &versionData);
private:
class CopyrightDesc
@@ -103,9 +106,13 @@ private:
void initialize();
void populateMapSchemes();
+ void updateVersion(const QJsonObject &newVersionData);
+ void saveMapVersion();
+ void loadMapVersion();
QHash<QString, QList<CopyrightDesc> > m_copyrights;
QHash<int, QString> m_mapSchemes;
+ QGeoMapVersion m_mapVersion;
};
QT_END_NAMESPACE
diff --git a/src/plugins/geoservices/nokia/qgeotilefetcher_nokia.cpp b/src/plugins/geoservices/nokia/qgeotilefetcher_nokia.cpp
index c7f16eeb..a6ce9c0a 100644
--- a/src/plugins/geoservices/nokia/qgeotilefetcher_nokia.cpp
+++ b/src/plugins/geoservices/nokia/qgeotilefetcher_nokia.cpp
@@ -246,28 +246,42 @@ QString QGeoTileFetcherNokia::applicationId() const
void QGeoTileFetcherNokia::copyrightsFetched()
{
- if (m_engineNokia) {
+ if (m_engineNokia && m_copyrightsReply->error() == QNetworkReply::NoError) {
QMetaObject::invokeMethod(m_engineNokia.data(),
"loadCopyrightsDescriptorsFromJson",
Qt::QueuedConnection,
Q_ARG(QByteArray, m_copyrightsReply->readAll()));
}
+
+ m_copyrightsReply->deleteLater();
+}
+
+void QGeoTileFetcherNokia::versionFetched()
+{
+ if (m_engineNokia && m_versionReply->error() == QNetworkReply::NoError) {
+ QMetaObject::invokeMethod(m_engineNokia.data(),
+ "parseNewVersionInfo",
+ Qt::QueuedConnection,
+ Q_ARG(QByteArray, m_versionReply->readAll()));
+ }
+
+ m_versionReply->deleteLater();
}
void QGeoTileFetcherNokia::fetchCopyrightsData()
{
- QString copyrightUrl = "http://";
+ QString copyrightUrl = QStringLiteral("http://");
copyrightUrl += m_baseUriProvider->getCurrentHost();
- copyrightUrl += "/maptile/2.1/copyright/newest?output=json";
+ copyrightUrl += QStringLiteral("/maptile/2.1/copyright/newest?output=json");
if (!token().isEmpty()) {
- copyrightUrl += "&token=";
+ copyrightUrl += QStringLiteral("&token=");
copyrightUrl += token();
}
if (!applicationId().isEmpty()) {
- copyrightUrl += "&app_id=";
+ copyrightUrl += QStringLiteral("&app_id=");
copyrightUrl += applicationId();
}
@@ -286,4 +300,36 @@ void QGeoTileFetcherNokia::fetchCopyrightsData()
}
}
+void QGeoTileFetcherNokia::fetchVersionData()
+{
+ QString versionUrl = QStringLiteral("http://");
+
+ versionUrl += m_baseUriProvider->getCurrentHost();
+ versionUrl += QStringLiteral("/maptile/2.1/version");
+
+ if (!token().isEmpty()) {
+ versionUrl += QStringLiteral("?token=");
+ versionUrl += token();
+ }
+
+ if (!applicationId().isEmpty()) {
+ versionUrl += QStringLiteral("&app_id=");
+ versionUrl += applicationId();
+ }
+
+ QNetworkRequest netRequest((QUrl(versionUrl)));
+ m_versionReply = m_networkManager->get(netRequest);
+
+ if (m_versionReply->error() != QNetworkReply::NoError) {
+ qWarning() << __FUNCTION__ << m_versionReply->errorString();
+ m_versionReply->deleteLater();
+ return;
+ }
+
+ if (m_versionReply->isFinished())
+ versionFetched();
+ else
+ connect(m_versionReply, SIGNAL(finished()), this, SLOT(versionFetched()));
+}
+
QT_END_NAMESPACE
diff --git a/src/plugins/geoservices/nokia/qgeotilefetcher_nokia.h b/src/plugins/geoservices/nokia/qgeotilefetcher_nokia.h
index a5e1801a..8d5fea45 100644
--- a/src/plugins/geoservices/nokia/qgeotilefetcher_nokia.h
+++ b/src/plugins/geoservices/nokia/qgeotilefetcher_nokia.h
@@ -80,6 +80,8 @@ public:
public Q_SLOTS:
void copyrightsFetched();
void fetchCopyrightsData();
+ void versionFetched();
+ void fetchVersionData();
private:
Q_DISABLE_COPY(QGeoTileFetcherNokia)
@@ -93,6 +95,7 @@ private:
QSize m_tileSize;
QString m_token;
QNetworkReply *m_copyrightsReply;
+ QNetworkReply *m_versionReply;
QString m_applicationId;
QGeoUriProvider *m_baseUriProvider;