diff options
author | Basel Hashisho <basel.hashisho@nokia.com> | 2012-02-17 12:07:01 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-03-09 16:04:55 +0100 |
commit | 53e5f30e06091f5b05c9283657e454bc45896075 (patch) | |
tree | a9a5be51418b008f61165b510f1d87aa748a020e /src/plugins/geoservices/nokia | |
parent | f61e60ec2d66e181caf9e81b126936075e6fca5d (diff) | |
download | qtlocation-53e5f30e06091f5b05c9283657e454bc45896075.tar.gz |
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>
Diffstat (limited to 'src/plugins/geoservices/nokia')
-rw-r--r-- | src/plugins/geoservices/nokia/nokia.pro | 8 | ||||
-rw-r--r-- | src/plugins/geoservices/nokia/qgeoserviceproviderplugin_nokia.cpp | 4 | ||||
-rw-r--r-- | src/plugins/geoservices/nokia/qgeotiledmapdata_nokia.cpp | 169 | ||||
-rw-r--r-- | src/plugins/geoservices/nokia/qgeotiledmapdata_nokia.h | 23 | ||||
-rw-r--r-- | src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.cpp | 101 | ||||
-rw-r--r-- | src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.h | 75 | ||||
-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 |
8 files changed, 287 insertions, 292 deletions
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> ¶meters, 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> ¶meters, + 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(¶meters); + 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> ¶meters, + 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> ¶meters, 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 ¶m) +bool QGeoTileFetcherNokia::isValidParameter(const QString ¶m) { 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> ¶meters, - 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 }; |