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
qgeoroutesegment.cpp
Go to the documentation of this file.
1// Copyright (C) 2015 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
6
8#include <QDateTime>
9
10QT_BEGIN_NAMESPACE
11
12QT_DEFINE_QESDP_SPECIALIZATION_DTOR(QGeoRouteSegmentPrivate)
13
14/*!
15 \class QGeoRouteSegment
16 \inmodule QtLocation
17 \ingroup QtLocation-routing
18 \since 5.6
19
20 \brief The QGeoRouteSegment class represents a segment of a route.
21
22 A QGeoRouteSegment instance has information about the physical layout
23 of the route segment, the length of the route and estimated time required
24 to traverse the route segment and an optional QGeoManeuver associated with
25 the beginning of the route segment.
26
27 QGeoRouteSegment instances can be thought of as edges on a routing
28 graph, with QGeoManeuver instances as optional labels attached to the
29 vertices of the graph.
30*/
31
32/*!
33 \qmltype routeSegment
34 \inqmlmodule QtLocation
35 \ingroup qml-QtLocation5-routing
36 \since QtLocation 5.5
37
38 \brief The routeSegment type represents a segment of a Route.
39
40 A routeSegment instance has information about the physical layout
41 of the route segment, the length of the route and estimated time required
42 to traverse the route segment and optional \l {routeManeuver}s associated with
43 the end of the route segment.
44
45 Instances of routeSegment can be thought of as edges on a routing
46 graph, with routeManeuver instances as optional labels attached to the
47 vertices of the graph.
48
49 The primary means of acquiring Route objects is via Routes via \l RouteModel.
50
51 \section1 Example
52
53 The following QML snippet demonstrates how to print information about a
54 route segment:
55
56 \snippet declarative/routing.qml QtQuick import
57 \snippet declarative/maps.qml QtLocation import
58 \codeline
59 \snippet declarative/routing.qml routeSegment
60*/
61
62/*!
63 Constructs an invalid route segment object.
64
65 The route segment will remain invalid until one of setNextRouteSegment(),
66 setTravelTime(), setDistance(), setPath() or setManeuver() is called.
67*/
68QGeoRouteSegment::QGeoRouteSegment()
69 : d_ptr(new QGeoRouteSegmentPrivate()) {}
70
71/*!
72 Constructs a route segment object from the contents of \a other.
73*/
74QGeoRouteSegment::QGeoRouteSegment(const QGeoRouteSegment &other) noexcept = default;
75
76/*!
77 \internal
78*/
79QGeoRouteSegment::QGeoRouteSegment(QExplicitlySharedDataPointer<QGeoRouteSegmentPrivate> &&dd)
80 : d_ptr(dd) {}
81
82/*!
83 Destroys this route segment object.
84*/
85QGeoRouteSegment::~QGeoRouteSegment() = default;
86
87
88/*!
89 Assigns \a other to this route segment object and then returns a
90 reference to this route segment object.
91*/
92QGeoRouteSegment &QGeoRouteSegment::operator=(const QGeoRouteSegment & other) noexcept
93{
94 if (this == &other)
95 return *this;
96
97 d_ptr = other.d_ptr;
98 return *this;
99}
100
101/*!
102 \fn bool QGeoRouteSegment::operator==(const QGeoRouteSegment &lhs, const QGeoRouteSegment &rhs) noexcept
103 Returns whether the route segments \a lhs and \a rhs are equal.
104
105 The value of nextRouteSegment() is not considered in the comparison.
106*/
107
108/*!
109 \fn bool QGeoRouteSegment::operator!=(const QGeoRouteSegment &lhs, const QGeoRouteSegment &rhs) noexcept
110
111 Returns whether the route segments \a lhs and \a rhs are not equal.
112
113 The value of nextRouteSegment() is not considered in the comparison.
114*/
115
116bool QGeoRouteSegment::isEqual(const QGeoRouteSegment &other) const noexcept
117{
118 return ( (d_ptr.constData() == other.d_ptr.constData())
119 || (*d_ptr) == (*other.d_ptr));
120}
121
122/*!
123 Returns whether this route segment is valid or not.
124
125 If nextRouteSegment() is called on the last route segment of a route, the
126 returned value will be an invalid route segment.
127*/
128bool QGeoRouteSegment::isValid() const
129{
130 return d_ptr->valid();
131}
132
133/*!
134 Returns whether this route segment is the last segment of a route leg.
135
136 \since 5.12
137*/
138bool QGeoRouteSegment::isLegLastSegment() const
139{
140 if (!d_ptr->valid())
141 return false;
142
143 if (!d_ptr->nextRouteSegment())
144 return true;
145 return d_ptr->isLegLastSegment();
146}
147
148/*!
149 Sets the next route segment in the route to \a routeSegment.
150*/
151void QGeoRouteSegment::setNextRouteSegment(const QGeoRouteSegment &routeSegment)
152{
153 d_ptr->setValid(true);
154 d_ptr->setNextRouteSegment(routeSegment.d_ptr);
155}
156
157/*!
158 Returns the next route segment in the route.
159
160 Will return an invalid route segment if this is the last route
161 segment in the route.
162*/
163QGeoRouteSegment QGeoRouteSegment::nextRouteSegment() const
164{
165 if (d_ptr->valid() && d_ptr->nextRouteSegment())
166 return QGeoRouteSegment(d_ptr->nextRouteSegment());
167
168 return QGeoRouteSegment();
169}
170
171/*!
172 \qmlproperty int QtLocation::routeSegment::travelTime
173
174 Read-only property which holds the estimated amount of time it will take to
175 traverse this segment, in seconds.
176
177*/
178
179/*!
180 \property QGeoRouteSegment::travelTime
181 \brief the estimated amount of time, in seconds, that it will take to
182 traverse this segment.
183*/
184void QGeoRouteSegment::setTravelTime(int secs)
185{
186 d_ptr->setValid(true);
187 d_ptr->setTravelTime(secs);
188}
189
190int QGeoRouteSegment::travelTime() const
191{
192 return d_ptr->travelTime();
193}
194
195/*!
196 \qmlproperty real QtLocation::routeSegment::distance
197
198 Read-only property which holds the distance covered by this segment of
199 the route, in meters.
200*/
201
202/*!
203 \property QGeoRouteSegment::distance
204 \brief the distance covered by this segment of the route, in meters.
205*/
206void QGeoRouteSegment::setDistance(qreal distance)
207{
208 d_ptr->setValid(true);
209 d_ptr->setDistance(distance);
210}
211
212qreal QGeoRouteSegment::distance() const
213{
214 return d_ptr->distance();
215}
216
217/*!
218 \qmlproperty list<coordinate> QtLocation::routeSegment::path
219
220 Read-only property which holds the geographical coordinates of this segment.
221 Coordinates are listed in the order in which they would be traversed by someone
222 traveling along this segment of the route.
223
224 To access individual segments you can use standard list accessors: 'path.length'
225 indicates the number of objects and 'path[index starting from zero]' gives
226 the actual object.
227
228 \sa QtPositioning::coordinate
229*/
230
231/*!
232 \property QGeoRouteSegment::path
233 \brief the geometric shape of this route segment of the route.
234
235 The coordinates should be listed in the order in which they
236 would be traversed by someone traveling along this segment of the route.
237*/
238void QGeoRouteSegment::setPath(const QList<QGeoCoordinate> &path)
239{
240 d_ptr->setValid(true);
241 d_ptr->setPath(path);
242}
243
244QList<QGeoCoordinate> QGeoRouteSegment::path() const
245{
246 return d_ptr->path();
247}
248
249/*!
250 \qmlproperty RouteManeuver QtLocation::routeSegment::maneuver
251
252 Read-only property which holds the maneuver for this route segment.
253
254 Will return invalid maneuver if no information has been attached to the endpoint
255 of this route segment.
256*/
257
258/*!
259 \property QGeoRouteSegment::maneuver
260 \brief the maneuver for this route segment.
261
262 Holds an invalid QGeoManeuver if no information has been attached
263 to the starting point of this route segment.
264*/
265void QGeoRouteSegment::setManeuver(const QGeoManeuver &maneuver)
266{
267 d_ptr->setValid(true);
268 d_ptr->setManeuver(maneuver);
269}
270
271QGeoManeuver QGeoRouteSegment::maneuver() const
272{
273 return d_ptr->maneuver();
274}
275
276/*******************************************************************************
277*******************************************************************************/
278
279QGeoRouteSegmentPrivate::QGeoRouteSegmentPrivate() = default;
280
281bool operator==(const QGeoRouteSegmentPrivate &lhs, const QGeoRouteSegmentPrivate &rhs)
282{
283 return lhs.m_valid == rhs.m_valid
284 && lhs.m_travelTime == rhs.m_travelTime
285 && lhs.m_distance == rhs.m_distance
286 && lhs.m_path == rhs.m_path
287 && lhs.m_maneuver == rhs.m_maneuver;
288}
289
290bool QGeoRouteSegmentPrivate::valid() const
291{
292 return m_valid;
293}
294
295void QGeoRouteSegmentPrivate::setValid(bool valid)
296{
297 m_valid = valid;
298}
299
300bool QGeoRouteSegmentPrivate::isLegLastSegment() const
301{
302 return m_legLastSegment;
303}
304
305void QGeoRouteSegmentPrivate::setLegLastSegment(bool lastSegment)
306{
307 m_legLastSegment = lastSegment;
308}
309
310int QGeoRouteSegmentPrivate::travelTime() const
311{
312 return m_travelTime;
313}
314
315void QGeoRouteSegmentPrivate::setTravelTime(int travelTime)
316{
317 m_travelTime = travelTime;
318}
319
320qreal QGeoRouteSegmentPrivate::distance() const
321{
322 return m_distance;
323}
324
325void QGeoRouteSegmentPrivate::setDistance(qreal distance)
326{
327 m_distance = distance;
328}
329
330QList<QGeoCoordinate> QGeoRouteSegmentPrivate::path() const
331{
332 return m_path;
333}
334
335void QGeoRouteSegmentPrivate::setPath(const QList<QGeoCoordinate> &path)
336{
337 m_path = path;
338}
339
340QGeoManeuver QGeoRouteSegmentPrivate::maneuver() const
341{
342 return m_maneuver;
343}
344
345void QGeoRouteSegmentPrivate::setManeuver(const QGeoManeuver &maneuver)
346{
347 m_maneuver = maneuver;
348}
349
350QExplicitlySharedDataPointer<QGeoRouteSegmentPrivate> QGeoRouteSegmentPrivate::nextRouteSegment() const
351{
352 return m_nextSegment;
353}
354
355void QGeoRouteSegmentPrivate::setNextRouteSegment(const QExplicitlySharedDataPointer<QGeoRouteSegmentPrivate> &next)
356{
357 m_nextSegment = next;
358}
359
360QGeoRouteSegmentPrivate *QGeoRouteSegmentPrivate::get(QGeoRouteSegment &segment)
361{
362 return segment.d_ptr.data();
363}
364
365QT_END_NAMESPACE
366
367#include "moc_qgeoroutesegment.cpp"
bool operator==(const QGeoRouteSegmentPrivate &lhs, const QGeoRouteSegmentPrivate &rhs)