libosmscout  1.1.1
NavigationModel.h
Go to the documentation of this file.
1 #ifndef OSMSCOUT_CLIENT_QT_NAVIGATIONMODEL_H
2 #define OSMSCOUT_CLIENT_QT_NAVIGATIONMODEL_H
3 
4 /*
5  OSMScout - a Qt backend for libosmscout and libosmscout-map
6  Copyright (C) 2018 Lukas Karas
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Lesser General Public
10  License as published by the Free Software Foundation; either
11  version 2.1 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public
19  License along with this library; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21  */
22 
24 #include <osmscout/OverlayObject.h>
25 
27 
28 #include <QObject>
29 
30 #include <optional>
31 
32 namespace osmscout {
33 
40 class OSMSCOUT_CLIENT_QT_API NavigationModel : public QAbstractListModel
41 {
42  Q_OBJECT
43  Q_PROPERTY(QObject *route READ getRoute WRITE setRoute NOTIFY routeChanged)
44  Q_PROPERTY(QObject *routeWay READ getRouteWay NOTIFY routeChanged)
45  Q_PROPERTY(QObject *routeWayAhead READ getRouteWayAhead NOTIFY routeAheadChanged)
46  Q_PROPERTY(QObject *routeWayPassed READ getRouteWayPassed NOTIFY routeAheadChanged)
47  Q_PROPERTY(QObject *nextRouteStep READ getNextRoutStep NOTIFY update)
48 
49  Q_PROPERTY(QObject *vehiclePosition READ getVehiclePosition NOTIFY vehiclePositionChanged)
50 
51  Q_PROPERTY(QDateTime arrivalEstimate READ getArrivalEstimate NOTIFY arrivalUpdate)
52  Q_PROPERTY(double remainingDistance READ getRemainingDinstance NOTIFY arrivalUpdate)
53 
54  // km/h, <0 when unknown
55  Q_PROPERTY(double currentSpeed READ getCurrentSpeed NOTIFY currentSpeedUpdate)
56  // km/h <0 when unknown
57  Q_PROPERTY(double maxAllowedSpeed READ getMaxAllowedSpeed NOTIFY maxAllowedSpeedUpdate)
58 
59  Q_PROPERTY(int laneCount READ getLaneCount NOTIFY laneUpdate)
60  Q_PROPERTY(bool laneSuggested READ isLaneSuggested NOTIFY laneUpdate)
61  Q_PROPERTY(int suggestedLaneFrom READ getSuggestedLaneFrom NOTIFY laneUpdate)
62  Q_PROPERTY(int suggestedLaneTo READ getSuggestedLaneTo NOTIFY laneUpdate)
63  Q_PROPERTY(QStringList laneTurns READ getLaneTurns NOTIFY laneUpdate)
64 
65 signals:
66  void update();
67 
68  void arrivalUpdate();
69  void routeAheadChanged();
70 
71  void vehiclePositionChanged();
72 
73  void routeChanged(QtRouteData route,
74  osmscout::Vehicle vehicle);
75 
76  void positionChange(osmscout::GeoCoord coord,
77  bool horizontalAccuracyValid, double horizontalAccuracy);
78 
79  void rerouteRequest(double fromLat, double fromLon,
80  const QString bearing,
81  double bearingAngle,
82  double toLat, double toLon);
83 
84  void targetReached(QString targetBearing, double targetDistance);
85 
86  void positionEstimate(osmscout::PositionAgent::PositionState state, double lat, double lon, QString bearing);
87 
88  void currentSpeedUpdate(double currentSpeed);
89  void maxAllowedSpeedUpdate(double maxAllowedSpeed);
90 
91  void laneUpdate();
92 
93 public slots:
94  void locationChanged(bool locationValid,
95  double lat, double lon,
96  bool horizontalAccuracyValid, double horizontalAccuracy);
97 
98  void onUpdate(std::list<RouteStep> instructions);
99 
100  void onUpdateNext(RouteStep nextRouteInstruction);
101 
102  void onPositionEstimate(const PositionAgent::PositionState state,
103  const GeoCoord coord,
104  const std::optional<osmscout::Bearing> bearing);
105 
106  void onTargetReached(const osmscout::Bearing targetBearing,
107  const osmscout::Distance targetDistance);
108 
109  void onRerouteRequest(const GeoCoord from,
110  const std::optional<osmscout::Bearing> initialBearing,
111  const GeoCoord to);
112 
113  void onArrivalEstimate(QDateTime arrivalEstimate, osmscout::Distance remainingDistance);
114 
115  void onCurrentSpeed(double currentSpeed);
116  void onMaxAllowedSpeed(double maxAllowedSpeed);
117 
118  void onLaneUpdate(osmscout::LaneAgent::Lane lane);
119 
120 public:
122 
123 public:
124  NavigationModel();
125 
126  virtual ~NavigationModel();
127 
128  bool isPositionOnRoute();
129 
130  QObject *getRoute() const;
131  void setRoute(QObject *route);
132 
133  QObject *getNextRoutStep();
134 
135  QVariant data(const QModelIndex &index, int role) const;
136 
137  int rowCount(const QModelIndex &parent = QModelIndex()) const;
138 
139  Qt::ItemFlags flags(const QModelIndex &index) const;
140 
141  QHash<int, QByteArray> roleNames() const;
142 
143  inline OverlayWay* getRouteWay() const
144  {
145  if (!route){
146  return nullptr;
147  }
148  return new OverlayWay(route.routeWay().nodes);
149  }
150 
151  OverlayWay* getRouteWayAhead() const;
152  OverlayWay* getRouteWayPassed() const;
153 
155  {
156  if (!route || vehicleState==PositionAgent::Uninitialised){
157  return nullptr;
158  }
159  return new VehiclePosition(vehicle, vehicleState, vehicleCoord, vehicleBearing,
160  nextRouteStep.getType().isEmpty() ? std::nullopt : std::optional<GeoCoord>(nextRouteStep.GetCoord()));
161  }
162 
163  inline QDateTime getArrivalEstimate() const
164  {
165  return arrivalEstimate;
166  }
167 
168  inline double getRemainingDinstance() const
169  {
170  if (!remainingDistance.has_value()){
171  return 0;
172  }
173  return remainingDistance->AsMeter();
174  }
175 
176  inline double getCurrentSpeed() const
177  {
178  return currentSpeed;
179  }
180 
181  inline double getMaxAllowedSpeed() const
182  {
183  return maxAllowedSpeed;
184  }
185 
186  int getLaneCount() const
187  {
188  return lane.count;
189  }
190 
191  bool isLaneSuggested() const
192  {
193  return lane.suggested;
194  }
195 
197  {
198  return lane.suggestedFrom;
199  }
200 
201  int getSuggestedLaneTo() const
202  {
203  return lane.suggestedTo;
204  }
205 
206  QStringList getLaneTurns() const
207  {
208  QStringList result;
209  for (const auto &turn : lane.turns){
210  result << QString::fromStdString(turn);
211  }
212  return result;
213  }
214 
215 private:
216  NavigationModule* navigationModule;
217  QtRouteData route;
218 
219  Vehicle vehicle;
220  PositionAgent::PositionState vehicleState{PositionAgent::Uninitialised};
221  GeoCoord vehicleCoord;
222  std::optional<osmscout::Bearing> vehicleBearing;
223 
224  std::vector<RouteStep> routeSteps;
225  RouteStep nextRouteStep;
226 
227  QDateTime arrivalEstimate;
228  std::optional<osmscout::Distance> remainingDistance;
229 
230  double currentSpeed{-1};
231  double maxAllowedSpeed{-1};
232 
233  LaneAgent::Lane lane;
234 };
235 
236 }
237 
238 #endif //OSMSCOUT_CLIENT_QT_NAVIGATIONMODEL_H
#define OSMSCOUT_CLIENT_QT_API
Definition: ClientQtImportExport.h:45
QDateTime getArrivalEstimate() const
Definition: NavigationModel.h:163
STL namespace.
Vehicle
Definition: OSMScoutTypes.h:55
double getMaxAllowedSpeed() const
Definition: NavigationModel.h:181
Definition: QtRouteData.h:40
QStringList getLaneTurns() const
Definition: NavigationModel.h:206
double getCurrentSpeed() const
Definition: NavigationModel.h:176
int getSuggestedLaneFrom() const
Definition: NavigationModel.h:196
Definition: OverlayObject.h:189
Definition: NavigationModel.h:40
Definition: Area.h:38
VehiclePosition * getVehiclePosition() const
Definition: NavigationModel.h:154
Definition: RouteStep.h:42
Roles
Definition: RouteStep.h:63
bool isLaneSuggested() const
Definition: NavigationModel.h:191
double getRemainingDinstance() const
Definition: NavigationModel.h:168
int getSuggestedLaneTo() const
Definition: NavigationModel.h:201
Definition: VehiclePosition.h:40
Definition: NavigationModule.h:54
int getLaneCount() const
Definition: NavigationModel.h:186