summaryrefslogtreecommitdiff
path: root/src/location
diff options
context:
space:
mode:
authorDavid Laing <david.laing@nokia.com>2011-12-19 15:54:34 +1000
committerQt by Nokia <qt-info@nokia.com>2011-12-19 15:38:19 +0100
commitc0bab81c8a47d4a4f20d31f7d861c86c59235503 (patch)
tree1fc0db40c2b41e4afc072caf80d53111a78e7d0e /src/location
parent8144d76e7ea855b3fbba5938f6815175c87b9acc (diff)
downloadqtlocation-c0bab81c8a47d4a4f20d31f7d861c86c59235503.tar.gz
Refactors the caching and tile fetching code.
The code now supports - multiple Maps sharing a QGeoMappingManager instance - several Maps can share a cache - plugins providing a hint to the cache about where the tiles should be stored (combinations of disk / memory / texture cache) Change-Id: I2dad40401d2bf06bfa142d2c51b804e1c35bfa61 Reviewed-by: Juha Vuolle <juha.vuolle@nokia.com>
Diffstat (limited to 'src/location')
-rw-r--r--src/location/maps/qgeomappingmanager.cpp156
-rw-r--r--src/location/maps/qgeomappingmanager.h17
-rw-r--r--src/location/maps/qgeomappingmanager_p.h10
-rw-r--r--src/location/maps/qgeomappingmanagerengine.cpp59
-rw-r--r--src/location/maps/qgeomappingmanagerengine.h9
-rw-r--r--src/location/maps/qgeomappingmanagerengine_p.h3
-rw-r--r--src/location/mapsgl/map.cpp33
-rw-r--r--src/location/mapsgl/map.h6
-rw-r--r--src/location/mapsgl/map_p.h5
-rw-r--r--src/location/mapsgl/mapsphere.cpp39
-rw-r--r--src/location/mapsgl/mapsphere_p.h13
-rw-r--r--src/location/mapsgl/tilecache.cpp62
-rw-r--r--src/location/mapsgl/tilecache.h24
13 files changed, 282 insertions, 154 deletions
diff --git a/src/location/maps/qgeomappingmanager.cpp b/src/location/maps/qgeomappingmanager.cpp
index ea115f7e..822eb392 100644
--- a/src/location/maps/qgeomappingmanager.cpp
+++ b/src/location/maps/qgeomappingmanager.cpp
@@ -43,6 +43,11 @@
#include "qgeomappingmanager_p.h"
#include "qgeomappingmanagerengine.h"
#include "qgeotiledmapreply.h"
+
+
+#include "map.h"
+#include "map_p.h"
+#include "tilecache.h"
#include "tilespec.h"
#include <QTimer>
@@ -103,17 +108,12 @@ QGeoMappingManager::QGeoMappingManager(QGeoMappingManagerEngine *engine, QObject
connect(d_ptr->engine,
SIGNAL(tileFinished(TileSpec,QByteArray)),
this,
- SIGNAL(tileFinished(TileSpec,QByteArray)),
+ SLOT(engineTileFinished(TileSpec,QByteArray)),
Qt::QueuedConnection);
connect(d_ptr->engine,
SIGNAL(tileError(TileSpec,QString)),
this,
- SIGNAL(tileError(TileSpec,QString)),
- Qt::QueuedConnection);
- connect(d_ptr->engine,
- SIGNAL(queueFinished()),
- this,
- SIGNAL(queueFinished()),
+ SLOT(engineTileError(TileSpec,QString)),
Qt::QueuedConnection);
connect(d_ptr->engine,
@@ -180,36 +180,133 @@ int QGeoMappingManager::managerVersion() const
return d_ptr->engine->managerVersion();
}
-void QGeoMappingManager::requestTiles(const QList<TileSpec> &tiles)
+void QGeoMappingManager::registerMap(Map *map)
{
- QMetaObject::invokeMethod(d_ptr->engine, "requestTiles",
- Qt::QueuedConnection,
- Q_ARG(QList<TileSpec>, tiles));
+ TileCache *cache = map->tileCache();
+ QSet<Map*> maps = d_ptr->caches.value(cache);
+ maps.insert(map);
+ d_ptr->caches.insert(cache, maps);
}
-QList<MapType> QGeoMappingManager::supportedMapTypes() const
+void QGeoMappingManager::deregisterMap(Map *map)
{
- return d_ptr->engine->supportedMapTypes();
+// TileCache *cache = map->tileCache();
+// QSet<Map*> maps = d_ptr->caches.value(cache);
+// maps.remove(map);
+// if (maps.isEmpty()) {
+// d_ptr->caches.remove(cache);
+// } else {
+// d_ptr->caches.insert(cache, maps);
+// }
+
+ // clear any tileHash / mapHash entries
}
-//QGeoTiledMapReply* QGeoMappingManager::getTileImage(const TileSpec &spec)
-//{
-// qWarning() << d_ptr->engine->minimumZoomLevel() << d_ptr->engine->maximumZoomLevel();
-// QGeoTiledMapReply* reply = d_ptr->engine->getTileImage(spec);
+void QGeoMappingManager::updateTileRequests(Map *map,
+ const QSet<TileSpec> &tilesAdded,
+ const QSet<TileSpec> &tilesRemoved)
+{
+ typedef QSet<TileSpec>::const_iterator tile_iter;
-// connect(reply, SIGNAL(finished()), this, SLOT(tileFinished()));
+ // add and remove tiles from tileset for this map
-// return reply;
-//}
+ QSet<TileSpec> oldTiles = d_ptr->mapHash.value(map);
-//void QGeoMappingManager::tileFinished()
-//{
-// QGeoTiledMapReply *reply = qobject_cast<QGeoTiledMapReply*>(sender());
-// if (!reply)
-// return;
+ tile_iter rem = tilesRemoved.constBegin();
+ tile_iter remEnd = tilesRemoved.constEnd();
+ for (; rem != remEnd; ++rem) {
+ oldTiles.remove(*rem);
+ }
-// emit finished(reply);
-//}
+ tile_iter add = tilesAdded.constBegin();
+ tile_iter addEnd = tilesAdded.constEnd();
+ for (; add != addEnd; ++add) {
+ oldTiles.insert(*add);
+ }
+
+ d_ptr->mapHash.insert(map, oldTiles);
+
+ // add and remove map from mapset for the tiles
+
+ QSet<TileSpec> reqTiles;
+ QSet<TileSpec> cancelTiles;
+
+ rem = tilesRemoved.constBegin();
+ for (; rem != remEnd; ++rem) {
+ QSet<Map*> mapSet = d_ptr->tileHash.value(*rem);
+ mapSet.remove(map);
+ if (mapSet.isEmpty()) {
+ cancelTiles.insert(*rem);
+ d_ptr->tileHash.remove(*rem);
+ } else {
+ d_ptr->tileHash.insert(*rem, mapSet);
+ }
+ }
+
+ add = tilesAdded.constBegin();
+ for (; add != addEnd; ++add) {
+ QSet<Map*> mapSet = d_ptr->tileHash.value(*add);
+ if (mapSet.isEmpty()) {
+ reqTiles.insert(*add);
+ }
+ mapSet.insert(map);
+ d_ptr->tileHash.insert(*add, mapSet);
+ }
+
+ cancelTiles -= reqTiles;
+
+ QMetaObject::invokeMethod(d_ptr->engine, "updateTileRequests",
+ Qt::QueuedConnection,
+ Q_ARG(QSet<TileSpec>, reqTiles),
+ Q_ARG(QSet<TileSpec>, cancelTiles));
+}
+
+void QGeoMappingManager::engineTileFinished(const TileSpec &spec, const QByteArray &bytes)
+{
+ QSet<TileCache*> caches;
+
+ QSet<Map*> maps = d_ptr->tileHash.value(spec);
+
+ typedef QSet<Map*>::const_iterator map_iter;
+
+ map_iter map = maps.constBegin();
+ map_iter mapEnd = maps.constEnd();
+ for (; map != mapEnd; ++map) {
+ caches.insert((*map)->tileCache());
+
+ QSet<TileSpec> tileSet = d_ptr->mapHash.value(*map);
+ tileSet.remove(spec);
+ if (tileSet.isEmpty())
+ d_ptr->mapHash.remove(*map);
+ else
+ d_ptr->mapHash.insert(*map, tileSet);
+ }
+
+ d_ptr->tileHash.remove(spec);
+
+ typedef QSet<TileCache*>::const_iterator cache_iter;
+
+ cache_iter cache = caches.constBegin();
+ cache_iter cacheEnd = caches.constEnd();
+ for (; cache != cacheEnd; ++cache) {
+ (*cache)->insert(spec, bytes, d_ptr->engine->cacheHint());
+ }
+
+ map = maps.constBegin();
+ for (; map != mapEnd; ++map) {
+ (*map)->d_ptr->tileFetched(spec);
+ }
+}
+
+void QGeoMappingManager::engineTileError(const TileSpec &spec, const QString &errorString)
+{
+ emit tileError(spec, errorString);
+}
+
+QList<MapType> QGeoMappingManager::supportedMapTypes() const
+{
+ return d_ptr->engine->supportedMapTypes();
+}
///*!
// Returns a list of the connectivity modes supported by this manager.
@@ -312,6 +409,11 @@ QLocale QGeoMappingManager::locale() const
return d_ptr->engine->locale();
}
+TileCache::CacheAreas QGeoMappingManager::cacheHint() const
+{
+ return d_ptr->engine->cacheHint();
+}
+
/*******************************************************************************
*******************************************************************************/
diff --git a/src/location/maps/qgeomappingmanager.h b/src/location/maps/qgeomappingmanager.h
index 35655e81..3c810ddf 100644
--- a/src/location/maps/qgeomappingmanager.h
+++ b/src/location/maps/qgeomappingmanager.h
@@ -47,6 +47,7 @@
#include <QPair>
#include <QtLocation/qlocationglobal.h>
#include "maptype.h"
+#include "tilecache.h"
QT_BEGIN_HEADER
@@ -59,7 +60,9 @@ class QGeoMappingManagerPrivate;
class QGeoMapRequestOptions;
class QGeoMappingManagerEngine;
class QGeoTiledMapReply;
+
class TileSpec;
+class Map;
class Q_LOCATION_EXPORT QGeoMappingManager : public QObject
{
@@ -71,7 +74,12 @@ public:
QString managerName() const;
int managerVersion() const;
- void requestTiles(const QList<TileSpec> &tiles);
+ void registerMap(Map *map);
+ void deregisterMap(Map *map);
+
+ void updateTileRequests(Map *map,
+ const QSet<TileSpec> &tilesAdded,
+ const QSet<TileSpec> &tilesRemoved);
QList<MapType> supportedMapTypes() const;
// QList<QGraphicsGeoMap::ConnectivityMode> supportedConnectivityModes() const;
@@ -86,13 +94,18 @@ public:
qreal minimumTilt() const;
qreal maximumTilt() const;
+ TileCache::CacheAreas cacheHint() const;
+
void setLocale(const QLocale &locale);
QLocale locale() const;
+private Q_SLOTS:
+ void engineTileFinished(const TileSpec &spec, const QByteArray &bytes);
+ void engineTileError(const TileSpec &spec, const QString &errorString);
+
Q_SIGNALS:
void tileFinished(const TileSpec &spec, const QByteArray &bytes);
void tileError(const TileSpec &spec, const QString &errorString);
- void queueFinished();
void initialized();
private:
diff --git a/src/location/maps/qgeomappingmanager_p.h b/src/location/maps/qgeomappingmanager_p.h
index 1e559b15..124b51d2 100644
--- a/src/location/maps/qgeomappingmanager_p.h
+++ b/src/location/maps/qgeomappingmanager_p.h
@@ -55,8 +55,14 @@
#include <QSize>
#include <QList>
+#include <QHash>
+#include <QSet>
#include <QThread>
+class Map;
+class TileCache;
+class TileSpec;
+
QT_BEGIN_NAMESPACE
class QGeoMappingManagerEngine;
@@ -70,6 +76,10 @@ public:
QThread *thread;
QGeoMappingManagerEngine *engine;
+ QHash<TileCache*, QSet<Map*> > caches;
+ QHash<Map*, QSet<TileSpec> > mapHash;
+ QHash<TileSpec, QSet<Map*> > tileHash;
+
private:
Q_DISABLE_COPY(QGeoMappingManagerPrivate)
};
diff --git a/src/location/maps/qgeomappingmanagerengine.cpp b/src/location/maps/qgeomappingmanagerengine.cpp
index 5d64e0fa..63752f34 100644
--- a/src/location/maps/qgeomappingmanagerengine.cpp
+++ b/src/location/maps/qgeomappingmanagerengine.cpp
@@ -155,32 +155,41 @@ void QGeoMappingManagerEngine::threadFinished()
this->deleteLater();
}
-void QGeoMappingManagerEngine::requestTiles(const QList<TileSpec> &tiles)
+void QGeoMappingManagerEngine::updateTileRequests(const QSet<TileSpec> &tilesAdded,
+ const QSet<TileSpec> &tilesRemoved)
{
Q_D(QGeoMappingManagerEngine);
if (d->stopped_)
return;
- if (!d->started_) {
- d->queue_ = tiles;
- return;
- }
+ cancelTileRequests(tilesRemoved);
+
+ d->queue_ = tilesAdded.toList();
+
+ if (!d->queue_.empty())
+ d->timer_->start();
+}
- for (int i = 0; i < d->queue_.size(); ++i) {
- QGeoTiledMapReply* reply = d->invmap_.value(d->queue_.at(i), 0);
+void QGeoMappingManagerEngine::cancelTileRequests(const QSet<TileSpec> &tiles)
+{
+ Q_D(QGeoMappingManagerEngine);
+
+ typedef QSet<TileSpec>::const_iterator tile_iter;
+ tile_iter tile = tiles.constBegin();
+ tile_iter end = tiles.constEnd();
+ for (; tile != end; ++tile) {
+ QGeoTiledMapReply* reply = d->invmap_.value(*tile, 0);
if (reply) {
+ d->invmap_.remove(*tile);
reply->abort();
- d->map_.remove(reply);
- d->invmap_.remove(d->queue_.at(i));
reply->deleteLater();
}
+ d->queue_.removeAll(*tile);
}
- d->queue_ = tiles;
-
- if (!d->queue_.empty())
- d->timer_->start();
+ if (d->queue_.isEmpty())
+ d->timer_->stop();
}
void QGeoMappingManagerEngine::requestNextTile()
@@ -202,7 +211,6 @@ void QGeoMappingManagerEngine::requestNextTile()
this,
SLOT(finished()));
- d->map_.insert(reply, ts);
d->invmap_.insert(ts, reply);
}
@@ -218,14 +226,13 @@ void QGeoMappingManagerEngine::finished()
if (!reply)
return;
- if (!d->map_.contains(reply)) {
+ TileSpec spec = reply->tileSpec();
+
+ if (!d->invmap_.contains(spec)) {
reply->deleteLater();
return;
}
- TileSpec spec = d->map_.value(reply);
-
- d->map_.remove(reply);
d->invmap_.remove(spec);
handleReply(reply, spec);
@@ -247,9 +254,6 @@ void QGeoMappingManagerEngine::handleReply(QGeoTiledMapReply *reply, const TileS
emit tileError(spec, reply->errorString());
}
- if (d->queue_.isEmpty())
- emit queueFinished();
-
reply->deleteLater();
}
@@ -555,6 +559,18 @@ QLocale QGeoMappingManagerEngine::locale() const
return d_ptr->locale;
}
+TileCache::CacheAreas QGeoMappingManagerEngine::cacheHint() const
+{
+ Q_D(const QGeoMappingManagerEngine);
+ return d->cacheHint;
+}
+
+void QGeoMappingManagerEngine::setCacheHint(TileCache::CacheAreas cacheHint)
+{
+ Q_D(QGeoMappingManagerEngine);
+ d->cacheHint = cacheHint;
+}
+
/*******************************************************************************
*******************************************************************************/
@@ -566,6 +582,7 @@ QGeoMappingManagerEnginePrivate::QGeoMappingManagerEnginePrivate()
supportsTilting(false),
minimumTilt(0.0),
maximumTilt(0.0),
+ cacheHint(TileCache::AllCaches),
started_(false),
stopped_(false) {}
diff --git a/src/location/maps/qgeomappingmanagerengine.h b/src/location/maps/qgeomappingmanagerengine.h
index dc97c883..633654d4 100644
--- a/src/location/maps/qgeomappingmanagerengine.h
+++ b/src/location/maps/qgeomappingmanagerengine.h
@@ -47,6 +47,7 @@
#include <QPair>
#include <QtLocation/qlocationglobal.h>
#include "maptype.h"
+#include "tilecache.h"
QT_BEGIN_HEADER
@@ -94,6 +95,8 @@ public:
qreal minimumTilt() const;
qreal maximumTilt() const;
+ TileCache::CacheAreas cacheHint() const;
+
void setLocale(const QLocale &locale);
QLocale locale() const;
@@ -103,7 +106,8 @@ public:
public Q_SLOTS:
void threadStarted();
void threadFinished();
- void requestTiles(const QList<TileSpec> &tiles);
+ void updateTileRequests(const QSet<TileSpec> &tilesAdded, const QSet<TileSpec> &tilesRemoved);
+ void cancelTileRequests(const QSet<TileSpec> &tiles);
private Q_SLOTS:
void requestNextTile();
@@ -112,7 +116,6 @@ private Q_SLOTS:
Q_SIGNALS:
void tileFinished(const TileSpec &spec, const QByteArray &bytes);
void tileError(const TileSpec &spec, const QString &errorString);
- void queueFinished();
void initialized();
protected:
@@ -132,6 +135,8 @@ protected:
void setSupportsBearing(bool supportsBearing);
void setSupportsTilting(bool supportsTilting);
+ void setCacheHint(TileCache::CacheAreas cacheHint);
+
QGeoMappingManagerEnginePrivate* d_ptr;
private:
diff --git a/src/location/maps/qgeomappingmanagerengine_p.h b/src/location/maps/qgeomappingmanagerengine_p.h
index 68057928..f4a66958 100644
--- a/src/location/maps/qgeomappingmanagerengine_p.h
+++ b/src/location/maps/qgeomappingmanagerengine_p.h
@@ -61,6 +61,7 @@
#include <QLocale>
#include <QTimer>
#include "maptype.h"
+#include "tilecache.h"
class TileSpec;
class QGeoTiledMapReply;
@@ -87,6 +88,7 @@ public:
bool supportsTilting;
qreal minimumTilt;
qreal maximumTilt;
+ TileCache::CacheAreas cacheHint;
QLocale locale;
bool started_;
@@ -94,7 +96,6 @@ public:
bool stopped_;
QTimer *timer_;
QList<TileSpec> queue_;
- QHash<QGeoTiledMapReply*, TileSpec> map_;
QHash<TileSpec, QGeoTiledMapReply*> invmap_;
private:
diff --git a/src/location/mapsgl/map.cpp b/src/location/mapsgl/map.cpp
index 8cffa51a..eabe8198 100644
--- a/src/location/mapsgl/map.cpp
+++ b/src/location/mapsgl/map.cpp
@@ -78,6 +78,11 @@ Map::~Map()
delete d_ptr;
}
+TileCache* Map::tileCache()
+{
+ return d_ptr->tileCache();
+}
+
MapController* Map::mapController()
{
return d_ptr->mapController();
@@ -123,11 +128,6 @@ bool Map::autoUpdate() const
return d_ptr->autoUpdate();
}
-void Map::clearCache()
-{
-// sphere_->clearCache();
-}
-
void Map::setCameraData(const CameraData &cameraData)
{
if (cameraData == d_ptr->cameraData())
@@ -309,6 +309,7 @@ void IntersectGenerator::generateValue()
MapPrivate::MapPrivate(Map *parent, TileCache *cache, int maxZoom, int tileSize)
: autoUpdate_(true),
map_(parent),
+ cache_(cache),
manager_(0),
controller_(0),
activeMapType_(MapType()),
@@ -344,12 +345,18 @@ MapPrivate::MapPrivate(Map *parent, TileCache *cache, int maxZoom, int tileSize)
MapPrivate::~MapPrivate()
{
// controller_ is a child of map_, don't need to delete it here
+ manager_->deregisterMap(map_);
delete sphere_;
delete glCamera_;
// TODO map items are not deallocated!
// However: how to ensure this is done in rendering thread?
}
+TileCache* MapPrivate::tileCache()
+{
+ return cache_;
+}
+
QGLSceneNode* MapPrivate::createTileNode(const Tile &tile)
{
QGLSceneNode* node = createTileSpecNode(tile.tileSpec());
@@ -364,11 +371,14 @@ QGLSceneNode* MapPrivate::createTileNode(const Tile &tile)
void MapPrivate::setMappingManager(QGeoMappingManager *manager)
{
- manager_ = manager;
- if (manager_) {
- pluginString_ = manager_->managerName() + QLatin1String("_") + QString::number(manager->managerVersion());
- sphere_->setMappingManager(manager_);
+ if (manager) {
+ manager->registerMap(map_);
+ pluginString_ = manager->managerName() + QLatin1String("_") + QString::number(manager->managerVersion());
+ sphere_->setMappingManager(manager);
+ } else {
+ manager->deregisterMap(map_);
}
+ manager_ = manager;
}
MapController* MapPrivate::mapController()
@@ -495,6 +505,11 @@ const MapType MapPrivate::activeMapType() const
return activeMapType_;
}
+void MapPrivate::tileFetched(const TileSpec &spec)
+{
+ sphere_->tileFetched(spec);
+}
+
QRect MapPrivate::specToRect(const TileSpec &tileSpec) const
{
int geomZoom = tileSpec.zoom();
diff --git a/src/location/mapsgl/map.h b/src/location/mapsgl/map.h
index b1233dd3..534dabd9 100644
--- a/src/location/mapsgl/map.h
+++ b/src/location/mapsgl/map.h
@@ -75,6 +75,8 @@ public:
Map(TileCache *cache, QObject *parent = 0);
virtual ~Map();
+ TileCache* tileCache();
+
void setMappingManager(QGeoMappingManager *manager);
MapController* mapController();
@@ -99,17 +101,17 @@ public:
const MapType activeMapType() const;
public Q_SLOTS:
- void clearCache();
void update();
Q_SIGNALS:
void updateRequired();
- void updatesFinished();
void cameraDataChanged(const CameraData &cameraData);
void activeMapTypeChanged();
private:
MapPrivate *d_ptr;
+
+ friend class QGeoMappingManager;
};
QT_END_NAMESPACE
diff --git a/src/location/mapsgl/map_p.h b/src/location/mapsgl/map_p.h
index d31a9a7e..98bad9a1 100644
--- a/src/location/mapsgl/map_p.h
+++ b/src/location/mapsgl/map_p.h
@@ -145,6 +145,8 @@ public:
MapPrivate(Map *parent, TileCache *cache, int maxZoom, int tileSize);
virtual ~MapPrivate();
+ TileCache* tileCache();
+
void setMappingManager(QGeoMappingManager *manager);
MapController* mapController();
@@ -180,6 +182,8 @@ public:
QVector3D tileXIntersectToPoint(int zoomLevel, int x) const;
QVector3D tileYIntersectToPoint(int zoomLevel, int y) const;
+ void tileFetched(const TileSpec &spec);
+
private:
void updateGlCamera(QGLCamera* glCamera);
void updateFrustum(Frustum &frustum);
@@ -192,6 +196,7 @@ private:
double aspectRatio_;
Map *map_;
+ TileCache* cache_;
QGeoMappingManager *manager_;
QString pluginString_;
MapController *controller_;
diff --git a/src/location/mapsgl/mapsphere.cpp b/src/location/mapsgl/mapsphere.cpp
index 359ccbbb..0a56f9b4 100644
--- a/src/location/mapsgl/mapsphere.cpp
+++ b/src/location/mapsgl/mapsphere.cpp
@@ -46,6 +46,8 @@
#include "map.h"
#include "map_p.h"
+#include "qgeomappingmanager.h"
+
#include <QOpenGLFramebufferObject>
#include <Qt3D/qglscenenode.h>
@@ -60,29 +62,16 @@ MapSphere::MapSphere(Map* map, MapPrivate *mapPrivate, TileCache *tileCache)
: QObject(0),
tileCache_(tileCache),
map_(map),
- mapPrivate_(mapPrivate)
+ mapPrivate_(mapPrivate),
+ manager_(0)
{
sphereNode_ = new QGLSceneNode(this);
- connect(tileCache_,
- SIGNAL(prefetchingFinished()),
- this,
- SLOT(prefetchingFinished()));
- connect(tileCache_,
- SIGNAL(tileFetched(TileSpec)),
- this,
- SLOT(tileFetched(TileSpec)));
-
connect(this,
SIGNAL(tileUpdated()),
map,
SIGNAL(updateRequired()));
-
- connect(this,
- SIGNAL(sphereUpdated()),
- map,
- SIGNAL(updatesFinished()));
}
MapSphere::~MapSphere()
@@ -99,7 +88,7 @@ MapSphere::~MapSphere()
void MapSphere::setMappingManager(QGeoMappingManager *manager)
{
- tileCache_->setMappingManager(manager);
+ manager_ = manager;
}
QGLSceneNode* MapSphere::sphereSceneNode() const
@@ -107,11 +96,6 @@ QGLSceneNode* MapSphere::sphereSceneNode() const
return sphereNode_;
}
-void MapSphere::clearCache()
-{
- // clear cache
-}
-
// Function to perform housekeeping that require access to GL context
// (access to GL context varies depending on if we are running as
// c++ app or QML app).
@@ -136,6 +120,8 @@ void MapSphere::update(const QList<TileSpec> &tiles)
QVector<TileSpec> req(tiles.size());
QVector<TileSpec> draw(tiles.size());
+ QSet<TileSpec> cancelTiles = requested_ - tiles.toSet();
+
int reqSize = 0;
int drawSize = 0;
QList<TileSpec>::const_iterator i = tiles.constBegin();
@@ -186,17 +172,14 @@ void MapSphere::update(const QList<TileSpec> &tiles)
displayTile(draw.at(i));
if (req.isEmpty()) {
- emit sphereUpdated();
+ emit tileUpdated();
} else {
- tileCache_->prefetch(req.toList());
+ if (manager_) {
+ manager_->updateTileRequests(map_, req.toList().toSet(), cancelTiles);
+ }
}
}
-void MapSphere::prefetchingFinished()
-{
- emit sphereUpdated();
-}
-
void MapSphere::tileFetched(const TileSpec &spec)
{
if (!requested_.contains(spec))
diff --git a/src/location/mapsgl/mapsphere_p.h b/src/location/mapsgl/mapsphere_p.h
index d98e03ce..c66d683f 100644
--- a/src/location/mapsgl/mapsphere_p.h
+++ b/src/location/mapsgl/mapsphere_p.h
@@ -97,17 +97,13 @@ public:
void paintGL(QGLPainter *painter);
-public slots:
- void clearCache();
- void update(const QList<TileSpec> &tiles);
-
-private slots:
void tileFetched(const TileSpec &spec);
- void prefetchingFinished();
-signals:
+public Q_SLOTS:
+ void update(const QList<TileSpec> &tiles);
+
+Q_SIGNALS:
void tileUpdated();
- void sphereUpdated();
private:
void displayTile(const TileSpec &spec);
@@ -124,6 +120,7 @@ private:
Map *map_;
MapPrivate* mapPrivate_;
+ QGeoMappingManager *manager_;
};
QT_END_NAMESPACE
diff --git a/src/location/mapsgl/tilecache.cpp b/src/location/mapsgl/tilecache.cpp
index e2f47d9e..ebc1f7ec 100644
--- a/src/location/mapsgl/tilecache.cpp
+++ b/src/location/mapsgl/tilecache.cpp
@@ -53,6 +53,7 @@
#include <Qt3D/qglscenenode.h>
Q_DECLARE_METATYPE(QList<TileSpec>)
+Q_DECLARE_METATYPE(QSet<TileSpec>)
QT_BEGIN_NAMESPACE
@@ -100,10 +101,11 @@ public:
};
TileCache::TileCache(const QString &directory, QObject *parent)
-: QObject(parent), directory_(directory), manager_(0)
+: QObject(parent), directory_(directory)
{
qRegisterMetaType<TileSpec>();
qRegisterMetaType<QList<TileSpec> >();
+ qRegisterMetaType<QSet<TileSpec> >();
if (directory_.isEmpty()) {
@@ -122,27 +124,7 @@ TileCache::TileCache(const QString &directory, QObject *parent)
loadTiles();
}
-TileCache::~TileCache()
-{
- delete manager_;
-}
-
-void TileCache::setMappingManager(QGeoMappingManager *manager)
-{
- manager_ = manager;
- connect(manager_,
- SIGNAL(tileFinished(TileSpec,QByteArray)),
- this,
- SLOT(insert(TileSpec,QByteArray)));
- connect(manager_,
- SIGNAL(tileError(TileSpec,QString)),
- this,
- SLOT(handleError(TileSpec,QString)));
- connect(manager_,
- SIGNAL(queueFinished()),
- this,
- SIGNAL(prefetchingFinished()));
-}
+TileCache::~TileCache() {}
void TileCache::setMaxDiskUsage(int diskUsage)
{
@@ -189,14 +171,6 @@ int TileCache::textureUsage() const
return textureCache_.totalCost();
}
-void TileCache::prefetch(const QList<TileSpec> &tiles)
-{
- if (!manager_)
- return;
-
- manager_->requestTiles(tiles);
-}
-
void TileCache::GLContextAvailable(QGLSceneNode *parentNode)
{
int size = cleanupList_.size();
@@ -270,28 +244,34 @@ void TileCache::update(const TileSpec &spec, const Tile &tile)
}
}
-void TileCache::insert(const TileSpec &spec, const QByteArray &bytes)
+void TileCache::insert(const TileSpec &spec, const QByteArray &bytes, TileCache::CacheAreas areas)
{
keys_.insert(spec);
- QString filename = tileSpecToFilename(spec, directory_);
-
QPixmap pixmap;
if (!pixmap.loadFromData(bytes)) {
handleError(spec, QLatin1String("Problem with tile image"));
return;
}
- QFile file(filename);
- file.open(QIODevice::WriteOnly);
- file.write(bytes);
- file.close();
+ if (areas & TileCache::DiskCache) {
+ QString filename = tileSpecToFilename(spec, directory_);
+
+ QFile file(filename);
+ file.open(QIODevice::WriteOnly);
+ file.write(bytes);
+ file.close();
+
+ addToDiskCache(spec, filename);
+ }
- addToDiskCache(spec, filename);
-// addToMemoryCache(spec, pixmap);
- addToTextureCache(spec, pixmap);
+ if (areas & TileCache::MemoryCache) {
+// addToMemoryCache(spec, pixmap);
+ }
- emit tileFetched(spec);
+ if (areas & TileCache::TextureCache) {
+ addToTextureCache(spec, pixmap);
+ }
}
void TileCache::evictFromDiskCache(TileDisk *td)
diff --git a/src/location/mapsgl/tilecache.h b/src/location/mapsgl/tilecache.h
index f915a9e0..06432d9f 100644
--- a/src/location/mapsgl/tilecache.h
+++ b/src/location/mapsgl/tilecache.h
@@ -71,11 +71,17 @@ class Q_LOCATION_EXPORT TileCache : public QObject
{
Q_OBJECT
public:
+ enum CacheArea {
+ DiskCache = 0x01,
+ MemoryCache = 0x02,
+ TextureCache = 0x04,
+ AllCaches = 0xFF
+ };
+ Q_DECLARE_FLAGS(CacheAreas, CacheArea)
+
TileCache(const QString &directory = QString(), QObject *parent = 0);
~TileCache();
- void setMappingManager(QGeoMappingManager *manager);
-
void setMaxDiskUsage(int diskUsage);
int maxDiskUsage() const;
int diskUsage() const;
@@ -95,21 +101,13 @@ public:
void update(const TileSpec &spec, const Tile &tile);
- void prefetch(const QList<TileSpec> &tiles);
-
void evictFromDiskCache(TileDisk *td);
void evictFromMemoryCache(TileMemory *tm);
void evictFromTextureCache(TileTexture *tt);
-private Q_SLOTS:
- void insert(const TileSpec &spec, const QByteArray &bytes);
+ void insert(const TileSpec &spec, const QByteArray &bytes, CacheAreas areas = AllCaches);
void handleError(const TileSpec &spec, const QString &errorString);
-Q_SIGNALS:
- void beginPrefetch(const QList<TileSpec> &tiles);
- void tileFetched(const TileSpec &spec);
- void prefetchingFinished();
-
private:
void loadTiles();
@@ -128,10 +126,10 @@ private:
QCache<TileSpec, TileTexture > textureCache_;
QList<Tile> cleanupList_;
-
- QGeoMappingManager *manager_;
};
+Q_DECLARE_OPERATORS_FOR_FLAGS(TileCache::CacheAreas)
+
QT_END_NAMESPACE
QT_END_HEADER