Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qgeotilefetcher_nokia.cpp
Go to the documentation of this file.
1// Copyright (C) 2015 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
9#include "qgeouriprovider.h"
10#include "uri_constants.h"
11
12#include <QtLocation/private/qgeotilespec_p.h>
13
14#include <QDebug>
15#include <QSize>
16#include <QDir>
17#include <QUrl>
18#include <QTime>
19
20#include <map>
21
23
24namespace
25{
27 {
28 if (size > 256)
29 return QStringLiteral("512");
30 else if (size > 128)
31 return QStringLiteral("256");
32 else
33 return QStringLiteral("128"); // 128 pixel tiles are deprecated.
34 }
35
36 bool isAerialType(const QString mapScheme)
37 {
38 return mapScheme.startsWith("satellite") || mapScheme.startsWith("hybrid") || mapScheme.startsWith("terrain");
39 }
40}
42 QGeoNetworkAccessManager *networkManager,
44 const QSize &tileSize,
45 int ppi)
46: QGeoTileFetcher(engine), m_engineNokia(engine), m_networkManager(networkManager), m_ppi(ppi), m_copyrightsReply(nullptr),
47 m_baseUriProvider(new QGeoUriProvider(this, parameters, QStringLiteral("here.mapping.host"), MAP_TILES_HOST)),
48 m_aerialUriProvider(new QGeoUriProvider(this, parameters, QStringLiteral("here.mapping.host.aerial"), MAP_TILES_HOST_AERIAL))
49{
50 Q_ASSERT(networkManager);
51 m_tileSize = qMax(tileSize.width(), tileSize.height());
52 m_networkManager->setParent(this);
53
54 m_apiKey = parameters.value(QStringLiteral("here.apiKey")).toString();
55}
56
60
62{
63 // TODO add error detection for if request.connectivityMode() != QGraphicsGeoMap::OnlineMode
64 int ppi = m_ppi;
65 if ((spec.mapId() == 2) || (spec.mapId() == 12) || (spec.mapId() == 21)) {
66 ppi = 72; // HiDpi apparently not supported for these maps
67 } else if ((spec.mapId() >= 7 && spec.mapId() <= 11)
68 || (spec.mapId() == 14)
69 || (spec.mapId() == 16)
70 || (spec.mapId() == 18)
71 || (spec.mapId() == 20)) {
72 ppi = 250; // LoDpi apparently not supported for these maps
73 }
74
75 QString rawRequest = getRequestString(spec, ppi);
76 if (rawRequest.isEmpty()) {
78 tr("Mapping manager no longer exists"), this);
79 }
80
81 QNetworkRequest netRequest((QUrl(rawRequest))); // The extra pair of parens disambiguates this from a function declaration
82 netRequest.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true);
83
84 QNetworkReply *netReply = m_networkManager->get(netRequest);
85
86 QGeoTiledMapReply *mapReply = new QGeoMapReplyNokia(netReply, spec);
87
88 return mapReply;
89}
90
91QString QGeoTileFetcherNokia::getRequestString(const QGeoTileSpec &spec, int ppi) const
92{
93 if (!m_engineNokia)
94 return QString();
95
96 static const QString http("https://");
97 static const QString path("/maptile/2.1/maptile/newest/");
98 static const QChar slash('/');
99
100 QString requestString = http;
101
102 const QString mapScheme = m_engineNokia->getScheme(spec.mapId());
103 if (isAerialType(mapScheme))
104 requestString += m_aerialUriProvider->getCurrentHost();
105 else
106 requestString += m_baseUriProvider->getCurrentHost();
107
108 requestString += path;
109 requestString += mapScheme;
110 requestString += slash;
111 requestString += QString::number(spec.zoom());
112 requestString += slash;
113 requestString += QString::number(spec.x());
114 requestString += slash;
115 requestString += QString::number(spec.y());
116 requestString += slash;
117 requestString += ((ppi > 72)) ? sizeToStr(m_tileSize * 2) : sizeToStr(m_tileSize);
118 static const QString slashpng("/png8");
119 requestString += slashpng;
120
121 if (!m_apiKey.isEmpty()) { // TODO: remove the if
122 requestString += "?apiKey=";
123 requestString += m_apiKey;
124 }
125
126 requestString += "&ppi=" + QString::number(ppi);
127
128 requestString += "&lg=";
129 requestString += getLanguageString();
130 return requestString;
131}
132
133QString QGeoTileFetcherNokia::getLanguageString() const
134{
135 if (!m_engineNokia)
136 return QStringLiteral("ENG");
137
138 QLocale locale = m_engineNokia.data()->locale();
139
140 // English is the default, where no ln is specified. We hardcode the languages
141 // here even though the entire list is updated automagically from the server.
142 // The current languages are Arabic, Chinese, Simplified Chinese, English
143 // French, German, Italian, Polish, Russian and Spanish. The default is English.
144 // These are actually available from the same host under the URL: /maptiler/v2/info
145
146 switch (locale.language()) {
147 case QLocale::Arabic:
148 return QStringLiteral("ARA");
149 case QLocale::Chinese:
151 return QStringLiteral("CHI");
152 else
153 return QStringLiteral("CHT");
154 case QLocale::Dutch:
155 return QStringLiteral("DUT");
156 case QLocale::French:
157 return QStringLiteral("FRE");
158 case QLocale::German:
159 return QStringLiteral("GER");
160 case QLocale::Gaelic:
161 return QStringLiteral("GLE");
162 case QLocale::Greek:
163 return QStringLiteral("GRE");
164 case QLocale::Hebrew:
165 return QStringLiteral("HEB");
166 case QLocale::Hindi:
167 return QStringLiteral("HIN");
169 return QStringLiteral("IND");
170 case QLocale::Italian:
171 return QStringLiteral("ITA");
172 case QLocale::Persian:
173 return QStringLiteral("PER");
174 case QLocale::Polish:
175 return QStringLiteral("POL");
177 return QStringLiteral("POR");
178 case QLocale::Russian:
179 return QStringLiteral("RUS");
180 case QLocale::Sinhala:
181 return QStringLiteral("SIN");
182 case QLocale::Spanish:
183 return QStringLiteral("SPA");
184 case QLocale::Thai:
185 return QStringLiteral("THA");
186 case QLocale::Turkish:
187 return QStringLiteral("TUR");
189 return QStringLiteral("UKR");
190 case QLocale::Urdu:
191 return QStringLiteral("URD");
193 return QStringLiteral("VIE");
194
195 default:
196 return QStringLiteral("ENG");
197 }
198 // No "lg" param means that we want English.
199}
200
202{
203 return m_apiKey;
204}
205
207{
208 if (m_engineNokia && m_copyrightsReply->error() == QNetworkReply::NoError) {
209 QMetaObject::invokeMethod(m_engineNokia.data(),
210 "loadCopyrightsDescriptorsFromJson",
212 Q_ARG(QByteArray, m_copyrightsReply->readAll()));
213 }
214
215 m_copyrightsReply->deleteLater();
216}
217
219{
220 if (m_engineNokia && m_versionReply->error() == QNetworkReply::NoError) {
221 QMetaObject::invokeMethod(m_engineNokia.data(),
222 "parseNewVersionInfo",
224 Q_ARG(QByteArray, m_versionReply->readAll()));
225 }
226
227 m_versionReply->deleteLater();
228}
229
231{
232 QString copyrightUrl = QStringLiteral("https://");
233
234 copyrightUrl += m_baseUriProvider->getCurrentHost();
235 copyrightUrl += QStringLiteral("/maptile/2.1/copyright/newest?output=json");
236
237 if (!apiKey().isEmpty()) {
238 copyrightUrl += QStringLiteral("&apiKey=");
239 copyrightUrl += apiKey();
240 }
241
242 QNetworkRequest netRequest((QUrl(copyrightUrl)));
243 m_copyrightsReply = m_networkManager->get(netRequest);
244 if (m_copyrightsReply->error() != QNetworkReply::NoError) {
245 qWarning() << __FUNCTION__ << m_copyrightsReply->errorString();
246 m_copyrightsReply->deleteLater();
247 return;
248 }
249
250 if (m_copyrightsReply->isFinished()) {
252 } else {
253 connect(m_copyrightsReply, &QNetworkReply::finished,
255 }
256}
257
259{
260 QString versionUrl = QStringLiteral("https://");
261
262 versionUrl += m_baseUriProvider->getCurrentHost();
263 versionUrl += QStringLiteral("/maptile/2.1/version");
264
265 if (!apiKey().isEmpty()) {
266 versionUrl += QStringLiteral("?apiKey=");
267 versionUrl += apiKey();
268 }
269
270 QNetworkRequest netRequest((QUrl(versionUrl)));
271 m_versionReply = m_networkManager->get(netRequest);
272
273 if (m_versionReply->error() != QNetworkReply::NoError) {
274 qWarning() << __FUNCTION__ << m_versionReply->errorString();
275 m_versionReply->deleteLater();
276 return;
277 }
278
279 if (m_versionReply->isFinished())
281 else
282 connect(m_versionReply, &QNetworkReply::finished,
284}
285
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore
QLocale locale() const
Returns the locale used to hint to this mapping manager about what language to use for map labels.
virtual QNetworkReply * get(const QNetworkRequest &request)=0
QGeoTiledMapReply * getTileImage(const QGeoTileSpec &spec) override
QGeoTileFetcherNokia(const QVariantMap &parameters, QGeoNetworkAccessManager *networkManager, QGeoTiledMappingManagerEngineNokia *engine, const QSize &tileSize, int ppi)
int x() const
int zoom() const
int mapId() const
int y() const
\inmodule QtLocation
QString getCurrentHost() const
QByteArray readAll()
Reads all remaining data from the device, and returns it as a byte array.
QString errorString() const
Returns a human-readable description of the last device error that occurred.
@ TraditionalChineseScript
Definition qlocale.h:561
@ Polish
Definition qlocale.h:274
@ Italian
Definition qlocale.h:163
@ Spanish
Definition qlocale.h:314
@ Dutch
Definition qlocale.h:116
@ Greek
Definition qlocale.h:140
@ Chinese
Definition qlocale.h:102
@ Persian
Definition qlocale.h:272
@ Portuguese
Definition qlocale.h:275
@ Russian
Definition qlocale.h:283
@ Indonesian
Definition qlocale.h:156
@ Arabic
Definition qlocale.h:58
@ Hebrew
Definition qlocale.h:147
@ Sinhala
Definition qlocale.h:304
@ German
Definition qlocale.h:138
@ Ukrainian
Definition qlocale.h:347
@ Vietnamese
Definition qlocale.h:354
@ French
Definition qlocale.h:129
@ Turkish
Definition qlocale.h:342
@ Gaelic
Definition qlocale.h:132
@ Hindi
Definition qlocale.h:149
T value(const Key &key, const T &defaultValue=T()) const
Definition qmap.h:357
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
bool isFinished() const
NetworkError error() const
Returns the error that was found during the processing of this request.
void finished()
This signal is emitted when the reply has finished processing.
The QNetworkRequest class holds a request to be sent with QNetworkAccessManager.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
void setParent(QObject *parent)
Makes the object a child of parent.
Definition qobject.cpp:2195
void deleteLater()
\threadsafe
Definition qobject.cpp:2435
T * data() const noexcept
Definition qpointer.h:73
\inmodule QtCore
Definition qsize.h:25
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:192
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:8084
\inmodule QtCore
Definition qurl.h:94
QString toString() const
Returns the variant as a QString if the variant has a userType() including, but not limited to:
#define this
Definition dialogs.cpp:9
Q_QML_EXPORT QV4::ReturnedValue locale(QV4::ExecutionEngine *engine, const QString &localeName)
Provides locale specific properties and formatted data.
Combined button and popup list for selecting options.
bool isAerialType(const QString mapScheme)
QString sizeToStr(int size)
@ QueuedConnection
#define qWarning
Definition qlogging.h:166
static QT_BEGIN_NAMESPACE const int tileSize
Definition qmemrotate.cpp:9
constexpr const T & qMax(const T &a, const T &b)
Definition qminmax.h:42
#define Q_ARG(Type, data)
Definition qobjectdefs.h:63
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLsizei const GLchar *const * path
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define QStringLiteral(str)
#define tr(X)
QObject::connect nullptr
QJSEngine engine
[0]
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(nullptr), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
\threadsafe This is an overloaded member function, provided for convenience. It differs from the abov...
const QString MAP_TILES_HOST
const QString MAP_TILES_HOST_AERIAL