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
qgeoroutingmanagerengineosm.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 Aaron McCarthy <mccarthy.aaron@gmail.com>
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5#include "qgeoroutereplyosm.h"
7#include "QtLocation/private/qgeorouteparserosrmv5_p.h"
8
9#include <QtCore/QUrlQuery>
10
11#include <QtCore/QDebug>
12
15 QString *errorString)
16: QGeoRoutingManagerEngine(parameters), m_networkManager(new QNetworkAccessManager(this))
17{
18 if (parameters.contains(QStringLiteral("osm.useragent")))
19 m_userAgent = parameters.value(QStringLiteral("osm.useragent")).toString().toLatin1();
20 else
21 m_userAgent = "Qt Location based application";
22
23 if (parameters.contains(QStringLiteral("osm.routing.host")))
24 m_urlPrefix = parameters.value(QStringLiteral("osm.routing.host")).toString().toLatin1();
25 else
26 m_urlPrefix = QStringLiteral("http://router.project-osrm.org/route/v1/driving/");
27 // for v4 it was "http://router.project-osrm.org/viaroute"
28
29 if (parameters.contains(QStringLiteral("osm.routing.apiversion"))
30 && (parameters.value(QStringLiteral("osm.routing.apiversion")).toString().toLatin1() == QByteArray("v4")))
31 m_routeParser = new QGeoRouteParserOsrmV4(this);
32 else
33 m_routeParser = new QGeoRouteParserOsrmV5(this);
34 if (parameters.contains(QStringLiteral("osm.routing.traffic_side"))) {
35 QString trafficSide = parameters.value(QStringLiteral("mapbox.routing.traffic_side")).toString();
36 if (trafficSide == QStringLiteral("right"))
38 else if (trafficSide == QStringLiteral("left"))
40 }
41
43 errorString->clear();
44}
45
49
51{
52 QNetworkRequest networkRequest;
53 networkRequest.setHeader(QNetworkRequest::UserAgentHeader, m_userAgent);
54
55 networkRequest.setUrl(routeParser()->requestUrl(request, m_urlPrefix));
56
57 QNetworkReply *reply = m_networkManager->get(networkRequest);
58
59 QGeoRouteReplyOsm *routeReply = new QGeoRouteReplyOsm(reply, request, this);
60
62 this, &QGeoRoutingManagerEngineOsm::replyFinished);
64 this, &QGeoRoutingManagerEngineOsm::replyError);
65
66 return routeReply;
67}
68
70{
71 return m_routeParser;
72}
73
74void QGeoRoutingManagerEngineOsm::replyFinished()
75{
76 QGeoRouteReply *reply = qobject_cast<QGeoRouteReply *>(sender());
77 if (reply)
79}
80
81void QGeoRoutingManagerEngineOsm::replyError(QGeoRouteReply::Error errorCode,
82 const QString &errorString)
83{
84 QGeoRouteReply *reply = qobject_cast<QGeoRouteReply *>(sender());
85 if (reply)
86 emit errorOccurred(reply, errorCode, errorString);
87}
void setTrafficSide(TrafficSide trafficSide)
\inmodule QtLocation
void finished()
This signal is emitted when this reply has finished processing.
Error
Describes an error which prevented the completion of the operation.
void errorOccurred(QGeoRouteReply::Error error, const QString &errorString=QString())
This signal is emitted when an error has been detected in the processing of this reply.
\inmodule QtLocation
const QGeoRouteParser * routeParser() const
QGeoRouteReply * calculateRoute(const QGeoRouteRequest &request) override
QGeoRoutingManagerEngineOsm(const QVariantMap &parameters, QGeoServiceProvider::Error *error, QString *errorString)
void errorOccurred(QGeoRouteReply *reply, QGeoRouteReply::Error error, const QString &errorString=QString())
This signal is emitted when an error has been detected in the processing of reply.
void finished(QGeoRouteReply *reply)
This signal is emitted when reply has finished processing.
Error
Describes an error related to the loading and setup of a service provider plugin.
T value(const Key &key, const T &defaultValue=T()) const
Definition qmap.h:357
bool contains(const Key &key) const
Definition qmap.h:341
The QNetworkAccessManager class allows the application to send network requests and receive replies.
QNetworkReply * get(const QNetworkRequest &request)
Posts a request to obtain the contents of the target request and returns a new QNetworkReply object o...
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
The QNetworkRequest class holds a request to be sent with QNetworkAccessManager.
void setHeader(KnownHeaders header, const QVariant &value)
Sets the value of the known header header to be value, overriding any previously set headers.
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
QObject * sender() const
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; othe...
Definition qobject.cpp:2658
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
QByteArray toLatin1() const &
Definition qstring.h:630
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
DBusConnection const char DBusError * error
typedef QByteArray(EGLAPIENTRYP PFNQGSGETDISPLAYSPROC)()
#define QStringLiteral(str)
#define emit
QNetworkRequest request(url)
QNetworkReply * reply
char * toString(const MyType &t)
[31]