libosmscout 1.1.1
Loading...
Searching...
No Matches
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
26
28
29#include <QAbstractListModel>
30#include <QDateTime>
31#include <QObject>
32
33#include <optional>
34
35namespace osmscout {
36
43class OSMSCOUT_CLIENT_QT_API NavigationModel : public QAbstractListModel
44{
45 Q_OBJECT
46 Q_PROPERTY(QObject *route READ getRoute WRITE setRoute NOTIFY routeChanged)
47 Q_PROPERTY(QObject *routeWay READ getRouteWay NOTIFY routeChanged)
48 Q_PROPERTY(QObject *routeWayAhead READ getRouteWayAhead NOTIFY routeAheadChanged)
49 Q_PROPERTY(QObject *routeWayPassed READ getRouteWayPassed NOTIFY routeAheadChanged)
50 Q_PROPERTY(QObject *nextRouteStep READ getNextRoutStep NOTIFY update)
51
54
55 Q_PROPERTY(QDateTime arrivalEstimate READ getArrivalEstimate NOTIFY arrivalUpdate)
57
58 // km/h, <0 when unknown
59 Q_PROPERTY(double currentSpeed READ getCurrentSpeed NOTIFY currentSpeedUpdate)
60 // km/h <0 when unknown
62
63 Q_PROPERTY(int laneCount READ getLaneCount NOTIFY laneUpdate)
64 Q_PROPERTY(bool laneSuggested READ isLaneSuggested NOTIFY laneUpdate)
66 Q_PROPERTY(int suggestedLaneTo READ getSuggestedLaneTo NOTIFY laneUpdate)
67 Q_PROPERTY(QStringList laneTurns READ getLaneTurns NOTIFY laneUpdate)
68
69signals:
70 void update();
71
74
76
78 osmscout::Vehicle vehicle);
79
80 void positionChange(osmscout::GeoCoord coord,
81 bool horizontalAccuracyValid, double horizontalAccuracy);
82
84
89 void rerouteRequest(double fromLat, double fromLon,
90 const QString bearing,
91 double bearingAngle,
92 double toLat, double toLon);
93
94 void targetReached(QString targetBearing, double targetDistance);
95
96 void positionEstimate(osmscout::PositionAgent::PositionState state, double lat, double lon, QString bearing);
97
100
102
103public slots:
104 void locationChanged(bool locationValid,
105 double lat, double lon,
106 bool horizontalAccuracyValid, double horizontalAccuracy);
107
108 void onUpdate(std::list<RouteStep> instructions);
109
110 void onUpdateNext(RouteStep nextRouteInstruction);
111
112 void onPositionEstimate(const PositionAgent::PositionState state,
113 const GeoCoord coord,
114 const std::optional<osmscout::Bearing> bearing);
115
116 void onTargetReached(const osmscout::Bearing targetBearing,
117 const osmscout::Distance targetDistance);
118
119 void onRerouteRequest(const GeoCoord from,
120 const std::optional<osmscout::Bearing> initialBearing,
121 const GeoCoord to);
122
124
127
128 void onLaneUpdate(osmscout::LaneAgent::Lane lane);
129
130public:
132
133public:
135
136 ~NavigationModel() override;
137
139
140 QObject *getRoute() const;
141 void setRoute(QObject *route);
142
143 QObject *getNextRoutStep();
144
145 QVariant data(const QModelIndex &index, int role) const override;
146
147 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
148
149 Qt::ItemFlags flags(const QModelIndex &index) const override;
150
151 QHash<int, QByteArray> roleNames() const override;
152
153 inline OverlayWay* getRouteWay() const
154 {
155 if (!route){
156 return nullptr;
157 }
158 return new OverlayWay(route.routeWay().nodes);
159 }
160
163
165 {
166 if (!route || vehicleState==PositionAgent::Uninitialised){
167 return nullptr;
168 }
169 return new VehiclePosition(vehicle, vehicleState, vehicleCoord, vehicleBearing,
170 nextRouteStep.getType().isEmpty() ? std::nullopt : std::optional<GeoCoord>(nextRouteStep.GetCoord()));
171 }
172
173 inline bool getPositionEstimateInTunnel() const
174 {
175 return vehicleState==PositionAgent::EstimateInTunnel;
176 }
177
178 inline QDateTime getArrivalEstimate() const
179 {
180 return arrivalEstimate;
181 }
182
183 inline double getRemainingDinstance() const
184 {
185 if (!remainingDistance.has_value()){
186 return 0;
187 }
188 return remainingDistance->AsMeter();
189 }
190
191 inline double getCurrentSpeed() const
192 {
193 return currentSpeed;
194 }
195
196 inline double getMaxAllowedSpeed() const
197 {
198 return maxAllowedSpeed;
199 }
200
201 int getLaneCount() const
202 {
203 return lane.count;
204 }
205
206 bool isLaneSuggested() const
207 {
208 return lane.suggested;
209 }
210
212 {
213 return lane.suggestedFrom;
214 }
215
217 {
218 return lane.suggestedTo;
219 }
220
221 QStringList getLaneTurns() const
222 {
223 QStringList result;
224 for (const auto &turn : lane.turns){
225 result << QString::fromStdString(LaneTurnString(turn));
226 }
227 return result;
228 }
229
230private:
231 NavigationModule* navigationModule;
232 QtRouteData route;
233
234 Vehicle vehicle;
235 PositionAgent::PositionState vehicleState{PositionAgent::Uninitialised};
236 GeoCoord vehicleCoord;
237 std::optional<osmscout::Bearing> vehicleBearing;
238
239 std::vector<RouteStep> routeSteps;
240 RouteStep nextRouteStep;
241
242 QDateTime arrivalEstimate;
243 std::optional<osmscout::Distance> remainingDistance;
244
245 double currentSpeed{-1};
246 double maxAllowedSpeed{-1};
247
248 LaneAgent::Lane lane;
249};
250
251}
252
253#endif //OSMSCOUT_CLIENT_QT_NAVIGATIONMODEL_H
#define OSMSCOUT_CLIENT_QT_API
Definition ClientQtImportExport.h:45
void targetReached(QString targetBearing, double targetDistance)
void onLaneUpdate(osmscout::LaneAgent::Lane lane)
QObject * getRoute() const
Qt::ItemFlags flags(const QModelIndex &index) const override
int suggestedLaneFrom
Definition NavigationModel.h:65
QObject * routeWayPassed
Definition NavigationModel.h:49
double maxAllowedSpeed
Definition NavigationModel.h:61
QDateTime getArrivalEstimate() const
Definition NavigationModel.h:178
QHash< int, QByteArray > roleNames() const override
int laneCount
Definition NavigationModel.h:63
double remainingDistance
Definition NavigationModel.h:56
QVariant data(const QModelIndex &index, int role) const override
QObject * nextRouteStep
Definition NavigationModel.h:50
QObject * routeWayAhead
Definition NavigationModel.h:48
void currentSpeedUpdate(double currentSpeed)
double currentSpeed
Definition NavigationModel.h:59
RouteStep::Roles Roles
Definition NavigationModel.h:131
void routeChanged(QtRouteData route, osmscout::Vehicle vehicle)
bool positionEstimateInTunnel
Definition NavigationModel.h:53
int suggestedLaneTo
Definition NavigationModel.h:66
int getSuggestedLaneFrom() const
Definition NavigationModel.h:211
void onCurrentSpeed(double currentSpeed)
void onUpdateNext(RouteStep nextRouteInstruction)
int getLaneCount() const
Definition NavigationModel.h:201
void locationChanged(bool locationValid, double lat, double lon, bool horizontalAccuracyValid, double horizontalAccuracy)
int rowCount(const QModelIndex &parent=QModelIndex()) const override
bool getPositionEstimateInTunnel() const
Definition NavigationModel.h:173
bool laneSuggested
Definition NavigationModel.h:64
void onRerouteRequest(const GeoCoord from, const std::optional< osmscout::Bearing > initialBearing, const GeoCoord to)
int getSuggestedLaneTo() const
Definition NavigationModel.h:216
double getRemainingDinstance() const
Definition NavigationModel.h:183
void rerouteRequest(double fromLat, double fromLon, const QString bearing, double bearingAngle, double toLat, double toLon)
void positionEstimate(osmscout::PositionAgent::PositionState state, double lat, double lon, QString bearing)
QDateTime arrivalEstimate
Definition NavigationModel.h:55
void positionChange(osmscout::GeoCoord coord, bool horizontalAccuracyValid, double horizontalAccuracy)
void onUpdate(std::list< RouteStep > instructions)
double getCurrentSpeed() const
Definition NavigationModel.h:191
double getMaxAllowedSpeed() const
Definition NavigationModel.h:196
QObject * routeWay
Definition NavigationModel.h:47
VehiclePosition * getVehiclePosition() const
Definition NavigationModel.h:164
OverlayWay * getRouteWay() const
Definition NavigationModel.h:153
void setRoute(QObject *route)
void onTargetReached(const osmscout::Bearing targetBearing, const osmscout::Distance targetDistance)
OverlayWay * getRouteWayAhead() const
void onArrivalEstimate(QDateTime arrivalEstimate, osmscout::Distance remainingDistance)
QStringList laneTurns
Definition NavigationModel.h:67
void onPositionEstimate(const PositionAgent::PositionState state, const GeoCoord coord, const std::optional< osmscout::Bearing > bearing)
QObject * vehiclePosition
Definition NavigationModel.h:52
void maxAllowedSpeedUpdate(double maxAllowedSpeed)
bool isLaneSuggested() const
Definition NavigationModel.h:206
QStringList getLaneTurns() const
Definition NavigationModel.h:221
QObject * route
Definition NavigationModel.h:46
OverlayWay * getRouteWayPassed() const
void onMaxAllowedSpeed(double maxAllowedSpeed)
Definition NavigationModule.h:67
Definition OverlayObject.h:190
Definition QtRouteData.h:40
Definition RouteStep.h:43
Definition VehiclePosition.h:41
Definition Area.h:39
std::string OSMSCOUT_API LaneTurnString(LaneTurn turn)
Vehicle
Definition OSMScoutTypes.h:55
STL namespace.