Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qgeoserviceproviderplugin_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
5
12
13#include <QtPlugin>
14#include <QNetworkProxy>
15#include <QCoreApplication>
16
18
19namespace
20{
21 bool isValidParameter(const QString &param)
22 {
23 if (param.isEmpty())
24 return false;
25
26 if (param.length() > 512)
27 return false;
28
29 for (const auto &c : param) {
30 if (!c.isLetterOrNumber() && c.toLatin1() != '%' && c.toLatin1() != '-' &&
31 c.toLatin1() != '+' && c.toLatin1() != '_') {
32 return false;
33 }
34 }
35 return true;
36 }
37
39 {
40 return static_cast<QGeoNetworkAccessManager *>(qvariant_cast<void *>(parameters.value(QStringLiteral("nam"))));
41 }
42
43 void checkUsageTerms(const QVariantMap &parameters, QGeoServiceProvider::Error *error, QString *errorString)
44 {
45 const QString apiKey = parameters.value(QStringLiteral("here.apiKey")).toString();
46
47 if (isValidParameter(apiKey))
48 return;
49 else
50 qWarning() << "Invalid here.apiKey";
51
52 if (parameters.contains(QStringLiteral("apiKey")))
53 qWarning() << QStringLiteral("Please prefix 'apiKey' with prefix 'here' (e.g.: 'here.apiKey')");
54
55 *error = QGeoServiceProvider::MissingRequiredParameterError;
56 *errorString = QCoreApplication::translate(NOKIA_PLUGIN_CONTEXT_NAME, MISSED_CREDENTIALS);
57 }
58
59 template<class TInstance>
60 TInstance * CreateInstanceOf(const QVariantMap &parameters, QGeoServiceProvider::Error *error, QString *errorString)
61 {
62 checkUsageTerms(parameters, error, errorString);
63
64 if (*error != QGeoServiceProvider::NoError)
65 return nullptr;
66
67 QGeoNetworkAccessManager *networkManager = tryGetNetworkAccessManager(parameters);
68 if (!networkManager)
69 networkManager = new QGeoIntrinsicNetworkAccessManager(parameters);
70
71 return new TInstance(networkManager, parameters, error, errorString);
72 }
73}
74
75QGeoServiceProviderFactoryNokia::QGeoServiceProviderFactoryNokia()
76{
77}
78
80 const QVariantMap &parameters,
81 QGeoServiceProvider::Error *error,
82 QString *errorString) const
83{
84 return CreateInstanceOf<QGeoCodingManagerEngineNokia>(parameters, error, errorString);
85}
86
88 const QVariantMap &parameters,
89 QGeoServiceProvider::Error *error,
90 QString *errorString) const
91{
92 return CreateInstanceOf<QGeoTiledMappingManagerEngineNokia>(parameters, error, errorString);
93}
94
96 const QVariantMap &parameters,
97 QGeoServiceProvider::Error *error,
98 QString *errorString) const
99{
100 return CreateInstanceOf<QGeoRoutingManagerEngineNokia>(parameters, error, errorString);
101}
102
104 const QVariantMap &parameters,
105 QGeoServiceProvider::Error *error,
106 QString *errorString) const
107{
108 return CreateInstanceOf<QPlaceManagerEngineNokiaV2>(parameters, error, errorString);
109}
110
111QT_END_NAMESPACE
QGeoMappingManagerEngine * createMappingManagerEngine(const QVariantMap &parameters, QGeoServiceProvider::Error *error, QString *errorString) const override
Returns a new QGeoMappingManagerEngine instance, initialized with parameters, which implements mappin...
Q_PLUGIN_METADATA(IID "org.qt-project.qt.geoservice.serviceproviderfactory/6.0" FILE "nokia_plugin.json") public QGeoCodingManagerEngine * createGeocodingManagerEngine(const QVariantMap &parameters, QGeoServiceProvider::Error *error, QString *errorString) const override
Returns a new QGeoCodingManagerEngine instance, initialized with parameters, which implements the loc...
QPlaceManagerEngine * createPlaceManagerEngine(const QVariantMap &parameters, QGeoServiceProvider::Error *error, QString *errorString) const override
Returns a new QPlaceManagerEngine instance, initialized with parameters, which implements the place s...
QGeoRoutingManagerEngine * createRoutingManagerEngine(const QVariantMap &parameters, QGeoServiceProvider::Error *error, QString *errorString) const override
Returns a new QGeoRoutingManagerEngine instance, initialized with parameters, which implements routin...
Combined button and popup list for selecting options.
QGeoNetworkAccessManager * tryGetNetworkAccessManager(const QVariantMap &parameters)
bool isValidParameter(const QString &param)
TInstance * CreateInstanceOf(const QVariantMap &parameters, QGeoServiceProvider::Error *error, QString *errorString)
void checkUsageTerms(const QVariantMap &parameters, QGeoServiceProvider::Error *error, QString *errorString)