File indexing completed on 2024-04-28 03:49:29
0001 // SPDX-License-Identifier: LGPL-2.1-or-later 0002 // 0003 // SPDX-FileCopyrightText: 2010 Dennis Nienhüser <nienhueser@kde.org> 0004 // 0005 0006 #ifndef MARBLE_ROUTINGMODEL_H 0007 #define MARBLE_ROUTINGMODEL_H 0008 0009 #include "marble_export.h" 0010 0011 #include <QAbstractListModel> 0012 0013 class QIODevice; 0014 0015 /** 0016 * A QAbstractItemModel that contains a list of routing instructions. 0017 * Each item represents a routing step in the way from source to 0018 * destination. Steps near the source come first, steps near the target 0019 * last. 0020 */ 0021 namespace Marble 0022 { 0023 0024 class RoutingModelPrivate; 0025 class Route; 0026 class RouteRequest; 0027 class GeoDataCoordinates; 0028 class PositionTracking; 0029 0030 class MARBLE_EXPORT RoutingModel : public QAbstractListModel 0031 { 0032 Q_OBJECT 0033 0034 Q_PROPERTY( bool deviatedFromRoute READ deviatedFromRoute NOTIFY deviatedFromRoute ) 0035 0036 public: 0037 enum RoutingModelRoles { 0038 CoordinateRole = Qt::UserRole + 3, 0039 TurnTypeIconRole, 0040 LongitudeRole, 0041 LatitudeRole 0042 }; 0043 0044 /** Constructor */ 0045 explicit RoutingModel(RouteRequest *request, PositionTracking *positionTracking, QObject *parent = nullptr); 0046 0047 /** Destructor */ 0048 ~RoutingModel() override; 0049 0050 // Model querying 0051 0052 /** Overload of QAbstractListModel */ 0053 int rowCount ( const QModelIndex &parent = QModelIndex() ) const override; 0054 0055 /** Overload of QAbstractListModel */ 0056 QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override; 0057 0058 /** Overload of QAbstractListModel */ 0059 QVariant data ( const QModelIndex &index, int role = Qt::DisplayRole ) const override; 0060 0061 /** Overload of QAbstractListModel */ 0062 QHash<int, QByteArray> roleNames() const override; 0063 0064 // Model data filling 0065 0066 /** 0067 * Export waypoints and instructions in gpx format 0068 */ 0069 void exportGpx( QIODevice *device ) const; 0070 0071 /** 0072 * Clear any data held in the model 0073 */ 0074 void clear(); 0075 0076 /** 0077 * Maps points from the provided route request to waypoints in the model 0078 * according to their global minimal distance. Returns the right neighbor 0079 * (next route request item along the waypoints) of the provided position. 0080 * Provided route must not be null. 0081 * @return -1 If the provided route is empty, the index of the right 0082 * neighbor along the waypoints otherwise (result is a valid RouteRequest 0083 * index in that case) 0084 */ 0085 int rightNeighbor( const GeoDataCoordinates &position, RouteRequest const *const route ) const; 0086 0087 /** 0088 * returns whether the gps location is on route 0089 */ 0090 bool deviatedFromRoute() const; 0091 0092 const Route & route() const; 0093 0094 public Q_SLOTS: 0095 /** 0096 * Old data in the model is discarded and a model reset is done 0097 */ 0098 void setRoute( const Route &route ); 0099 0100 void updatePosition( const GeoDataCoordinates&, qreal ); 0101 0102 Q_SIGNALS: 0103 /** 0104 * emits a signal regarding information about total time( seconds ) and distance( metres ) remaining to reach destination 0105 */ 0106 void positionChanged(); 0107 void deviatedFromRoute( bool deviated ); 0108 0109 /** A different route was loaded */ 0110 void currentRouteChanged(); 0111 0112 private: 0113 RoutingModelPrivate *const d; 0114 }; 0115 0116 } // namespace Marble 0117 0118 #endif