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
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
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
16
18 QObject *parent)
19: QGeoRouteReply(request, parent)
20{
21 if (!reply) {
22 setError(UnknownError, QStringLiteral("Null reply"));
23 return;
24 }
26 this, &QGeoRouteReplyMapbox::networkReplyFinished);
28 this, &QGeoRouteReplyMapbox::networkReplyError);
31}
32
36
37void QGeoRouteReplyMapbox::networkReplyFinished()
38{
39 QNetworkReply *reply = static_cast<QNetworkReply *>(sender());
41
43 return;
44
45 QGeoRoutingManagerEngineMapbox *engine = qobject_cast<QGeoRoutingManagerEngineMapbox *>(parent());
46 const QGeoRouteParser *parser = engine->routeParser();
47
48 QList<QGeoRoute> routes;
50
51 QByteArray routeReply = reply->readAll();
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
76 setRoutes(mapboxRoutes);
77 // setError(QGeoRouteReply::NoError, status); // can't do this, or NoError is emitted and does damages
78 setFinished(true);
79 } else {
81 }
82}
83
84void QGeoRouteReplyMapbox::networkReplyError(QNetworkReply::NetworkError error)
85{
87 QNetworkReply *reply = static_cast<QNetworkReply *>(sender());
90}
91
\inmodule QtCore
Definition qbytearray.h:57
QGeoRouteReply::Error parseReply(QList< QGeoRoute > &routes, QString &errorString, const QByteArray &reply) const
QGeoRouteReplyMapbox(QNetworkReply *reply, const QGeoRouteRequest &request, QObject *parent=nullptr)
\inmodule QtLocation
QList< QGeoRoute > routes() const
Returns the list of routes which were requested.
Error error() const
Returns the error state of this reply.
void setError(Error error, const QString &errorString)
Sets the error state of this reply to error and the textual representation of the error to errorStrin...
void setRoutes(const QList< QGeoRoute > &routes)
Sets the list of routes in the reply to routes.
QGeoRouteRequest request() const
Returns the route request which specified the route.
QString errorString() const
Returns the textual representation of the error state of this reply.
Error
Describes an error which prevented the completion of the operation.
void setFinished(bool finished)
Sets whether or not this reply has finished to finished.
\inmodule QtLocation
\inmodule QtLocation
Definition qgeoroute.h:24
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.
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
void errorOccurred(QNetworkReply::NetworkError)
NetworkError error() const
Returns the error that was found during the processing of this request.
virtual void abort()=0
Aborts the operation immediately and close down any network connections still open.
NetworkError
Indicates all possible error conditions found during the processing of the request.
void finished()
This signal is emitted when the reply has finished processing.
\inmodule QtCore
Definition qobject.h:103
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
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
void destroyed(QObject *=nullptr)
This signal is emitted immediately before the object obj is destroyed, after any instances of QPointe...
void deleteLater()
\threadsafe
Definition qobject.cpp:2435
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
Combined button and popup list for selecting options.
DBusConnection const char DBusError * error
#define QStringLiteral(str)
#define Q_UNUSED(x)
QNetworkRequest request(url)
QNetworkReply * reply
QJSEngine engine
[0]