Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qdeclarativegeoroutemodel_p.h
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QDECLARATIVEGEOROUTEMODEL_H
5#define QDECLARATIVEGEOROUTEMODEL_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QObject>
19#include <QAbstractListModel>
20#include <QtPositioning/QGeoCoordinate>
21#include <QtPositioning/QGeoRectangle>
22#include <qgeorouterequest.h>
23#include <qgeoroutereply.h>
24#include <QtQml/qqml.h>
25#include <QtQml/QQmlParserStatus>
26
27#include <QtLocation/private/qlocationglobal_p.h>
28#include <QtLocation/private/qdeclarativegeoserviceprovider_p.h>
29
30#include <QtPositioning/private/qgeocoordinateobject_p.h>
31
33
34class QGeoServiceProvider;
35class QGeoRoutingManager;
36class QDeclarativeGeoRoute;
37class QDeclarativeGeoRouteQuery;
38
39class Q_LOCATION_EXPORT QDeclarativeGeoRouteModel : public QAbstractListModel, public QQmlParserStatus
40{
41 Q_OBJECT
42 QML_NAMED_ELEMENT(RouteModel)
43 QML_ADDED_IN_VERSION(5, 0)
44 Q_ENUMS(Status)
45 Q_ENUMS(RouteError)
46
47 Q_PROPERTY(QDeclarativeGeoServiceProvider *plugin READ plugin WRITE setPlugin NOTIFY pluginChanged)
48 Q_PROPERTY(QDeclarativeGeoRouteQuery *query READ query WRITE setQuery NOTIFY queryChanged)
49 Q_PROPERTY(int count READ count NOTIFY countChanged)
50 Q_PROPERTY(bool autoUpdate READ autoUpdate WRITE setAutoUpdate NOTIFY autoUpdateChanged)
51 Q_PROPERTY(Status status READ status NOTIFY statusChanged)
52 Q_PROPERTY(QString errorString READ errorString NOTIFY errorChanged)
53 Q_PROPERTY(RouteError error READ error NOTIFY errorChanged)
54 Q_PROPERTY(QLocale::MeasurementSystem measurementSystem READ measurementSystem WRITE setMeasurementSystem NOTIFY measurementSystemChanged)
55
56 Q_INTERFACES(QQmlParserStatus)
57
58public:
59 enum Roles {
60 RouteRole = Qt::UserRole + 500
61 };
62
63 enum Status {
64 Null,
65 Ready,
66 Loading,
67 Error
68 };
69
70 enum RouteError {
71 NoError = QGeoRouteReply::NoError,
72 EngineNotSetError = QGeoRouteReply::EngineNotSetError,
73 CommunicationError = QGeoRouteReply::CommunicationError,
74 ParseError = QGeoRouteReply::ParseError,
75 UnsupportedOptionError = QGeoRouteReply::UnsupportedOptionError,
76 UnknownError = QGeoRouteReply::UnknownError,
77 //we leave gap for future QGeoRouteReply errors
78
79 //QGeoServiceProvider related errors start here
80 UnknownParameterError = 100,
81 MissingRequiredParameterError
82 };
83
84 explicit QDeclarativeGeoRouteModel(QObject *parent = nullptr);
85
86 // From QQmlParserStatus
87 void classBegin() override {}
88 void componentComplete() override;
89
90 // From QAbstractListModel
91 int rowCount(const QModelIndex &parent) const override;
92 QVariant data(const QModelIndex &index, int role) const override;
93 QHash<int,QByteArray> roleNames() const override;
94
95 void setPlugin(QDeclarativeGeoServiceProvider *plugin);
96 QDeclarativeGeoServiceProvider *plugin() const;
97
98 void setQuery(QDeclarativeGeoRouteQuery *query);
99 QDeclarativeGeoRouteQuery *query() const;
100
101 void setAutoUpdate(bool autoUpdate);
102 bool autoUpdate() const;
103
104 void setMeasurementSystem(QLocale::MeasurementSystem ms);
105 QLocale::MeasurementSystem measurementSystem() const;
106
107 Status status() const;
108 QString errorString() const;
109 RouteError error() const;
110
111 int count() const;
112 Q_INVOKABLE QGeoRoute get(int index);
113 Q_INVOKABLE void reset();
114 Q_INVOKABLE void cancel();
115
116Q_SIGNALS:
117 void countChanged();
118 void pluginChanged();
119 void queryChanged();
120 void autoUpdateChanged();
121 void statusChanged();
122 void errorChanged(); //emitted also for errorString notification
123 void routesChanged();
124 void measurementSystemChanged();
125 void abortRequested();
126
127public Q_SLOTS:
128 void update();
129
130private Q_SLOTS:
131 void routingFinished(QGeoRouteReply *reply);
132 void routingError(QGeoRouteReply *reply,
133 QGeoRouteReply::Error error,
134 const QString &errorString);
135 void queryDetailsChanged();
136 void pluginReady();
137
138private:
139 void setStatus(Status status);
140 void setError(RouteError error, const QString &errorString);
141
142 bool complete_ = false;
143
144 QDeclarativeGeoServiceProvider *plugin_ = nullptr;
145 QDeclarativeGeoRouteQuery *routeQuery_ = nullptr;
146
147 QList<QGeoRoute> routes_;
148 bool autoUpdate_ = false;
149 Status status_ = QDeclarativeGeoRouteModel::Null;
150 QString errorString_;
151 RouteError error_ = QDeclarativeGeoRouteModel::NoError;
152};
153
154class Q_LOCATION_EXPORT QDeclarativeGeoRouteQuery : public QObject, public QQmlParserStatus
155{
156 Q_OBJECT
157 QML_NAMED_ELEMENT(RouteQuery)
158 QML_ADDED_IN_VERSION(5, 0)
159 Q_ENUMS(TravelMode)
160 Q_ENUMS(FeatureType)
161 Q_ENUMS(FeatureWeight)
162 Q_ENUMS(SegmentDetail)
163 Q_ENUMS(ManeuverDetail)
164 Q_ENUMS(RouteOptimization)
165 Q_FLAGS(RouteOptimizations)
166 Q_FLAGS(ManeuverDetails)
167 Q_FLAGS(SegmentDetails)
168 Q_FLAGS(TravelModes)
169
170 Q_PROPERTY(int numberAlternativeRoutes READ numberAlternativeRoutes WRITE setNumberAlternativeRoutes NOTIFY numberAlternativeRoutesChanged)
171 Q_PROPERTY(TravelModes travelModes READ travelModes WRITE setTravelModes NOTIFY travelModesChanged)
172 Q_PROPERTY(RouteOptimizations routeOptimizations READ routeOptimizations WRITE setRouteOptimizations NOTIFY routeOptimizationsChanged)
173 Q_PROPERTY(SegmentDetail segmentDetail READ segmentDetail WRITE setSegmentDetail NOTIFY segmentDetailChanged)
174 Q_PROPERTY(ManeuverDetail maneuverDetail READ maneuverDetail WRITE setManeuverDetail NOTIFY maneuverDetailChanged)
175 Q_PROPERTY(QList<QGeoCoordinate> waypoints READ waypoints WRITE setWaypoints NOTIFY waypointsChanged)
176 Q_PROPERTY(QList<QGeoRectangle> excludedAreas READ excludedAreas WRITE setExcludedAreas NOTIFY excludedAreasChanged)
177 Q_PROPERTY(QList<int> featureTypes READ featureTypes NOTIFY featureTypesChanged)
178 Q_PROPERTY(QDateTime departureTime READ departureTime WRITE setDepartureTime NOTIFY departureTimeChanged REVISION(5, 13))
179 Q_INTERFACES(QQmlParserStatus)
180
181public:
182
183 explicit QDeclarativeGeoRouteQuery(QObject *parent = nullptr);
184 QDeclarativeGeoRouteQuery(const QGeoRouteRequest &request, QObject *parent = nullptr); // init from request. For instances intended to be read only
185 ~QDeclarativeGeoRouteQuery();
186
187 // From QQmlParserStatus
188 void classBegin() override {}
189 void componentComplete() override;
190
191 QGeoRouteRequest routeRequest() const;
192
193 enum TravelMode {
194 CarTravel = QGeoRouteRequest::CarTravel,
195 PedestrianTravel = QGeoRouteRequest::PedestrianTravel,
196 BicycleTravel = QGeoRouteRequest::BicycleTravel,
197 PublicTransitTravel = QGeoRouteRequest::PublicTransitTravel,
198 TruckTravel = QGeoRouteRequest::TruckTravel
199 };
200 Q_DECLARE_FLAGS(TravelModes, TravelMode)
201
202 enum FeatureType {
203 NoFeature = QGeoRouteRequest::NoFeature,
204 TollFeature = QGeoRouteRequest::TollFeature,
205 HighwayFeature = QGeoRouteRequest::HighwayFeature,
206 PublicTransitFeature = QGeoRouteRequest::PublicTransitFeature,
207 FerryFeature = QGeoRouteRequest::FerryFeature,
208 TunnelFeature = QGeoRouteRequest::TunnelFeature,
209 DirtRoadFeature = QGeoRouteRequest::DirtRoadFeature,
210 ParksFeature = QGeoRouteRequest::ParksFeature,
211 MotorPoolLaneFeature = QGeoRouteRequest::MotorPoolLaneFeature,
212 TrafficFeature = QGeoRouteRequest::TrafficFeature
213 };
214 Q_DECLARE_FLAGS(FeatureTypes, FeatureType)
215
216 enum FeatureWeight {
217 NeutralFeatureWeight = QGeoRouteRequest::NeutralFeatureWeight,
218 PreferFeatureWeight = QGeoRouteRequest::PreferFeatureWeight,
219 RequireFeatureWeight = QGeoRouteRequest::RequireFeatureWeight,
220 AvoidFeatureWeight = QGeoRouteRequest::AvoidFeatureWeight,
221 DisallowFeatureWeight = QGeoRouteRequest::DisallowFeatureWeight
222 };
223 Q_DECLARE_FLAGS(FeatureWeights, FeatureWeight)
224
225 enum RouteOptimization {
226 ShortestRoute = QGeoRouteRequest::ShortestRoute,
227 FastestRoute = QGeoRouteRequest::FastestRoute,
228 MostEconomicRoute = QGeoRouteRequest::MostEconomicRoute,
229 MostScenicRoute = QGeoRouteRequest::MostScenicRoute
230 };
231 Q_DECLARE_FLAGS(RouteOptimizations, RouteOptimization)
232
233 enum SegmentDetail {
234 NoSegmentData = 0x0000,
235 BasicSegmentData = 0x0001
236 };
237 Q_DECLARE_FLAGS(SegmentDetails, SegmentDetail)
238
239 enum ManeuverDetail {
240 NoManeuvers = 0x0000,
241 BasicManeuvers = 0x0001
242 };
243 Q_DECLARE_FLAGS(ManeuverDetails, ManeuverDetail)
244
245 void setNumberAlternativeRoutes(int numberAlternativeRoutes);
246 int numberAlternativeRoutes() const;
247
248 //QList<FeatureType> featureTypes();
249 QList<int> featureTypes() const;
250
251
252 QList<QGeoCoordinate> waypoints() const;
253 void setWaypoints(const QList<QGeoCoordinate> &value);
254
255 QList<QGeoRectangle> excludedAreas() const;
256 void setExcludedAreas(const QList<QGeoRectangle> &value);
257
258 Q_INVOKABLE void addWaypoint(const QGeoCoordinate &w);
259 Q_INVOKABLE void removeWaypoint(const QGeoCoordinate &waypoint);
260 Q_INVOKABLE void clearWaypoints();
261
262 Q_INVOKABLE void addExcludedArea(const QGeoRectangle &area);
263 Q_INVOKABLE void removeExcludedArea(const QGeoRectangle &area);
264 Q_INVOKABLE void clearExcludedAreas();
265
266 Q_INVOKABLE void setFeatureWeight(FeatureType featureType, FeatureWeight featureWeight);
267 Q_INVOKABLE int featureWeight(FeatureType featureType);
268 Q_INVOKABLE void resetFeatureWeights();
269
270 /*
271 feature weights
272 */
273
274 void setTravelModes(TravelModes travelModes);
275 TravelModes travelModes() const;
276
277 void setSegmentDetail(SegmentDetail segmentDetail);
278 SegmentDetail segmentDetail() const;
279
280 void setManeuverDetail(ManeuverDetail maneuverDetail);
281 ManeuverDetail maneuverDetail() const;
282
283 void setRouteOptimizations(RouteOptimizations optimization);
284 RouteOptimizations routeOptimizations() const;
285
286 void setDepartureTime(const QDateTime &departureTime);
287 QDateTime departureTime() const;
288
289Q_SIGNALS:
290 void numberAlternativeRoutesChanged();
291 void travelModesChanged();
292 void routeOptimizationsChanged();
293
294 void waypointsChanged();
295 void excludedAreasChanged();
296
297 void featureTypesChanged();
298 void maneuverDetailChanged();
299 void segmentDetailChanged();
300
301 void queryDetailsChanged();
302 void departureTimeChanged();
303
304private Q_SLOTS:
305 void excludedAreaCoordinateChanged();
306 void waypointChanged();
307
308private:
309 Q_INVOKABLE void doCoordinateChanged();
310
311 mutable QGeoRouteRequest request_;
312 bool complete_ = false;
313 bool m_excludedAreaCoordinateChanged = false;
314 mutable bool m_waypointsChanged = false;
315 QList<QGeoCoordinate> m_waypoints;
316};
317
318QT_END_NAMESPACE
319
320#endif