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
qgeoroutereplyosm.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
7
9
10QGeoRouteReplyOsm::QGeoRouteReplyOsm(QNetworkReply *reply, const QGeoRouteRequest &request,
12: QGeoRouteReply(request, parent)
13{
14 if (!reply) {
15 setError(UnknownError, QStringLiteral("Null reply"));
16 return;
17 }
18 connect(reply, &QNetworkReply::finished,
19 this, &QGeoRouteReplyOsm::networkReplyFinished);
20 connect(reply, &QNetworkReply::errorOccurred,
21 this, &QGeoRouteReplyOsm::networkReplyError);
22 connect(this, &QGeoRouteReply::aborted, reply, &QNetworkReply::abort);
23 connect(this, &QObject::destroyed, reply, &QObject::deleteLater);
24}
25
26QGeoRouteReplyOsm::~QGeoRouteReplyOsm()
27{
28}
29
30void QGeoRouteReplyOsm::networkReplyFinished()
31{
32 QNetworkReply *reply = static_cast<QNetworkReply *>(sender());
33 reply->deleteLater();
34
35 if (reply->error() != QNetworkReply::NoError)
36 return;
37
38 QGeoRoutingManagerEngineOsm *engine = qobject_cast<QGeoRoutingManagerEngineOsm *>(parent());
39 const QGeoRouteParser *parser = engine->routeParser();
40
41 QList<QGeoRoute> routes;
42 QString errorString;
43 QGeoRouteReply::Error error = parser->parseReply(routes, errorString, reply->readAll());
44 // Setting the request into the result
45 for (QGeoRoute &route : routes) {
46 route.setRequest(request());
47 for (QGeoRoute &leg: route.routeLegs()) {
48 leg.setRequest(request());
49 }
50 }
51
52 if (error == QGeoRouteReply::NoError) {
53 setRoutes(routes.mid(0, request().numberAlternativeRoutes() + 1));
54 // setError(QGeoRouteReply::NoError, status); // can't do this, or NoError is emitted and does damages
55 setFinished(true);
56 } else {
57 setError(error, errorString);
58 }
59}
60
61void QGeoRouteReplyOsm::networkReplyError(QNetworkReply::NetworkError error)
62{
63 Q_UNUSED(error);
64 QNetworkReply *reply = static_cast<QNetworkReply *>(sender());
65 reply->deleteLater();
66 setError(QGeoRouteReply::CommunicationError, reply->errorString());
67}
68
69QT_END_NAMESPACE
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
Combined button and popup list for selecting options.