libosmscout  1.1.1
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 
23 #include <osmscout/Location.h>
24 #include <osmscout/util/Breaker.h>
26 
28 
30 #include <osmscout/DBThread.h>
31 #include <osmscout/Router.h>
32 #include <osmscout/OverlayObject.h>
34 
35 #include <QObject>
36 #include <QAbstractListModel>
37 
38 #include <map>
39 
40 namespace osmscout {
41 
45 class OSMSCOUT_CLIENT_QT_API RoutingListModel : public QAbstractListModel
46 {
47  Q_OBJECT
48  Q_PROPERTY(int count READ rowCount NOTIFY computingChanged)
49  Q_PROPERTY(bool ready READ isReady NOTIFY computingChanged)
50  Q_PROPERTY(QObject *routeWay READ getRouteWay NOTIFY computingChanged)
51  Q_PROPERTY(QObject *route READ getRoute NOTIFY computingChanged)
52  Q_PROPERTY(double length READ getRouteLength NOTIFY computingChanged)
53  Q_PROPERTY(double duration READ getRouteDuration NOTIFY computingChanged)
54 
55 signals:
56  void routeRequest(LocationEntryRef start,
57  LocationEntryRef target,
58  QmlRoutingProfileRef profile,
59  int requestId,
60  osmscout::BreakerRef breaker);
61 
62  void computingChanged();
63 
64  void routeFailed(QString reason);
65 
66  void routingProgress(int percent);
67 
68 public slots:
69  void setStartAndTarget(LocationEntry* start,
70  LocationEntry* target,
71  QString vehicleStr="car");
72 
73  void setStartAndTarget(LocationEntry* start,
74  LocationEntry* target,
75  QmlRoutingProfile *routingProfile);
76 
77  void clear();
78 
79  void cancel();
80 
81  void onRouteComputed(QtRouteData route,
82  int requestId);
83 
84  void onRouteFailed(QString reason,
85  int requestId);
86 
87  void onRoutingProgress(int percent,
88  int requestId);
89 
90 private:
91  Router *router;
92  QtRouteData route;
93  int requestId;
94  bool computing;
95  osmscout::BreakerRef breaker;
96 
97 public:
98  using Roles = RouteStep::Roles;
99 
100 public:
101  explicit RoutingListModel(QObject* parent = 0);
102  virtual ~RoutingListModel();
103 
104  QVariant data(const QModelIndex &index, int role) const;
105 
106  int rowCount(const QModelIndex &parent = QModelIndex()) const;
107 
112  double getRouteLength() const;
113 
118  double getRouteDuration() const;
119 
120  Qt::ItemFlags flags(const QModelIndex &index) const;
121 
122  QHash<int, QByteArray> roleNames() const;
123 
124  Q_INVOKABLE QObject* get(int row) const;
125 
126  inline bool isReady()
127  {
128  return !computing;
129  }
130 
131  inline Q_INVOKABLE QStringList availableVehicles()
132  {
133  QStringList vehicles;
134  vehicles << "car";
135  vehicles << "bicycle";
136  vehicles << "foot";
137  return vehicles;
138  }
139 
144  inline Q_INVOKABLE QObject* locationEntryFromPosition(double lat, double lon, QString label="")
145  {
146  return new LocationEntry(label,osmscout::GeoCoord(lat,lon));
147  }
148 
149  inline QObject *getRoute() const
150  {
151  return new QtRouteData(route);
152  }
153 
155  {
156  if (!route){
157  return nullptr;
158  }
159  return new OverlayWay(route.routeWay().nodes);
160  }
161 };
162 
163 }
164 
165 #endif
Q_INVOKABLE QStringList availableVehicles()
Definition: RoutingModel.h:131
#define OSMSCOUT_CLIENT_QT_API
Definition: ClientQtImportExport.h:45
std::shared_ptr< LocationEntry > LocationEntryRef
Definition: LocationEntry.h:112
Q_INVOKABLE QObject * locationEntryFromPosition(double lat, double lon, QString label="")
Definition: RoutingModel.h:144
std::shared_ptr< Breaker > BreakerRef
Definition: Breaker.h:65
Definition: QtRouteData.h:40
Definition: RoutingModel.h:45
Definition: OverlayObject.h:189
std::shared_ptr< QmlRoutingProfile > QmlRoutingProfileRef
Definition: QmlRoutingProfile.h:117
Definition: Area.h:38
Definition: QmlRoutingProfile.h:42
QObject * getRoute() const
Definition: RoutingModel.h:149
Definition: RouteStep.h:42
Roles
Definition: RouteStep.h:63
Definition: LocationEntry.h:42
Definition: Router.h:46
OverlayWay * getRouteWay()
Definition: RoutingModel.h:154