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