summaryrefslogtreecommitdiff
path: root/src/location/labs/qdeclarativenavigator.cpp
blob: 69f450f3689bbdefbaf81d17c8f360653dd67c7b (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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtLocation module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 or (at your option) any later version
** approved by the KDE Free Qt Foundation. The licenses are as published by
** the Free Software Foundation and appearing in the file LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "qdeclarativenavigator_p.h"
#include "qdeclarativenavigator_p_p.h"
#include <QtLocation/private/qdeclarativegeomap_p.h>
#include <QtLocation/private/qdeclarativegeoserviceprovider_p.h>
#include <QtLocation/private/qnavigationmanager_p.h>
#include <QtLocation/private/qnavigationmanagerengine_p.h>
#include <QtLocation/private/qgeomapparameter_p.h>
#include <QtLocation/private/qdeclarativegeoroute_p.h>
#include <QtLocation/private/qdeclarativegeoroutemodel_p.h>
#include <QtLocation/private/qdeclarativegeoroutesegment_p.h>
#include <QtLocation/qgeoserviceprovider.h>
#include <QtPositioningQuick/private/qdeclarativepositionsource_p.h>
#include <QtQml/qqmlinfo.h>

QT_BEGIN_NAMESPACE

/*!
    \qmlmodule Qt.labs.location 1.0
    \title Qt Labs Location QML Types
    \ingroup qmlmodules
    \brief Provides experimental QtLocation QML types, such as \l Navigator and
    various map objects types (not to be confused with map items).

    To use this module, import the module with the following line:

    \code
    import Qt.labs.location 1.0
    \endcode

    \note These types are experimental and subject to source-incompatible changes from one
    Qt minor release to the next, until they are ready to be moved to the stable QtLocation QML
    module.
*/

/*!
    \qmltype Navigator
    \instantiates QDeclarativeNavigator
    \inqmlmodule Qt.labs.location
    \ingroup qml-QtLocation5-maps

    \brief The Navigator type offers functionalities to perform turn-by-turn navigation.

    The Navigator purpose is to use a plugin's turn-by-turn navigation implementation in a QML
    application in a seamless manner.
    This object may take control of the map position, orientation, tilting and zoom, as well as changing
    the map style, elements on the map such as direction information.
    In certain cases, it may also restrict user interaction with the Map and with the items on it.
*/

/*!
    \qmlproperty Plugin Qt.labs.location::Navigator::plugin

    This property holds the plugin which provides the navigation functionality.

    This is a write-once property. Once the Navigator has a plugin associated with
    it, any attempted modifications of the plugin property will be ignored.

    \sa Plugin
*/

/*!
    \qmlproperty Map Qt.labs.location::Navigator::map

    This property holds the Map that the navigator is in charge of controlling.

    This is a write-once property. Once the Navigator has a Map associated with
    it, any attempted modifications of the map property will be ignored.

    \sa Map
*/

/*!
    \qmlproperty Route Qt.labs.location::Navigator::route

    This property holds the Route that the navigator is using
    to perform the navigation.

    \note Setting this property while a navigation session is ongoing will
    stop the navigation.

    \sa Route
*/

/*!
    \qmlproperty PositionSource Qt.labs.location::Navigator::positionSource

    This property holds the PositionSource that the navigator will receive position
    updates from to perform the navigation.

    This is a write-once property. Once the Navigator has a PositionSource associated with
    it, any attempted modifications of the positionSource property will be ignored.

    \sa PositionSource
*/

/*!
    \qmlproperty bool Qt.labs.location::Navigator::active

    This property tells whether the Navigator is navigating or not.
    Set this property to \c true to start the navigation.
    Set it to \c false to stop an active navigation session.
*/

/*!
    \qmlproperty bool Qt.labs.location::Navigator::navigatorReady

    This read-only property tells whether the navigator is ready
    to start the navigation or not.
    A Navigator becomes ready once the plugin is attached and a navigation engine has been
    instantiated, and the other required properties are set to valid values.
*/

/*!
    \qmlproperty bool Qt.labs.location::Navigator::trackPositionSource

    This property tells whether the Navigator should control the Map camera to
    keep track of position source updates. This property is enabled (\c true) by
    default, and setting it to \c false is useful in cases where e.g. the user
    starts gesturing over the map area.

    Navigator plugins can also control this property directly e.g. user map
    interaction could trigger the property change. Honoring the user-specified
    value of this property is plugin dependent.
*/

/*!
    \qmlproperty bool Qt.labs.location::Navigator::automaticReroutingEnabled

    This property tells whether the Navigator should automatically recalculate
    the route when the position from \l positionSource ends too far from the route.
    The operation performed in such case is equivalent to calling \l recalculateRoutes.
    The default value is \c true.

    \note Whether this property has any effect is plugin-dependent.
    Also, whether or not it has an effect while the navigator is active is plugin-dependent.
*/

/*!
    \qmlproperty bool Qt.labs.location::Navigator::isOnRoute

    While the Navigator is in active tracking mode, this property tells
    whether the position from \l positionSource is on the route or not.
*/

/*!
    \qmlmethod void Qt.labs.location::Navigator::recalculateRoutes()

    Calling this method forces the backend to trigger a routes recalculation.

    \sa automaticReroutingEnabled
*/

/*!
    \qmlproperty enumeration Qt.labs.location::Navigator::error
    \readonly

    This read-only property holds the latest error value of the geocoding request.

    \value Navigator.NoError
           No error has occurred.
    \value Navigator.NotSupportedError
           Navigation is not supported by the service provider.
    \value Navigator.ConnectionError
           An error occurred while communicating with the service provider.
    \value Navigator.LoaderError
           The geoservice provider library could not be loaded. Setting
           QT_DEBUG_PLUGINS environment variable may help diagnosing the
           problem.
    \value Navigator.UnknownParameterError
           An unknown parameter was specified.
    \value Navigator.MissingRequiredParameterError
           Required parameter was not specified.
    \value Navigator.UnknownError
           Unknown error occurred.
*/

QDeclarativeNavigatorPrivate::QDeclarativeNavigatorPrivate(QParameterizableObject *q_)
    : q(q_), m_params(new QDeclarativeNavigatorParams), m_basicDirections(static_cast<QDeclarativeNavigator *>(q_))
{
}

QDeclarativeNavigator::QDeclarativeNavigator(QObject *parent)
    : QParameterizableObject(parent), d_ptr(new QDeclarativeNavigatorPrivate(this))
{
}

QDeclarativeNavigator::~QDeclarativeNavigator()
{
}

void QDeclarativeNavigator::classBegin()
{
}

void QDeclarativeNavigator::componentComplete()
{
    d_ptr->m_completed = true;
    // Children have been completed
    for (auto param : quickChildren<QGeoMapParameter>())
        d_ptr->m_params->m_parameters.push_back(param);
    if (d_ptr->m_plugin && d_ptr->m_plugin->isAttached())
        pluginReady();
}

QDeclarativeGeoServiceProvider *QDeclarativeNavigator::plugin() const
{
    return d_ptr->m_plugin;
}

void QDeclarativeNavigator::setMap(QDeclarativeGeoMap *map)
{
    if (d_ptr->m_params->m_map || !map) // set once prop
        return;

    d_ptr->m_params->m_map = map;
    connect(map, &QObject::destroyed, this,
            [this]() {
                this->mapChanged();
                this->updateReadyState();
            });
    emit mapChanged();
    updateReadyState();
}

QDeclarativeGeoMap *QDeclarativeNavigator::map() const
{
    return d_ptr->m_params->m_map;
}

void QDeclarativeNavigator::setRoute(QDeclarativeGeoRoute *route)
{
    if (d_ptr->m_params->m_route == route) // This isn't set-once
        return;

    const bool isReady = d_ptr->m_navigator && d_ptr->m_navigator->ready();
    const bool isActive = active();
    if (isReady && isActive)
        setActive(false); // Stop current session

    d_ptr->m_params->m_route = route;
    d_ptr->m_params->m_geoRoute = route ? route->route() : QGeoRoute();
    if (route) {
        connect(route, &QObject::destroyed,
                [this]() {
                    // Do not stop navigation if route disappears. d_ptr->m_geoRoute will still be valid.
                    // Engines can stop navigation if desired.
                    this->routeChanged();
                });
    }
    emit routeChanged();
    updateReadyState();
}

QDeclarativeGeoRoute *QDeclarativeNavigator::route() const
{
    return d_ptr->m_params->m_route;
}

void QDeclarativeNavigator::setPositionSource(QDeclarativePositionSource *positionSource)
{
    if (d_ptr->m_params->m_positionSource || !positionSource) // set once prop
        return;

    d_ptr->m_params->m_positionSource = positionSource;
    QObject::connect(positionSource, &QObject::destroyed,
            [this]() {
                this->positionSourceChanged();
                this->updateReadyState();
            }
    );
    emit positionSourceChanged();
    updateReadyState();
}

QDeclarativePositionSource *QDeclarativeNavigator::positionSource() const
{
    return d_ptr->m_params->m_positionSource;
}

// navigator automatically adjusts route when user leaves it
bool QDeclarativeNavigator::automaticReroutingEnabled() const
{
    if (d_ptr->m_navigator)
        return d_ptr->m_navigator->automaticReroutingEnabled();
    return d_ptr->m_params->m_autoRerouting;
}

// Whether or not it has an effect while the navigator is active should be plugin-dependent
void QDeclarativeNavigator::setAutomaticReroutingEnabled(bool autoRerouting)
{
    const bool autoReroutingOld = automaticReroutingEnabled();
    d_ptr->m_params->m_autoRerouting = autoRerouting;
    // Done this way, and not via signal like setTrackPositionSource because
    // plugins might not support automatic rerouting.
    if (d_ptr->m_navigator)
        d_ptr->m_navigator->setAutomaticReroutingEnabled(autoRerouting);
    if (autoRerouting != autoReroutingOld)
        emit automaticReroutingEnabledChanged();
}


bool QDeclarativeNavigator::navigatorReady() const
{
    if (d_ptr->m_navigator)
        return d_ptr->m_navigator->ready();
    return d_ptr->m_ready;
}

bool QDeclarativeNavigator::trackPositionSource() const
{
    return d_ptr->m_params->m_trackPositionSource;
}

// Navigator is in active tracking mode and the route is being followed.
// This may turn \c false if the user leaves the route.
bool QDeclarativeNavigator::isOnRoute() const
{
    if (d_ptr->m_navigator)
        return d_ptr->m_navigator->isOnRoute();
    return false;
}

void QDeclarativeNavigator::setTrackPositionSource(bool trackPositionSource)
{
    if (trackPositionSource == d_ptr->m_params->m_trackPositionSource)
        return;

    d_ptr->m_params->m_trackPositionSource = trackPositionSource;

    emit trackPositionSourceChanged(trackPositionSource);
}

QDeclarativeNavigationBasicDirections *QDeclarativeNavigator::directions() const
{
    return &d_ptr->m_basicDirections;
}

QDeclarativeNavigator::NavigationError QDeclarativeNavigator::error() const
{
    return d_ptr->m_error;
}

QString QDeclarativeNavigator::errorString() const
{
    return d_ptr->m_errorString;
}

void QDeclarativeNavigator::recalculateRoutes()
{
    if (d_ptr->m_navigator)
        d_ptr->m_navigator->recalculateRoutes();
}

/*  !NOT DOCUMENTED YET!
    \qmlproperty QAbstractNavigator *Qt.labs.location::Navigator::engineHandle

    This property returns a handle to the navigation object created by the engine.
    This object can carry engine-specific properties, signals and methods, to expose
    engine-specific features and data.

    \warning Using this property leads to writing code that's likely to work
             with only a single plugin.
*/
QAbstractNavigator *QDeclarativeNavigator::abstractNavigator() const
{
    return d_ptr->m_navigator.data();

}

bool QDeclarativeNavigator::active() const
{
    return d_ptr->m_active;
}

void QDeclarativeNavigator::setPlugin(QDeclarativeGeoServiceProvider *plugin)
{
    if (d_ptr->m_plugin)
        return; // set once property.

    d_ptr->m_plugin = plugin;
    emit pluginChanged();

    if (d_ptr->m_plugin->isAttached()) {
        pluginReady();
    } else {
        connect(d_ptr->m_plugin, &QDeclarativeGeoServiceProvider::attached,
                this, &QDeclarativeNavigator::pluginReady);
    }
}

void QDeclarativeNavigator::setActive(bool active)
{
    if (d_ptr->m_active == active)
        return;

    d_ptr->m_active = active;
    if (!d_ptr->m_plugin)
        return;

    if (active)
        start();
    else
        stop();
}

void QDeclarativeNavigator::start()
{
    if (!d_ptr->m_ready) {
        qmlWarning(this) << QStringLiteral("Navigation manager not ready.");
        return;
    }

    if (!d_ptr->m_navigator->active())
        d_ptr->m_active = d_ptr->m_navigator->start();
}

void QDeclarativeNavigator::stop()
{
    if (!ensureEngine()) { // If somebody re-set route to null or something, this may become !d_ptr->m_ready
        qmlWarning(this) << QStringLiteral("Navigation manager not ready.");
        return;
    }

    if (d_ptr->m_navigator->active())
        d_ptr->m_active = d_ptr->m_navigator->stop();

    // Cached data are cleared in response to signals emitted by m_navigator upon stop().
    // For example, m_navigator emits currentRouteChanged with an empty route,
    // and QDeclarativeNavigationBasicDirections reacts by clearing the declarative route.
}

void QDeclarativeNavigator::pluginReady()
{
    if (!d_ptr->m_completed)
        return;

    ensureEngine();
    updateReadyState();
    if (d_ptr->m_active)
        start();
}

bool QDeclarativeNavigator::ensureEngine()
{
    if (d_ptr->m_navigator)
        return true;
    if (!d_ptr->m_completed || !d_ptr->m_plugin->isAttached())
        return false;

    QGeoServiceProvider *serviceProvider = d_ptr->m_plugin->sharedGeoServiceProvider();
    // if m_plugin->isAttached(), serviceProvider cannot be null
    QNavigationManager *manager = serviceProvider->navigationManager();

    if (serviceProvider->navigationError() != QGeoServiceProvider::NoError) {
        QDeclarativeNavigator::NavigationError newError = UnknownError;
        switch (serviceProvider->navigationError()) {
        case QGeoServiceProvider::NotSupportedError:
            newError = NotSupportedError; break;
        case QGeoServiceProvider::UnknownParameterError:
            newError = UnknownParameterError; break;
        case QGeoServiceProvider::MissingRequiredParameterError:
            newError = MissingRequiredParameterError; break;
        case QGeoServiceProvider::ConnectionError:
            newError = ConnectionError; break;
        case QGeoServiceProvider::LoaderError:
            newError = LoaderError; break;
        default:
            break;
        }

        setError(newError, serviceProvider->navigationErrorString());
        return false;
    }

    if (!manager) {
        setError(NotSupportedError, tr("Plugin does not support navigation."));
        return false;
    }

    d_ptr->m_navigator.reset(manager->createNavigator(d_ptr->m_params));
    if (!d_ptr->m_navigator) {
        setError(UnknownError, tr("Failed to create a navigator object."));
        return false;
    }

    d_ptr->m_navigator->setLocale(manager->locale());
    d_ptr->m_navigator->setMeasurementSystem(manager->measurementSystem());

    connect(d_ptr->m_navigator.get(), &QAbstractNavigator::activeChanged, this, [this](bool active){
        d_ptr->m_active = active;
        emit activeChanged(active);
    });
    connect(this, &QDeclarativeNavigator::trackPositionSourceChanged, d_ptr->m_navigator.get(), &QAbstractNavigator::setTrackPosition);

    // read-only progress info updates
    connect(d_ptr->m_navigator.get(), &QAbstractNavigator::waypointReached,
            &d_ptr->m_basicDirections, &QDeclarativeNavigationBasicDirections::waypointReached);
    connect(d_ptr->m_navigator.get(), &QAbstractNavigator::destinationReached,
            &d_ptr->m_basicDirections, &QDeclarativeNavigationBasicDirections::destinationReached);
    connect(d_ptr->m_navigator.get(), &QAbstractNavigator::currentRouteChanged,
            &d_ptr->m_basicDirections, &QDeclarativeNavigationBasicDirections::onCurrentRouteChanged);
    connect(d_ptr->m_navigator.get(), &QAbstractNavigator::currentRouteLegChanged,
            &d_ptr->m_basicDirections, &QDeclarativeNavigationBasicDirections::onCurrentRouteLegChanged);
    connect(d_ptr->m_navigator.get(), &QAbstractNavigator::currentSegmentChanged,
            &d_ptr->m_basicDirections, &QDeclarativeNavigationBasicDirections::currentSegmentChanged);
    connect(d_ptr->m_navigator.get(), &QAbstractNavigator::nextManeuverIconChanged,
            &d_ptr->m_basicDirections, &QDeclarativeNavigationBasicDirections::nextManeuverIconChanged);
    connect(d_ptr->m_navigator.get(), &QAbstractNavigator::progressInformationChanged,
            &d_ptr->m_basicDirections, &QDeclarativeNavigationBasicDirections::progressInformationChanged);
    connect(d_ptr->m_navigator.get(), &QAbstractNavigator::isOnRouteChanged,
            this, &QDeclarativeNavigator::isOnRouteChanged);
    connect(d_ptr->m_navigator.get(), &QAbstractNavigator::alternativeRoutesChanged,
            &d_ptr->m_basicDirections, &QDeclarativeNavigationBasicDirections::onAlternativeRoutesChanged);

    emit navigatorReadyChanged(true);
    return true;
}

void QDeclarativeNavigator::updateReadyState() {
    const bool oldReady = d_ptr->m_ready;
    if (!d_ptr->m_navigator)
        d_ptr->m_ready = false;
    else
        d_ptr->m_ready = d_ptr->m_navigator->ready();

    if (oldReady != d_ptr->m_ready)
        emit navigatorReadyChanged(d_ptr->m_ready);
}

void QDeclarativeNavigator::setError(QDeclarativeNavigator::NavigationError error, const QString &errorString)
{
    d_ptr->m_error = error;
    d_ptr->m_errorString = errorString;
    emit errorChanged();
}

QDeclarativeNavigationBasicDirections::QDeclarativeNavigationBasicDirections(QDeclarativeNavigator *parent)
:   QObject(parent), m_navigator(parent), m_routes(QByteArrayLiteral("routeData"), this)
{
    if (m_navigator)
        m_navigatorPrivate = m_navigator->d_ptr.data();
}

/*!
    \qmlpropertygroup Qt.labs.location::Navigator::directions
    \readonly
    \qmlproperty Variant Qt.labs.location::Navigator::directions.nextManeuverIcon
    \qmlproperty real Qt.labs.location::Navigator::directions.distanceToNextManeuver
    \qmlproperty real Qt.labs.location::Navigator::directions.remainingTravelDistance
    \qmlproperty real Qt.labs.location::Navigator::directions.remainingTravelDistanceToNextWaypoint
    \qmlproperty real Qt.labs.location::Navigator::directions.traveledDistance
    \qmlproperty int Qt.labs.location::Navigator::directions.timeToNextManeuver
    \qmlproperty int Qt.labs.location::Navigator::directions.remainingTravelTime
    \qmlproperty int Qt.labs.location::Navigator::directions.remainingTravelTimeToNextWaypoint
    \qmlproperty int Qt.labs.location::Navigator::directions.traveledTime
    \qmlproperty Route Qt.labs.location::Navigator::directions.currentRoute
    \qmlproperty RouteLeg Qt.labs.location::Navigator::directions.currentRouteLeg
    \qmlproperty int Qt.labs.location::Navigator::directions.currentSegment
    \qmlproperty model Qt.labs.location::Navigator::directions.alternativeRoutes

    These read-only properties are part of the \e directions property group.
    This property group holds the navigation progress information that can be
    used to access the route data and to extract directions.

    \note Some backends might not provide a full set of navigation progress
          information.

    \list
        \li The \c nextManeuverIcon property holds the next turn icon.
        \li The \c distanceToNextManeuver property holds the distance to the
            next maneuver, in meters.
        \li The \c remainingTravelDistance property holds the remaining travel
            distance, in meters.
        \li The \c remainingTravelDistanceToNextWaypoint property holds the
            remaining travel distance to the next waypoint, in meters.
        \li The \c traveledDistance property holds the traveled distance, in
            meters.
        \li The \c timeToNextManeuver property holds the time to the next
            maneuver, in milliseconds.
        \li The \c remainingTravelTime property holds the remaining travel
            time, in milliseconds.
        \li The \c remainingTravelTimeToNextWaypoint property holds the
            remaining travel time to the next waypoint, in milliseconds.
        \li The \c traveledTime property holds the traveled time, in
            milliseconds.
        \li The \c currentRoute property holds the current route the navigator
            is following. This can be the same as \l route, or can be
            different, if the navigator cannot follow the user-specified route.
            For example, if the position coming from \l positionSource is
            considerably off route, the navigation engine may recalculate and
            start to follow a new route.
        \li The \c currentRouteLeg property holds the current route leg the
            navigator is following. This is always a part of \c currentRoute,
            so the \l {RouteLeg::}{overallRoute} property of \c currentRouteLeg
            holds the same route as \c currentRoute.
        \li The \c currentSegment property holds the index of the current
            RouteSegment in the \c currentRoute.
        \li The \c alternativeRoutes property holds the list of alternative routes provided by
            the engine. If no alternative routes are present, the model will be empty.
    \endlist

    \sa directions.waypointReached(), directions.destinationReached(), Route, RouteLeg, RouteSegment, Waypoint
*/

/*!
    \qmlsignal Qt.labs.location::Navigator::directions.waypointReached(Waypoint waypoint)

    This signal is emitted when a \a waypoint has been reached.

    \sa directions, directions.destinationReached()
*/

/*!
    \qmlsignal Qt.labs.location::Navigator::directions.destinationReached()

    This signal is emitted when the last waypoint of the route, the
    destination, has been reached.

    \sa directions, directions.waypointReached()
*/
QVariant QDeclarativeNavigationBasicDirections::nextManeuverIcon() const
{
    if (m_navigatorPrivate->m_navigator)
        return m_navigatorPrivate->m_navigator->nextManeuverIcon();
    return QVariant();
}

qreal QDeclarativeNavigationBasicDirections::distanceToNextManeuver() const
{
    if (m_navigatorPrivate->m_navigator)
        return m_navigatorPrivate->m_navigator->distanceToNextManeuver();
    return qQNaN();
}

qreal QDeclarativeNavigationBasicDirections::remainingTravelDistance() const
{
    if (m_navigatorPrivate->m_navigator)
        return m_navigatorPrivate->m_navigator->remainingTravelDistance();
    return qQNaN();
}

qreal QDeclarativeNavigationBasicDirections::remainingTravelDistanceToNextWaypoint() const
{
    if (m_navigatorPrivate->m_navigator)
        return m_navigatorPrivate->m_navigator->remainingTravelDistanceToNextWaypoint();
    return qQNaN();
}

qreal QDeclarativeNavigationBasicDirections::traveledDistance() const
{
    if (m_navigatorPrivate->m_navigator)
        return m_navigatorPrivate->m_navigator->traveledDistance();
    return 0;
}

int QDeclarativeNavigationBasicDirections::timeToNextManeuver() const
{
    if (m_navigatorPrivate->m_navigator)
        return m_navigatorPrivate->m_navigator->timeToNextManeuver();
    return -1;
}

int QDeclarativeNavigationBasicDirections::remainingTravelTime() const
{
    if (m_navigatorPrivate->m_navigator)
        return m_navigatorPrivate->m_navigator->remainingTravelTime();
    return -1;
}

int QDeclarativeNavigationBasicDirections::remainingTravelTimeToNextWaypoint() const
{
    if (m_navigatorPrivate->m_navigator)
        return m_navigatorPrivate->m_navigator->remainingTravelTimeToNextWaypoint();
    return -1;
}

int QDeclarativeNavigationBasicDirections::traveledTime() const
{
    if (m_navigatorPrivate->m_navigator)
        return m_navigatorPrivate->m_navigator->traveledTime();
    return 0;
}

QDeclarativeGeoRoute *QDeclarativeNavigationBasicDirections::currentRoute() const
{
    if (!m_navigatorPrivate->m_ready
            || !m_navigatorPrivate->m_navigator
            || !m_navigatorPrivate->m_navigator->active())
        return m_navigatorPrivate->m_params->m_route.data(); // the user-specified route, if any
    return m_currentRoute;
}

QDeclarativeGeoRouteLeg *QDeclarativeNavigationBasicDirections::currentRouteLeg() const
{
    if (!m_navigatorPrivate->m_ready
            || !m_navigatorPrivate->m_navigator
            || !m_navigatorPrivate->m_navigator->active())
        return nullptr;
    return m_currentRouteLeg;
}

int QDeclarativeNavigationBasicDirections::currentSegment() const
{
    if (!m_navigatorPrivate->m_ready
            || !m_navigatorPrivate->m_navigator
            || !m_navigatorPrivate->m_navigator->active())
        return 0;
    return m_navigatorPrivate->m_navigator->currentSegment();
}

QAbstractItemModel *QDeclarativeNavigationBasicDirections::alternativeRoutes()
{
    return &m_routes;
}

void QDeclarativeNavigationBasicDirections::onCurrentRouteChanged()
{
    if (m_currentRoute)
        m_currentRoute->deleteLater();
    m_currentRoute = new QDeclarativeGeoRoute(m_navigatorPrivate->m_navigator->currentRoute(), this);
    emit currentRouteChanged();
}

void QDeclarativeNavigationBasicDirections::onCurrentRouteLegChanged()
{
    if (m_currentRouteLeg)
        m_currentRouteLeg->deleteLater();
    m_currentRouteLeg = new QDeclarativeGeoRouteLeg(m_navigatorPrivate->m_navigator->currentRouteLeg(), this);
    emit currentRouteLegChanged();
}

void QDeclarativeNavigationBasicDirections::onAlternativeRoutesChanged()
{
    const QList<QGeoRoute> &routes = m_navigatorPrivate->m_navigator->alternativeRoutes();
    QList<QDeclarativeGeoRoute *> declarativeRoutes;
    for (int i = 0; i < routes.size(); ++i) {
        QDeclarativeGeoRoute *route = new QDeclarativeGeoRoute(routes.at(i), &m_routes);
        QQmlEngine::setContextForObject(route, QQmlEngine::contextForObject(this));
        declarativeRoutes.append(route);
    }
    m_routes.updateData(declarativeRoutes);
}

QT_END_NAMESPACE