summaryrefslogtreecommitdiff
path: root/src/location
diff options
context:
space:
mode:
authorAnders Gunnarsson <anders.gunnarsson@appello.com>2014-02-12 09:01:03 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-03-03 16:08:00 +0100
commit61d235c2f5af88a0a22105722142f2c72817ee00 (patch)
treed310f0c75bc939589bdc9f20e28b824f63ac58f2 /src/location
parent985a8b9c608503d90b7fe73f5a995ad2091f0070 (diff)
downloadqtlocation-61d235c2f5af88a0a22105722142f2c72817ee00.tar.gz
Tile cache versioning for Nokia maps
Added to avoid mixing of different map versions in map view. Generic cache versioning by adding an incremental version number to tile specs and filenames. Default version -1 falls back to not using version in file names for backward compatibility. Nokia specific version management by implementing the version request, comparing all version information and increment the version if anything has changed. Task-number: QTBUG-25559 Change-Id: I6820f2efbe7458701475cc833d3077022797b2df Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
Diffstat (limited to 'src/location')
-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
11 files changed, 104 insertions, 16 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