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
qgeoroutereplymapbox.cpp
Go to the documentation of this file.
1
// Copyright (C) 2016 Vlad Seryakov <vseryakov@gmail.com>
2
// Copyright (C) 2016 Aaron McCarthy <mccarthy.aaron@gmail.com>
3
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5
#
include
"qgeoroutereplymapbox.h"
6
#
include
"qgeoroutingmanagerenginemapbox.h"
7
#
include
<
QtLocation
/
private
/
qgeorouteparser_p
.
h
>
8
#
include
<
QtLocation
/
private
/
qgeoroute_p
.
h
>
9
#
include
<
QtCore
/
QJsonDocument
>
10
#
include
<
QtCore
/
QJsonObject
>
11
#
include
<
QtCore
/
QJsonArray
>
12
#
include
<
QtLocation
/
QGeoRouteSegment
>
13
#
include
<
QtLocation
/
QGeoManeuver
>
14
15
QT_BEGIN_NAMESPACE
16
17
QGeoRouteReplyMapbox::QGeoRouteReplyMapbox(
QNetworkReply
*
reply
,
const
QGeoRouteRequest
&
request
,
18
QObject
*
parent
)
19
: QGeoRouteReply(request, parent)
20
{
21
if
(!reply) {
22
setError(UnknownError, QStringLiteral(
"Null reply"
));
23
return
;
24
}
25
connect(reply, &QNetworkReply::finished,
26
this
, &QGeoRouteReplyMapbox::networkReplyFinished);
27
connect(reply, &QNetworkReply::errorOccurred,
28
this
, &QGeoRouteReplyMapbox::networkReplyError);
29
connect(
this
, &QGeoRouteReply::aborted, reply, &QNetworkReply::abort);
30
connect(
this
, &QObject::destroyed, reply, &QObject::deleteLater);
31
}
32
33
QGeoRouteReplyMapbox::~QGeoRouteReplyMapbox()
34
{
35
}
36
37
void
QGeoRouteReplyMapbox::networkReplyFinished()
38
{
39
QNetworkReply *reply =
static_cast
<QNetworkReply *>(sender());
40
reply->deleteLater();
41
42
if
(reply->error() != QNetworkReply::NoError)
43
return
;
44
45
QGeoRoutingManagerEngineMapbox
*engine = qobject_cast<
QGeoRoutingManagerEngineMapbox
*>(parent());
46
const
QGeoRouteParser *parser = engine
->
routeParser
(
)
;
47
48
QList<QGeoRoute> routes;
49
QString errorString;
50
51
QByteArray routeReply = reply->readAll();
52
QGeoRouteReply::Error error = parser->parseReply(routes, errorString, routeReply);
53
// Setting the request into the result
54
for
(QGeoRoute &route : routes) {
55
route.setRequest(request());
56
for
(QGeoRoute &leg: route.routeLegs()) {
57
leg.setRequest(request());
58
}
59
}
60
61
QVariantMap metadata;
62
metadata[
"osrm.reply-json"
] = routeReply;
63
64
QVariantMap extAttr;
65
extAttr[
"engine"
] =
"mapbox"
;
66
extAttr[
"metadata"
] = metadata;
67
68
QList<QGeoRoute> mapboxRoutes;
69
for
(
const
QGeoRoute &route : routes.mid(0, request().numberAlternativeRoutes() + 1)) {
70
QGeoRoute mapboxRoute(route);
71
mapboxRoute.setExtendedAttributes(extAttr);
72
mapboxRoutes.append(mapboxRoute);
73
}
74
75
if
(error == QGeoRouteReply::NoError) {
76
setRoutes(mapboxRoutes);
77
// setError(QGeoRouteReply::NoError, status); // can't do this, or NoError is emitted and does damages
78
setFinished(
true
);
79
}
else
{
80
setError(error, errorString);
81
}
82
}
83
84
void
QGeoRouteReplyMapbox::networkReplyError(QNetworkReply::NetworkError error)
85
{
86
Q_UNUSED(error);
87
QNetworkReply *reply =
static_cast
<QNetworkReply *>(sender());
88
reply->deleteLater();
89
setError(QGeoRouteReply::CommunicationError, reply->errorString());
90
}
91
92
QT_END_NAMESPACE
QGeoRoutingManagerEngineMapbox
Definition
qgeoroutingmanagerenginemapbox.h:17
QGeoRoutingManagerEngineMapbox::routeParser
const QGeoRouteParser * routeParser() const
Definition
qgeoroutingmanagerenginemapbox.cpp:260
QNetworkReply
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
Definition
qnetworkreply.h:30
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtlocation
src
plugins
geoservices
mapbox
qgeoroutereplymapbox.cpp
Generated on
for Qt by
1.18.0