Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
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
// Qt-Security score:significant reason:default
4
5
#
include
"qgeoroutingmanagerengineosm.h"
6
#
include
"qgeoroutereplyosm.h"
7
#
include
"qgeorouteparserosrmv4_p.h"
8
#
include
"QtLocation/private/qgeorouteparserosrmv5_p.h"
9
10
#
include
<
QtCore
/
QUrlQuery
>
11
12
#
include
<
QtCore
/
QDebug
>
13
14
QGeoRoutingManagerEngineOsm::QGeoRoutingManagerEngineOsm(
const
QVariantMap ¶meters,
15
QGeoServiceProvider::Error *error,
16
QString *errorString)
17
: QGeoRoutingManagerEngine(parameters), m_networkManager(
new
QNetworkAccessManager(
this
))
18
{
19
if
(parameters.contains(QStringLiteral(
"osm.useragent"
)))
20
m_userAgent = parameters.value(QStringLiteral(
"osm.useragent"
)).toString().toLatin1();
21
else
22
m_userAgent =
"Qt Location based application"
;
23
24
if
(parameters.contains(QStringLiteral(
"osm.routing.host"
)))
25
m_urlPrefix = parameters.value(QStringLiteral(
"osm.routing.host"
)).toString().toLatin1();
26
else
27
m_urlPrefix = QStringLiteral(
"http://router.project-osrm.org/route/v1/driving/"
);
28
// for v4 it was "http://router.project-osrm.org/viaroute"
29
30
if
(parameters.contains(QStringLiteral(
"osm.routing.apiversion"
))
31
&& (parameters.value(QStringLiteral(
"osm.routing.apiversion"
)).toString().toLatin1() == QByteArray(
"v4"
)))
32
m_routeParser =
new
QGeoRouteParserOsrmV4(
this
);
33
else
34
m_routeParser =
new
QGeoRouteParserOsrmV5(
this
);
35
if
(parameters.contains(QStringLiteral(
"osm.routing.traffic_side"
))) {
36
QString trafficSide = parameters.value(QStringLiteral(
"mapbox.routing.traffic_side"
)).toString();
37
if
(trafficSide == QStringLiteral(
"right"
))
38
m_routeParser->setTrafficSide(QGeoRouteParser::RightHandTraffic);
39
else
if
(trafficSide == QStringLiteral(
"left"
))
40
m_routeParser->setTrafficSide(QGeoRouteParser::LeftHandTraffic);
41
}
42
43
*error = QGeoServiceProvider::NoError;
44
errorString->clear();
45
}
46
47
QGeoRoutingManagerEngineOsm
::~
QGeoRoutingManagerEngineOsm
()
48
{
49
}
50
51
QGeoRouteReply
*
QGeoRoutingManagerEngineOsm
::
calculateRoute
(
const
QGeoRouteRequest &request)
52
{
53
QNetworkRequest networkRequest;
54
networkRequest.setHeader(QNetworkRequest::UserAgentHeader, m_userAgent);
55
56
networkRequest.setUrl(routeParser()->requestUrl(request, m_urlPrefix));
57
58
QNetworkReply *reply = m_networkManager->get(networkRequest);
59
60
QGeoRouteReplyOsm *routeReply =
new
QGeoRouteReplyOsm(reply, request,
this
);
61
62
connect(routeReply, &QGeoRouteReplyOsm::finished,
63
this
, &QGeoRoutingManagerEngineOsm::replyFinished);
64
connect(routeReply, &QGeoRouteReplyOsm::errorOccurred,
65
this
, &QGeoRoutingManagerEngineOsm::replyError);
66
67
return
routeReply;
68
}
69
70
const
QGeoRouteParser
*
QGeoRoutingManagerEngineOsm
::
routeParser
()
const
71
{
72
return
m_routeParser;
73
}
74
75
void
QGeoRoutingManagerEngineOsm
::replyFinished()
76
{
77
QGeoRouteReply *reply = qobject_cast<QGeoRouteReply *>(sender());
78
if
(reply)
79
emit finished(reply);
80
}
81
82
void
QGeoRoutingManagerEngineOsm
::replyError(QGeoRouteReply::Error errorCode,
83
const
QString &errorString)
84
{
85
QGeoRouteReply *reply = qobject_cast<QGeoRouteReply *>(sender());
86
if
(reply)
87
emit errorOccurred(reply, errorCode, errorString);
88
}
QGeoRoutingManagerEngineOsm
Definition
qgeoroutingmanagerengineosm.h:17
QGeoRoutingManagerEngineOsm::~QGeoRoutingManagerEngineOsm
~QGeoRoutingManagerEngineOsm()
Definition
qgeoroutingmanagerengineosm.cpp:47
QGeoRoutingManagerEngineOsm::routeParser
const QGeoRouteParser * routeParser() const
Definition
qgeoroutingmanagerengineosm.cpp:70
QGeoRoutingManagerEngineOsm::calculateRoute
QGeoRouteReply * calculateRoute(const QGeoRouteRequest &request) override
Begins the calculation of the route specified by request.
Definition
qgeoroutingmanagerengineosm.cpp:51
qtlocation
src
plugins
geoservices
osm
qgeoroutingmanagerengineosm.cpp
Generated on
for Qt by
1.18.0