Marble

RoutingModel.h
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 //
3 // SPDX-FileCopyrightText: 2010 Dennis Nienhüser <[email protected]>
4 //
5 
6 #ifndef MARBLE_ROUTINGMODEL_H
7 #define MARBLE_ROUTINGMODEL_H
8 
9 #include "marble_export.h"
10 
11 #include <QAbstractListModel>
12 
13 class QIODevice;
14 
15 /**
16  * A QAbstractItemModel that contains a list of routing instructions.
17  * Each item represents a routing step in the way from source to
18  * destination. Steps near the source come first, steps near the target
19  * last.
20  */
21 namespace Marble
22 {
23 
24 class RoutingModelPrivate;
25 class Route;
26 class RouteRequest;
27 class GeoDataCoordinates;
28 class PositionTracking;
29 
30 class MARBLE_EXPORT RoutingModel : public QAbstractListModel
31 {
32  Q_OBJECT
33 
34  Q_PROPERTY( bool deviatedFromRoute READ deviatedFromRoute NOTIFY deviatedFromRoute )
35 
36 public:
37  enum RoutingModelRoles {
38  CoordinateRole = Qt::UserRole + 3,
39  TurnTypeIconRole,
40  LongitudeRole,
41  LatitudeRole
42  };
43 
44  /** Constructor */
45  explicit RoutingModel(RouteRequest *request, PositionTracking *positionTracking, QObject *parent = nullptr);
46 
47  /** Destructor */
48  ~RoutingModel() override;
49 
50  // Model querying
51 
52  /** Overload of QAbstractListModel */
53  int rowCount ( const QModelIndex &parent = QModelIndex() ) const override;
54 
55  /** Overload of QAbstractListModel */
56  QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
57 
58  /** Overload of QAbstractListModel */
59  QVariant data ( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
60 
61  /** Overload of QAbstractListModel */
62  QHash<int, QByteArray> roleNames() const override;
63 
64  // Model data filling
65 
66  /**
67  * Export waypoints and instructions in gpx format
68  */
69  void exportGpx( QIODevice *device ) const;
70 
71  /**
72  * Clear any data held in the model
73  */
74  void clear();
75 
76  /**
77  * Maps points from the provided route request to waypoints in the model
78  * according to their global minimal distance. Returns the right neighbor
79  * (next route request item along the waypoints) of the provided position.
80  * Provided route must not be null.
81  * @return -1 If the provided route is empty, the index of the right
82  * neighbor along the waypoints otherwise (result is a valid RouteRequest
83  * index in that case)
84  */
85  int rightNeighbor( const GeoDataCoordinates &position, RouteRequest const *const route ) const;
86 
87  /**
88  * returns whether the gps location is on route
89  */
90  bool deviatedFromRoute() const;
91 
92  const Route & route() const;
93 
94 public Q_SLOTS:
95  /**
96  * Old data in the model is discarded and a model reset is done
97  */
98  void setRoute( const Route &route );
99 
100  void updatePosition( const GeoDataCoordinates&, qreal );
101 
102 Q_SIGNALS:
103  /**
104  * emits a signal regarding information about total time( seconds ) and distance( metres ) remaining to reach destination
105  */
106  void positionChanged();
107  void deviatedFromRoute( bool deviated );
108 
109  /** A different route was loaded */
110  void currentRouteChanged();
111 
112 private:
113  RoutingModelPrivate *const d;
114 };
115 
116 } // namespace Marble
117 
118 #endif
UserRole
Orientation
Binds a QML item to a specific geodetic location in screen coordinates.
QAction * clear(const QObject *recvr, const char *slot, QObject *parent)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Thu Sep 21 2023 04:12:28 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.