summaryrefslogtreecommitdiff
path: root/src/location/labs
diff options
context:
space:
mode:
Diffstat (limited to 'src/location/labs')
-rw-r--r--src/location/labs/qdeclarativenavigator.cpp104
-rw-r--r--src/location/labs/qdeclarativenavigator_p.h26
-rw-r--r--src/location/labs/qdeclarativenavigator_p_p.h3
3 files changed, 111 insertions, 22 deletions
diff --git a/src/location/labs/qdeclarativenavigator.cpp b/src/location/labs/qdeclarativenavigator.cpp
index 86c2b85a..dd3eaabf 100644
--- a/src/location/labs/qdeclarativenavigator.cpp
+++ b/src/location/labs/qdeclarativenavigator.cpp
@@ -37,6 +37,7 @@
#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>
@@ -186,6 +187,23 @@ QT_BEGIN_NAMESPACE
has been reached.
*/
+/*!
+ \qmlproperty enumeration Qt.labs.location::Navigator::error
+
+ This read-only property holds the latest error value of the geocoding request.
+
+ \list
+ \li Navigator.NoError - No error has occurred.
+ \li GeocodeModel.NotSupportedError - Navigation is not supported by the service provider.
+ \li GeocodeModel.ConnectionError - An error occurred while communicating with the service provider.
+ \li GeocodeModel.LoaderError - The geoservice provider library could not be loaded. Setting QT_DEBUG_PLUGINS environment variable may help diagnosing the reason.
+ \li GeocodeModel.UnknownParameterError - An unknown parameter was specified
+ \li GeocodeModel.MissingRequiredParameterError - required parameter was not specified.
+ \li GeocodeModel.UnknownError - An error occurred which does not fit into any of the other categories.
+
+ \endlist
+*/
+
QDeclarativeNavigatorPrivate::QDeclarativeNavigatorPrivate(QParameterizableObject *q_)
: q(q_), m_params(new QDeclarativeNavigatorParams)
{
@@ -360,6 +378,16 @@ int QDeclarativeNavigator::currentSegment() const
return d_ptr->m_currentSegment;
}
+QDeclarativeNavigator::NavigationError QDeclarativeNavigator::error() const
+{
+ return d_ptr->m_error;
+}
+
+QString QDeclarativeNavigator::errorString() const
+{
+ return d_ptr->m_errorString;
+}
+
bool QDeclarativeNavigator::active() const
{
return d_ptr->m_active;
@@ -439,27 +467,56 @@ bool QDeclarativeNavigator::ensureEngine()
if (!d_ptr->m_completed || !d_ptr->m_plugin->isAttached())
return false;
- auto manager = d_ptr->m_plugin->sharedGeoServiceProvider()->navigationManager();
- if (manager) {
- d_ptr->m_navigator.reset(manager->createNavigator(d_ptr->m_params));
- if (!d_ptr->m_navigator)
- return false;
- d_ptr->m_navigator->setLocale(manager->locale());
- d_ptr->m_navigator->setMeasurementSystem(manager->measurementSystem());
- connect(d_ptr->m_navigator.get(), &QAbstractNavigator::waypointReached, this, &QDeclarativeNavigator::waypointReached);
- connect(d_ptr->m_navigator.get(), &QAbstractNavigator::destinationReached, this, &QDeclarativeNavigator::destinationReached);
- connect(d_ptr->m_navigator.get(), &QAbstractNavigator::currentRouteChanged, this, &QDeclarativeNavigator::onCurrentRouteChanged);
- connect(d_ptr->m_navigator.get(), &QAbstractNavigator::currentRouteLegChanged, this, &QDeclarativeNavigator::onCurrentRouteLegChanged);
- connect(d_ptr->m_navigator.get(), &QAbstractNavigator::currentSegmentChanged, this, &QDeclarativeNavigator::onCurrentSegmentChanged);
- 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);
- emit navigatorReadyChanged(true);
- return true;
+ 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;
}
- return false;
+
+ d_ptr->m_navigator->setLocale(manager->locale());
+ d_ptr->m_navigator->setMeasurementSystem(manager->measurementSystem());
+ connect(d_ptr->m_navigator.get(), &QAbstractNavigator::waypointReached, this, &QDeclarativeNavigator::waypointReached);
+ connect(d_ptr->m_navigator.get(), &QAbstractNavigator::destinationReached, this, &QDeclarativeNavigator::destinationReached);
+ connect(d_ptr->m_navigator.get(), &QAbstractNavigator::currentRouteChanged, this, &QDeclarativeNavigator::onCurrentRouteChanged);
+ connect(d_ptr->m_navigator.get(), &QAbstractNavigator::currentRouteLegChanged, this, &QDeclarativeNavigator::onCurrentRouteLegChanged);
+ connect(d_ptr->m_navigator.get(), &QAbstractNavigator::currentSegmentChanged, this, &QDeclarativeNavigator::onCurrentSegmentChanged);
+ 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);
+ emit navigatorReadyChanged(true);
+ return true;
}
void QDeclarativeNavigator::updateReadyState() {
@@ -473,6 +530,13 @@ void QDeclarativeNavigator::updateReadyState() {
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();
+}
+
void QDeclarativeNavigator::onCurrentRouteChanged(const QGeoRoute &route)
{
if (d_ptr->m_currentRoute)
diff --git a/src/location/labs/qdeclarativenavigator_p.h b/src/location/labs/qdeclarativenavigator_p.h
index 2a425e70..b9949431 100644
--- a/src/location/labs/qdeclarativenavigator_p.h
+++ b/src/location/labs/qdeclarativenavigator_p.h
@@ -52,6 +52,7 @@
#include <QtQml/qqml.h>
#include <QSharedPointer>
#include <QtLocation/private/qparameterizableobject_p.h>
+#include <QtLocation/qgeoserviceprovider.h>
QT_BEGIN_NAMESPACE
@@ -81,9 +82,25 @@ class Q_LOCATION_PRIVATE_EXPORT QDeclarativeNavigator : public QParameterizableO
Q_PROPERTY(QDeclarativeGeoRoute *currentRoute READ currentRoute NOTIFY currentRouteChanged)
Q_PROPERTY(QDeclarativeGeoRouteLeg *currentRouteLeg READ currentRouteLeg NOTIFY currentRouteChanged)
Q_PROPERTY(int currentSegment READ currentSegment NOTIFY currentSegmentChanged)
+ Q_PROPERTY(NavigationError error READ error NOTIFY errorChanged)
+ Q_PROPERTY(QString errorString READ errorString NOTIFY errorChanged)
Q_INTERFACES(QQmlParserStatus)
public:
+ enum NavigationError {
+ //QGeoServiceProvider related errors start here
+ NoError = QGeoServiceProvider::NoError,
+ NotSupportedError = QGeoServiceProvider::NotSupportedError, //TODO Qt6 consider merge with NotSupportedError
+ ConnectionError = QGeoServiceProvider::ConnectionError, //TODO Qt6 merge with Map's ConnectionError
+ LoaderError = QGeoServiceProvider::LoaderError,
+ UnknownParameterError = QGeoServiceProvider::UnknownParameterError, //TODO Qt6 consider rename UnsupportedOperationError
+ MissingRequiredParameterError = QGeoServiceProvider::MissingRequiredParameterError,
+ //we leave gap for future QGeoCodeReply errors
+
+ // Navigation-specific error should start at 100
+ UnknownError = 100
+ };
+
explicit QDeclarativeNavigator(QObject *parent = nullptr);
~QDeclarativeNavigator();
@@ -119,6 +136,9 @@ public:
QDeclarativeGeoRouteLeg *currentRouteLeg() const;
int currentSegment() const;
+ NavigationError error() const;
+ QString errorString() const;
+
signals:
void navigatorReadyChanged(bool ready);
void trackPositionSourceChanged(bool trackPositionSource);
@@ -133,13 +153,15 @@ signals:
void currentRouteChanged();
void currentRouteLegChanged();
void currentSegmentChanged();
+ void errorChanged();
-private:
+protected:
void pluginReady();
bool ensureEngine();
void updateReadyState();
+ void setError(NavigationError error, const QString &errorString);
-private slots:
+protected slots:
void onCurrentRouteChanged(const QGeoRoute &route);
void onCurrentRouteLegChanged(const QGeoRouteLeg &routeLeg);
void onCurrentSegmentChanged(int segment);
diff --git a/src/location/labs/qdeclarativenavigator_p_p.h b/src/location/labs/qdeclarativenavigator_p_p.h
index 8849ec7a..74bc3a19 100644
--- a/src/location/labs/qdeclarativenavigator_p_p.h
+++ b/src/location/labs/qdeclarativenavigator_p_p.h
@@ -52,6 +52,7 @@
#include <QtLocation/private/qlocationglobal_p.h>
#include <QtCore/qpointer.h>
#include <QtLocation/qgeoroute.h>
+#include <QtLocation/private/qdeclarativenavigator_p.h>
QT_BEGIN_NAMESPACE
@@ -94,6 +95,8 @@ public:
bool m_active = false;
bool m_completed = false;
bool m_ready = false;
+ QDeclarativeNavigator::NavigationError m_error = QDeclarativeNavigator::NoError;
+ QString m_errorString;
};
QT_END_NAMESPACE