summaryrefslogtreecommitdiff
path: root/src/location/maps/qgeoroutesegment.cpp
blob: eed2cb03ff76629bb311831c9100d408510caee3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
// Copyright (C) 2015 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#include "qgeoroutesegment.h"
#include "qgeoroutesegment_p.h"

#include "qgeocoordinate.h"
#include <QDateTime>

QT_BEGIN_NAMESPACE

QT_DEFINE_QESDP_SPECIALIZATION_DTOR(QGeoRouteSegmentPrivate)

/*!
    \class QGeoRouteSegment
    \inmodule QtLocation
    \ingroup QtLocation-routing
    \since 5.6

    \brief The QGeoRouteSegment class represents a segment of a route.

    A QGeoRouteSegment instance has information about the physical layout
    of the route segment, the length of the route and estimated time required
    to traverse the route segment and an optional QGeoManeuver associated with
    the beginning of the route segment.

    QGeoRouteSegment instances can be thought of as edges on a routing
    graph, with QGeoManeuver instances as optional labels attached to the
    vertices of the graph.
*/

/*!
    \qmltype routeSegment
    \inqmlmodule QtLocation
    \ingroup qml-QtLocation5-routing
    \since QtLocation 5.5

    \brief The routeSegment type represents a segment of a Route.

    A routeSegment instance has information about the physical layout
    of the route segment, the length of the route and estimated time required
    to traverse the route segment and optional \l {routeManeuver}s associated with
    the end of the route segment.

    Instances of routeSegment can be thought of as edges on a routing
    graph, with routeManeuver instances as optional labels attached to the
    vertices of the graph.

    The primary means of acquiring Route objects is via Routes via \l RouteModel.

    \section1 Example

    The following QML snippet demonstrates how to print information about a
    route segment:

    \snippet declarative/routing.qml QtQuick import
    \snippet declarative/maps.qml QtLocation import
    \codeline
    \snippet declarative/routing.qml routeSegment
*/

/*!
    Constructs an invalid route segment object.

    The route segment will remain invalid until one of setNextRouteSegment(),
    setTravelTime(), setDistance(), setPath() or setManeuver() is called.
*/
QGeoRouteSegment::QGeoRouteSegment()
    : d_ptr(new QGeoRouteSegmentPrivate()) {}

/*!
    Constructs a route segment object from the contents of \a other.
*/
QGeoRouteSegment::QGeoRouteSegment(const QGeoRouteSegment &other) noexcept = default;

/*!
    \internal
*/
QGeoRouteSegment::QGeoRouteSegment(QExplicitlySharedDataPointer<QGeoRouteSegmentPrivate> &&dd)
    : d_ptr(dd) {}

/*!
    Destroys this route segment object.
*/
QGeoRouteSegment::~QGeoRouteSegment() = default;


/*!
    Assigns \a other to this route segment object and then returns a
    reference to this route segment object.
*/
QGeoRouteSegment &QGeoRouteSegment::operator=(const QGeoRouteSegment & other) noexcept
{
    if (this == &other)
        return *this;

    d_ptr = other.d_ptr;
    return *this;
}

/*!
    \fn bool QGeoRouteSegment::operator==(const QGeoRouteSegment &lhs, const QGeoRouteSegment &rhs) noexcept
    Returns whether the route segments \a lhs and \a rhs are equal.

    The value of nextRouteSegment() is not considered in the comparison.
*/

/*!
    \fn bool QGeoRouteSegment::operator!=(const QGeoRouteSegment &lhs, const QGeoRouteSegment &rhs) noexcept

    Returns whether the route segments \a lhs and \a rhs are not equal.

    The value of nextRouteSegment() is not considered in the comparison.
*/

bool QGeoRouteSegment::isEqual(const QGeoRouteSegment &other) const noexcept
{
    return ( (d_ptr.constData() == other.d_ptr.constData())
            || (*d_ptr) == (*other.d_ptr));
}

/*!
    Returns whether this route segment is valid or not.

    If nextRouteSegment() is called on the last route segment of a route, the
    returned value will be an invalid route segment.
*/
bool QGeoRouteSegment::isValid() const
{
    return d_ptr->valid();
}

/*!
    Returns whether this route segment is the last segment of a route leg.

    \since 5.12
*/
bool QGeoRouteSegment::isLegLastSegment() const
{
    if (!d_ptr->valid())
        return false;

    if (!d_ptr->nextRouteSegment())
        return true;
    return d_ptr->isLegLastSegment();
}

/*!
    Sets the next route segment in the route to \a routeSegment.
*/
void QGeoRouteSegment::setNextRouteSegment(const QGeoRouteSegment &routeSegment)
{
    d_ptr->setValid(true);
    d_ptr->setNextRouteSegment(routeSegment.d_ptr);
}

/*!
    Returns the next route segment in the route.

    Will return an invalid route segment if this is the last route
    segment in the route.
*/
QGeoRouteSegment QGeoRouteSegment::nextRouteSegment() const
{
    if (d_ptr->valid() && d_ptr->nextRouteSegment())
        return QGeoRouteSegment(d_ptr->nextRouteSegment());

    return QGeoRouteSegment();
}

/*!
    \qmlproperty int QtLocation::routeSegment::travelTime

    Read-only property which holds the estimated amount of time it will take to
    traverse this segment, in seconds.

*/

/*!
    \property QGeoRouteSegment::travelTime
    \brief the estimated amount of time, in seconds, that it will take to
    traverse this segment.
*/
void QGeoRouteSegment::setTravelTime(int secs)
{
    d_ptr->setValid(true);
    d_ptr->setTravelTime(secs);
}

int QGeoRouteSegment::travelTime() const
{
    return d_ptr->travelTime();
}

/*!
    \qmlproperty real QtLocation::routeSegment::distance

    Read-only property which holds the distance covered by this segment of
    the route, in meters.
*/

/*!
    \property QGeoRouteSegment::distance
    \brief the distance covered by this segment of the route, in meters.
*/
void QGeoRouteSegment::setDistance(qreal distance)
{
    d_ptr->setValid(true);
    d_ptr->setDistance(distance);
}

qreal QGeoRouteSegment::distance() const
{
    return d_ptr->distance();
}

/*!
    \qmlproperty list<coordinate> QtLocation::routeSegment::path

    Read-only property which holds the geographical coordinates of this segment.
    Coordinates are listed in the order in which they would be traversed by someone
    traveling along this segment of the route.

    To access individual segments you can use standard list accessors: 'path.length'
    indicates the number of objects and 'path[index starting from zero]' gives
    the actual object.

    \sa QtPositioning::coordinate
*/

/*!
    \property QGeoRouteSegment::path
    \brief the geometric shape of this route segment of the route.

    The coordinates should be listed in the order in which they
    would be traversed by someone traveling along this segment of the route.
*/
void QGeoRouteSegment::setPath(const QList<QGeoCoordinate> &path)
{
    d_ptr->setValid(true);
    d_ptr->setPath(path);
}

QList<QGeoCoordinate> QGeoRouteSegment::path() const
{
    return d_ptr->path();
}

/*!
    \qmlproperty RouteManeuver QtLocation::routeSegment::maneuver

    Read-only property which holds the maneuver for this route segment.

    Will return invalid maneuver if no information has been attached to the endpoint
    of this route segment.
*/

/*!
    \property QGeoRouteSegment::maneuver
    \brief the maneuver for this route segment.

    Holds an invalid QGeoManeuver if no information has been attached
    to the starting point of this route segment.
*/
void QGeoRouteSegment::setManeuver(const QGeoManeuver &maneuver)
{
    d_ptr->setValid(true);
    d_ptr->setManeuver(maneuver);
}

QGeoManeuver QGeoRouteSegment::maneuver() const
{
    return d_ptr->maneuver();
}

/*******************************************************************************
*******************************************************************************/

QGeoRouteSegmentPrivate::QGeoRouteSegmentPrivate() = default;

bool operator==(const QGeoRouteSegmentPrivate &lhs, const QGeoRouteSegmentPrivate &rhs)
{
    return lhs.m_valid == rhs.m_valid
        && lhs.m_travelTime == rhs.m_travelTime
        && lhs.m_distance == rhs.m_distance
        && lhs.m_path == rhs.m_path
        && lhs.m_maneuver == rhs.m_maneuver;
}

bool QGeoRouteSegmentPrivate::valid() const
{
    return m_valid;
}

void QGeoRouteSegmentPrivate::setValid(bool valid)
{
    m_valid = valid;
}

bool QGeoRouteSegmentPrivate::isLegLastSegment() const
{
    return m_legLastSegment;
}

void QGeoRouteSegmentPrivate::setLegLastSegment(bool lastSegment)
{
    m_legLastSegment = lastSegment;
}

int QGeoRouteSegmentPrivate::travelTime() const
{
    return m_travelTime;
}

void QGeoRouteSegmentPrivate::setTravelTime(int travelTime)
{
    m_travelTime = travelTime;
}

qreal QGeoRouteSegmentPrivate::distance() const
{
    return m_distance;
}

void QGeoRouteSegmentPrivate::setDistance(qreal distance)
{
    m_distance = distance;
}

QList<QGeoCoordinate> QGeoRouteSegmentPrivate::path() const
{
    return m_path;
}

void QGeoRouteSegmentPrivate::setPath(const QList<QGeoCoordinate> &path)
{
    m_path = path;
}

QGeoManeuver QGeoRouteSegmentPrivate::maneuver() const
{
    return m_maneuver;
}

void QGeoRouteSegmentPrivate::setManeuver(const QGeoManeuver &maneuver)
{
    m_maneuver = maneuver;
}

QExplicitlySharedDataPointer<QGeoRouteSegmentPrivate> QGeoRouteSegmentPrivate::nextRouteSegment() const
{
    return m_nextSegment;
}

void QGeoRouteSegmentPrivate::setNextRouteSegment(const QExplicitlySharedDataPointer<QGeoRouteSegmentPrivate> &next)
{
    m_nextSegment = next;
}

QGeoRouteSegmentPrivate *QGeoRouteSegmentPrivate::get(QGeoRouteSegment &segment)
{
    return segment.d_ptr.data();
}

QT_END_NAMESPACE

#include "moc_qgeoroutesegment.cpp"