From a0cc254c5b0a300772bba886b48b73929636c281 Mon Sep 17 00:00:00 2001 From: Paolo Angelelli Date: Thu, 9 May 2019 13:49:05 +0200 Subject: Expose automaticReroutingEnabled and isOnRoute properties in Navigator This patch adds these two properties to the Navigator API to let the user know when the engine detects that the position source gets off the route and to choose whether or not let the engine automatically recalculate routes in that case. Change-Id: I1f3afc8820dee1dd2042aa05fb0b3284108cb581 Reviewed-by: Alex Blasche --- src/location/labs/qdeclarativenavigator.cpp | 32 ++++++++++++++++++++++++++ src/location/labs/qdeclarativenavigator_p.h | 11 +++++++++ src/location/labs/qdeclarativenavigator_p_p.h | 1 + src/location/maps/qnavigationmanagerengine_p.h | 4 ++++ 4 files changed, 48 insertions(+) diff --git a/src/location/labs/qdeclarativenavigator.cpp b/src/location/labs/qdeclarativenavigator.cpp index 3fc9fb88..89b5abef 100644 --- a/src/location/labs/qdeclarativenavigator.cpp +++ b/src/location/labs/qdeclarativenavigator.cpp @@ -284,6 +284,27 @@ 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 { @@ -297,6 +318,15 @@ 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) @@ -478,6 +508,8 @@ bool QDeclarativeNavigator::ensureEngine() &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); emit navigatorReadyChanged(true); return true; diff --git a/src/location/labs/qdeclarativenavigator_p.h b/src/location/labs/qdeclarativenavigator_p.h index e12d6ba4..3c168c70 100644 --- a/src/location/labs/qdeclarativenavigator_p.h +++ b/src/location/labs/qdeclarativenavigator_p.h @@ -81,6 +81,8 @@ class Q_LOCATION_PRIVATE_EXPORT QDeclarativeNavigator : public QParameterizableO Q_PROPERTY(bool active READ active WRITE setActive NOTIFY activeChanged) Q_PROPERTY(bool navigatorReady READ navigatorReady NOTIFY navigatorReadyChanged) Q_PROPERTY(bool trackPositionSource READ trackPositionSource WRITE setTrackPositionSource NOTIFY trackPositionSourceChanged) + Q_PROPERTY(bool automaticReroutingEnabled READ automaticReroutingEnabled WRITE setAutomaticReroutingEnabled NOTIFY automaticReroutingEnabledChanged) + Q_PROPERTY(bool isOnRoute READ isOnRoute NOTIFY isOnRouteChanged) Q_PROPERTY(QDeclarativeNavigationBasicDirections *directions READ directions CONSTANT) Q_PROPERTY(NavigationError error READ error NOTIFY errorChanged) Q_PROPERTY(QString errorString READ errorString NOTIFY errorChanged) @@ -129,11 +131,18 @@ public: void setPositionSource(QDeclarativePositionSource *positionSource); QDeclarativePositionSource *positionSource() const; + // To enable/disable automatic route recalculation in the engines + bool automaticReroutingEnabled() const; + void setAutomaticReroutingEnabled(bool autoRerouting); + bool navigatorReady() const; void setTrackPositionSource(bool trackPositionSource); bool trackPositionSource() const; + // To discover/notify when the tracked position goes off the active navigation route + bool isOnRoute() const; + QDeclarativeNavigationBasicDirections *directions() const; QAbstractNavigator *abstractNavigator() const; @@ -150,6 +159,8 @@ signals: void routeChanged(); void positionSourceChanged(); void errorChanged(); + void automaticReroutingEnabledChanged(); + void isOnRouteChanged(); protected: void pluginReady(); diff --git a/src/location/labs/qdeclarativenavigator_p_p.h b/src/location/labs/qdeclarativenavigator_p_p.h index 77fe2ff2..04b8b1ef 100644 --- a/src/location/labs/qdeclarativenavigator_p_p.h +++ b/src/location/labs/qdeclarativenavigator_p_p.h @@ -132,6 +132,7 @@ public: QPointer m_positionSource; QList> m_parameters; bool m_trackPositionSource = true; + bool m_autoRerouting = true; }; class QDeclarativeNavigatorPrivate diff --git a/src/location/maps/qnavigationmanagerengine_p.h b/src/location/maps/qnavigationmanagerengine_p.h index 331df64f..9089316f 100644 --- a/src/location/maps/qnavigationmanagerengine_p.h +++ b/src/location/maps/qnavigationmanagerengine_p.h @@ -99,6 +99,9 @@ public: virtual QGeoRoute currentRoute() const; virtual QGeoRouteLeg currentRouteLeg() const; virtual int currentSegment() const; + virtual void setAutomaticReroutingEnabled(bool autoRerouting) = 0; + virtual bool automaticReroutingEnabled() const = 0; // configured via navigation params at construction time + virtual bool isOnRoute() = 0; public slots: virtual bool start() = 0; @@ -116,6 +119,7 @@ signals: void nextManeuverIconChanged(); void progressInformationChanged(); + void isOnRouteChanged(); private: QScopedPointer d; -- cgit v1.2.3