File indexing completed on 2024-06-23 03:50:29

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2010 Dennis Nienhüser <nienhueser@kde.org>
0004 //
0005 
0006 
0007 #ifndef MARBLE_OSMOPENROUTESERVICERUNNER_H
0008 #define MARBLE_OSMOPENROUTESERVICERUNNER_H
0009 
0010 #include "RoutingRunner.h"
0011 #include "routing/instructions/RoutingInstruction.h"
0012 
0013 #include <QString>
0014 #include <QNetworkAccessManager>
0015 #include <QNetworkReply>
0016 
0017 namespace Marble
0018 {
0019 
0020 class GeoDataCoordinates;
0021 
0022 class OpenRouteServiceRunner : public RoutingRunner
0023 {
0024     Q_OBJECT
0025 
0026     enum PointType {
0027         StartPoint,
0028         ViaPoint,
0029         EndPoint
0030     };
0031 
0032 public:
0033     explicit OpenRouteServiceRunner(QObject *parent = nullptr);
0034 
0035     // Overriding MarbleAbstractRunner
0036     void retrieveRoute( const RouteRequest *request ) override;
0037 
0038 private Q_SLOTS:
0039     /** Route data was retrieved via http */
0040     void retrieveData( QNetworkReply *reply );
0041 
0042     /** A network error occurred */
0043     void handleError( QNetworkReply::NetworkError );
0044 
0045     void get();
0046 
0047 private:
0048     static QString formatCoordinates(const GeoDataCoordinates &coordinates);
0049 
0050     GeoDataDocument* parse( const QByteArray &input ) const;
0051 
0052     static RoutingInstruction::TurnType parseTurnType( const QString &text, QString* road );
0053 
0054     QNetworkAccessManager m_networkAccessManager;
0055 
0056     QNetworkRequest m_request;
0057 };
0058 
0059 }
0060 
0061 #endif