libosmscout 1.1.1
Loading...
Searching...
No Matches
RoutingModel.h
Go to the documentation of this file.
1#ifndef OSMSCOUT_CLIENT_QT_ROUTINGMODEL_H
2#define OSMSCOUT_CLIENT_QT_ROUTINGMODEL_H
3
4/*
5 OSMScout - a Qt backend for libosmscout and libosmscout-map
6 Copyright (C) 2014 Tim Teulings
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
27#include <osmscoutclient/DBThread.h>
28
30
35
36#include <QObject>
37#include <QAbstractListModel>
38
39#include <map>
40
41namespace osmscout {
42
46class OSMSCOUT_CLIENT_QT_API RoutingListModel : public QAbstractListModel
47{
48 Q_OBJECT
49 Q_PROPERTY(int count READ rowCount NOTIFY computingChanged)
50 Q_PROPERTY(bool ready READ isReady NOTIFY computingChanged)
51 Q_PROPERTY(QObject *routeWay READ getRouteWay NOTIFY computingChanged)
52 Q_PROPERTY(QObject *route READ getRoute NOTIFY computingChanged)
53 Q_PROPERTY(double length READ getRouteLength NOTIFY computingChanged)
54 Q_PROPERTY(double duration READ getRouteDuration NOTIFY computingChanged)
55
56signals:
58 LocationEntryRef target,
60 int requestId,
61 osmscout::BreakerRef breaker,
62 std::optional<osmscout::Bearing> bearing);
63
65
66 void routeFailed(QString reason);
67
68 void routingProgress(int percent);
69
70public slots:
71
80 LocationEntry* target,
81 QString vehicleStr="car",
82 double vehicleBearing = -1);
83
92 LocationEntry* target,
93 QmlRoutingProfile *routingProfile,
94 double vehicleBearing = -1);
95
96 void clear();
97
98 void cancel();
99
101 int requestId);
102
103 void onRouteFailed(QString reason,
104 int requestId);
105
106 void onRoutingProgress(int percent,
107 int requestId);
108
109private:
110 Router *router;
112 int requestId;
113 bool computing;
114 osmscout::BreakerRef breaker;
115
116public:
118
119public:
120 explicit RoutingListModel(QObject* parent = nullptr);
123 ~RoutingListModel() override;
124
125 RoutingListModel& operator=(const RoutingListModel&) = delete;
126 RoutingListModel& operator=(RoutingListModel&&) = delete;
127
128 QVariant data(const QModelIndex &index, int role) const override;
129
130 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
131
136 double getRouteLength() const;
137
142 double getRouteDuration() const;
143
144 Qt::ItemFlags flags(const QModelIndex &index) const override;
145
146 QHash<int, QByteArray> roleNames() const override;
147
148 Q_INVOKABLE QObject* get(int row) const;
149
150 inline bool isReady()
151 {
152 return !computing;
153 }
154
155 inline Q_INVOKABLE QStringList availableVehicles()
156 {
157 QStringList vehicles;
158 vehicles << "car";
159 vehicles << "bicycle";
160 vehicles << "foot";
161 return vehicles;
162 }
163
168 inline Q_INVOKABLE QObject* locationEntryFromPosition(double lat, double lon, QString label="")
169 {
170 return new LocationEntry(label,osmscout::GeoCoord(lat,lon));
171 }
172
173 inline QObject *getRoute() const
174 {
175 assert(route.parent()==nullptr); // Ownership is copied. To transfer ownership to QML, parent have to be null.
176 return new QtRouteData(route);
177 }
178
180 {
181 if (!route){
182 return nullptr;
183 }
184 return new OverlayWay(route.routeWay().nodes);
185 }
186};
187
188}
189
190#endif
#define OSMSCOUT_CLIENT_QT_API
Definition ClientQtImportExport.h:45
Definition LocationEntry.h:47
Definition OverlayObject.h:190
Definition QmlRoutingProfile.h:42
Definition QtRouteData.h:40
Definition RouteStep.h:43
Definition Router.h:50
void onRoutingProgress(int percent, int requestId)
double duration
Definition RoutingModel.h:54
void routeFailed(QString reason)
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Q_INVOKABLE QObject * locationEntryFromPosition(double lat, double lon, QString label="")
Definition RoutingModel.h:168
void onRouteFailed(QString reason, int requestId)
RouteStep::Roles Roles
Definition RoutingModel.h:117
double getRouteLength() const
void routingProgress(int percent)
QObject * route
Definition RoutingModel.h:52
Q_INVOKABLE QObject * get(int row) const
double length
Definition RoutingModel.h:53
OverlayWay * getRouteWay()
Definition RoutingModel.h:179
QVariant data(const QModelIndex &index, int role) const override
QHash< int, QByteArray > roleNames() const override
RoutingListModel(QObject *parent=nullptr)
bool isReady()
Definition RoutingModel.h:150
int count
Definition RoutingModel.h:49
Qt::ItemFlags flags(const QModelIndex &index) const override
double getRouteDuration() const
void routeRequest(LocationEntryRef start, LocationEntryRef target, QmlRoutingProfileRef profile, int requestId, osmscout::BreakerRef breaker, std::optional< osmscout::Bearing > bearing)
bool ready
Definition RoutingModel.h:50
QObject * routeWay
Definition RoutingModel.h:51
void setStartAndTarget(LocationEntry *start, LocationEntry *target, QString vehicleStr="car", double vehicleBearing=-1)
Q_INVOKABLE QStringList availableVehicles()
Definition RoutingModel.h:155
QObject * getRoute() const
Definition RoutingModel.h:173
void onRouteComputed(QtRouteData route, int requestId)
Definition Area.h:39
std::shared_ptr< Breaker > BreakerRef
Definition Breaker.h:64
std::shared_ptr< LocationEntry > LocationEntryRef
Definition LocationEntry.h:119
std::shared_ptr< QmlRoutingProfile > QmlRoutingProfileRef
Definition QmlRoutingProfile.h:117
STL namespace.