summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBasel Hashisho <basel.hashisho@nokia.com>2012-02-17 12:07:01 +0100
committerQt by Nokia <qt-info@nokia.com>2012-03-09 16:04:55 +0100
commit53e5f30e06091f5b05c9283657e454bc45896075 (patch)
treea9a5be51418b008f61165b510f1d87aa748a020e
parentf61e60ec2d66e181caf9e81b126936075e6fca5d (diff)
Refactoring of QtLocation API
Refactoring QGeoMap, QGeoMappingManager, QGeoMappingManagerEngine Introducing QGeoMapData, QGeoTiledMap, QGeoTiledMappingManagerEngine, QGeoTileFetcher QGeoMap: Container for QGeoMapData QGeoMapData: No tiles data/functionality QGeoTiledMapData: Implements tiles data/functionality. QGeoMappingManager: Looses tiles-related data/functionality. QGeoMappingManagerEngine => QGeoMappingManagerEngine (no tiles data/functionality) QGeoTiledMappingManagerEngine (implements tiles-related data/functionality). QGeoTileFetcher: Implements tile fetching functionality from tiles provider. This commit compiles and runs through mapviewer example. Tests also were adjusted to fit refactored architecture. Change-Id: Id2b62d62d5cd4aaca8295c67e44c009cde636462 Reviewed-by: Alex <alex.blasche@nokia.com>
-rw-r--r--src/imports/location/qdeclarativegeomap.cpp21
-rw-r--r--src/imports/location/qdeclarativegeomap_p.h2
-rw-r--r--src/location/maps/maps.pri17
-rw-r--r--src/location/maps/qgeomap.cpp316
-rw-r--r--src/location/maps/qgeomap_p.h19
-rw-r--r--src/location/maps/qgeomapcontroller.cpp6
-rw-r--r--src/location/maps/qgeomapcontroller_p.h6
-rw-r--r--src/location/maps/qgeomapdata.cpp320
-rw-r--r--src/location/maps/qgeomapdata_p.h132
-rw-r--r--src/location/maps/qgeomapdata_p_p.h (renamed from src/location/maps/qgeomap_p_p.h)51
-rw-r--r--src/location/maps/qgeomapgeometry.cpp68
-rw-r--r--src/location/maps/qgeomapgeometry_p.h4
-rw-r--r--src/location/maps/qgeomapimages.cpp34
-rw-r--r--src/location/maps/qgeomapimages_p.h9
-rw-r--r--src/location/maps/qgeomappingmanager.cpp251
-rw-r--r--src/location/maps/qgeomappingmanager.h38
-rw-r--r--src/location/maps/qgeomappingmanager_p.h10
-rw-r--r--src/location/maps/qgeomappingmanagerengine.cpp244
-rw-r--r--src/location/maps/qgeomappingmanagerengine.h43
-rw-r--r--src/location/maps/qgeomappingmanagerengine_p.h13
-rw-r--r--src/location/maps/qgeotilecache.cpp8
-rw-r--r--src/location/maps/qgeotilecache_p.h7
-rw-r--r--src/location/maps/qgeotiledmapdata.cpp322
-rw-r--r--src/location/maps/qgeotiledmapdata_p.h102
-rw-r--r--src/location/maps/qgeotiledmapdata_p_p.h116
-rw-r--r--src/location/maps/qgeotiledmappingmanagerengine.cpp304
-rw-r--r--src/location/maps/qgeotiledmappingmanagerengine.h132
-rw-r--r--src/location/maps/qgeotiledmappingmanagerengine_p.h92
-rw-r--r--src/location/maps/qgeotilefetcher.cpp230
-rw-r--r--src/location/maps/qgeotilefetcher.h103
-rw-r--r--src/location/maps/qgeotilefetcher_p.h92
-rw-r--r--src/plugins/geoservices/nokia/nokia.pro8
-rw-r--r--src/plugins/geoservices/nokia/qgeoserviceproviderplugin_nokia.cpp4
-rw-r--r--src/plugins/geoservices/nokia/qgeotiledmapdata_nokia.cpp169
-rw-r--r--src/plugins/geoservices/nokia/qgeotiledmapdata_nokia.h23
-rw-r--r--src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.cpp101
-rw-r--r--src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.h75
-rw-r--r--src/plugins/geoservices/nokia/qgeotilefetcher_nokia.cpp (renamed from src/plugins/geoservices/nokia/qgeomappingmanagerengine_nokia.cpp)159
-rw-r--r--src/plugins/geoservices/nokia/qgeotilefetcher_nokia.h (renamed from src/plugins/geoservices/nokia/qgeomappingmanagerengine_nokia.h)40
-rw-r--r--tests/auto/declarative_ui/tst_map_itemview.qml109
-rw-r--r--tests/auto/declarative_ui/tst_map_mouse.qml6
-rw-r--r--tests/auto/geotestplugin/geotestplugin.pro4
-rw-r--r--tests/auto/geotestplugin/qgeoserviceproviderplugin_test.cpp4
-rw-r--r--tests/auto/geotestplugin/qgeotiledmapdata_test.h59
-rw-r--r--tests/auto/geotestplugin/qgeotiledmappingmanagerengine_test.h94
-rw-r--r--tests/auto/geotestplugin/qgeotilefetcher_test.h177
46 files changed, 2768 insertions, 1376 deletions
diff --git a/src/imports/location/qdeclarativegeomap.cpp b/src/imports/location/qdeclarativegeomap.cpp
index baa06aea..72c79bbb 100644
--- a/src/imports/location/qdeclarativegeomap.cpp
+++ b/src/imports/location/qdeclarativegeomap.cpp
@@ -57,7 +57,7 @@
#include <cmath>
#include <qgeoserviceprovider.h>
-#include <qgeomappingmanager.h>
+#include "qgeomappingmanager.h"
#include <QtQml/QQmlContext>
#include <QtQml/qqmlinfo.h>
@@ -196,7 +196,7 @@ QDeclarativeGeoMap::QDeclarativeGeoMap(QQuickItem *parent)
pinchArea_(0),
canvas_(0),
touchTimer_(-1),
- tileCache_(0)
+ map_(0)
{
QLOC_TRACE0;
setAcceptHoverEvents(false);
@@ -204,11 +204,7 @@ QDeclarativeGeoMap::QDeclarativeGeoMap(QQuickItem *parent)
setFlags(QQuickItem::ItemHasContents | QQuickItem::ItemClipsChildrenToShape);
// Create internal flickable and pinch area.
- tileCache_ = new QGeoTileCache();
- map_ = new QGeoMap(tileCache_, this);
- map_->setActiveMapType(QGeoMapType());
flickable_ = new QDeclarativeGeoMapFlickable(this);
- flickable_->setMap(map_);
pinchArea_ = new QDeclarativeGeoMapPinchArea(this, this);
}
@@ -226,6 +222,9 @@ void QDeclarativeGeoMap::pluginReady()
{
serviceProvider_ = plugin_->sharedGeoServiceProvider();
mappingManager_ = serviceProvider_->mappingManager();
+ map_ = mappingManager_->createMap(this);
+ flickable_->setMap(map_);
+ pinchArea_->zoomLevelLimits(mappingManager_->cameraCapabilities().minimumZoomLevel(), mappingManager_->cameraCapabilities().maximumZoomLevel());
if (!mappingManager_ || serviceProvider_->error() != QGeoServiceProvider::NoError) {
qmlInfo(this) << tr("Warning: Plugin does not support mapping.");
@@ -405,6 +404,9 @@ QSGNode* QDeclarativeGeoMap::updatePaintNode(QSGNode* oldNode, UpdatePaintNodeDa
node = new MapNode(map_);
}
+ if (!mappingManagerInitialized_)
+ return 0;
+
node->setSize(QSize(width(), height()));
node->update();
@@ -443,6 +445,9 @@ void QDeclarativeGeoMap::mappingManagerInitialized()
{
mappingManagerInitialized_ = true;
+ map_->setActiveMapType(QGeoMapType());
+ flickable_->setMap(map_);
+
pinchArea_->zoomLevelLimits(mappingManager_->cameraCapabilities().minimumZoomLevel(),
mappingManager_->cameraCapabilities().maximumZoomLevel());
@@ -472,7 +477,6 @@ void QDeclarativeGeoMap::mappingManagerInitialized()
this,
SLOT(mapZoomLevelChanged(qreal)));
- map_->setMappingManager(mappingManager_);
map_->resize(width(), height());
AnimatableCoordinate acenter = map_->mapController()->center();
acenter.setCoordinate(center()->coordinate());
@@ -965,6 +969,9 @@ QDeclarativeGeoMapType * QDeclarativeGeoMap::activeMapType() const
void QDeclarativeGeoMap::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
{
+ if (!mappingManagerInitialized_)
+ return;
+
map_->resize(newGeometry.width(), newGeometry.height());
QQuickItem::geometryChanged(newGeometry, oldGeometry);
}
diff --git a/src/imports/location/qdeclarativegeomap_p.h b/src/imports/location/qdeclarativegeomap_p.h
index 94335315..1ca93eb8 100644
--- a/src/imports/location/qdeclarativegeomap_p.h
+++ b/src/imports/location/qdeclarativegeomap_p.h
@@ -56,7 +56,6 @@
#include "qdeclarativegeomapflickable_p.h"
#include "qdeclarativegeomappincharea_p.h"
#include "qgeomapcontroller_p.h"
-#include "qgeomappingmanager.h"
//#define QT_DECLARATIVE_LOCATION_TRACE 1
@@ -82,6 +81,7 @@ class QGeoTileCache;
class Tile;
class QGeoTileSpec;
class QGeoMapSphere;
+class QGeoMappingManager;
class QGeoCoordinate;
class QGeoMapObject;
diff --git a/src/location/maps/maps.pri b/src/location/maps/maps.pri
index f7278bd1..22efb353 100644
--- a/src/location/maps/maps.pri
+++ b/src/location/maps/maps.pri
@@ -9,8 +9,10 @@ PUBLIC_HEADERS += \
maps/qgeocodingmanagerengine.h \
maps/qgeocodingmanager.h \
maps/qgeomaneuver.h \
- maps/qgeomappingmanagerengine.h \
+ maps/qgeotilefetcher.h \
maps/qgeomappingmanager.h \
+ maps/qgeomappingmanagerengine.h \
+ maps/qgeotiledmappingmanagerengine.h \
maps/qgeomaptype.h \
maps/qgeoroute.h \
maps/qgeoroutereply.h \
@@ -37,9 +39,14 @@ PRIVATE_HEADERS += \
maps/qgeomapgeometry_p.h \
maps/qgeomapimages_p.h \
maps/qgeomap_p.h \
- maps/qgeomap_p_p.h \
- maps/qgeomappingmanagerengine_p.h \
+ maps/qgeomapdata_p.h \
+ maps/qgeomapdata_p_p.h \
+ maps/qgeotiledmapdata_p.h \
+ maps/qgeotiledmapdata_p_p.h \
+ maps/qgeotilefetcher_p.h \
maps/qgeomappingmanager_p.h \
+ maps/qgeomappingmanagerengine_p.h \
+ maps/qgeotiledmappingmanagerengine_p.h \
maps/qgeomaptype_p.h \
maps/qgeoprojection_p.h \
maps/qgeoroute_p.h \
@@ -68,8 +75,12 @@ SOURCES += \
maps/qgeomapgeometry.cpp \
maps/qgeomapimages.cpp \
maps/qgeomap.cpp \
+ maps/qgeomapdata.cpp \
+ maps/qgeotiledmapdata.cpp \
maps/qgeomappingmanager.cpp \
maps/qgeomappingmanagerengine.cpp \
+ maps/qgeotiledmappingmanagerengine.cpp \
+ maps/qgeotilefetcher.cpp \
maps/qgeomaptype.cpp \
maps/qgeoprojection.cpp \
maps/qgeoroute.cpp \
diff --git a/src/location/maps/qgeomap.cpp b/src/location/maps/qgeomap.cpp
index d4a8e2e2..a5205cb2 100644
--- a/src/location/maps/qgeomap.cpp
+++ b/src/location/maps/qgeomap.cpp
@@ -38,8 +38,9 @@
** $QT_END_LICENSE$
**
****************************************************************************/
+
#include "qgeomap_p.h"
-#include "qgeomap_p_p.h"
+#include "qgeomapdata_p.h"
#include "qgeotilecache_p.h"
#include "qgeotilespec.h"
@@ -73,346 +74,93 @@
QT_BEGIN_NAMESPACE
-QGeoMap::QGeoMap(QGeoTileCache *cache, QObject *parent)
+QGeoMap::QGeoMap(QGeoMapData *mapData, QObject *parent)
: QObject(parent),
- d_ptr(new QGeoMapPrivate(this, cache)) {}
-
-QGeoMap::~QGeoMap()
+ mapData_(mapData)
{
- delete d_ptr;
+ connect(mapData_, SIGNAL(cameraDataChanged(const QGeoCameraData&)), this, SIGNAL(cameraDataChanged(const QGeoCameraData&)));
+ connect(mapData_, SIGNAL(updateRequired()), this, SIGNAL(updateRequired()));
+ connect(mapData_, SIGNAL(activeMapTypeChanged()), this, SIGNAL(activeMapTypeChanged()));
}
-QGeoTileCache* QGeoMap::tileCache()
+QGeoMap::~QGeoMap()
{
- Q_D(QGeoMap);
- return d->tileCache();
+ delete mapData_;
}
QGeoMapController* QGeoMap::mapController()
{
- Q_D(QGeoMap);
- return d->mapController();
+ return mapData_->mapController();
}
-void QGeoMap::setMappingManager(QGeoMappingManager *manager)
+QGLCamera* QGeoMap::glCamera() const
{
- Q_D(QGeoMap);
- d->setMappingManager(manager);
+ return mapData_->glCamera();
}
void QGeoMap::paintGL(QGLPainter *painter)
{
- Q_D(QGeoMap);
- d->paintGL(painter);
-}
-
-QGLCamera* QGeoMap::glCamera() const
-{
- Q_D(const QGeoMap);
- return d->glCamera();
+ mapData_->paintGL(painter);
}
void QGeoMap::resize(int width, int height)
{
- Q_D(QGeoMap);
- d->resize(width, height);
-
- // always emit this signal to trigger items to redraw
- emit cameraDataChanged(d->cameraData());
+ mapData_->resize(width, height);
}
int QGeoMap::width() const
{
- Q_D(const QGeoMap);
- return d->width();
+ return mapData_->width();
}
int QGeoMap::height() const
{
- Q_D(const QGeoMap);
- return d->height();
+ return mapData_->height();
}
-void QGeoMap::setCameraData(const QGeoCameraData &cameraData)
-{
- Q_D(QGeoMap);
-
- if (cameraData == d->cameraData())
- return;
-
- d->setCameraData(cameraData);
- update();
-
- emit cameraDataChanged(d->cameraData());
-}
-
-QGeoCameraData QGeoMap::cameraData() const
+QGeoCameraCapabilities QGeoMap::cameraCapabilities() const
{
- Q_D(const QGeoMap);
- return d->cameraData();
+ return mapData_->cameraCapabilities();
}
-QGeoCameraCapabilities QGeoMap::cameraCapabilities() const
+void QGeoMap::setCameraData(const QGeoCameraData &cameraData)
{
- Q_D(const QGeoMap);
- if (d->manager())
- return d->manager()->cameraCapabilities();
- else
- return QGeoCameraCapabilities();
+ mapData_->setCameraData(cameraData);
}
-void QGeoMap::update()
+QGeoCameraData QGeoMap::cameraData() const
{
- emit updateRequired();
+ return mapData_->cameraData();
}
QGeoCoordinate QGeoMap::screenPositionToCoordinate(const QPointF &pos, bool clipToViewport) const
{
- Q_D(const QGeoMap);
- if (clipToViewport) {
- int w = d->width();
- int h = d->height();
-
- if ((pos.x() < 0) || (w < pos.x()) || (pos.y() < 0) || (h < pos.y()))
- return QGeoCoordinate();
- }
-
- return d->screenPositionToCoordinate(pos);
+ return mapData_->screenPositionToCoordinate(pos, clipToViewport);
}
QPointF QGeoMap::coordinateToScreenPosition(const QGeoCoordinate &coordinate, bool clipToViewport) const
{
- Q_D(const QGeoMap);
- QPointF pos = d->coordinateToScreenPosition(coordinate);
-
- if (clipToViewport) {
- int w = d->width();
- int h = d->height();
-
- if ((pos.x() < 0) || (w < pos.x()) || (pos.y() < 0) || (h < pos.y()))
- return QPointF(qQNaN(), qQNaN());
- }
-
- return pos;
-}
-
-void QGeoMap::setActiveMapType(const QGeoMapType type)
-{
- Q_D(QGeoMap);
- d->setActiveMapType(type);
-}
-
-const QGeoMapType QGeoMap::activeMapType() const
-{
- Q_D(const QGeoMap);
- return d->activeMapType();
-}
-
-QGeoMapPrivate::QGeoMapPrivate(QGeoMap *parent, QGeoTileCache *cache)
- : width_(0),
- height_(0),
- aspectRatio_(0.0),
- map_(parent),
- cache_(cache),
- controller_(0),
- cameraTiles_(new QGeoCameraTiles()),
- mapGeometry_(new QGeoMapGeometry()),
- mapImages_(0),
- activeMapType_(QGeoMapType()) {}
-
-QGeoMapPrivate::~QGeoMapPrivate()
-{
- // controller_ is a child of map_, don't need to delete it here
-
- delete mapImages_;
- delete mapGeometry_;
- delete cameraTiles_;
-
- if (manager_)
- manager_.data()->deregisterMap(map_);
- // TODO map items are not deallocated!
- // However: how to ensure this is done in rendering thread?
-}
-
-QGeoTileCache* QGeoMapPrivate::tileCache()
-{
- return cache_;
-}
-
-void QGeoMapPrivate::setMappingManager(QGeoMappingManager *manager)
-{
- if (manager_)
- manager_.data()->deregisterMap(map_);
-
- if (manager) {
- manager->registerMap(map_);
-
- cameraTiles_->setMaximumZoomLevel(static_cast<int>(ceil(manager->cameraCapabilities().maximumZoomLevel())));
-
- cameraTiles_->setTileSize(manager->tileSize());
- mapGeometry_->setTileSize(manager->tileSize());
-
- pluginString_ = manager->managerName() + QLatin1String("_") + QString::number(manager->managerVersion());
- cameraTiles_->setPluginString(pluginString_);
-
- mapImages_ = new QGeoMapImages(map_);
- mapImages_->setMappingManager(manager);
- }
-
- manager_ = manager;
-}
-
-QGeoMapController* QGeoMapPrivate::mapController()
-{
- if (!controller_)
- controller_ = new QGeoMapController(map_, mapGeometry_->coordinateInterpolator());
- return controller_;
-}
-
-QGLCamera* QGeoMapPrivate::glCamera() const
-{
- return mapGeometry_->camera();
-}
-
-void QGeoMapPrivate::setCameraData(const QGeoCameraData &cameraData)
-{
- double lat = cameraData_.center().latitude();
-
- cameraData_ = cameraData;
-
- if (mapGeometry_->verticalLock()) {
- QGeoCoordinate coord = cameraData_.center();
- coord.setLatitude(lat);
- cameraData_.setCenter(coord);
- }
-
- if (manager_) {
- QGeoCameraCapabilities capabilities = manager_.data()->cameraCapabilities();
- if (cameraData_.zoomLevel() < capabilities.minimumZoomLevel())
- cameraData_.setZoomLevel(capabilities.minimumZoomLevel());
-
- if (cameraData_.zoomLevel() > capabilities.maximumZoomLevel())
- cameraData_.setZoomLevel(capabilities.maximumZoomLevel());
-
- if (!capabilities.supportsBearing())
- cameraData_.setBearing(0.0);
-
- if (capabilities.supportsTilting()) {
- if (cameraData_.tilt() < capabilities.minimumTilt())
- cameraData_.setTilt(capabilities.minimumTilt());
-
- if (cameraData_.tilt() > capabilities.maximumTilt())
- cameraData_.setTilt(capabilities.maximumTilt());
- } else {
- cameraData_.setTilt(0.0);
- }
-
- if (!capabilities.supportsRolling())
- cameraData_.setRoll(0.0);
- }
-
- cameraData_.setCoordinateInterpolator(mapGeometry_->coordinateInterpolator().toWeakRef());
-
- cameraTiles_->setCamera(cameraData_);
- visibleTiles_ = cameraTiles_->tiles();
-
- mapGeometry_->setCameraData(cameraData_);
- mapGeometry_->setVisibleTiles(visibleTiles_);
-
- if (mapImages_) {
- mapImages_->setVisibleTiles(visibleTiles_);
-
- //QSet<QGeoTileSpec> cachedTiles = mapImages_->cachedTiles();
- // TODO make this more efficient
- QSet<QGeoTileSpec> cachedTiles = visibleTiles_;
-
- typedef QSet<QGeoTileSpec>::const_iterator iter;
- iter i = cachedTiles.constBegin();
- iter end = cachedTiles.constEnd();
- for (; i != end; ++i) {
- QGeoTileSpec tile = *i;
- if (cache_->contains(tile))
- mapGeometry_->addTile(tile, cache_->get(tile));
- }
-
- if (!cachedTiles.isEmpty())
- map_->update();
-
- }
-}
-
-QGeoCameraData QGeoMapPrivate::cameraData() const
-{
- return cameraData_;
-}
-
-QGeoMappingManager *QGeoMapPrivate::manager() const
-{
- return manager_.data();
-}
-
-void QGeoMapPrivate::resize(int width, int height)
-{
- width_ = width;
- height_ = height;
- aspectRatio_ = 1.0 * width_ / height_;
- cameraTiles_->setScreenSize(QSize(width, height));
- mapGeometry_->setScreenSize(QSize(width, height));
- setCameraData(cameraData_);
+ return mapData_->coordinateToScreenPosition(coordinate, clipToViewport);
}
-int QGeoMapPrivate::width() const
-{
- return width_;
-}
-
-int QGeoMapPrivate::height() const
-{
- return height_;
-}
-
-double QGeoMapPrivate::aspectRatio() const
-{
- return aspectRatio_;
-}
-
-void QGeoMapPrivate::setActiveMapType(const QGeoMapType &type)
-{
- activeMapType_ = type;
- cameraTiles_->setMapType(type);
- visibleTiles_ = cameraTiles_->tiles();
-
- setCameraData(cameraData_);
-
- map_->update();
-}
-
-const QGeoMapType QGeoMapPrivate::activeMapType() const
-{
- return activeMapType_;
-}
-
-void QGeoMapPrivate::tileFetched(const QGeoTileSpec &spec)
+void QGeoMap::update()
{
- if (cache_->contains(spec))
- mapGeometry_->addTile(spec, cache_->get(spec));
- mapImages_->tileFetched(spec);
- map_->update();
+ emit mapData_->update();
}
-void QGeoMapPrivate::paintGL(QGLPainter *painter)
+void QGeoMap::setActiveMapType(const QGeoMapType type)
{
- mapGeometry_->paintGL(painter);
+ mapData_->setActiveMapType(type);
}
-QGeoCoordinate QGeoMapPrivate::screenPositionToCoordinate(const QPointF &pos) const
+const QGeoMapType QGeoMap::activeMapType() const
{
- return QGeoProjection::mercatorToCoord(mapGeometry_->screenPositionToMercator(pos));
+ return mapData_->activeMapType();
}
-QPointF QGeoMapPrivate::coordinateToScreenPosition(const QGeoCoordinate &coordinate) const
+QString QGeoMap::pluginString()
{
- return mapGeometry_->mercatorToScreenPosition(QGeoProjection::coordToMercator(coordinate));
+ return mapData_->pluginString();
}
QT_END_NAMESPACE
diff --git a/src/location/maps/qgeomap_p.h b/src/location/maps/qgeomap_p.h
index d10d3292..cee98de9 100644
--- a/src/location/maps/qgeomap_p.h
+++ b/src/location/maps/qgeomap_p.h
@@ -56,6 +56,7 @@
#include "qgeocameradata_p.h"
#include "qgeomaptype.h"
+#include "qgeocoordinateinterpolator_p.h"
QT_BEGIN_NAMESPACE
@@ -63,14 +64,13 @@ class QGeoCoordinate;
class QGeoMappingManager;
-class QGeoTileCache;
-class QGeoMapPrivate;
class MapItem;
class QGeoMapController;
class QGeoCameraCapabilities;
class QGLCamera;
class QGLPainter;
+class QGeoMapData;
class QPointF;
@@ -82,13 +82,9 @@ class Q_LOCATION_EXPORT QGeoMap : public QObject
Q_PROPERTY(QGeoMapType activeMapType READ activeMapType WRITE setActiveMapType NOTIFY activeMapTypeChanged)
public:
- QGeoMap(QGeoTileCache *cache, QObject *parent = 0);
+ QGeoMap(QGeoMapData *mapData, QObject *parent = 0);
virtual ~QGeoMap();
- QGeoTileCache* tileCache();
-
- void setMappingManager(QGeoMappingManager *manager);
-
QGeoMapController* mapController();
QGLCamera* glCamera() const;
@@ -108,19 +104,18 @@ public:
void setActiveMapType(const QGeoMapType mapType);
const QGeoMapType activeMapType() const;
+ QString pluginString();
+
public Q_SLOTS:
void update();
Q_SIGNALS:
- void updateRequired();
void cameraDataChanged(const QGeoCameraData &cameraData);
+ void updateRequired();
void activeMapTypeChanged();
private:
- QGeoMapPrivate *d_ptr;
- Q_DECLARE_PRIVATE(QGeoMap)
-
- friend class QGeoMappingManager;
+ QGeoMapData *mapData_;
};
QT_END_NAMESPACE
diff --git a/src/location/maps/qgeomapcontroller.cpp b/src/location/maps/qgeomapcontroller.cpp
index 842912d7..428b330b 100644
--- a/src/location/maps/qgeomapcontroller.cpp
+++ b/src/location/maps/qgeomapcontroller.cpp
@@ -41,7 +41,7 @@
#include "qgeomapcontroller_p.h"
-#include "qgeomap_p.h"
+#include "qgeomapdata_p.h"
#include "qgeoprojection_p.h"
#include <QPointF>
@@ -102,7 +102,7 @@ void AnimatableCoordinate::setInterpolator(QSharedPointer<QGeoCoordinateInterpol
interpolator_ = interpolator;
}
-QGeoMapController::QGeoMapController(QGeoMap *map, QSharedPointer<QGeoCoordinateInterpolator> interpolator)
+QGeoMapController::QGeoMapController(QGeoMapData *map, QSharedPointer<QGeoCoordinateInterpolator> interpolator)
: QObject(map),
map_(map),
interpolator_(interpolator)
@@ -112,7 +112,7 @@ QGeoMapController::QGeoMapController(QGeoMap *map, QSharedPointer<QGeoCoordinate
oldCameraData_ = map_->cameraData();
- connect(map,
+ connect(map_,
SIGNAL(cameraDataChanged(QGeoCameraData)),
this,
SLOT(cameraDataChanged(QGeoCameraData)));
diff --git a/src/location/maps/qgeomapcontroller_p.h b/src/location/maps/qgeomapcontroller_p.h
index e57a8e49..3dfb1f41 100644
--- a/src/location/maps/qgeomapcontroller_p.h
+++ b/src/location/maps/qgeomapcontroller_p.h
@@ -60,7 +60,7 @@
QT_BEGIN_NAMESPACE
-class QGeoMap;
+class QGeoMapData;
class Q_LOCATION_EXPORT AnimatableCoordinate {
public:
@@ -90,7 +90,7 @@ class Q_LOCATION_EXPORT QGeoMapController : public QObject
Q_PROPERTY(qreal zoom READ zoom WRITE setZoom NOTIFY zoomChanged)
public:
- QGeoMapController(QGeoMap *map, QSharedPointer<QGeoCoordinateInterpolator> coordinateInterpolator);
+ QGeoMapController(QGeoMapData *map, QSharedPointer<QGeoCoordinateInterpolator> coordinateInterpolator);
~QGeoMapController();
AnimatableCoordinate center() const;
@@ -121,7 +121,7 @@ signals:
void zoomChanged(qreal zoom);
private:
- QGeoMap *map_;
+ QGeoMapData *map_;
QSharedPointer<QGeoCoordinateInterpolator> interpolator_;
QGeoCameraData oldCameraData_;
};
diff --git a/src/location/maps/qgeomapdata.cpp b/src/location/maps/qgeomapdata.cpp
new file mode 100644
index 00000000..1eb54538
--- /dev/null
+++ b/src/location/maps/qgeomapdata.cpp
@@ -0,0 +1,320 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtLocation module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "qgeomapdata_p.h"
+#include "qgeomapdata_p_p.h"
+#include "qgeomap_p.h"
+
+#include "qgeotilecache_p.h"
+#include "qgeotilespec.h"
+#include "qgeoprojection_p.h"
+#include "qgeocameracapabilities_p.h"
+#include "qgeomapcontroller_p.h"
+#include "qdoublevector2d_p.h"
+#include "qdoublevector3d_p.h"
+
+#include "qgeocameratiles_p.h"
+#include "qgeomapimages_p.h"
+#include "qgeomapgeometry_p.h"
+
+#include "qgeomappingmanager.h"
+
+#include <QMutex>
+#include <QMap>
+
+#include <qnumeric.h>
+
+#include <qglscenenode.h>
+#include <qgeometrydata.h>
+#include <qglbuilder.h>
+#include <Qt3D/qglpainter.h>
+#include <Qt3D/qgeometrydata.h>
+#include <Qt3D/qglbuilder.h>
+#include <Qt3D/qglcamera.h>
+#include <Qt3D/qglsubsurface.h>
+
+#include <cmath>
+
+QT_BEGIN_NAMESPACE
+
+QGeoMapData::QGeoMapData(QGeoMappingManagerEngine *engine, QObject *parent)
+ : QObject(parent),
+ d_ptr(new QGeoMapDataPrivate(engine, this)) {}
+
+QGeoMapData::~QGeoMapData()
+{
+ delete d_ptr;
+}
+
+QGeoMapController* QGeoMapData::mapController()
+{
+ Q_D(QGeoMapData);
+ return d->mapController();
+}
+
+QGLCamera* QGeoMapData::glCamera() const
+{
+ Q_D(const QGeoMapData);
+ return d->glCamera();
+}
+
+void QGeoMapData::resize(int width, int height)
+{
+ Q_D(QGeoMapData);
+ d->resize(width, height);
+
+ // always emit this signal to trigger items to redraw
+ emit cameraDataChanged(d->cameraData());
+}
+
+int QGeoMapData::width() const
+{
+ Q_D(const QGeoMapData);
+ return d->width();
+}
+
+int QGeoMapData::height() const
+{
+ Q_D(const QGeoMapData);
+ return d->height();
+}
+
+void QGeoMapData::setCameraData(const QGeoCameraData &cameraData)
+{
+ Q_D(QGeoMapData);
+
+ if (cameraData == d->cameraData())
+ return;
+
+ d->setCameraData(cameraData);
+ update();
+
+ emit cameraDataChanged(d->cameraData());
+}
+
+QGeoCameraData QGeoMapData::cameraData() const
+{
+ Q_D(const QGeoMapData);
+ return d->cameraData();
+}
+
+void QGeoMapData::update()
+{
+ emit updateRequired();
+}
+
+void QGeoMapData::setActiveMapType(const QGeoMapType type)
+{
+ Q_D(QGeoMapData);
+ d->setActiveMapType(type);
+}
+
+const QGeoMapType QGeoMapData::activeMapType() const
+{
+ Q_D(const QGeoMapData);
+ return d->activeMapType();
+}
+
+QString QGeoMapData::pluginString()
+{
+ Q_D(QGeoMapData);
+ return d->pluginString();
+}
+
+QSharedPointer<QGeoCoordinateInterpolator> QGeoMapData::coordinateInterpolator()
+{
+ Q_D(QGeoMapData);
+ return d->coordinateInterpolator();
+}
+
+void QGeoMapData::setCoordinateInterpolator(QSharedPointer<QGeoCoordinateInterpolator> interpolator)
+{
+ Q_D(QGeoMapData);
+ return d->setCoordinateInterpolator(interpolator);
+}
+
+QGeoCameraCapabilities QGeoMapData::cameraCapabilities()
+{
+ Q_D(QGeoMapData);
+ if (d->engine())
+ return d->engine()->cameraCapabilities();
+ else
+ return QGeoCameraCapabilities();
+}
+
+QGeoMappingManagerEngine *QGeoMapData::engine()
+{
+ Q_D(QGeoMapData);
+ return d->engine();
+}
+
+QGeoMapDataPrivate::QGeoMapDataPrivate(QGeoMappingManagerEngine *engine, QGeoMapData *parent)
+ : width_(0),
+ height_(0),
+ aspectRatio_(0.0),
+ map_(parent),
+ engine_(engine),
+ controller_(0),
+ camera_(new QGLCamera()),
+ activeMapType_(QGeoMapType())
+{
+ pluginString_ = engine_->managerName() + QLatin1String("_") + QString::number(engine_->managerVersion());
+}
+
+QGeoMapDataPrivate::~QGeoMapDataPrivate()
+{
+ // controller_ is a child of map_, don't need to delete it here
+
+ delete camera_;
+ // TODO map items are not deallocated!
+ // However: how to ensure this is done in rendering thread?
+}
+
+QGeoMappingManagerEngine *QGeoMapDataPrivate::engine() const
+{
+ return engine_;
+}
+
+QString QGeoMapDataPrivate::pluginString()
+{
+ return pluginString_;
+}
+
+QSharedPointer<QGeoCoordinateInterpolator> QGeoMapDataPrivate::coordinateInterpolator() const
+{
+ return coordinateInterpolator_;
+}
+
+void QGeoMapDataPrivate::setCoordinateInterpolator(QSharedPointer<QGeoCoordinateInterpolator> interpolator)
+{
+ coordinateInterpolator_ = interpolator;
+}
+
+QGeoMapController* QGeoMapDataPrivate::mapController()
+{
+ if (!controller_)
+ controller_ = new QGeoMapController(map_, coordinateInterpolator_);
+ return controller_;
+}
+
+QGLCamera* QGeoMapDataPrivate::glCamera() const
+{
+ return camera_;
+}
+
+void QGeoMapDataPrivate::setCameraData(const QGeoCameraData &cameraData)
+{
+ QGeoCameraData oldCameraData = cameraData_;
+ cameraData_ = cameraData;
+
+ if (engine_) {
+ QGeoCameraCapabilities capabilities = engine_->cameraCapabilities();
+ if (cameraData_.zoomLevel() < capabilities.minimumZoomLevel())
+ cameraData_.setZoomLevel(capabilities.minimumZoomLevel());
+
+ if (cameraData_.zoomLevel() > capabilities.maximumZoomLevel())
+ cameraData_.setZoomLevel(capabilities.maximumZoomLevel());
+
+ if (!capabilities.supportsBearing())
+ cameraData_.setBearing(0.0);
+
+ if (capabilities.supportsTilting()) {
+ if (cameraData_.tilt() < capabilities.minimumTilt())
+ cameraData_.setTilt(capabilities.minimumTilt());
+
+ if (cameraData_.tilt() > capabilities.maximumTilt())
+ cameraData_.setTilt(capabilities.maximumTilt());
+ } else {
+ cameraData_.setTilt(0.0);
+ }
+
+ if (!capabilities.supportsRolling())
+ cameraData_.setRoll(0.0);
+ }
+
+ cameraData_.setCoordinateInterpolator(coordinateInterpolator_.toWeakRef());
+ map_->changeCameraData(oldCameraData);
+}
+
+QGeoCameraData QGeoMapDataPrivate::cameraData() const
+{
+ return cameraData_;
+}
+
+void QGeoMapDataPrivate::resize(int width, int height)
+{
+ width_ = width;
+ height_ = height;
+ aspectRatio_ = 1.0 * width_ / height_;
+ map_->mapResized(width, height);
+ setCameraData(cameraData_);
+}
+
+int QGeoMapDataPrivate::width() const
+{
+ return width_;
+}
+
+int QGeoMapDataPrivate::height() const
+{
+ return height_;
+}
+
+double QGeoMapDataPrivate::aspectRatio() const
+{
+ return aspectRatio_;
+}
+
+void QGeoMapDataPrivate::setActiveMapType(const QGeoMapType &type)
+{
+ activeMapType_ = type;
+
+ map_->changeActiveMapType(type);
+ setCameraData(cameraData_);
+
+ map_->update();
+}
+
+const QGeoMapType QGeoMapDataPrivate::activeMapType() const
+{
+ return activeMapType_;
+}
+
+QT_END_NAMESPACE
diff --git a/src/location/maps/qgeomapdata_p.h b/src/location/maps/qgeomapdata_p.h
new file mode 100644
index 00000000..0d9e6309
--- /dev/null
+++ b/src/location/maps/qgeomapdata_p.h
@@ -0,0 +1,132 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtLocation module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef QGEOMAPDATA_P_H
+#define QGEOMAPDATA_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QObject>
+
+#include "qgeocameradata_p.h"
+#include "qgeomaptype.h"
+#include "qgeocoordinateinterpolator_p.h"
+#include "qgeocoordinateinterpolator_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class QGeoCoordinate;
+
+class QGeoMappingManagerEngine;
+
+class QGeoMapDataPrivate;
+class MapItem;
+class QGeoMapController;
+class QGeoCameraCapabilities;
+
+class QGLCamera;
+class QGLPainter;
+class QGeoMap;
+
+class QPointF;
+
+class Q_LOCATION_EXPORT QGeoMapData : public QObject
+{
+ Q_OBJECT
+public:
+ QGeoMapData(QGeoMappingManagerEngine *engine, QObject *parent = 0);
+ virtual ~QGeoMapData();
+
+ QGeoMapController* mapController();
+
+ QGLCamera* glCamera() const;
+ virtual void paintGL(QGLPainter *painter) = 0;
+
+ void resize(int width, int height);
+ int width() const;
+ int height() const;
+
+ void setCameraData(const QGeoCameraData &cameraData);
+ QGeoCameraData cameraData() const;
+
+ void setActiveMapType(const QGeoMapType mapType);
+ const QGeoMapType activeMapType() const;
+
+ QSharedPointer<QGeoCoordinateInterpolator> coordinateInterpolator();
+
+ virtual QGeoCoordinate screenPositionToCoordinate(const QPointF &pos, bool clipToViewport = true) const = 0;
+ virtual QPointF coordinateToScreenPosition(const QGeoCoordinate &coordinate, bool clipToViewport = true) const = 0;
+
+ QString pluginString();
+ QGeoCameraCapabilities cameraCapabilities();
+
+protected:
+ void setCoordinateInterpolator(QSharedPointer<QGeoCoordinateInterpolator> interpolator);
+ QGeoMappingManagerEngine *engine();
+
+ virtual void mapResized(int width, int height) = 0;
+ virtual void changeCameraData(const QGeoCameraData &oldCameraData) = 0;
+ virtual void changeActiveMapType(const QGeoMapType mapType) = 0;
+
+public Q_SLOTS:
+ void update();
+
+Q_SIGNALS:
+ void cameraDataChanged(const QGeoCameraData &cameraData);
+ void updateRequired();
+ void activeMapTypeChanged();
+
+private:
+ QGeoMapDataPrivate *d_ptr;
+ Q_DECLARE_PRIVATE(QGeoMapData)
+};
+
+QT_END_NAMESPACE
+
+#endif // QGEOMAP_P_H
diff --git a/src/location/maps/qgeomap_p_p.h b/src/location/maps/qgeomapdata_p_p.h
index a2ed3496..8242d67c 100644
--- a/src/location/maps/qgeomap_p_p.h
+++ b/src/location/maps/qgeomapdata_p_p.h
@@ -38,8 +38,8 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#ifndef QGEOMAP_P_P_H
-#define QGEOMAP_P_P_H
+#ifndef QGEOMAPDATA_P_P_H
+#define QGEOMAPDATA_P_P_H
//
// W A R N I N G
@@ -61,7 +61,6 @@
#include <QMatrix4x4>
#include <QString>
#include <QSharedPointer>
-#include <QWeakPointer>
#include "qgeocameradata_p.h"
#include "qgeomaptype.h"
@@ -70,38 +69,25 @@
QT_BEGIN_NAMESPACE
-class QGeoMappingManager;
+class QGeoMappingManagerEngine;
-class QGeoTile;
-class QGeoTileCache;
-class QGeoTileSpec;
-class QGeoMap;
+class QGeoMapData;
class QGeoMapController;
-class QGeoProjection;
-
-class QGeoCameraTiles;
-class QGeoMapImages;
-class QGeoMapGeometry;
class QGLCamera;
-class QGLSceneNode;
class QGLPainter;
-class QGeoMapPrivate
+class QGeoMapDataPrivate
{
public:
- QGeoMapPrivate(QGeoMap *parent, QGeoTileCache *cache);
- virtual ~QGeoMapPrivate();
-
- QGeoTileCache* tileCache();
+ QGeoMapDataPrivate(QGeoMappingManagerEngine *engine, QGeoMapData *parent);
+ virtual ~QGeoMapDataPrivate();
- void setMappingManager(QGeoMappingManager *manager);
- QGeoMappingManager *manager() const;
+ QGeoMappingManagerEngine *engine() const;
QGeoMapController* mapController();
QGLCamera* glCamera() const;
- void paintGL(QGLPainter *painter);
void setCameraData(const QGeoCameraData &cameraData);
QGeoCameraData cameraData() const;
@@ -113,31 +99,26 @@ public:
const QGeoMapType activeMapType() const;
void setActiveMapType(const QGeoMapType &mapType);
+ QString pluginString();
- QGeoCoordinate screenPositionToCoordinate(const QPointF &pos) const;
- QPointF coordinateToScreenPosition(const QGeoCoordinate &coordinate) const;
-
- void tileFetched(const QGeoTileSpec &spec);
+ QSharedPointer<QGeoCoordinateInterpolator> coordinateInterpolator() const;
+ void setCoordinateInterpolator(QSharedPointer<QGeoCoordinateInterpolator> interpolator);
private:
int width_;
int height_;
double aspectRatio_;
- QGeoMap *map_;
- QGeoTileCache* cache_;
- QWeakPointer<QGeoMappingManager> manager_;
+ QGLCamera *camera_;
+ QGeoMapData *map_;
+ QGeoMappingManagerEngine *engine_;
QString pluginString_;
QGeoMapController *controller_;
QGeoCameraData cameraData_;
- QSet<QGeoTileSpec> visibleTiles_;
-
- QGeoCameraTiles *cameraTiles_;
- QGeoMapGeometry *mapGeometry_;
- QGeoMapImages *mapImages_;
-
QGeoMapType activeMapType_;
+
+ QSharedPointer<QGeoCoordinateInterpolator> coordinateInterpolator_;
};
QT_END_NAMESPACE
diff --git a/src/location/maps/qgeomapgeometry.cpp b/src/location/maps/qgeomapgeometry.cpp
index dda47c10..5a4e6d61 100644
--- a/src/location/maps/qgeomapgeometry.cpp
+++ b/src/location/maps/qgeomapgeometry.cpp
@@ -62,62 +62,6 @@
#include <cmath>
QT_BEGIN_NAMESPACE
-
-class QGeoCoordinateInterpolator2D : public QGeoCoordinateInterpolator
-{
-public:
- QGeoCoordinateInterpolator2D();
- virtual ~QGeoCoordinateInterpolator2D();
-
- virtual QGeoCoordinate interpolate(const QGeoCoordinate &start, const QGeoCoordinate &end, qreal progress);
-};
-
-QGeoCoordinateInterpolator2D::QGeoCoordinateInterpolator2D() {}
-
-QGeoCoordinateInterpolator2D::~QGeoCoordinateInterpolator2D() {}
-
-QGeoCoordinate QGeoCoordinateInterpolator2D::interpolate(const QGeoCoordinate &start, const QGeoCoordinate &end, qreal progress)
-{
- if (start == end) {
- if (progress < 0.5) {
- return start;
- } else {
- return end;
- }
- }
-
- QGeoCoordinate s2 = start;
- QGeoCoordinate e2 = end;
- QDoubleVector2D s = QGeoProjection::coordToMercator(s2);
- QDoubleVector2D e = QGeoProjection::coordToMercator(e2);
-
- double x = s.x();
-
- if (0.5 < qAbs(e.x() - s.x())) {
- // handle dateline crossing
- double ex = e.x();
- double sx = s.x();
- if (ex < sx)
- sx -= 1.0;
- else if (sx < ex)
- ex -= 1.0;
-
- x = (1.0 - progress) * sx + progress * ex;
-
- if (!qFuzzyIsNull(x) && (x < 0.0))
- x += 1.0;
-
- } else {
- x = (1.0 - progress) * s.x() + progress * e.x();
- }
-
- double y = (1.0 - progress) * s.y() + progress * e.y();
-
- QGeoCoordinate result = QGeoProjection::mercatorToCoord(QDoubleVector2D(x, y));
- result.setAltitude((1.0 - progress) * start.altitude() + progress * end.altitude());
- return result;
-}
-
class QGeoMapGeometryPrivate {
public:
QGeoMapGeometryPrivate();
@@ -157,8 +101,6 @@ public:
bool useVerticalLock_;
bool verticalLock_;
- QSharedPointer<QGeoCoordinateInterpolator> coordinateInterpolator_;
-
void addTile(const QGeoTileSpec &spec, QGLTexture2D *texture);
QDoubleVector2D screenPositionToMercator(const QPointF &pos) const;
@@ -172,7 +114,6 @@ public:
void paintGL(QGLPainter *painter);
};
-
QGeoMapGeometry::QGeoMapGeometry()
: d_ptr(new QGeoMapGeometryPrivate()) {}
@@ -255,12 +196,6 @@ void QGeoMapGeometry::paintGL(QGLPainter *painter)
d->paintGL(painter);
}
-QSharedPointer<QGeoCoordinateInterpolator> QGeoMapGeometry::coordinateInterpolator() const
-{
- Q_D(const QGeoMapGeometry);
- return d->coordinateInterpolator_;
-}
-
QGeoMapGeometryPrivate::QGeoMapGeometryPrivate()
: tileSize_(0),
camera_(new QGLCamera()),
@@ -276,8 +211,7 @@ QGeoMapGeometryPrivate::QGeoMapGeometryPrivate()
screenOffsetX_(0.0),
screenOffsetY_(0.0),
useVerticalLock_(false),
- verticalLock_(false),
- coordinateInterpolator_(QSharedPointer<QGeoCoordinateInterpolator>(new QGeoCoordinateInterpolator2D())) {}
+ verticalLock_(false) {}
QGeoMapGeometryPrivate::~QGeoMapGeometryPrivate()
{
diff --git a/src/location/maps/qgeomapgeometry_p.h b/src/location/maps/qgeomapgeometry_p.h
index 91bff47e..57e15291 100644
--- a/src/location/maps/qgeomapgeometry_p.h
+++ b/src/location/maps/qgeomapgeometry_p.h
@@ -56,8 +56,6 @@
#include <QSharedPointer>
#include <QSize>
-#include "qgeocoordinateinterpolator_p.h"
-
QT_BEGIN_NAMESPACE
class QGeoCoordinate;
@@ -98,8 +96,6 @@ public:
bool verticalLock() const;
- QSharedPointer<QGeoCoordinateInterpolator> coordinateInterpolator() const;
-
private:
QGeoMapGeometryPrivate *d_ptr;
Q_DECLARE_PRIVATE(QGeoMapGeometry)
diff --git a/src/location/maps/qgeomapimages.cpp b/src/location/maps/qgeomapimages.cpp
index e7f984dc..91e1d0f3 100644
--- a/src/location/maps/qgeomapimages.cpp
+++ b/src/location/maps/qgeomapimages.cpp
@@ -41,8 +41,8 @@
#include "qgeomapimages_p.h"
#include "qgeotilespec.h"
-#include "qgeomap_p.h"
-#include "qgeomappingmanager.h"
+#include "qgeotiledmapdata_p.h"
+#include "qgeotiledmappingmanagerengine.h"
#include "qgeotilecache_p.h"
QT_BEGIN_NAMESPACE
@@ -50,12 +50,11 @@ QT_BEGIN_NAMESPACE
class QGeoMapImagesPrivate
{
public:
- QGeoMapImagesPrivate(QGeoMap *map);
+ QGeoMapImagesPrivate(QGeoTiledMapData *map, QGeoTileCache *cache);
~QGeoMapImagesPrivate();
- QGeoMap *map_;
+ QGeoTiledMapData *map_;
QGeoTileCache *cache_;
- QGeoMappingManager *manager_;
void setVisibleTiles(const QSet<QGeoTileSpec> &tiles);
void tileFetched(const QGeoTileSpec &tile);
@@ -65,22 +64,14 @@ public:
QSet<QGeoTileSpec> requested_;
};
-QGeoMapImages::QGeoMapImages(QGeoMap *map)
- : d_ptr(new QGeoMapImagesPrivate(map))
-{
-}
+QGeoMapImages::QGeoMapImages(QGeoTiledMapData *map, QGeoTileCache *cache)
+ : d_ptr(new QGeoMapImagesPrivate(map, cache)) {}
QGeoMapImages::~QGeoMapImages()
{
delete d_ptr;
}
-void QGeoMapImages::setMappingManager(QGeoMappingManager *manager)
-{
- Q_D(QGeoMapImages);
- d->manager_ = manager;
-}
-
void QGeoMapImages::setVisibleTiles(const QSet<QGeoTileSpec> &tiles)
{
Q_D(QGeoMapImages);
@@ -99,14 +90,9 @@ void QGeoMapImages::tileFetched(const QGeoTileSpec &tile)
d->tileFetched(tile);
}
-QGeoMapImagesPrivate::QGeoMapImagesPrivate(QGeoMap *map)
+QGeoMapImagesPrivate::QGeoMapImagesPrivate(QGeoTiledMapData *map, QGeoTileCache *cache)
: map_(map),
- cache_(0),
- manager_(0)
-{
- if (map_)
- cache_ = map_->tileCache();
-}
+ cache_(cache) {}
QGeoMapImagesPrivate::~QGeoMapImagesPrivate()
{
@@ -139,8 +125,8 @@ void QGeoMapImagesPrivate::setVisibleTiles(const QSet<QGeoTileSpec> &tiles)
requested_ += requestTiles;
if (!requestTiles.isEmpty() || !cancelTiles.isEmpty()) {
- if (manager_) {
- manager_->updateTileRequests(map_, requestTiles, cancelTiles);
+ if (map_) {
+ map_->updateTileRequests(requestTiles, cancelTiles);
}
}
}
diff --git a/src/location/maps/qgeomapimages_p.h b/src/location/maps/qgeomapimages_p.h
index 7eb10172..fed625e1 100644
--- a/src/location/maps/qgeomapimages_p.h
+++ b/src/location/maps/qgeomapimages_p.h
@@ -56,20 +56,19 @@
QT_BEGIN_NAMESPACE
-class QGeoMap;
-class QGeoMappingManager;
+class QGeoTiledMapData;
+class QGeoTiledMappingManagerEngine;
class QGeoTileSpec;
+class QGeoTileCache;
class QGeoMapImagesPrivate;
class QGeoMapImages
{
public:
- QGeoMapImages(QGeoMap *map);
+ QGeoMapImages(QGeoTiledMapData *map, QGeoTileCache *cache);
~QGeoMapImages();
- void setMappingManager(QGeoMappingManager *manager);
-
void setVisibleTiles(const QSet<QGeoTileSpec> &tiles);
QSet<QGeoTileSpec> cachedTiles() const;
diff --git a/src/location/maps/qgeomappingmanager.cpp b/src/location/maps/qgeomappingmanager.cpp
index 13eba293..d142fa37 100644
--- a/src/location/maps/qgeomappingmanager.cpp
+++ b/src/location/maps/qgeomappingmanager.cpp
@@ -43,13 +43,10 @@
#include "qgeomappingmanager_p.h"
#include "qgeomappingmanagerengine.h"
#include "qgeotiledmapreply.h"
+#include "qgeocameracapabilities_p.h"
#include "qgeomap_p.h"
-#include "qgeomap_p_p.h"
-#include "qgeocameracapabilities_p.h"
-#include "qgeotilecache_p.h"
-#include "qgeotilespec.h"
#include <QTimer>
#include <QNetworkProxy>
@@ -57,9 +54,6 @@
QT_BEGIN_NAMESPACE
-#define Q_SHARED_D(type) \
- QSharedPointer< type > d = d_ptr;
-
/*!
\class QGeoMappingManager
\inmodule QtLocation
@@ -87,44 +81,11 @@ QGeoMappingManager::QGeoMappingManager(QGeoMappingManagerEngine *engine, QObject
qFatal("The mapping manager engine that was set for this mapping manager was NULL.");
}
- d_ptr->thread= new QThread;
-
- qRegisterMetaType<QGeoTileSpec>();
-
- connect(d_ptr->engine,
- SIGNAL(tileFinished(QGeoTileSpec,QByteArray,QString)),
- this,
- SLOT(engineTileFinished(QGeoTileSpec,QByteArray,QString)),
- Qt::QueuedConnection);
- connect(d_ptr->engine,
- SIGNAL(tileError(QGeoTileSpec,QString)),
- this,
- SLOT(engineTileError(QGeoTileSpec,QString)),
- Qt::QueuedConnection);
-
connect(d_ptr->engine,
SIGNAL(initialized()),
this,
- SIGNAL(initialized()));
-
- d_ptr->engine->moveToThread(d_ptr->thread);
-
- connect(d_ptr->thread,
- SIGNAL(started()),
- d_ptr->engine,
- SLOT(threadStarted()));
-
- connect(d_ptr->thread,
- SIGNAL(finished()),
- d_ptr->engine,
- SLOT(threadFinished()));
-
- connect(d_ptr->engine,
- SIGNAL(destroyed()),
- d_ptr->thread,
- SLOT(deleteLater()));
-
- QTimer::singleShot(0, d_ptr->thread, SLOT(start()));
+ SIGNAL(initialized()),
+ Qt::QueuedConnection);
}
/*!
@@ -132,6 +93,7 @@ QGeoMappingManager::QGeoMappingManager(QGeoMappingManagerEngine *engine, QObject
*/
QGeoMappingManager::~QGeoMappingManager()
{
+ delete d_ptr;
}
/*!
@@ -150,9 +112,7 @@ QGeoMappingManager::~QGeoMappingManager()
*/
QString QGeoMappingManager::managerName() const
{
- Q_SHARED_D(QGeoMappingManagerPrivate);
- if (!d) return QString();
- return d->engine->managerName();
+ return d_ptr->engine->managerName();
}
/*!
@@ -164,180 +124,27 @@ QString QGeoMappingManager::managerName() const
*/
int QGeoMappingManager::managerVersion() const
{
- Q_SHARED_D(QGeoMappingManagerPrivate);
- if (!d) return 0;
return d_ptr->engine->managerVersion();
}
-void QGeoMappingManager::registerMap(QGeoMap *map)
-{
- Q_SHARED_D(QGeoMappingManagerPrivate);
- if (!d) return;
-
- QGeoTileCache *cache = map->tileCache();
- QSet<QGeoMap*> maps = d->caches.value(cache);
- maps.insert(map);
- d->caches.insert(cache, maps);
-}
-
-void QGeoMappingManager::deregisterMap(QGeoMap *map)
-{
- Q_SHARED_D(QGeoMappingManagerPrivate);
- if (!d) return;
-
- QGeoTileCache *cache = map->tileCache();
- QSet<QGeoMap*> maps = d->caches.value(cache);
- maps.remove(map);
- if (maps.isEmpty()) {
- d->caches.remove(cache);
- } else {
- d->caches.insert(cache, maps);
- }
-
- // clear any tileHash / mapHash entries
- d->mapHash.remove(map);
-
- QHash<QGeoTileSpec, QSet<QGeoMap*> > newTileHash = d->tileHash;
- typedef QHash<QGeoTileSpec, QSet<QGeoMap*> >::const_iterator h_iter;
- h_iter hi = d->tileHash.constBegin();
- h_iter hend = d->tileHash.constEnd();
- for (; hi != hend; ++hi) {
- QSet<QGeoMap*> maps = hi.value();
- if (maps.contains(map)) {
- maps.remove(map);
- if (maps.isEmpty())
- newTileHash.remove(hi.key());
- else
- newTileHash.insert(hi.key(), maps);
- }
- }
- d->tileHash = newTileHash;
-}
-
-void QGeoMappingManager::updateTileRequests(QGeoMap *map,
- const QSet<QGeoTileSpec> &tilesAdded,
- const QSet<QGeoTileSpec> &tilesRemoved)
-{
- Q_SHARED_D(QGeoMappingManagerPrivate);
- if (!d) return;
-
- typedef QSet<QGeoTileSpec>::const_iterator tile_iter;
-
- // add and remove tiles from tileset for this map
-
- QSet<QGeoTileSpec> oldTiles = d->mapHash.value(map);
-
- tile_iter rem = tilesRemoved.constBegin();
- tile_iter remEnd = tilesRemoved.constEnd();
- for (; rem != remEnd; ++rem) {
- oldTiles.remove(*rem);
- }
-
- tile_iter add = tilesAdded.constBegin();
- tile_iter addEnd = tilesAdded.constEnd();
- for (; add != addEnd; ++add) {
- oldTiles.insert(*add);
- }
-
- d->mapHash.insert(map, oldTiles);
-
- // add and remove map from mapset for the tiles
-
- QSet<QGeoTileSpec> reqTiles;
- QSet<QGeoTileSpec> cancelTiles;
-
- rem = tilesRemoved.constBegin();
- for (; rem != remEnd; ++rem) {
- QSet<QGeoMap*> mapSet = d->tileHash.value(*rem);
- mapSet.remove(map);
- if (mapSet.isEmpty()) {
- cancelTiles.insert(*rem);
- d->tileHash.remove(*rem);
- } else {
- d->tileHash.insert(*rem, mapSet);
- }
- }
-
- add = tilesAdded.constBegin();
- for (; add != addEnd; ++add) {
- QSet<QGeoMap*> mapSet = d->tileHash.value(*add);
- if (mapSet.isEmpty()) {
- reqTiles.insert(*add);
- }
- mapSet.insert(map);
- d->tileHash.insert(*add, mapSet);
- }
-
- cancelTiles -= reqTiles;
-
- QMetaObject::invokeMethod(d->engine, "updateTileRequests",
- Qt::QueuedConnection,
- Q_ARG(QSet<QGeoTileSpec>, reqTiles),
- Q_ARG(QSet<QGeoTileSpec>, cancelTiles));
-}
-
-void QGeoMappingManager::engineTileFinished(const QGeoTileSpec &spec, const QByteArray &bytes, const QString &format)
+QGeoCameraCapabilities QGeoMappingManager::cameraCapabilities() const
{
- Q_SHARED_D(QGeoMappingManagerPrivate);
- if (!d) return;
-
- QSet<QGeoTileCache*> caches;
-
- QSet<QGeoMap*> maps = d->tileHash.value(spec);
-
- typedef QSet<QGeoMap*>::const_iterator map_iter;
-
- map_iter map = maps.constBegin();
- map_iter mapEnd = maps.constEnd();
- for (; map != mapEnd; ++map) {
- caches.insert((*map)->tileCache());
-
- QSet<QGeoTileSpec> tileSet = d->mapHash.value(*map);
- tileSet.remove(spec);
- if (tileSet.isEmpty())
- d->mapHash.remove(*map);
- else
- d->mapHash.insert(*map, tileSet);
- }
-
- d->tileHash.remove(spec);
-
- typedef QSet<QGeoTileCache*>::const_iterator cache_iter;
-
- cache_iter cache = caches.constBegin();
- cache_iter cacheEnd = caches.constEnd();
- for (; cache != cacheEnd; ++cache) {
- (*cache)->insert(spec, bytes, format, d->engine->cacheHint());
- }
-
- map = maps.constBegin();
- for (; map != mapEnd; ++map) {
- (*map)->d_ptr->tileFetched(spec);
- }
+ return d_ptr->engine->cameraCapabilities();
}
-void QGeoMappingManager::engineTileError(const QGeoTileSpec &spec, const QString &errorString)
+/*!
+ Returns a new QGeoMap instance which will be managed by this manager.
+*/
+QGeoMap *QGeoMappingManager::createMap(QObject *parent)
{
- emit tileError(spec, errorString);
+ QGeoMapData *mapData = d_ptr->engine->createMapData();
+ QGeoMap *map = new QGeoMap(mapData);
+ return map;
}
QList<QGeoMapType> QGeoMappingManager::supportedMapTypes() const
{
- Q_SHARED_D(QGeoMappingManagerPrivate);
- if (!d) return QList<QGeoMapType>();
- return d->engine->supportedMapTypes();
-}
-
-/*!
- Returns the length of the edge of the tiles returned by this manager.
-
- The tiles are assumed to be square.
-*/
-int QGeoMappingManager::tileSize() const
-{
- Q_SHARED_D(QGeoMappingManagerPrivate);
- if (!d) return -1;
- return d->engine->tileSize();
+ return d_ptr->engine->supportedMapTypes();
}
/*!
@@ -347,19 +154,7 @@ int QGeoMappingManager::tileSize() const
*/
bool QGeoMappingManager::isInitialized() const
{
- Q_SHARED_D(QGeoMappingManagerPrivate);
- if (!d) return false;
- return d->engine->isInitialized();
-}
-
-/*!
- Returns the camera capabilities supported by this manager.
-*/
-QGeoCameraCapabilities QGeoMappingManager::cameraCapabilities() const
-{
- Q_SHARED_D(QGeoMappingManagerPrivate);
- if (!d) return QGeoCameraCapabilities();
- return d->engine->cameraCapabilities();
+ return d_ptr->engine->isInitialized();
}
/*!
@@ -372,9 +167,7 @@ QGeoCameraCapabilities QGeoMappingManager::cameraCapabilities() const
*/
void QGeoMappingManager::setLocale(const QLocale &locale)
{
- Q_SHARED_D(QGeoMappingManagerPrivate);
- if (!d) return;
- d->engine->setLocale(locale);
+ d_ptr->engine->setLocale(locale);
}
/*!
@@ -383,18 +176,9 @@ void QGeoMappingManager::setLocale(const QLocale &locale)
*/
QLocale QGeoMappingManager::locale() const
{
- Q_SHARED_D(QGeoMappingManagerPrivate);
- if (!d) return QLocale();
return d_ptr->engine->locale();
}
-QGeoMappingManager::CacheAreas QGeoMappingManager::cacheHint() const
-{
- Q_SHARED_D(QGeoMappingManagerPrivate);
- if (!d) return QGeoMappingManager::CacheAreas();
- return d_ptr->engine->cacheHint();
-}
-
/*******************************************************************************
*******************************************************************************/
@@ -403,7 +187,6 @@ QGeoMappingManagerPrivate::QGeoMappingManagerPrivate()
QGeoMappingManagerPrivate::~QGeoMappingManagerPrivate()
{
- thread->quit();
}
#include "moc_qgeomappingmanager.cpp"
diff --git a/src/location/maps/qgeomappingmanager.h b/src/location/maps/qgeomappingmanager.h
index aa877985..995288d9 100644
--- a/src/location/maps/qgeomappingmanager.h
+++ b/src/location/maps/qgeomappingmanager.h
@@ -45,7 +45,6 @@
#include <QObject>
#include <QSize>
#include <QPair>
-#include <QSharedPointer>
#include <QtLocation/qlocationglobal.h>
#include "qgeomaptype.h"
@@ -53,75 +52,50 @@ QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
+class QGeoMap;
class QLocale;
class QGeoBoundingBox;
-class QGeoCameraCapabilities;
class QGeoCoordinate;
class QGeoMappingManagerPrivate;
class QGeoMapRequestOptions;
class QGeoMappingManagerEngine;
-class QGeoTiledMapReply;
+class QGeoCameraCapabilities;
-class QGeoTileSpec;
-class QGeoMap;
class Q_LOCATION_EXPORT QGeoMappingManager : public QObject
{
Q_OBJECT
public:
- enum CacheArea {
- DiskCache = 0x01,
- MemoryCache = 0x02,
- TextureCache = 0x04,
- AllCaches = 0xFF
- };
- Q_DECLARE_FLAGS(CacheAreas, CacheArea)
-
~QGeoMappingManager();
QString managerName() const;
int managerVersion() const;
- void registerMap(QGeoMap *map);
- void deregisterMap(QGeoMap *map);
-
- void updateTileRequests(QGeoMap *map,
- const QSet<QGeoTileSpec> &tilesAdded,
- const QSet<QGeoTileSpec> &tilesRemoved);
+ QGeoMap* createMap(QObject *parent);
QList<QGeoMapType> supportedMapTypes() const;
- int tileSize() const;
-
bool isInitialized() const;
QGeoCameraCapabilities cameraCapabilities() const;
- CacheAreas cacheHint() const;
-
void setLocale(const QLocale &locale);
QLocale locale() const;
-private Q_SLOTS:
- void engineTileFinished(const QGeoTileSpec &spec, const QByteArray &bytes, const QString &format);
- void engineTileError(const QGeoTileSpec &spec, const QString &errorString);
-
Q_SIGNALS:
- void tileError(const QGeoTileSpec &spec, const QString &errorString);
void initialized();
-private:
+protected:
QGeoMappingManager(QGeoMappingManagerEngine *engine, QObject *parent = 0);
- QSharedPointer<QGeoMappingManagerPrivate> d_ptr;
+private:
+ QGeoMappingManagerPrivate* d_ptr;
Q_DISABLE_COPY(QGeoMappingManager)
friend class QGeoServiceProvider;
};
-Q_DECLARE_OPERATORS_FOR_FLAGS(QGeoMappingManager::CacheAreas)
-
QT_END_NAMESPACE
QT_END_HEADER
diff --git a/src/location/maps/qgeomappingmanager_p.h b/src/location/maps/qgeomappingmanager_p.h
index dcdb346d..df61fb0d 100644
--- a/src/location/maps/qgeomappingmanager_p.h
+++ b/src/location/maps/qgeomappingmanager_p.h
@@ -61,24 +61,14 @@
QT_BEGIN_NAMESPACE
-class QGeoMap;
-class QGeoTileCache;
-class QGeoTileSpec;
-class QGeoMappingManagerEngine;
-
class QGeoMappingManagerPrivate
{
public:
QGeoMappingManagerPrivate();
~QGeoMappingManagerPrivate();
- QThread *thread;
QGeoMappingManagerEngine *engine;
- QHash<QGeoTileCache*, QSet<QGeoMap*> > caches;
- QHash<QGeoMap*, QSet<QGeoTileSpec> > mapHash;
- QHash<QGeoTileSpec, QSet<QGeoMap*> > tileHash;
-
private:
Q_DISABLE_COPY(QGeoMappingManagerPrivate)
};
diff --git a/src/location/maps/qgeomappingmanagerengine.cpp b/src/location/maps/qgeomappingmanagerengine.cpp
index 3626e94c..a91cdd64 100644
--- a/src/location/maps/qgeomappingmanagerengine.cpp
+++ b/src/location/maps/qgeomappingmanagerengine.cpp
@@ -61,23 +61,11 @@ QT_BEGIN_NAMESPACE
*/
/*!
- Constructs a new engine with the specified \a parent, using \a parameters
- to pass any implementation specific data to the engine.
+ Constructs a new engine with the specified \a parent.
*/
-QGeoMappingManagerEngine::QGeoMappingManagerEngine(const QMap<QString, QVariant> &parameters, QObject *parent)
+QGeoMappingManagerEngine::QGeoMappingManagerEngine(QObject *parent)
: QObject(parent),
- d_ptr(new QGeoMappingManagerEnginePrivate())
-{
- d_ptr->parameters = parameters;
- d_ptr->initialized = false;
-}
-
-/*!
- \internal
-*/
-QGeoMappingManagerEngine::QGeoMappingManagerEngine(QGeoMappingManagerEnginePrivate *dd, QObject *parent)
- : QObject(parent),
- d_ptr(dd) {}
+ d_ptr(new QGeoMappingManagerEnginePrivate()) {}
/*!
Destroys this engine.
@@ -88,169 +76,18 @@ QGeoMappingManagerEngine::~QGeoMappingManagerEngine()
delete d;
}
-QMap<QString, QVariant> QGeoMappingManagerEngine::parameters() const
-{
- Q_D(const QGeoMappingManagerEngine);
- return d->parameters;
-}
-
/*!
- Initializes the engine. Subclasses of QGeoMappingManagerEngine may
- implement this function to perform (potentially asynchronous) initialization.
-
- Static/already known data (such as min/max zoom levels) is better to
- initialize already earlier (e.g. in constructor).
-
- Once subclasses are done with initialization, they should call this baseclass
- implementation of init().
+ Marks the engine as initialized. Subclasses of QGeoMappingManagerEngine are to
+ call this method after performing implementation-specific initializatioin within
+ the constructor.
*/
-void QGeoMappingManagerEngine::init()
+void QGeoMappingManagerEngine::engineInitialized()
{
Q_D(QGeoMappingManagerEngine);
- if (d->stopped_)
- return;
d->initialized = true;
emit initialized();
}
-void QGeoMappingManagerEngine::threadStarted()
-{
- Q_D(QGeoMappingManagerEngine);
-
- if (d->stopped_)
- return;
-
- init();
-
- d->timer_ = new QTimer(this);
-
- d->timer_->setInterval(0);
-
- connect(d->timer_,
- SIGNAL(timeout()),
- this,
- SLOT(requestNextTile()));
-
- d->started_ = true;
- if (!d->queue_.isEmpty())
- d->timer_->start();
-}
-
-void QGeoMappingManagerEngine::threadFinished()
-{
- Q_D(QGeoMappingManagerEngine);
- d->stopped_ = true;
- disconnect(d->timer_);
- d->timer_->stop();
- this->deleteLater();
-}
-
-void QGeoMappingManagerEngine::updateTileRequests(const QSet<QGeoTileSpec> &tilesAdded,
- const QSet<QGeoTileSpec> &tilesRemoved)
-{
- Q_D(QGeoMappingManagerEngine);
-
- if (d->stopped_)
- return;
-
- cancelTileRequests(tilesRemoved);
-
- d->queue_ += tilesAdded.toList();
-
- if (!d->queue_.empty())
- d->timer_->start();
-}
-
-void QGeoMappingManagerEngine::cancelTileRequests(const QSet<QGeoTileSpec> &tiles)
-{
- Q_D(QGeoMappingManagerEngine);
-
- typedef QSet<QGeoTileSpec>::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();
- reply->deleteLater();
- }
- d->queue_.removeAll(*tile);
- }
-
- if (d->queue_.isEmpty())
- d->timer_->stop();
-}
-
-void QGeoMappingManagerEngine::requestNextTile()
-{
- Q_D(QGeoMappingManagerEngine);
-
- if (d->stopped_)
- return;
-
- if (d->queue_.isEmpty()) {
- d->timer_->stop();
- return;
- }
-
- QGeoTileSpec ts = d->queue_.takeFirst();
-
- QGeoTiledMapReply *reply = getTileImage(ts);
-
- if (reply->isFinished()) {
- handleReply(reply, ts);
- } else {
- connect(reply,
- SIGNAL(finished()),
- this,
- SLOT(finished()));
-
- d->invmap_.insert(ts, reply);
- }
-
- if (d->queue_.isEmpty())
- d->timer_->stop();
-}
-
-void QGeoMappingManagerEngine::finished()
-{
- Q_D(QGeoMappingManagerEngine);
-
- QGeoTiledMapReply *reply = qobject_cast<QGeoTiledMapReply*>(sender());
- if (!reply)
- return;
-
- QGeoTileSpec spec = reply->tileSpec();
-
- if (!d->invmap_.contains(spec)) {
- reply->deleteLater();
- return;
- }
-
- d->invmap_.remove(spec);
-
- handleReply(reply, spec);
-}
-
-void QGeoMappingManagerEngine::handleReply(QGeoTiledMapReply *reply, const QGeoTileSpec &spec)
-{
- Q_D(QGeoMappingManagerEngine);
-
- if (d->stopped_) {
- reply->deleteLater();
- return;
- }
-
- if (reply->error() == QGeoTiledMapReply::NoError) {
- emit tileFinished(spec, reply->mapImageData(), reply->mapImageFormat());
- } else {
- emit tileError(spec, reply->errorString());
- }
-
- reply->deleteLater();
-}
-
/*!
Sets the name which this engine implementation uses to distinguish itself
from the implementations provided by other plugins to \a managerName.
@@ -315,19 +152,18 @@ void QGeoMappingManagerEngine::setSupportedMapTypes(const QList<QGeoMapType> &su
d->supportedMapTypes = supportedMapTypes;
}
-void QGeoMappingManagerEngine::setTileSize(int tileSize)
+QGeoCameraCapabilities QGeoMappingManagerEngine::cameraCapabilities()
{
Q_D(QGeoMappingManagerEngine);
- d->tileSize = tileSize;
+ return d->capabilities_;
}
-int QGeoMappingManagerEngine::tileSize() const
+void QGeoMappingManagerEngine::setCameraCapabilities(const QGeoCameraCapabilities &capabilities)
{
- Q_D(const QGeoMappingManagerEngine);
- return d->tileSize;
+ Q_D(QGeoMappingManagerEngine);
+ d->capabilities_ = capabilities;
}
-
/*!
Return whether the engine has been initialized and is ready to be used.
*/
@@ -339,45 +175,7 @@ bool QGeoMappingManagerEngine::isInitialized() const
}
/*!
- \fn void QGeoMappingManagerEngine::initialized()
-
- This signal is emitted when the mapping manager has been initialized
- and is ready to be used.
-
- Subclasses of QGeoMappingManagerEngine should call the
- QGeoMappingManagerEngine init() when they have initialized themselves.
-*/
-
-/*!
- Sets the camera capabilities associated with this engine to \a cameraCapabilities.
-
- This is used to limit the modifications applied to the camera associated with
- maps created for use with this plugin.
-
- Since different plugins support different ranges of zoom levels, and
- have different capabilities with respect to the support of things like
- bearing and tilting, this information is important.
-
- Subclasses of QGeoMappingManagerEngine should use this function to ensure
- cameraCapabilities() provides accurate information.
-*/
-void QGeoMappingManagerEngine::setCameraCapabilities(const QGeoCameraCapabilities &cameraCapabilities)
-{
- Q_D(QGeoMappingManagerEngine);
- d->cameraCapabilities_ = cameraCapabilities;
-}
-
-/*!
- Returns the camera capabilities associated with this engine.
-*/
-QGeoCameraCapabilities QGeoMappingManagerEngine::cameraCapabilities() const
-{
- Q_D(const QGeoMappingManagerEngine);
- return d->cameraCapabilities_;
-}
-
-/*!
- Sets the locale to be used by this manager to \a locale.
+ Sets the locale to be used by the this manager to \a locale.
If this mapping manager supports returning map labels
in different languages, they will be returned in the language of \a locale.
@@ -398,26 +196,12 @@ QLocale QGeoMappingManagerEngine::locale() const
return d_ptr->locale;
}
-QGeoMappingManager::CacheAreas QGeoMappingManagerEngine::cacheHint() const
-{
- Q_D(const QGeoMappingManagerEngine);
- return d->cacheHint;
-}
-
-void QGeoMappingManagerEngine::setCacheHint(QGeoMappingManager::CacheAreas cacheHint)
-{
- Q_D(QGeoMappingManagerEngine);
- d->cacheHint = cacheHint;
-}
-
/*******************************************************************************
*******************************************************************************/
QGeoMappingManagerEnginePrivate::QGeoMappingManagerEnginePrivate()
: managerVersion(-1),
- cacheHint(QGeoMappingManager::AllCaches),
- started_(false),
- stopped_(false) {}
+ initialized(false) {}
QGeoMappingManagerEnginePrivate::~QGeoMappingManagerEnginePrivate() {}
diff --git a/src/location/maps/qgeomappingmanagerengine.h b/src/location/maps/qgeomappingmanagerengine.h
index 4f5a97b7..5a14b1ee 100644
--- a/src/location/maps/qgeomappingmanagerengine.h
+++ b/src/location/maps/qgeomappingmanagerengine.h
@@ -63,24 +63,23 @@ QT_BEGIN_NAMESPACE
class QLocale;
class QGeoBoundingBox;
-class QGeoCameraCapabilities;
class QGeoCoordinate;
class QGeoMappingManagerPrivate;
class QGeoMapRequestOptions;
class QGeoMappingManagerEnginePrivate;
-
-class QGeoTiledMapReply;
-class QGeoTileSpec;
+class QGeoMapData;
class Q_LOCATION_EXPORT QGeoMappingManagerEngine : public QObject
{
Q_OBJECT
public:
- QGeoMappingManagerEngine(const QMap<QString, QVariant> &parameters, QObject *parent = 0);
+ QGeoMappingManagerEngine(QObject *parent = 0);
virtual ~QGeoMappingManagerEngine();
+ virtual QGeoMapData* createMapData() = 0;
+
QMap<QString, QVariant> parameters() const;
QString managerName() const;
@@ -88,50 +87,24 @@ public:
QList<QGeoMapType> supportedMapTypes() const;
- int tileSize() const;
-
- QGeoCameraCapabilities cameraCapabilities() const;
-
- QGeoMappingManager::CacheAreas cacheHint() const;
+ QGeoCameraCapabilities cameraCapabilities();
void setLocale(const QLocale &locale);
QLocale locale() const;
- virtual void init();
bool isInitialized() const;
-public Q_SLOTS:
- void threadStarted();
- void threadFinished();
- void updateTileRequests(const QSet<QGeoTileSpec> &tilesAdded, const QSet<QGeoTileSpec> &tilesRemoved);
- void cancelTileRequests(const QSet<QGeoTileSpec> &tiles);
-
-private Q_SLOTS:
- void requestNextTile();
- void finished();
-
Q_SIGNALS:
- void tileFinished(const QGeoTileSpec &spec, const QByteArray &bytes, const QString &format);
- void tileError(const QGeoTileSpec &spec, const QString &errorString);
void initialized();
protected:
- QGeoMappingManagerEngine(QGeoMappingManagerEnginePrivate *dd, QObject *parent = 0);
-
void setSupportedMapTypes(const QList<QGeoMapType> &supportedMapTypes);
+ void setCameraCapabilities(const QGeoCameraCapabilities &capabilities);
- void setTileSize(int tileSize);
-
- void setCameraCapabilities(const QGeoCameraCapabilities &cameraCapabilities);
-
- void setCacheHint(QGeoMappingManager::CacheAreas cacheHint);
-
- QGeoMappingManagerEnginePrivate* d_ptr;
+ void engineInitialized();
private:
- virtual QGeoTiledMapReply* getTileImage(const QGeoTileSpec &spec) = 0;
-
- void handleReply(QGeoTiledMapReply *reply, const QGeoTileSpec &spec);
+ QGeoMappingManagerEnginePrivate* d_ptr;
void setManagerName(const QString &managerName);
void setManagerVersion(int managerVersion);
diff --git a/src/location/maps/qgeomappingmanagerengine_p.h b/src/location/maps/qgeomappingmanagerengine_p.h
index cca76aef..8d986d20 100644
--- a/src/location/maps/qgeomappingmanagerengine_p.h
+++ b/src/location/maps/qgeomappingmanagerengine_p.h
@@ -72,25 +72,16 @@ class QGeoMappingManagerEnginePrivate
{
public:
QGeoMappingManagerEnginePrivate();
- virtual ~QGeoMappingManagerEnginePrivate();
-
- QMap<QString, QVariant> parameters;
+ ~QGeoMappingManagerEnginePrivate();
QString managerName;
int managerVersion;
QList<QGeoMapType> supportedMapTypes;
- int tileSize;
- QGeoCameraCapabilities cameraCapabilities_;
- QGeoMappingManager::CacheAreas cacheHint;
+ QGeoCameraCapabilities capabilities_;
QLocale locale;
- bool started_;
bool initialized;
- bool stopped_;
- QTimer *timer_;
- QList<QGeoTileSpec> queue_;
- QHash<QGeoTileSpec, QGeoTiledMapReply*> invmap_;
private:
Q_DISABLE_COPY(QGeoMappingManagerEnginePrivate)
diff --git a/src/location/maps/qgeotilecache.cpp b/src/location/maps/qgeotilecache.cpp
index bbbff6c1..e689013c 100644
--- a/src/location/maps/qgeotilecache.cpp
+++ b/src/location/maps/qgeotilecache.cpp
@@ -210,7 +210,7 @@ QGLTexture2D* QGeoTileCache::get(const QGeoTileSpec &spec)
void QGeoTileCache::insert(const QGeoTileSpec &spec,
const QByteArray &bytes,
const QString &format,
- QGeoMappingManager::CacheAreas areas)
+ QGeoTiledMappingManagerEngine::CacheAreas areas)
{
keys_.insert(spec);
@@ -221,7 +221,7 @@ void QGeoTileCache::insert(const QGeoTileSpec &spec,
return;
}
- if (areas & QGeoMappingManager::DiskCache) {
+ if (areas & QGeoTiledMappingManagerEngine::DiskCache) {
QString filename = tileSpecToFilename(spec, format, directory_);
QFile file(filename);
@@ -232,11 +232,11 @@ void QGeoTileCache::insert(const QGeoTileSpec &spec,
addToDiskCache(spec, filename);
}
- if (areas & QGeoMappingManager::MemoryCache) {
+ if (areas & QGeoTiledMappingManagerEngine::MemoryCache) {
// addToMemoryCache(spec, pixmap);
}
- if (areas & QGeoMappingManager::TextureCache) {
+ if (areas & QGeoTiledMappingManagerEngine::TextureCache) {
addToTextureCache(spec, pixmap);
}
}
diff --git a/src/location/maps/qgeotilecache_p.h b/src/location/maps/qgeotilecache_p.h
index a8c451c1..33120a75 100644
--- a/src/location/maps/qgeotilecache_p.h
+++ b/src/location/maps/qgeotilecache_p.h
@@ -58,12 +58,10 @@
#include <QCache>
#include <QSet>
-#include "qgeomappingmanager.h"
+#include "qgeotiledmappingmanagerengine.h"
QT_BEGIN_NAMESPACE
-class QGeoMappingManager;
-
class QGeoTileSpec;
class QGeoTile;
@@ -107,7 +105,7 @@ public:
void insert(const QGeoTileSpec &spec,
const QByteArray &bytes,
const QString &format,
- QGeoMappingManager::CacheAreas areas = QGeoMappingManager::AllCaches);
+ QGeoTiledMappingManagerEngine::CacheAreas areas = QGeoTiledMappingManagerEngine::AllCaches);
void handleError(const QGeoTileSpec &spec, const QString &errorString);
private:
@@ -121,7 +119,6 @@ private:
static QGeoTileSpec filenameToTileSpec(const QString &filename);
QString directory_;
-
QSet<QGeoTileSpec> keys_;
QCache<QGeoTileSpec, TileDisk > diskCache_;
QCache<QGeoTileSpec, TileMemory > memoryCache_;
diff --git a/src/location/maps/qgeotiledmapdata.cpp b/src/location/maps/qgeotiledmapdata.cpp
new file mode 100644
index 00000000..909bf93c
--- /dev/null
+++ b/src/location/maps/qgeotiledmapdata.cpp
@@ -0,0 +1,322 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtLocation module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "qgeotiledmapdata_p.h"
+#include "qgeotiledmapdata_p_p.h"
+
+#include "qgeotiledmappingmanagerengine.h"
+#include "qgeotilecache_p.h"
+#include "qgeotilespec.h"
+#include "qgeoprojection_p.h"
+
+#include "qgeocameratiles_p.h"
+#include "qgeomapimages_p.h"
+#include "qgeomapgeometry_p.h"
+#include "qgeocoordinateinterpolator_p.h"
+#include "qgeoprojection_p.h"
+#include "qdoublevector2d_p.h"
+#include "qgeocameracapabilities_p.h"
+
+#include <QMutex>
+#include <QMap>
+
+#include <qnumeric.h>
+
+#include <qglscenenode.h>
+#include <qgeometrydata.h>
+#include <qglbuilder.h>
+#include <Qt3D/qglpainter.h>
+#include <Qt3D/qgeometrydata.h>
+#include <Qt3D/qglbuilder.h>
+#include <Qt3D/qglcamera.h>
+#include <Qt3D/qglsubsurface.h>
+
+#include <cmath>
+
+QT_BEGIN_NAMESPACE
+
+class QGeoCoordinateInterpolator2D : public QGeoCoordinateInterpolator
+{
+public:
+ QGeoCoordinateInterpolator2D();
+ virtual ~QGeoCoordinateInterpolator2D();
+
+ virtual QGeoCoordinate interpolate(const QGeoCoordinate &start, const QGeoCoordinate &end, qreal progress);
+};
+
+QGeoCoordinateInterpolator2D::QGeoCoordinateInterpolator2D() {}
+
+QGeoCoordinateInterpolator2D::~QGeoCoordinateInterpolator2D() {}
+
+QGeoCoordinate QGeoCoordinateInterpolator2D::interpolate(const QGeoCoordinate &start, const QGeoCoordinate &end, qreal progress)
+{
+ if (start == end) {
+ if (progress < 0.5) {
+ return start;
+ } else {
+ return end;
+ }
+ }
+
+ QGeoCoordinate s2 = start;
+ QGeoCoordinate e2 = end;
+ QDoubleVector2D s = QGeoProjection::coordToMercator(s2);
+ QDoubleVector2D e = QGeoProjection::coordToMercator(e2);
+
+ double x = s.x();
+
+ if (0.5 < qAbs(e.x() - s.x())) {
+ // handle dateline crossing
+ double ex = e.x();
+ double sx = s.x();
+ if (ex < sx)
+ sx -= 1.0;
+ else if (sx < ex)
+ ex -= 1.0;
+
+ x = (1.0 - progress) * sx + progress * ex;
+
+ if (!qFuzzyIsNull(x) && (x < 0.0))
+ x += 1.0;
+
+ } else {
+ x = (1.0 - progress) * s.x() + progress * e.x();
+ }
+
+ double y = (1.0 - progress) * s.y() + progress * e.y();
+
+ QGeoCoordinate result = QGeoProjection::mercatorToCoord(QDoubleVector2D(x, y));
+ result.setAltitude((1.0 - progress) * start.altitude() + progress * end.altitude());
+ return result;
+}
+
+//------------------------
+//------------------------
+
+QGeoTiledMapData::QGeoTiledMapData(QGeoTiledMappingManagerEngine *engine, QObject *parent)
+ : QGeoMapData(engine, parent)
+{
+ d_ptr = new QGeoTiledMapDataPrivate(this, engine);
+ engine->registerMap(this);
+ setCoordinateInterpolator(QSharedPointer<QGeoCoordinateInterpolator>(new QGeoCoordinateInterpolator2D()));
+}
+
+QGeoTiledMapData::~QGeoTiledMapData()
+{
+ delete d_ptr;
+}
+
+void QGeoTiledMapData::tileFetched(const QGeoTileSpec &spec)
+{
+ Q_D(QGeoTiledMapData);
+ d->tileFetched(spec);
+}
+
+QGeoTileCache* QGeoTiledMapData::tileCache()
+{
+ Q_D(QGeoTiledMapData);
+ return d->tileCache();
+}
+
+void QGeoTiledMapData::paintGL(QGLPainter *painter)
+{
+ Q_D(QGeoTiledMapData);
+ d->paintGL(painter);
+}
+
+void QGeoTiledMapData::mapResized(int width, int height)
+{
+ Q_D(QGeoTiledMapData);
+ d->resized(width, height);
+}
+
+void QGeoTiledMapData::changeCameraData(const QGeoCameraData &oldCameraData)
+{
+ Q_D(QGeoTiledMapData);
+ d->changeCameraData(oldCameraData);
+}
+
+void QGeoTiledMapData::changeActiveMapType(const QGeoMapType mapType)
+{
+ Q_D(QGeoTiledMapData);
+ d->changeActiveMapType(mapType);
+}
+
+QGeoCoordinate QGeoTiledMapData::screenPositionToCoordinate(const QPointF &pos, bool clipToViewport) const
+{
+ Q_D(const QGeoTiledMapData);
+ if (clipToViewport) {
+ int w = width();
+ int h = height();
+
+ if ((pos.x() < 0) || (w < pos.x()) || (pos.y() < 0) || (h < pos.y()))
+ return QGeoCoordinate();
+ }
+
+ return d->screenPositionToCoordinate(pos);
+}
+
+QPointF QGeoTiledMapData::coordinateToScreenPosition(const QGeoCoordinate &coordinate, bool clipToViewport) const
+{
+ Q_D(const QGeoTiledMapData);
+ QPointF pos = d->coordinateToScreenPosition(coordinate);
+
+ if (clipToViewport) {
+ int w = width();
+ int h = height();
+
+ if ((pos.x() < 0) || (w < pos.x()) || (pos.y() < 0) || (h < pos.y()))
+ return QPointF(qQNaN(), qQNaN());
+ }
+
+ return pos;
+}
+
+void QGeoTiledMapData::updateTileRequests(const QSet<QGeoTileSpec> &tilesAdded, const QSet<QGeoTileSpec> &tilesRemoved)
+{
+ static_cast<QGeoTiledMappingManagerEngine*>(engine())->updateTileRequests(this, tilesAdded, tilesRemoved);
+}
+
+QGeoTiledMapDataPrivate::QGeoTiledMapDataPrivate(QGeoTiledMapData *parent, QGeoTiledMappingManagerEngine *engine)
+ : map_(parent),
+ cache_(engine->tileCache()),
+ cameraTiles_(new QGeoCameraTiles()),
+ mapGeometry_(new QGeoMapGeometry()),
+ mapImages_(new QGeoMapImages(parent, engine->tileCache()))
+{
+ cameraTiles_->setMaximumZoomLevel(static_cast<int>(ceil(engine->cameraCapabilities().maximumZoomLevel())));
+ cameraTiles_->setTileSize(engine->tileSize().width());
+ cameraTiles_->setPluginString(map_->pluginString());
+
+ mapGeometry_->setTileSize(engine->tileSize().width());
+}
+
+QGeoTiledMapDataPrivate::~QGeoTiledMapDataPrivate()
+{
+ // controller_ is a child of map_, don't need to delete it here
+
+ delete mapImages_;
+ delete mapGeometry_;
+ delete cameraTiles_;
+
+ // TODO map items are not deallocated!
+ // However: how to ensure this is done in rendering thread?
+}
+
+QGeoTileCache* QGeoTiledMapDataPrivate::tileCache()
+{
+ return cache_;
+}
+
+void QGeoTiledMapDataPrivate::changeCameraData(const QGeoCameraData &oldCameraData)
+{
+ double lat = oldCameraData.center().latitude();
+
+ if (mapGeometry_->verticalLock()) {
+ QGeoCoordinate coord = map_->cameraData().center();
+ coord.setLatitude(lat);
+ map_->cameraData().setCenter(coord);
+ }
+
+ cameraTiles_->setCamera(map_->cameraData());
+ visibleTiles_ = cameraTiles_->tiles();
+
+ mapGeometry_->setCameraData(map_->cameraData());
+ mapGeometry_->setVisibleTiles(visibleTiles_);
+
+ if (mapImages_) {
+ mapImages_->setVisibleTiles(visibleTiles_);
+
+ //QSet<QGeoTileSpec> cachedTiles = mapImages_->cachedTiles();
+ // TODO make this more efficient
+ QSet<QGeoTileSpec> cachedTiles = visibleTiles_;
+
+ typedef QSet<QGeoTileSpec>::const_iterator iter;
+ iter i = cachedTiles.constBegin();
+ iter end = cachedTiles.constEnd();
+ for (; i != end; ++i) {
+ QGeoTileSpec tile = *i;
+ if (cache_->contains(tile))
+ mapGeometry_->addTile(tile, cache_->get(tile));
+ }
+
+ if (!cachedTiles.isEmpty())
+ map_->update();
+
+ }
+}
+
+void QGeoTiledMapDataPrivate::changeActiveMapType(const QGeoMapType mapType)
+{
+ cameraTiles_->setMapType(mapType);
+ visibleTiles_ = cameraTiles_->tiles();
+}
+
+void QGeoTiledMapDataPrivate::resized(int width, int height)
+{
+ cameraTiles_->setScreenSize(QSize(width, height));
+ mapGeometry_->setScreenSize(QSize(width, height));
+ map_->setCameraData(map_->cameraData());
+}
+
+void QGeoTiledMapDataPrivate::tileFetched(const QGeoTileSpec &spec)
+{
+ if (cache_->contains(spec))
+ mapGeometry_->addTile(spec, cache_->get(spec));
+ mapImages_->tileFetched(spec);
+ map_->update();
+}
+
+void QGeoTiledMapDataPrivate::paintGL(QGLPainter *painter)
+{
+ mapGeometry_->paintGL(painter);
+}
+
+QGeoCoordinate QGeoTiledMapDataPrivate::screenPositionToCoordinate(const QPointF &pos) const
+{
+ return QGeoProjection::mercatorToCoord(mapGeometry_->screenPositionToMercator(pos));
+}
+
+QPointF QGeoTiledMapDataPrivate::coordinateToScreenPosition(const QGeoCoordinate &coordinate) const
+{
+ return mapGeometry_->mercatorToScreenPosition(QGeoProjection::coordToMercator(coordinate));
+}
+
+QT_END_NAMESPACE
diff --git a/src/location/maps/qgeotiledmapdata_p.h b/src/location/maps/qgeotiledmapdata_p.h
new file mode 100644
index 00000000..db262cc7
--- /dev/null
+++ b/src/location/maps/qgeotiledmapdata_p.h
@@ -0,0 +1,102 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtLocation module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef QGEOTILEDMAPDATA_P_H
+#define QGEOTILEDMAPDATA_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QObject>
+
+#include "qgeomapdata_p.h"
+#include "qgeocameradata_p.h"
+#include "qgeomaptype.h"
+
+QT_BEGIN_NAMESPACE
+
+class QGeoTileSpec;
+class QGeoTileCache;
+class QGeoTiledMapDataPrivate;
+class QGeoTiledMappingManagerEngine;
+class MapItem;
+
+class QPointF;
+
+class Q_LOCATION_EXPORT QGeoTiledMapData : public QGeoMapData
+{
+ Q_OBJECT
+public:
+ QGeoTiledMapData(QGeoTiledMappingManagerEngine *engine, QObject *parent);
+ virtual ~QGeoTiledMapData();
+
+ QGeoTileCache* tileCache();
+
+ void paintGL(QGLPainter *painter);
+
+ void tileFetched(const QGeoTileSpec &spec);
+
+ QGeoCoordinate screenPositionToCoordinate(const QPointF &pos, bool clipToViewport = true) const;
+ QPointF coordinateToScreenPosition(const QGeoCoordinate &coordinate, bool clipToViewport = true) const;
+
+ void updateTileRequests(const QSet<QGeoTileSpec> &tilesAdded, const QSet<QGeoTileSpec> &tilesRemoved);
+
+protected:
+ void mapResized(int width, int height);
+ void changeCameraData(const QGeoCameraData &oldCameraData);
+ void changeActiveMapType(const QGeoMapType mapType);
+
+private:
+ QGeoTiledMapDataPrivate *d_ptr;
+ Q_DECLARE_PRIVATE(QGeoTiledMapData)
+
+};
+
+QT_END_NAMESPACE
+
+#endif // QGEOMAP_P_H
diff --git a/src/location/maps/qgeotiledmapdata_p_p.h b/src/location/maps/qgeotiledmapdata_p_p.h
new file mode 100644
index 00000000..81aed64a
--- /dev/null
+++ b/src/location/maps/qgeotiledmapdata_p_p.h
@@ -0,0 +1,116 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtLocation module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef QGEOTILEDMAPDATA_P_P_H
+#define QGEOTILEDMAPDATA_P_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QList>
+#include <QSet>
+#include <QVector>
+#include <QPair>
+#include <QPolygonF>
+#include <QSizeF>
+#include <QMatrix4x4>
+#include <QString>
+#include <QSharedPointer>
+
+#include "qgeocameradata_p.h"
+#include "qgeomaptype.h"
+
+#include "qdoublevector3d_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class QGeoTile;
+class QGeoTileCache;
+class QGeoTileSpec;
+class QGeoMapController;
+class QGeoProjection;
+
+class QGeoCameraTiles;
+class QGeoMapImages;
+class QGeoMapGeometry;
+
+class QGLSceneNode;
+
+class QGeoTiledMapDataPrivate
+{
+public:
+ QGeoTiledMapDataPrivate(QGeoTiledMapData *parent, QGeoTiledMappingManagerEngine *engine);
+ ~QGeoTiledMapDataPrivate();
+
+ QGeoTileCache* tileCache();
+
+ void paintGL(QGLPainter *painter);
+
+ void changeCameraData(const QGeoCameraData &oldCameraData);
+ void changeActiveMapType(const QGeoMapType mapType);
+ void resized(int width, int height);
+
+ QGeoCoordinate screenPositionToCoordinate(const QPointF &pos) const;
+ QPointF coordinateToScreenPosition(const QGeoCoordinate &coordinate) const;
+
+ void tileFetched(const QGeoTileSpec &spec);
+
+private:
+ QGeoTiledMapData *map_;
+ QGeoTileCache* cache_;
+
+ QSet<QGeoTileSpec> visibleTiles_;
+
+ QGeoCameraTiles *cameraTiles_;
+ QGeoMapGeometry *mapGeometry_;
+ QGeoMapImages *mapImages_;
+};
+
+QT_END_NAMESPACE
+
+#endif // QGEOTILEDMAP_P_P_H
diff --git a/src/location/maps/qgeotiledmappingmanagerengine.cpp b/src/location/maps/qgeotiledmappingmanagerengine.cpp
new file mode 100644
index 00000000..023170e4
--- /dev/null
+++ b/src/location/maps/qgeotiledmappingmanagerengine.cpp
@@ -0,0 +1,304 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtLocation module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qgeotiledmappingmanagerengine.h"
+#include "qgeotiledmappingmanagerengine_p.h"
+#include "qgeotilefetcher.h"
+
+
+#include "qgeotiledmapdata_p.h"
+#include "qgeotilecache_p.h"
+#include "qgeotilespec.h"
+
+#include <QTimer>
+#include <QNetworkProxy>
+#include <QLocale>
+
+QT_BEGIN_NAMESPACE
+
+QGeoTiledMappingManagerEngine::QGeoTiledMappingManagerEngine(QObject *parent)
+ : QGeoMappingManagerEngine(parent),
+ d_ptr(new QGeoTiledMappingManagerEnginePrivate)
+{
+}
+
+/*!
+ Destroys this mapping manager.
+*/
+QGeoTiledMappingManagerEngine::~QGeoTiledMappingManagerEngine()
+{
+ delete d_ptr;
+}
+
+
+void QGeoTiledMappingManagerEngine::setTileFetcher(QGeoTileFetcher *fetcher)
+{
+ Q_D(QGeoTiledMappingManagerEngine);
+
+ d->fetcher_ = fetcher;
+ d->fetcher_->init();
+
+ d->thread= new QThread;
+
+ qRegisterMetaType<QGeoTileSpec>();
+
+ connect(d->fetcher_,
+ SIGNAL(tileFinished(QGeoTileSpec,QByteArray)),
+ this,
+ SLOT(engineTileFinished(QGeoTileSpec,QByteArray)),
+ Qt::QueuedConnection);
+ connect(d->fetcher_,
+ SIGNAL(tileError(QGeoTileSpec,QString)),
+ this,
+ SLOT(engineTileError(QGeoTileSpec,QString)),
+ Qt::QueuedConnection);
+
+ d->fetcher_->moveToThread(d_ptr->thread);
+
+ connect(d->thread,
+ SIGNAL(started()),
+ d->fetcher_,
+ SLOT(threadStarted()));
+
+ connect(d->thread,
+ SIGNAL(finished()),
+ d->fetcher_,
+ SLOT(threadFinished()));
+
+ connect(d->fetcher_,
+ SIGNAL(destroyed()),
+ d->thread,
+ SLOT(deleteLater()));
+
+ engineInitialized();
+
+ QTimer::singleShot(0, d->thread, SLOT(start()));
+}
+
+QGeoTileFetcher *QGeoTiledMappingManagerEngine::tileFetcher()
+{
+ Q_D(QGeoTiledMappingManagerEngine);
+ return d->fetcher_;
+}
+
+QGeoMap* QGeoTiledMappingManagerEngine::createMap(QObject *parent)
+{
+ Q_UNUSED(parent);
+ return NULL;
+}
+
+void QGeoTiledMappingManagerEngine::registerMap(QGeoTiledMapData *map)
+{
+ QSet<QGeoTiledMapData*> maps = d_ptr->caches.value(tileCache());
+ maps.insert(map);
+ d_ptr->caches.insert(tileCache(), maps);
+}
+
+void QGeoTiledMappingManagerEngine::deregisterMap(QGeoTiledMapData *map)
+{
+ QGeoTileCache *cache = map->tileCache();
+ QSet<QGeoTiledMapData*> maps = d_ptr->caches.value(cache);
+ maps.remove(map);
+ if (maps.isEmpty()) {
+ d_ptr->caches.remove(cache);
+ } else {
+ d_ptr->caches.insert(cache, maps);
+ }
+}
+
+void QGeoTiledMappingManagerEngine::updateTileRequests(QGeoTiledMapData *map,
+ const QSet<QGeoTileSpec> &tilesAdded,
+ const QSet<QGeoTileSpec> &tilesRemoved)
+{
+ Q_D(QGeoTiledMappingManagerEngine);
+
+ typedef QSet<QGeoTileSpec>::const_iterator tile_iter;
+
+ // add and remove tiles from tileset for this map
+
+ QSet<QGeoTileSpec> oldTiles = d->mapHash.value(map);
+
+ tile_iter rem = tilesRemoved.constBegin();
+ tile_iter remEnd = tilesRemoved.constEnd();
+ for (; rem != remEnd; ++rem) {
+ oldTiles.remove(*rem);
+ }
+
+ tile_iter add = tilesAdded.constBegin();
+ tile_iter addEnd = tilesAdded.constEnd();
+ for (; add != addEnd; ++add) {
+ oldTiles.insert(*add);
+ }
+
+ d->mapHash.insert(map, oldTiles);
+
+ // add and remove map from mapset for the tiles
+
+ QSet<QGeoTileSpec> reqTiles;
+ QSet<QGeoTileSpec> cancelTiles;
+
+ rem = tilesRemoved.constBegin();
+ for (; rem != remEnd; ++rem) {
+ QSet<QGeoTiledMapData*> mapSet = d->tileHash.value(*rem);
+ mapSet.remove(map);
+ if (mapSet.isEmpty()) {
+ cancelTiles.insert(*rem);
+ d->tileHash.remove(*rem);
+ } else {
+ d->tileHash.insert(*rem, mapSet);
+ }
+ }
+
+ add = tilesAdded.constBegin();
+ for (; add != addEnd; ++add) {
+ QSet<QGeoTiledMapData*> mapSet = d->tileHash.value(*add);
+ if (mapSet.isEmpty()) {
+ reqTiles.insert(*add);
+ }
+ mapSet.insert(map);
+ d->tileHash.insert(*add, mapSet);
+ }
+
+ cancelTiles -= reqTiles;
+
+ QMetaObject::invokeMethod(d->fetcher_, "updateTileRequests",
+ Qt::QueuedConnection,
+ Q_ARG(QSet<QGeoTileSpec>, reqTiles),
+ Q_ARG(QSet<QGeoTileSpec>, cancelTiles));
+}
+
+void QGeoTiledMappingManagerEngine::engineTileFinished(const QGeoTileSpec &spec, const QByteArray &bytes)
+{
+ Q_D(QGeoTiledMappingManagerEngine);
+
+ QSet<QGeoTileCache*> caches;
+
+ QSet<QGeoTiledMapData*> maps = d->tileHash.value(spec);
+
+ typedef QSet<QGeoTiledMapData*>::const_iterator map_iter;
+
+ map_iter map = maps.constBegin();
+ map_iter mapEnd = maps.constEnd();
+ for (; map != mapEnd; ++map) {
+ caches.insert((*map)->tileCache());
+
+ QSet<QGeoTileSpec> tileSet = d->mapHash.value(*map);
+ tileSet.remove(spec);
+ if (tileSet.isEmpty())
+ d->mapHash.remove(*map);
+ else
+ d->mapHash.insert(*map, tileSet);
+ }
+
+ d->tileHash.remove(spec);
+
+ typedef QSet<QGeoTileCache*>::const_iterator cache_iter;
+
+ cache_iter cache = caches.constBegin();
+ cache_iter cacheEnd = caches.constEnd();
+ for (; cache != cacheEnd; ++cache) {
+ (*cache)->insert(spec, bytes, "PNG", d->cacheHint);
+ }
+
+ map = maps.constBegin();
+ for (; map != mapEnd; ++map) {
+ (*map)->tileFetched(spec);
+ }
+}
+
+void QGeoTiledMappingManagerEngine::engineTileError(const QGeoTileSpec &spec, const QString &errorString)
+{
+ emit tileError(spec, errorString);
+}
+
+void QGeoTiledMappingManagerEngine::setTileSize(const QSize &tileSize)
+{
+ Q_D(QGeoTiledMappingManagerEngine);
+ d->tileSize = tileSize;
+}
+
+QSize QGeoTiledMappingManagerEngine::tileSize() const
+{
+ Q_D(const QGeoTiledMappingManagerEngine);
+ return d->tileSize;
+}
+
+QGeoTiledMappingManagerEngine::CacheAreas QGeoTiledMappingManagerEngine::cacheHint() const
+{
+ Q_D(const QGeoTiledMappingManagerEngine);
+ return d->cacheHint;
+}
+
+void QGeoTiledMappingManagerEngine::setCacheHint(QGeoTiledMappingManagerEngine::CacheAreas cacheHint)
+{
+ Q_D(QGeoTiledMappingManagerEngine);
+ d->cacheHint = cacheHint;
+}
+
+QGeoTileCache *QGeoTiledMappingManagerEngine::tileCache()
+{
+ Q_D(QGeoTiledMappingManagerEngine);
+ if (!d->tileCache_) {
+ d->tileCache_ = new QGeoTileCache();
+ }
+ return d->tileCache_;
+}
+
+/*******************************************************************************
+*******************************************************************************/
+
+QGeoTiledMappingManagerEnginePrivate::QGeoTiledMappingManagerEnginePrivate()
+ : tileCache_(0),
+ cacheHint(QGeoTiledMappingManagerEngine::AllCaches),
+ fetcher_(0) {}
+
+QGeoTiledMappingManagerEnginePrivate::~QGeoTiledMappingManagerEnginePrivate()
+{
+ if (tileCache_)
+ delete tileCache_;
+
+ if (fetcher_)
+ delete fetcher_;
+
+ thread->quit();
+}
+
+QT_END_NAMESPACE
diff --git a/src/location/maps/qgeotiledmappingmanagerengine.h b/src/location/maps/qgeotiledmappingmanagerengine.h
new file mode 100644
index 00000000..acfedec2
--- /dev/null
+++ b/src/location/maps/qgeotiledmappingmanagerengine.h
@@ -0,0 +1,132 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtLocation module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+** This file is part of the Ovi 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 OVI_SERVICES_TERMS_AND_CONDITIONS.txt in
+** this package, located in the directory containing the Ovi services
+** plugin source code.
+**
+****************************************************************************/
+
+#ifndef QGEOTILEDMAPPINGMANAGERENGINE_H
+#define QGEOTILEDMAPPINGMANAGERENGINE_H
+
+#include <QObject>
+#include <QSize>
+#include <QPair>
+#include <QtLocation/qlocationglobal.h>
+#include "qgeomaptype.h"
+#include "qgeomappingmanagerengine.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+class QGeoTiledMappingManagerEnginePrivate;
+class QGeoMapRequestOptions;
+class QGeoTileFetcher;
+
+class QGeoTileSpec;
+class QGeoTiledMapData;
+class QGeoTileCache;
+
+class Q_LOCATION_EXPORT QGeoTiledMappingManagerEngine : public QGeoMappingManagerEngine
+{
+ Q_OBJECT
+
+public:
+ enum CacheArea {
+ DiskCache = 0x01,
+ MemoryCache = 0x02,
+ TextureCache = 0x04,
+ AllCaches = 0xFF
+ };
+ Q_DECLARE_FLAGS(CacheAreas, CacheArea)
+
+ QGeoTiledMappingManagerEngine(QObject *parent = 0);
+ virtual ~QGeoTiledMappingManagerEngine();
+
+ QGeoTileFetcher *tileFetcher();
+
+ virtual QGeoMap* createMap(QObject *parent);
+
+ void registerMap(QGeoTiledMapData *map);
+ void deregisterMap(QGeoTiledMapData *map);
+
+ QSize tileSize() const;
+
+ void updateTileRequests(QGeoTiledMapData *map,
+ const QSet<QGeoTileSpec> &tilesAdded,
+ const QSet<QGeoTileSpec> &tilesRemoved);
+
+ QGeoTileCache *tileCache();
+
+ QGeoTiledMappingManagerEngine::CacheAreas cacheHint() const;
+
+private Q_SLOTS:
+ void engineTileFinished(const QGeoTileSpec &spec, const QByteArray &bytes);
+ void engineTileError(const QGeoTileSpec &spec, const QString &errorString);
+
+Q_SIGNALS:
+ void tileFinished(const QGeoTileSpec &spec, const QByteArray &bytes);
+ void tileError(const QGeoTileSpec &spec, const QString &errorString);
+
+protected:
+ void setTileFetcher(QGeoTileFetcher *fetcher);
+ void setTileSize(const QSize &tileSize);
+ void setCacheHint(QGeoTiledMappingManagerEngine::CacheAreas cacheHint);
+
+private:
+ QGeoTiledMappingManagerEnginePrivate* d_ptr;
+
+ Q_DECLARE_PRIVATE(QGeoTiledMappingManagerEngine)
+ Q_DISABLE_COPY(QGeoTiledMappingManagerEngine)
+
+ friend class QGeoTileFetcher;
+};
+
+Q_DECLARE_OPERATORS_FOR_FLAGS(QGeoTiledMappingManagerEngine::CacheAreas)
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/location/maps/qgeotiledmappingmanagerengine_p.h b/src/location/maps/qgeotiledmappingmanagerengine_p.h
new file mode 100644
index 00000000..10e04d72
--- /dev/null
+++ b/src/location/maps/qgeotiledmappingmanagerengine_p.h
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtLocation module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#ifndef QGEOTILEDMAPPINGMANAGER_P_H
+#define QGEOTILEDMAPPINGMANAGER_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QSize>
+#include <QList>
+#include <QHash>
+#include <QSet>
+#include <QThread>
+#include "qgeotiledmappingmanagerengine.h"
+
+QT_BEGIN_NAMESPACE
+
+class QGeoTiledMapData;
+class QGeoTileCache;
+class QGeoTileSpec;
+class QGeoTileFetcher;
+
+class QGeoTiledMappingManagerEnginePrivate
+{
+public:
+ QGeoTiledMappingManagerEnginePrivate();
+ ~QGeoTiledMappingManagerEnginePrivate();
+
+ QThread *thread;
+ QSize tileSize;
+ QHash<QGeoTileCache*, QSet<QGeoTiledMapData*> > caches;
+ QHash<QGeoTiledMapData*, QSet<QGeoTileSpec> > mapHash;
+ QHash<QGeoTileSpec, QSet<QGeoTiledMapData*> > tileHash;
+ QGeoTiledMappingManagerEngine::CacheAreas cacheHint;
+ QGeoTileCache *tileCache_;
+ QGeoTileFetcher *fetcher_;
+
+private:
+ Q_DISABLE_COPY(QGeoTiledMappingManagerEnginePrivate)
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/location/maps/qgeotilefetcher.cpp b/src/location/maps/qgeotilefetcher.cpp
new file mode 100644
index 00000000..8f1ae934
--- /dev/null
+++ b/src/location/maps/qgeotilefetcher.cpp
@@ -0,0 +1,230 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtLocation module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qgeomappingmanagerengine.h"
+#include "qgeotilefetcher.h"
+#include "qgeotilefetcher_p.h"
+#include "qgeotiledmapreply.h"
+#include "qgeotilespec.h"
+#include "qgeotiledmapdata_p.h"
+
+#include <QThread>
+#include <QNetworkProxy>
+
+QT_BEGIN_NAMESPACE
+
+QGeoTileFetcher::QGeoTileFetcher(QGeoTiledMappingManagerEngine *engine, QObject *parent)
+ : QObject(parent),
+ d_ptr(new QGeoTileFetcherPrivate(engine))
+{
+ Q_D(QGeoTileFetcher);
+ d->engine_ = engine;
+}
+
+QGeoTileFetcher::~QGeoTileFetcher()
+{
+ Q_D(QGeoTileFetcher);
+ delete d;
+}
+
+void QGeoTileFetcher::threadStarted()
+{
+ Q_D(QGeoTileFetcher);
+
+ if (d->stopped_)
+ return;
+
+ d->timer_ = new QTimer(this);
+
+ d->timer_->setInterval(0);
+
+ connect(d->timer_,
+ SIGNAL(timeout()),
+ this,
+ SLOT(requestNextTile()));
+
+ d->started_ = true;
+ if (!d->queue_.isEmpty())
+ d->timer_->start();
+}
+
+bool QGeoTileFetcher::init()
+{
+ return false;
+}
+
+void QGeoTileFetcher::threadFinished()
+{
+ Q_D(QGeoTileFetcher);
+ d->stopped_ = true;
+ disconnect(d->timer_);
+ d->timer_->stop();
+ this->deleteLater();
+}
+
+void QGeoTileFetcher::updateTileRequests(const QSet<QGeoTileSpec> &tilesAdded,
+ const QSet<QGeoTileSpec> &tilesRemoved)
+{
+ Q_D(QGeoTileFetcher);
+
+ if (d->stopped_)
+ return;
+
+ cancelTileRequests(tilesRemoved);
+
+ d->queue_ += tilesAdded.toList();
+
+ if (!d->queue_.empty())
+ d->timer_->start();
+}
+
+void QGeoTileFetcher::cancelTileRequests(const QSet<QGeoTileSpec> &tiles)
+{
+ Q_D(QGeoTileFetcher);
+
+ typedef QSet<QGeoTileSpec>::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();
+ reply->deleteLater();
+ }
+ d->queue_.removeAll(*tile);
+ }
+
+ if (d->queue_.isEmpty())
+ d->timer_->stop();
+}
+
+void QGeoTileFetcher::requestNextTile()
+{
+ Q_D(QGeoTileFetcher);
+
+ if (d->stopped_)
+ return;
+
+ if (d->queue_.isEmpty()) {
+ d->timer_->stop();
+ return;
+ }
+
+ QGeoTileSpec ts = d->queue_.takeFirst();
+
+ QGeoTiledMapReply *reply = getTileImage(ts);
+
+ if (reply->isFinished()) {
+ handleReply(reply, ts);
+ } else {
+ connect(reply,
+ SIGNAL(finished()),
+ this,
+ SLOT(finished()));
+
+ d->invmap_.insert(ts, reply);
+ }
+
+ if (d->queue_.isEmpty())
+ d->timer_->stop();
+}
+
+void QGeoTileFetcher::finished()
+{
+ Q_D(QGeoTileFetcher);
+
+ QGeoTiledMapReply *reply = qobject_cast<QGeoTiledMapReply*>(sender());
+ if (!reply)
+ return;
+
+ QGeoTileSpec spec = reply->tileSpec();
+
+ if (!d->invmap_.contains(spec)) {
+ reply->deleteLater();
+ return;
+ }
+
+ d->invmap_.remove(spec);
+
+ handleReply(reply, spec);
+}
+
+void QGeoTileFetcher::handleReply(QGeoTiledMapReply *reply, const QGeoTileSpec &spec)
+{
+ Q_D(QGeoTileFetcher);
+
+ if (d->stopped_) {
+ reply->deleteLater();
+ return;
+ }
+
+ if (reply->error() == QGeoTiledMapReply::NoError) {
+ QByteArray bytes = reply->mapImageData();
+ emit tileFinished(spec, bytes);
+ } else {
+ emit tileError(spec, reply->errorString());
+ }
+
+ reply->deleteLater();
+}
+
+/*******************************************************************************
+*******************************************************************************/
+
+QGeoTileFetcherPrivate::QGeoTileFetcherPrivate(QGeoTiledMappingManagerEngine *engine)
+ : started_(false),
+ stopped_(false),
+ engine_(engine) {}
+
+QGeoTileFetcherPrivate::~QGeoTileFetcherPrivate()
+{
+}
+
+QT_END_NAMESPACE
+
+
+
+
+
+
+
+
diff --git a/src/location/maps/qgeotilefetcher.h b/src/location/maps/qgeotilefetcher.h
new file mode 100644
index 00000000..51fd134b
--- /dev/null
+++ b/src/location/maps/qgeotilefetcher.h
@@ -0,0 +1,103 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtLocation module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QGEOTILEFETCHER_H
+#define QGEOTILEFETCHER_H
+
+#include <QObject>
+#include <qlocationglobal.h>
+#include "qgeomaptype.h"
+#include "qgeotiledmappingmanagerengine.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+class QGeoMapRequestOptions;
+
+class QGeoTileFetcherPrivate;
+class QGeoTiledMappingManagerEngine;
+class QGeoTiledMapReply;
+class QGeoTileSpec;
+
+class Q_LOCATION_EXPORT QGeoTileFetcher : public QObject
+{
+ Q_OBJECT
+
+public:
+ QGeoTileFetcher(QGeoTiledMappingManagerEngine *engine, QObject *parent = 0);
+ virtual ~QGeoTileFetcher();
+
+public Q_SLOTS:
+ void threadStarted();
+ void threadFinished();
+ void updateTileRequests(const QSet<QGeoTileSpec> &tilesAdded, const QSet<QGeoTileSpec> &tilesRemoved);
+ void cancelTileRequests(const QSet<QGeoTileSpec> &tiles);
+
+private Q_SLOTS:
+ void requestNextTile();
+ void finished();
+
+Q_SIGNALS:
+ void tileFinished(const QGeoTileSpec &spec, const QByteArray &bytes);
+ void tileError(const QGeoTileSpec &spec, const QString &errorString);
+
+protected:
+ virtual bool init();
+ QGeoTiledMappingManagerEngine::CacheAreas cacheHint() const;
+
+private:
+ QGeoTileFetcherPrivate* d_ptr;
+
+ virtual QGeoTiledMapReply* getTileImage(const QGeoTileSpec &spec) = 0;
+ void handleReply(QGeoTiledMapReply *reply, const QGeoTileSpec &spec);
+
+ Q_DECLARE_PRIVATE(QGeoTileFetcher)
+ Q_DISABLE_COPY(QGeoTileFetcher)
+
+ friend class QGeoTiledMappingManagerEngine;
+};
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/src/location/maps/qgeotilefetcher_p.h b/src/location/maps/qgeotilefetcher_p.h
new file mode 100644
index 00000000..659cc817
--- /dev/null
+++ b/src/location/maps/qgeotilefetcher_p.h
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtLocation module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QGEOTILEFETCHER_P_H
+#define QGEOTILEFETCHER_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QSize>
+#include <QList>
+#include <QMap>
+#include <QLocale>
+#include <QTimer>
+#include <QHash>
+#include "qgeomaptype.h"
+
+class QGeoTileSpec;
+class QGeoTiledMapReply;
+class QGeoTileCache;
+class QGeoTiledMappingManagerEngine;
+
+QT_BEGIN_NAMESPACE
+
+class QGeoTileFetcherPrivate
+{
+public:
+ QGeoTileFetcherPrivate(QGeoTiledMappingManagerEngine *engine);
+ virtual ~QGeoTileFetcherPrivate();
+
+ QGeoTiledMappingManagerEngine *engine_;
+
+ bool started_;
+ bool stopped_;
+ bool initialized_;
+ QTimer *timer_;
+ QList<QGeoTileSpec> queue_;
+ QHash<QGeoTileSpec, QGeoTiledMapReply*> invmap_;
+
+private:
+ Q_DISABLE_COPY(QGeoTileFetcherPrivate)
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/geoservices/nokia/nokia.pro b/src/plugins/geoservices/nokia/nokia.pro
index 06b051fa..248863bd 100644
--- a/src/plugins/geoservices/nokia/nokia.pro
+++ b/src/plugins/geoservices/nokia/nokia.pro
@@ -18,7 +18,9 @@ HEADERS += \
qgeocodereply_nokia.h \
qgeocodexmlparser.h \
qgeocodingmanagerengine_nokia.h \
- qgeomappingmanagerengine_nokia.h \
+ qgeotiledmappingmanagerengine_nokia.h \
+ qgeotilefetcher_nokia.h \
+ qgeotiledmapdata_nokia.h \
qgeomapreply_nokia.h \
qgeoroutereply_nokia.h \
qgeoroutexmlparser.h \
@@ -30,7 +32,9 @@ SOURCES += \
qgeocodereply_nokia.cpp \
qgeocodexmlparser.cpp \
qgeocodingmanagerengine_nokia.cpp \
- qgeomappingmanagerengine_nokia.cpp \
+ qgeotiledmappingmanagerengine_nokia.cpp \
+ qgeotilefetcher_nokia.cpp \
+ qgeotiledmapdata_nokia.cpp \
qgeomapreply_nokia.cpp \
qgeoroutereply_nokia.cpp \
qgeoroutexmlparser.cpp \
diff --git a/src/plugins/geoservices/nokia/qgeoserviceproviderplugin_nokia.cpp b/src/plugins/geoservices/nokia/qgeoserviceproviderplugin_nokia.cpp
index 7fd08bae..268af20a 100644
--- a/src/plugins/geoservices/nokia/qgeoserviceproviderplugin_nokia.cpp
+++ b/src/plugins/geoservices/nokia/qgeoserviceproviderplugin_nokia.cpp
@@ -50,7 +50,7 @@
#include "qgeocodingmanagerengine_nokia.h"
#include "qgeoroutingmanagerengine_nokia.h"
-#include "qgeomappingmanagerengine_nokia.h"
+#include "qgeotiledmappingmanagerengine_nokia.h"
#include "qplacemanagerengine_nokiav1.h"
#include "qplacemanagerengine_nokiav2.h"
@@ -74,7 +74,7 @@ QGeoMappingManagerEngine* QGeoServiceProviderFactoryNokia::createMappingManagerE
QGeoServiceProvider::Error *error,
QString *errorString) const
{
- return new QGeoMappingManagerEngineNokia(parameters, error, errorString);
+ return new QGeoTiledMappingManagerEngineNokia(parameters, error, errorString);
}
QGeoRoutingManagerEngine* QGeoServiceProviderFactoryNokia::createRoutingManagerEngine(const QMap<QString, QVariant> &parameters,
diff --git a/src/plugins/geoservices/nokia/qgeotiledmapdata_nokia.cpp b/src/plugins/geoservices/nokia/qgeotiledmapdata_nokia.cpp
index 71fe1bde..f8cfc489 100644
--- a/src/plugins/geoservices/nokia/qgeotiledmapdata_nokia.cpp
+++ b/src/plugins/geoservices/nokia/qgeotiledmapdata_nokia.cpp
@@ -48,7 +48,6 @@
#include "qgeotiledmapdata_nokia.h"
#include "jsonparser.h"
-#include "qgeomappingmanagerengine_nokia.h"
#include "qgeoboundingbox.h"
#include "qgeocoordinate.h"
@@ -61,178 +60,14 @@ QT_BEGIN_NAMESPACE
Constructs a new tiled map data object, which stores the map data required by
\a geoMap and makes use of the functionality provided by \a engine.
*/
-QGeoTiledMapDataNokia::QGeoTiledMapDataNokia(QGeoMappingManagerEngineNokia *engine) :
- QGeoTiledMapData(engine),
+QGeoTiledMapDataNokia::QGeoTiledMapDataNokia(QGeoTiledMappingManagerEngine *engine, QObject *parent /*= 0*/) :
+ QGeoTiledMapData(engine, parent),
watermark(":/images/watermark.png")
{
- m_networkManager = new QNetworkAccessManager(this);
- connect(m_networkManager, SIGNAL(finished(QNetworkReply*)), SLOT(copyrightReplyFinished(QNetworkReply*)));
-
- m_networkManager->get(QNetworkRequest(QUrl("http://maptile.maps.svc.ovi.com/maptiler/v2/copyright/newest")));
}
QGeoTiledMapDataNokia::~QGeoTiledMapDataNokia()
{
}
-static QGeoBoundingBox variantListToBoundingBox(const QVariantList & list) {
- if (list.size() < 4) return QGeoBoundingBox();
-
- qreal latTop = list[0].toReal();
- qreal latBottom = list[2].toReal();
- if (latTop < latBottom)
- qSwap(latTop, latBottom);
-
- return QGeoBoundingBox(QGeoCoordinate(latTop, list[1].toReal()), QGeoCoordinate(latBottom, list[3].toReal()));
-}
-
-void QGeoTiledMapDataNokia::copyrightReplyFinished(QNetworkReply * reply)
-{
- if (reply->error() != QNetworkReply::NoError)
- return;
-
- JSONParser jp(reply->readAll());
- QVariant root = jp.parse();
-
- if (!root.isValid())
- return;
-
- copyrights.clear();
-
- QVariantHash rootHash = root.toHash();
-
- foreach (QString key, rootHash.keys()) {
- QList<CopyrightDescriptor> copyrightDescriptorList;
- foreach (QVariant copyrightSource, rootHash[key].toList()) {
- QVariantHash copyrightSourceHash = copyrightSource.toHash();
- CopyrightDescriptor copyrightDescriptor;
- copyrightDescriptor.minLevel = copyrightSourceHash["minLevel"].toReal();
- copyrightDescriptor.maxLevel = copyrightSourceHash["maxLevel"].toReal();
- copyrightDescriptor.label = copyrightSourceHash["label"].toString();
- copyrightDescriptor.alt = copyrightSourceHash["alt"].toString();
-
- foreach (QVariant box, copyrightSourceHash["boxes"].toList()) {
- copyrightDescriptor.boxes << variantListToBoundingBox(box.toList());
- }
-
- copyrightDescriptorList << copyrightDescriptor;
- }
-
- copyrights[key] = copyrightDescriptorList;
- }
-}
-
-QString QGeoTiledMapDataNokia::getViewCopyright()
-{
- QGeoBoundingBox viewport = this->viewport();
-
- QString terraintype;
-
- switch (mapType()) {
- case QGraphicsGeoMap::StreetMap:
- terraintype = "normal";
- break;
-
- case QGraphicsGeoMap::SatelliteMapDay:
- case QGraphicsGeoMap::SatelliteMapNight:
- terraintype = "hybrid";
- break;
-
- case QGraphicsGeoMap::TerrainMap:
- terraintype = "terrain";
- break;
-
- default:
- terraintype = "normal";
- }
-
- CopyrightDescriptor fallback;
-
- QStringList copyrightStrings;
- bool contained = false;
- foreach (CopyrightDescriptor copyrightDescriptor, copyrights[terraintype]) {
- if (zoomLevel() < copyrightDescriptor.minLevel) continue;
- if (zoomLevel() > copyrightDescriptor.maxLevel) continue;
-
- if (copyrightDescriptor.boxes.isEmpty()) {
- fallback = copyrightDescriptor;
- }
- else {
- foreach (QGeoBoundingBox box, copyrightDescriptor.boxes) {
- if (box.intersects(viewport)) {
- copyrightStrings << copyrightDescriptor.label;
- if (box.contains(viewport)) {
- contained = true;
- break;
- }
- // TODO: consider the case where the viewport is fully contained by the combined bounding boxes, but not by one individual bounding box
- }
- }
- }
- }
-
- if (copyrightStrings.isEmpty() || !contained) {
- if (!fallback.label.isEmpty()) copyrightStrings << fallback.label;
- }
-
- copyrightStrings.removeDuplicates();
-
- QString ret = copyrightStrings.join(", ");
-
- return ret;
-}
-
-/*!
- \reimp
- */
-void QGeoTiledMapDataNokia::paintProviderNotices(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/)
-{
- QRect viewport = painter->combinedTransform().inverted().mapRect(painter->viewport());
-
- painter->drawPixmap(
- viewport.bottomLeft()+QPoint(5,-5-watermark.height()),
- watermark
- );
-
- QString copyrightText = getViewCopyright();
-
- if (copyrightText != lastCopyrightText || lastViewport != viewport) {
- lastCopyrightText = copyrightText;
- lastViewport = viewport;
-
- QRect maxBoundingRect(QPoint(viewport.left()+10+watermark.width(), viewport.top()), QPoint(viewport.right()-5, viewport.bottom()-5));
-
- QRect textBoundingRect = painter->boundingRect(maxBoundingRect, Qt::AlignLeft | Qt::AlignBottom | Qt::TextWordWrap, copyrightText);
- lastCopyrightRect = textBoundingRect.adjusted(-1, -1, 1, 1);
-
- lastCopyright = QPixmap(lastCopyrightRect.size());
- lastCopyright.fill(QColor(Qt::transparent));
-
- {
- QPainter painter2(&lastCopyright);
-
- painter2.drawText(
- QRect(QPoint(1, 2), textBoundingRect.size()),
- Qt::TextWordWrap,
- copyrightText
- );
-
- painter2.drawPixmap(QRect(QPoint(-1, -1), lastCopyrightRect.size()), lastCopyright);
- painter2.drawPixmap(QRect(QPoint(1, -1), lastCopyrightRect.size()), lastCopyright);
-
- painter2.setPen(QColor(Qt::white));
- painter2.drawText(
- QRect(QPoint(1, 1), textBoundingRect.size()),
- Qt::TextWordWrap,
- copyrightText
- );
- }
- }
-
- painter->drawPixmap(
- lastCopyrightRect,
- lastCopyright
- );
-}
-
QT_END_NAMESPACE
diff --git a/src/plugins/geoservices/nokia/qgeotiledmapdata_nokia.h b/src/plugins/geoservices/nokia/qgeotiledmapdata_nokia.h
index 826b6347..231bff86 100644
--- a/src/plugins/geoservices/nokia/qgeotiledmapdata_nokia.h
+++ b/src/plugins/geoservices/nokia/qgeotiledmapdata_nokia.h
@@ -49,30 +49,20 @@
#ifndef QGEOMAPDATA_NOKIA_H
#define QGEOMAPDATA_NOKIA_H
-#include <qgeotiledmapdata.h>
+#include "qgeotiledmapdata_p.h"
#include <QPixmap>
#include <QNetworkReply>
QT_BEGIN_NAMESPACE
-class QGeoMappingManagerEngineNokia;
-
-struct CopyrightDescriptor
-{
- qreal maxLevel;
- QString alt;
- QString label;
- qreal minLevel;
- QList<QGeoBoundingBox> boxes;
-};
+class QGeoTileCache;
class QGeoTiledMapDataNokia: public QGeoTiledMapData
{
Q_OBJECT
public:
- QGeoTiledMapDataNokia(QGeoMappingManagerEngineNokia *engine);
- virtual ~QGeoTiledMapDataNokia();
- void paintProviderNotices(QPainter *painter, const QStyleOptionGraphicsItem *option);
+ QGeoTiledMapDataNokia(QGeoTiledMappingManagerEngine *engine, QObject *parent = 0);
+ ~QGeoTiledMapDataNokia();
QString getViewCopyright();
@@ -86,11 +76,6 @@ private:
QRect lastViewport;
QRect lastCopyrightRect;
QNetworkAccessManager *m_networkManager;
-
- QHash<QString, QList<CopyrightDescriptor> > copyrights;
-
-private slots:
- void copyrightReplyFinished(QNetworkReply*);
};
QT_END_NAMESPACE
diff --git a/src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.cpp b/src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.cpp
new file mode 100644
index 00000000..a8744bdf
--- /dev/null
+++ b/src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.cpp
@@ -0,0 +1,101 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtLocation module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+** This file is part of the Ovi 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 OVI_SERVICES_TERMS_AND_CONDITIONS.txt in
+** this package, located in the directory containing the Ovi services
+** plugin source code.
+**
+****************************************************************************/
+
+#include "qgeocameracapabilities_p.h"
+#include "qgeotiledmappingmanagerengine_nokia.h"
+#include "qgeotiledmapdata_nokia.h"
+#include "qgeotilefetcher_nokia.h"
+
+QT_BEGIN_NAMESPACE
+
+QGeoTiledMappingManagerEngineNokia::QGeoTiledMappingManagerEngineNokia(const QMap<QString, QVariant> &parameters,
+ QGeoServiceProvider::Error *error,
+ QString *errorString)
+ : QGeoTiledMappingManagerEngine()
+{
+ Q_UNUSED(error);
+ Q_UNUSED(errorString);
+
+ QGeoCameraCapabilities capabilities;
+
+ capabilities.setMinimumZoomLevel(0.0);
+ capabilities.setMaximumZoomLevel(20.0);
+
+ setCameraCapabilities(capabilities);
+
+ setTileSize(QSize(256, 256));
+
+ QList<QGeoMapType> types;
+ types << QGeoMapType(QGeoMapType::StreetMap,tr("Street Map"),tr("Nokia Street Map"), false, 1);
+ types << QGeoMapType(QGeoMapType::SatelliteMapDay,tr("Satellite Map(day)"),tr("Nokia Satellite Map (day)"), false, 2);
+ types << QGeoMapType(QGeoMapType::TerrainMap,tr("Terrain Map"),tr("Nokia Terrain Map"), false, 3);
+ types << QGeoMapType(QGeoMapType::HybridMap,tr("Hybrid Map"),tr("Nokia Hybrid Map"), false, 4);
+ types << QGeoMapType(QGeoMapType::TransitMap,tr("Transit Map"),tr("Nokia Transit Map"), false, 5);
+ types << QGeoMapType(QGeoMapType::GrayStreetMap,tr("Gray Street Map"),tr("Nokia Gray Street Map"), false, 6);
+ types << QGeoMapType(QGeoMapType::StreetMap,tr("Mobile Street Map"),tr("Nokia Mobile Street Map"), true, 7);
+ types << QGeoMapType(QGeoMapType::TerrainMap,tr("Mobile Terrain Map"),tr("Nokia Mobile Terrain Map"), true, 8);
+ types << QGeoMapType(QGeoMapType::HybridMap,tr("Mobile Hybrid Map"),tr("Nokia Mobile Hybrid Map"), true, 9);
+ types << QGeoMapType(QGeoMapType::TransitMap,tr("Mobile Transit Map"),tr("Nokia Mobile Transit Map"), true, 10);
+ types << QGeoMapType(QGeoMapType::GrayStreetMap,tr("Mobile Gray Street Map"),tr("Nokia Mobile Gray Street Map"), true, 11);
+ setSupportedMapTypes(types);
+
+ QGeoTileFetcherNokia *fetcher = new QGeoTileFetcherNokia(this);
+ fetcher->setParams(&parameters);
+ fetcher->setTileSize(tileSize());
+ setTileFetcher(fetcher);
+}
+
+QGeoTiledMappingManagerEngineNokia::~QGeoTiledMappingManagerEngineNokia() {}
+
+QGeoMapData *QGeoTiledMappingManagerEngineNokia::createMapData()
+{
+ return new QGeoTiledMapDataNokia(this);;
+}
+
+QT_END_NAMESPACE
+
diff --git a/src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.h b/src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.h
new file mode 100644
index 00000000..13a23e5c
--- /dev/null
+++ b/src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtLocation module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+** This file is part of the Ovi 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 OVI_SERVICES_TERMS_AND_CONDITIONS.txt in
+** this package, located in the directory containing the Ovi services
+** plugin source code.
+**
+****************************************************************************/
+
+#ifndef QGEOTILEDMAPPINGMANAGERENGINE_NOKIA_H
+#define QGEOTILEDMAPPINGMANAGERENGINE_NOKIA_H
+
+#include "qgeotiledmappingmanagerengine.h"
+#include <QGeoServiceProvider>
+
+QT_BEGIN_NAMESPACE
+
+class QGeoTiledMappingManagerEngineNokia : public QGeoTiledMappingManagerEngine
+{
+ Q_OBJECT
+
+public:
+ QGeoTiledMappingManagerEngineNokia(const QMap<QString, QVariant> &parameters,
+ QGeoServiceProvider::Error *error,
+ QString *errorString);
+ ~QGeoTiledMappingManagerEngineNokia();
+
+ virtual QGeoMapData* createMapData();
+
+protected:
+ void initialize();
+};
+
+QT_END_NAMESPACE
+
+#endif // QGEOTILEDMAPPINGMANAGERENGINE_NOKIA_H
diff --git a/src/plugins/geoservices/nokia/qgeomappingmanagerengine_nokia.cpp b/src/plugins/geoservices/nokia/qgeotilefetcher_nokia.cpp
index 115bbcb6..49ff9d38 100644
--- a/src/plugins/geoservices/nokia/qgeomappingmanagerengine_nokia.cpp
+++ b/src/plugins/geoservices/nokia/qgeotilefetcher_nokia.cpp
@@ -46,11 +46,12 @@
**
****************************************************************************/
-#include "qgeomappingmanagerengine_nokia.h"
+#include "qgeotilefetcher_nokia.h"
#include "qgeomapreply_nokia.h"
+#include "qgeotiledmapdata_nokia.h"
#include <qgeotilespec.h>
-#include "qgeocameracapabilities_p.h"
+#include <qgeotilecache_p.h>
#include <QNetworkAccessManager>
#include <QNetworkDiskCache>
@@ -58,16 +59,9 @@
#include <QSize>
#include <QDir>
#include <QUrl>
-#ifdef USE_CHINA_NETWORK_REGISTRATION
-#include <QtSystemInfo/QNetworkInfo>
-#endif
-
-#include <map>
#define LARGE_TILE_DIMENSION 256
-#define DISK_CACHE_MAX_SIZE 50*1024*1024 //50MB
-
#if defined(Q_OS_WINCE_WM) || defined(Q_WS_MAEMO_5) || defined(Q_WS_MAEMO_6)
#undef DISK_CACHE_ENABLED
#else
@@ -81,59 +75,26 @@ QT_BEGIN_NAMESPACE
const char* MAPTILES_HOST = "1-4.maptile.lbs.ovi.com";
const char* MAPTILES_HOST_CN = "a-k.maptile.maps.svc.nokia.com.cn";
-QGeoMappingManagerEngineNokia::QGeoMappingManagerEngineNokia(const QMap<QString, QVariant> &parameters, QGeoServiceProvider::Error *error, QString *errorString)
- : QGeoMappingManagerEngine(parameters),
+QGeoTileFetcherNokia::QGeoTileFetcherNokia(QGeoTiledMappingManagerEngine *engine)
+ : QGeoTileFetcher(engine),
m_cache(0),
+ m_token(QGeoServiceProviderFactoryNokia::defaultToken),
+ m_referer(QGeoServiceProviderFactoryNokia::defaultReferer),
m_firstSubdomain(QChar::Null),
m_maxSubdomains(0)
{
- Q_UNUSED(error)
- Q_UNUSED(errorString)
-
- setHost(MAPTILES_HOST);
-
-#ifdef USE_CHINA_NETWORK_REGISTRATION
- m_networkInfo = 0;
-#endif
-
- QGeoCameraCapabilities capabilities;
-
- capabilities.setMinimumZoomLevel(0.0);
- capabilities.setMaximumZoomLevel(20.0);
-
- setCameraCapabilities(capabilities);
}
-QGeoMappingManagerEngineNokia::~QGeoMappingManagerEngineNokia() {}
+QGeoTileFetcherNokia::~QGeoTileFetcherNokia() {}
-void QGeoMappingManagerEngineNokia::init()
+bool QGeoTileFetcherNokia::init()
{
- setTileSize(256);
-
- QList<QGeoMapType> types;
- types << QGeoMapType(QGeoMapType::StreetMap,tr("Street Map"),tr("Nokia Street Map"), false, 1);
- types << QGeoMapType(QGeoMapType::SatelliteMapDay,tr("Satellite Map(day)"),tr("Nokia Satellite Map (day)"), false, 2);
- types << QGeoMapType(QGeoMapType::TerrainMap,tr("Terrain Map"),tr("Nokia Terrain Map"), false, 3);
- types << QGeoMapType(QGeoMapType::HybridMap,tr("Hybrid Map"),tr("Nokia Hybrid Map"), false, 4);
- types << QGeoMapType(QGeoMapType::TransitMap,tr("Transit Map"),tr("Nokia Transit Map"), false, 5);
- types << QGeoMapType(QGeoMapType::GrayStreetMap,tr("Gray Street Map"),tr("Nokia Gray Street Map"), false, 6);
- types << QGeoMapType(QGeoMapType::StreetMap,tr("Mobile Street Map"),tr("Nokia Mobile Street Map"), true, 7);
- types << QGeoMapType(QGeoMapType::TerrainMap,tr("Mobile Terrain Map"),tr("Nokia Mobile Terrain Map"), true, 8);
- types << QGeoMapType(QGeoMapType::HybridMap,tr("Mobile Hybrid Map"),tr("Nokia Mobile Hybrid Map"), true, 9);
- types << QGeoMapType(QGeoMapType::TransitMap,tr("Mobile Transit Map"),tr("Nokia Mobile Transit Map"), true, 10);
- types << QGeoMapType(QGeoMapType::GrayStreetMap,tr("Mobile Gray Street Map"),tr("Nokia Mobile Gray Street Map"), true, 11);
- setSupportedMapTypes(types);
-
-// QList<QGraphicsGeoMap::ConnectivityMode> modes;
-// modes << QGraphicsGeoMap::OnlineMode;
-// setSupportedConnectivityModes(modes);
+ setHost(MAPTILES_HOST);
m_networkManager = new QNetworkAccessManager(this);
- QMap<QString, QVariant> parameters = this->parameters();
-
- if (parameters.contains("mapping.proxy")) {
- QString proxy = parameters.value("mapping.proxy").toString();
+ if (m_parameters->contains("mapping.proxy")) {
+ QString proxy = m_parameters->value("mapping.proxy").toString();
if (!proxy.isEmpty()) {
QUrl proxyUrl(proxy);
if (proxyUrl.isValid()) {
@@ -146,24 +107,28 @@ void QGeoMappingManagerEngineNokia::init()
}
}
- if (parameters.contains("mapping.host")) {
- QString host = parameters.value("mapping.host").toString();
+ if (m_parameters->contains("mapping.host")) {
+ QString host = m_parameters->value("mapping.host").toString();
if (!host.isEmpty())
setHost(host);
}
- if (parameters.contains("mapping.app_id")) {
- m_applicationId = parameters.value("mapping.app_id").toString();
+ if (m_parameters->contains("mapping.referer")) {
+ m_referer = m_parameters->value("mapping.referer").toString();
+ }
+
+ if (m_parameters->contains("mapping.app_id")) {
+ m_applicationId = m_parameters->value("mapping.app_id").toString();
}
- else if (parameters.contains("app_id")) {
- m_applicationId = parameters.value("app_id").toString();
+ else if (m_parameters->contains("app_id")) {
+ m_applicationId = m_parameters->value("app_id").toString();
}
- if (parameters.contains("mapping.token")) {
- m_token = parameters.value("mapping.token").toString();
+ if (m_parameters->contains("mapping.token")) {
+ m_token = m_parameters->value("mapping.token").toString();
}
- else if (parameters.contains("token")) {
- m_token = parameters.value("token").toString();
+ else if (m_parameters->contains("token")) {
+ m_token = m_parameters->value("token").toString();
}
#ifdef DISK_CACHE_ENABLED
QString cacheDir;
@@ -196,15 +161,13 @@ void QGeoMappingManagerEngineNokia::init()
#endif
#ifdef USE_CHINA_NETWORK_REGISTRATION
- m_networkInfo = new QNetworkInfo(this);
- connect(m_networkInfo, SIGNAL(currentMobileCountryCodeChanged(int, const QString&)),
+ connect(&m_networkInfo, SIGNAL(currentMobileCountryCodeChanged(int, const QString&)),
SLOT(currentMobileCountryCodeChanged(int, const QString&)));
- currentMobileCountryCodeChanged(0, m_networkInfo->currentMobileCountryCode(0));
+ currentMobileCountryCodeChanged(0, m_networkInfo.currentMobileCountryCode(0));
#endif
- if (!isValidParameter(m_applicationId) || !isValidParameter(m_token)) {
- qWarning() << "This plug in must have a valid \"app_id\" and \"token\".";
- qWarning() << "These may be obtained from:";
+ if (!isValidParameter(m_applicationId) || !isValidParameter(m_referer)) {
+ qWarning() << "Qt Location requires usage of app_id and token parameters obtained from:";
qWarning() << "https://api.forum.nokia.com/ovi-api/ui/registration";
}
@@ -215,10 +178,10 @@ void QGeoMappingManagerEngineNokia::init()
setHost(MAPTILES_HOST_CN);
}
- QGeoMappingManagerEngine::init();
+ return true;
}
-QGeoTiledMapReply* QGeoMappingManagerEngineNokia::getTileImage(const QGeoTileSpec &spec)
+QGeoTiledMapReply* QGeoTileFetcherNokia::getTileImage(const QGeoTileSpec &spec)
{
// TODO add error detection for if request.connectivityMode() != QGraphicsGeoMap::OnlineMode
QString rawRequest = getRequestString(spec);
@@ -241,7 +204,7 @@ QGeoTiledMapReply* QGeoMappingManagerEngineNokia::getTileImage(const QGeoTileSpe
return mapReply;
}
-QString QGeoMappingManagerEngineNokia::getRequestString(const QGeoTileSpec &spec) const
+QString QGeoTileFetcherNokia::getRequestString(const QGeoTileSpec &spec)
{
const char subdomain = m_maxSubdomains ? m_firstSubdomain.toAscii() +
(spec.x() + spec.y()) % m_maxSubdomains : 0;
@@ -266,34 +229,41 @@ QString QGeoMappingManagerEngineNokia::getRequestString(const QGeoTileSpec &spec
requestString += slash;
requestString += QString::number(spec.y());
requestString += slash;
- requestString += sizeToStr(tileSize());
+ requestString += sizeToStr(m_tileSize);
static const QString slashpng("/png8");
requestString += slashpng;
- if (!m_token.isEmpty() && !m_applicationId.isEmpty()) {
+ if (!m_token.isEmpty()) {
requestString += "?token=";
requestString += m_token;
+
+ if (!m_referer.isEmpty()) {
+ requestString += "&referer=";
+ requestString += m_referer;
+ }
+ } else if (!m_referer.isEmpty()) {
+ requestString += "?referer=";
+ requestString += m_referer;
+ }
+ if (!m_applicationId.isEmpty()) {
requestString += "&app_id=";
requestString += m_applicationId;
}
- // Remove the code below when app_id and token are fully enforced
- else {
- requestString += "?token=ThisWillCeaseToWork";
- }
return requestString;
}
-QString QGeoMappingManagerEngineNokia::sizeToStr(int size)
+QString QGeoTileFetcherNokia::sizeToStr(const QSize &size)
{
static const QString s256("256");
static const QString s128("128");
- if (size >= LARGE_TILE_DIMENSION)
+ if (size.height() >= LARGE_TILE_DIMENSION ||
+ size.width() >= LARGE_TILE_DIMENSION)
return s256;
else
return s128;
}
-QString QGeoMappingManagerEngineNokia::mapIdToStr(int mapId)
+QString QGeoTileFetcherNokia::mapIdToStr(int mapId)
{
typedef std::map<int, QString> MapTypeRegistry;
static MapTypeRegistry registeredTypes;
@@ -321,31 +291,46 @@ QString QGeoMappingManagerEngineNokia::mapIdToStr(int mapId)
return "normal.day";
}
-const QString & QGeoMappingManagerEngineNokia::token() const
+const QString & QGeoTileFetcherNokia::referer() const
+{
+ return m_referer;
+}
+
+void QGeoTileFetcherNokia::setParams(const QMap<QString, QVariant> *parameters)
+{
+ m_parameters = parameters;
+}
+
+void QGeoTileFetcherNokia::setTileSize(QSize tileSize)
+{
+ m_tileSize = tileSize;
+}
+
+const QString & QGeoTileFetcherNokia::token() const
{
return m_token;
}
-const QString & QGeoMappingManagerEngineNokia::host() const
+const QString & QGeoTileFetcherNokia::host() const
{
return m_host;
}
-const QString & QGeoMappingManagerEngineNokia::applicationId() const
+const QString & QGeoTileFetcherNokia::applicationId() const
{
return m_applicationId;
}
-QChar QGeoMappingManagerEngineNokia::firstSubdomain() const
+QChar QGeoTileFetcherNokia::firstSubdomain() const
{
return m_firstSubdomain;
}
-unsigned char QGeoMappingManagerEngineNokia::maxSubdomains() const
+unsigned char QGeoTileFetcherNokia::maxSubdomains() const
{
return m_maxSubdomains;
}
-void QGeoMappingManagerEngineNokia::setHost(const QString &host)
+void QGeoTileFetcherNokia::setHost(const QString &host)
{
if (host.length() > 4 && host.at(1) == QChar('-') && host.at(3) == QChar('.')) {
QString realHost = host.right(host.length() - 4);
@@ -360,7 +345,7 @@ void QGeoMappingManagerEngineNokia::setHost(const QString &host)
}
#ifdef USE_CHINA_NETWORK_REGISTRATION
-void QGeoMappingManagerEngineNokia::currentMobileCountryCodeChanged(int interface, const QString & mcc)
+void QGeoTileFetcherNokia::currentMobileCountryCodeChanged(int interface, const QString & mcc)
{
Q_UNUSED(interface)
if (mcc == "460" || mcc == "461" || mcc == "454" || mcc == "455") {
@@ -369,7 +354,7 @@ void QGeoMappingManagerEngineNokia::currentMobileCountryCodeChanged(int interfac
}
#endif
-bool QGeoMappingManagerEngineNokia::isValidParameter(const QString &param)
+bool QGeoTileFetcherNokia::isValidParameter(const QString &param)
{
if (param.isEmpty())
return false;
diff --git a/src/plugins/geoservices/nokia/qgeomappingmanagerengine_nokia.h b/src/plugins/geoservices/nokia/qgeotilefetcher_nokia.h
index 9477f6f9..ccc06575 100644
--- a/src/plugins/geoservices/nokia/qgeomappingmanagerengine_nokia.h
+++ b/src/plugins/geoservices/nokia/qgeotilefetcher_nokia.h
@@ -46,33 +46,36 @@
**
****************************************************************************/
-#ifndef QGEOMAPPINGMANAGERENGINE_NOKIA_H
-#define QGEOMAPPINGMANAGERENGINE_NOKIA_H
+#ifndef QGEOTILEFETCHER_NOKIA_H
+#define QGEOTILEFETCHER_NOKIA_H
#include "qgeoserviceproviderplugin_nokia.h"
-#include <qgeoserviceprovider.h>
-#include <qgeomappingmanagerengine.h>
+#include <QGeoServiceProvider>
+#include "qgeotilefetcher.h"
+
+#ifdef USE_CHINA_NETWORK_REGISTRATION
+#include <qnetworkinfo.h>
+#endif
QT_BEGIN_NAMESPACE
class QNetworkAccessManager;
class QNetworkDiskCache;
-class QNetworkInfo;
class QGeoTiledMapReply;
class QGeoTileSpec;
+class QGeoTileCache;
+class QGeoTiledMappingManagerEngine;
-class QGeoMappingManagerEngineNokia : public QGeoMappingManagerEngine
+class QGeoTileFetcherNokia : public QGeoTileFetcher
{
Q_OBJECT
public:
- QGeoMappingManagerEngineNokia(const QMap<QString, QVariant> &parameters,
- QGeoServiceProvider::Error *error,
- QString *errorString);
- ~QGeoMappingManagerEngineNokia();
+ QGeoTileFetcherNokia(QGeoTiledMappingManagerEngine *engine);
+ ~QGeoTileFetcherNokia();
- void init();
+ bool init();
QGeoTiledMapReply* getTileImage(const QGeoTileSpec &spec);
@@ -83,17 +86,20 @@ public:
const QString& applicationId() const;
const QString& referer() const;
+ void setParams(const QMap<QString, QVariant> *parameters);
+ void setTileSize(QSize tileSize);
+
#ifdef USE_CHINA_NETWORK_REGISTRATION
private Q_SLOTS:
void currentMobileCountryCodeChanged(int interface, const QString& mcc);
#endif
private:
- Q_DISABLE_COPY(QGeoMappingManagerEngineNokia)
+ Q_DISABLE_COPY(QGeoTileFetcherNokia)
- QString getRequestString(const QGeoTileSpec &spec) const;
+ QString getRequestString(const QGeoTileSpec &spec);
- static QString sizeToStr(int size);
+ static QString sizeToStr(const QSize &size);
static QString mapIdToStr(int mapId);
void setHost(const QString& host);
@@ -101,14 +107,18 @@ private:
QNetworkAccessManager *m_networkManager;
QNetworkDiskCache *m_cache;
+ const QMap<QString, QVariant> *m_parameters;
+ QSize m_tileSize;
QString m_host;
QString m_token;
+ QString m_referer;
QChar m_firstSubdomain;
+
unsigned char m_maxSubdomains;
QString m_applicationId;
#ifdef USE_CHINA_NETWORK_REGISTRATION
- QNetworkInfo *m_networkInfo;
+ QNetworkInfo m_networkInfo;
#endif
};
diff --git a/tests/auto/declarative_ui/tst_map_itemview.qml b/tests/auto/declarative_ui/tst_map_itemview.qml
index 9cc1e1ff..99306071 100644
--- a/tests/auto/declarative_ui/tst_map_itemview.qml
+++ b/tests/auto/declarative_ui/tst_map_itemview.qml
@@ -178,7 +178,7 @@ Item {
}
RouteModel {id: routeModel; plugin: testPlugin_immediate; query: routeQuery }
- SignalSpy {id: mapItemsChangedSpy; target: mapForViewWithoutPlugin; signalName: "mapItemsChanged"}
+ SignalSpy {id: mapItemsChangedSpy; target: mapForTestingRouteModel; signalName: "mapItemsChanged"}
Map {
id: mapForView;
@@ -207,28 +207,11 @@ Item {
}
Map {
- id: mapForViewWithoutPlugin;
+ id: mapForTestingRouteModel;
+ plugin: testPlugin;
center: mapDefaultCenter;
anchors.fill: parent;
zoomLevel: 2
- MapCircle {
- id: internalCircle2
- radius: 2000000
- center: mapDefaultCenter
- }
- MapItemView {
- id: theItemView2
- model: testModel
- delegate: Component {
- MapCircle {
- radius: 1500000
- center: Coordinate {
- latitude: modeldata.coordinate.latitude;
- longitude: modeldata.coordinate.longitude;
- }
- }
- }
- }
MapItemView {
id: routeItemView
model: routeModel
@@ -374,80 +357,62 @@ Item {
compare(mapForView.mapItems.length, 4)
}
- SignalSpy {id: pluginChangedSpy; target: mapForViewWithoutPlugin; signalName: "pluginChanged"}
- function test_plugin_set_later() {
- testModel.datacount = 7
- testModel.update()
- compare(mapForViewWithoutPlugin.mapItems.length, 8) // 7 from testModel, + 1 from mapcircle
- mapForViewWithoutPlugin.plugin = testPlugin
- tryCompare(pluginChangedSpy, "count", 1, 1000)
- compare(mapForViewWithoutPlugin.mapItems.length, 8)
- mapForViewWithoutPlugin.clearMapItems();
- compare(mapForViewWithoutPlugin.mapItems.length, 0)
- testModel.reset();
- compare(mapForViewWithoutPlugin.mapItems.length, 0)
- testModel.reset();
- testModel.datacount = 7
- testModel.update()
- compare(mapForViewWithoutPlugin.mapItems.length, 7)
- }
-
function test_routemodel() {
testModel.reset();
mapItemsChangedSpy.clear()
- compare(mapForViewWithoutPlugin.mapItems.length, 0) // precondition
+ compare(mapForTestingRouteModel.mapItems.length, 0) // precondition
compare(mapItemsChangedSpy.count, 0)
routeQuery.numberAlternativeRoutes = 4
routeModel.update();
- compare(mapForViewWithoutPlugin.mapItems.length, 4)
+ compare(mapForTestingRouteModel.mapItems.length, 4)
routeQuery.numberAlternativeRoutes = 3
routeModel.update();
- compare(mapForViewWithoutPlugin.mapItems.length, 3)
+ compare(mapForTestingRouteModel.mapItems.length, 3)
routeModel.clear();
- compare(mapForViewWithoutPlugin.mapItems.length, 0)
+ compare(mapForTestingRouteModel.mapItems.length, 0)
routeModel.clear(); // clear empty model
routeQuery.numberAlternativeRoutes = 3
routeModel.update();
- compare(mapForViewWithoutPlugin.mapItems.length, 3)
- mapForViewWithoutPlugin.addMapItem(externalCircle2)
- compare(mapForViewWithoutPlugin.mapItems.length, 4)
- compare(mapForViewWithoutPlugin.mapItems[3], externalCircle2)
+ compare(mapForTestingRouteModel.mapItems.length, 3)
+ mapForTestingRouteModel.addMapItem(externalCircle2)
+ compare(mapForTestingRouteModel.mapItems.length, 4)
+ compare(mapForTestingRouteModel.mapItems[3], externalCircle2)
routeModel.reset();
- compare(mapForViewWithoutPlugin.mapItems.length, 1)
- mapForViewWithoutPlugin.clearMapItems()
- compare(mapForViewWithoutPlugin.mapItems.length, 0)
+ compare(mapForTestingRouteModel.mapItems.length, 1)
+ mapForTestingRouteModel.clearMapItems()
+ compare(mapForTestingRouteModel.mapItems.length, 0)
// Test the mapItems list
- mapForViewWithoutPlugin.addMapItem(externalCircle2)
- compare(mapForViewWithoutPlugin.mapItems.length, 1)
- compare(mapForViewWithoutPlugin.mapItems[0], externalCircle2)
+ mapForTestingRouteModel.addMapItem(externalCircle2)
+ compare(mapForTestingRouteModel.mapItems.length, 1)
+ compare(mapForTestingRouteModel.mapItems[0], externalCircle2)
- mapForViewWithoutPlugin.addMapItem(externalRectangle)
- compare(mapForViewWithoutPlugin.mapItems.length, 2)
- compare(mapForViewWithoutPlugin.mapItems[1], externalRectangle)
+ mapForTestingRouteModel.addMapItem(externalRectangle)
+ compare(mapForTestingRouteModel.mapItems.length, 2)
+ compare(mapForTestingRouteModel.mapItems[1], externalRectangle)
- mapForViewWithoutPlugin.addMapItem(externalRectangle)
- compare(mapForViewWithoutPlugin.mapItems.length, 2)
- compare(mapForViewWithoutPlugin.mapItems[1], externalRectangle)
+ mapForTestingRouteModel.addMapItem(externalRectangle)
+ compare(mapForTestingRouteModel.mapItems.length, 2)
+ compare(mapForTestingRouteModel.mapItems[1], externalRectangle)
- mapForViewWithoutPlugin.addMapItem(externalPolygon)
- compare(mapForViewWithoutPlugin.mapItems.length, 3)
- compare(mapForViewWithoutPlugin.mapItems[2], externalPolygon)
+ mapForTestingRouteModel.addMapItem(externalPolygon)
+ compare(mapForTestingRouteModel.mapItems.length, 3)
+ compare(mapForTestingRouteModel.mapItems[2], externalPolygon)
- mapForViewWithoutPlugin.addMapItem(externalQuickItem)
- compare(mapForViewWithoutPlugin.mapItems.length, 4)
- compare(mapForViewWithoutPlugin.mapItems[3], externalQuickItem)
+ mapForTestingRouteModel.addMapItem(externalQuickItem)
+ compare(mapForTestingRouteModel.mapItems.length, 4)
+ compare(mapForTestingRouteModel.mapItems[3], externalQuickItem)
- mapForViewWithoutPlugin.removeMapItem(externalCircle2)
- compare(mapForViewWithoutPlugin.mapItems.length, 3)
- compare(mapForViewWithoutPlugin.mapItems[0], externalRectangle)
+ mapForTestingRouteModel.removeMapItem(externalCircle2)
+ compare(mapForTestingRouteModel.mapItems.length, 3)
+ compare(mapForTestingRouteModel.mapItems[0], externalRectangle)
- mapForViewWithoutPlugin.removeMapItem(externalRectangle)
- compare(mapForViewWithoutPlugin.mapItems.length, 2)
- compare(mapForViewWithoutPlugin.mapItems[0], externalPolygon)
+ mapForTestingRouteModel.removeMapItem(externalRectangle)
+ compare(mapForTestingRouteModel.mapItems.length, 2)
+ compare(mapForTestingRouteModel.mapItems[0], externalPolygon)
- mapForViewWithoutPlugin.clearMapItems()
- compare(mapForViewWithoutPlugin.mapItems.length, 0)
+ mapForTestingRouteModel.clearMapItems()
+ compare(mapForTestingRouteModel.mapItems.length, 0)
}
}
}
diff --git a/tests/auto/declarative_ui/tst_map_mouse.qml b/tests/auto/declarative_ui/tst_map_mouse.qml
index 5a9be66a..574b38b8 100644
--- a/tests/auto/declarative_ui/tst_map_mouse.qml
+++ b/tests/auto/declarative_ui/tst_map_mouse.qml
@@ -298,6 +298,7 @@ Item {
function test_wheel() {
clear_data()
+ wait(500);
// on map but without mouse area
mouseWheel(map, 5, 5, 15, Qt.LeftButton, Qt.NoModifiers)
compare(mapWheelSpy.count, 1)
@@ -350,6 +351,7 @@ Item {
function test_basic_position_changed() {
// tests basic position changed/move when button is being pressed
clear_data();
+ wait(500);
mousePress(map, 5, 25)
compare(mouseUpperPressedSpy.count, 1)
compare(mouseUpper.lastAccepted, true)
@@ -470,6 +472,7 @@ Item {
function test_basic_press_release() {
clear_data()
+ wait(500);
// send to emptiness
mousePress(map, 5, 5)
compare(mouseUpperPressedSpy.count, 0)
@@ -539,6 +542,7 @@ Item {
function test_basic_click() {
clear_data();
+ wait(500);
mouseClick(map, 5, 5, Qt.RightButton, Qt.AltModifier)
compare(mouseUpperClickedSpy.count, 0)
@@ -606,6 +610,7 @@ Item {
function test_basic_double_click() {
clear_data();
+ wait(500);
real_double_click(map, 5, 5)
compare(mouseUpperDoubleClickedSpy.count, 0)
@@ -670,6 +675,7 @@ Item {
function test_zzz_basic_press_and_hold() { // _zzz_ to ensure execution last (takes time)
clear_data();
+ wait(1000);
real_press_and_hold(map, 5, 5)
compare(mouseUpperPressAndHoldSpy.count, 0)
compare(mouseLowerPressAndHoldSpy.count, 0)
diff --git a/tests/auto/geotestplugin/geotestplugin.pro b/tests/auto/geotestplugin/geotestplugin.pro
index bfed371b..352b1bce 100644
--- a/tests/auto/geotestplugin/geotestplugin.pro
+++ b/tests/auto/geotestplugin/geotestplugin.pro
@@ -11,7 +11,9 @@ HEADERS += qgeocodingmanagerengine_test.h \
qgeoserviceproviderplugin_test.h \
qgeoroutingmanagerengine_test.h \
qplacemanagerengine_test.h \
- qgeomappingmanagerengine_test.h
+ qgeotiledmappingmanagerengine_test.h \
+ qgeotiledmapdata_test.h \
+ qgeotilefetcher_test.h
SOURCES += qgeoserviceproviderplugin_test.cpp
diff --git a/tests/auto/geotestplugin/qgeoserviceproviderplugin_test.cpp b/tests/auto/geotestplugin/qgeoserviceproviderplugin_test.cpp
index 5b5b095a..371fc359 100644
--- a/tests/auto/geotestplugin/qgeoserviceproviderplugin_test.cpp
+++ b/tests/auto/geotestplugin/qgeoserviceproviderplugin_test.cpp
@@ -42,7 +42,7 @@
#include "qgeoserviceproviderplugin_test.h"
#include "qgeocodingmanagerengine_test.h"
#include "qgeoroutingmanagerengine_test.h"
-#include "qgeomappingmanagerengine_test.h"
+#include "qgeotiledmappingmanagerengine_test.h"
#include "qplacemanagerengine_test.h"
#include <QtPlugin>
@@ -74,7 +74,7 @@ QGeoMappingManagerEngine* QGeoServiceProviderFactoryTest::createMappingManagerEn
const QMap<QString, QVariant> & parameters,
QGeoServiceProvider::Error * error, QString * errorString ) const
{
- return new QGeoMappingManagerEngineTest(parameters, error, errorString);
+ return new QGeoTiledMappingManagerEngineTest(parameters, error, errorString);
}
QPlaceManagerEngine* QGeoServiceProviderFactoryTest::createPlaceManagerEngine(
diff --git a/tests/auto/geotestplugin/qgeotiledmapdata_test.h b/tests/auto/geotestplugin/qgeotiledmapdata_test.h
new file mode 100644
index 00000000..94c018c8
--- /dev/null
+++ b/tests/auto/geotestplugin/qgeotiledmapdata_test.h
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QGEOTILEDMAPDATA_TEST_H
+#define QGEOTILEDMAPDATA_TEST_H
+
+#include <qgeotiledmapdata_p.h>
+
+QT_USE_NAMESPACE
+
+
+class QGeoTiledMapDataTest: public QGeoTiledMapData
+{
+ Q_OBJECT
+public:
+ QGeoTiledMapDataTest(QGeoTiledMappingManagerEngine *engine, QObject *parent = 0)
+ : QGeoTiledMapData(engine, parent) {}
+
+};
+
+#endif
diff --git a/tests/auto/geotestplugin/qgeotiledmappingmanagerengine_test.h b/tests/auto/geotestplugin/qgeotiledmappingmanagerengine_test.h
new file mode 100644
index 00000000..559266b8
--- /dev/null
+++ b/tests/auto/geotestplugin/qgeotiledmappingmanagerengine_test.h
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QGEOTILEDMAPPINGMANAGERENGINE_TEST_H
+#define QGEOTILEDMAPPINGMANAGERENGINE_TEST_H
+
+#include <qgeoserviceprovider.h>
+#include <qgeotiledmappingmanagerengine.h>
+#include <QLocale>
+#include <qgeotiledmapreply.h>
+#include "qgeomaptype.h"
+#include "qgeocameracapabilities_p.h"
+
+#include "qgeotiledmapdata_test.h"
+#include "qgeotilefetcher_test.h"
+
+#include <QTimer>
+#include <QDebug>
+#include <QTimerEvent>
+
+QT_USE_NAMESPACE
+
+class QGeoTiledMappingManagerEngineTest: public QGeoTiledMappingManagerEngine
+{
+Q_OBJECT
+public:
+ QGeoTiledMappingManagerEngineTest(const QMap<QString, QVariant> &parameters,
+ QGeoServiceProvider::Error *error, QString *errorString) :
+ QGeoTiledMappingManagerEngine()
+ {
+ Q_UNUSED(error)
+ Q_UNUSED(errorString)
+
+ setLocale(QLocale (QLocale::German, QLocale::Germany));
+ QGeoCameraCapabilities capabilities;
+ capabilities.setMinimumZoomLevel(0.0);
+ capabilities.setMaximumZoomLevel(20.0);
+ capabilities.setSupportsBearing(true);
+ setCameraCapabilities(capabilities);
+
+ setTileSize(QSize(256, 256));
+
+ QGeoTileFetcherTest *fetcher = new QGeoTileFetcherTest(this);
+ fetcher->setParams(&parameters);
+ fetcher->setTileSize(QSize(256, 255));
+ setTileFetcher(fetcher);
+ }
+
+ QGeoMapData *createMapData()
+ {
+ return new QGeoTiledMapDataTest(this);;
+ }
+
+};
+
+#endif
diff --git a/tests/auto/geotestplugin/qgeotilefetcher_test.h b/tests/auto/geotestplugin/qgeotilefetcher_test.h
new file mode 100644
index 00000000..45788141
--- /dev/null
+++ b/tests/auto/geotestplugin/qgeotilefetcher_test.h
@@ -0,0 +1,177 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QGEOTILEFETCHER_TEST_H
+#define QGEOTILEFETCHER_TEST_H
+
+#include <qgeotiledmapreply.h>
+
+#include "qgeotilefetcher.h"
+#include "qgeotilespec.h"
+
+#include <QLocale>
+#include <QPainter>
+#include <QPixmap>
+#include <QByteArray>
+#include <QBuffer>
+#include <QTimer>
+#include <QDebug>
+#include <QTimerEvent>
+
+QT_USE_NAMESPACE
+
+class TiledMapReplyTest :public QGeoTiledMapReply
+{
+ Q_OBJECT
+public:
+ TiledMapReplyTest(const QGeoTileSpec &spec, QObject *parent=0): QGeoTiledMapReply (spec, parent) {}
+ void callSetError ( Error error, const QString & errorString ) {setError(error, errorString);}
+ void callSetFinished ( bool finished ) { setFinished(finished);}
+ void callSetCached(bool cached) { setFinished(cached);}
+ void callSetMapImageData(const QByteArray &data) { setMapImageData(data); }
+ void callSetMapImageFormat(const QString &format) { setMapImageFormat(format); }
+ void abort() { emit aborted(); }
+
+Q_SIGNALS:
+ void aborted();
+};
+
+class QGeoTileFetcherTest: public QGeoTileFetcher
+{
+Q_OBJECT
+public:
+ QGeoTileFetcherTest(QGeoTiledMappingManagerEngine *engine, QObject *parent = 0)
+ : QGeoTileFetcher(engine, parent) {}
+
+ bool init()
+ {
+ if (m_parameters->contains("finishRequestImmediately"))
+ finishRequestImmediately_ = qvariant_cast<bool>(m_parameters->value("finishRequestImmediately"));
+ return true;
+ }
+
+ QGeoTiledMapReply* getTileImage(const QGeoTileSpec &spec)
+ {
+ mappingReply_ = new TiledMapReplyTest(spec, this);
+
+ QImage im(256, 256, QImage::Format_RGB888);
+ im.fill(QColor("lightgray"));
+ QRectF rect;
+ QString text("X: " + QString::number(spec.x()) + "\nY: " + QString::number(spec.y()) + "\nZ: " + QString::number(spec.zoom()));
+ rect.setWidth(250);
+ rect.setHeight(250);
+ rect.setLeft(3);
+ rect.setTop(3);
+ QPainter painter;
+ QPen pen(QColor("firebrick"));
+ painter.begin(&im);
+ painter.setPen(pen);
+ painter.setFont( QFont("Times", 35, 10, false));
+ painter.drawText(rect, text);
+ // different border color for vertically and horizontally adjacent frames
+ if ((spec.x() + spec.y()) % 2 == 0)
+ pen.setColor(QColor("yellow"));
+ pen.setWidth(5);
+ painter.setPen(pen);
+ painter.drawRect(0,0,255,255);
+ painter.end();
+ QPixmap pm = QPixmap::fromImage(im);
+ QByteArray bytes;
+ QBuffer buffer(&bytes);
+ buffer.open(QIODevice::WriteOnly);
+ pm.save(&buffer, "PNG");
+
+ mappingReply_->callSetMapImageData(bytes);
+ mappingReply_->callSetMapImageFormat("png");
+ mappingReply_->callSetFinished(true);
+
+ return static_cast<QGeoTiledMapReply*>(mappingReply_);
+ }
+
+ void setParams(const QMap<QString, QVariant> *parameters)
+ {
+ m_parameters = parameters;
+ }
+
+ void setTileSize(QSize tileSize)
+ {
+ m_tileSize = tileSize;
+ }
+
+public Q_SLOTS:
+ void requestAborted()
+ {
+ if (timerId_) {
+ killTimer(timerId_);
+ timerId_ = 0;
+ }
+ errorString_ = "";
+ errorCode_ = QGeoTiledMapReply::NoError;
+ }
+
+protected:
+ void timerEvent(QTimerEvent *event)
+ {
+ Q_ASSERT(timerId_ == event->timerId());
+ Q_ASSERT(mappingReply_);
+ killTimer(timerId_);
+ timerId_ = 0;
+ if (errorCode_) {
+ mappingReply_->callSetError(errorCode_, errorString_);
+ emit tileError(mappingReply_->tileSpec(), errorString_);
+ } else {
+ mappingReply_->callSetError(QGeoTiledMapReply::NoError, "no error");
+ mappingReply_->callSetFinished(true);
+ }
+ // emit finished(mappingReply_); todo tileFinished
+ }
+
+private:
+ bool finishRequestImmediately_;
+ TiledMapReplyTest* mappingReply_;
+ int timerId_;
+ QGeoTiledMapReply::Error errorCode_;
+ QString errorString_;
+ const QMap<QString, QVariant> *m_parameters;
+ QSize m_tileSize;
+};
+
+#endif