diff options
author | Michal Klocek <michal.klocek@digia.com> | 2015-01-07 16:55:53 +0100 |
---|---|---|
committer | Alex Blasche <alexander.blasche@theqtcompany.com> | 2015-01-13 16:06:33 +0100 |
commit | ecf7772c46db2e5b011cdbb531bc6fd69ba8c76d (patch) | |
tree | d208eaece5c7097cca6cd4a1da33d6640ae86bd5 | |
parent | bcdc5cc06bd73b060157936f0b6fa40194cadff8 (diff) | |
download | qtlocation-ecf7772c46db2e5b011cdbb531bc6fd69ba8c76d.tar.gz |
Adds mapping manager error handling to qml
When map is created, plugins can report errors in case of
missing required parameters. Expose error message to qml.
Change-Id: I014e55cd4aad5ba15ffd0a15bc1f414c21feacc8
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
12 files changed, 189 insertions, 35 deletions
diff --git a/examples/location/mapviewer/mapviewer.qml b/examples/location/mapviewer/mapviewer.qml index e6404004..4f087c0a 100644 --- a/examples/location/mapviewer/mapviewer.qml +++ b/examples/location/mapviewer/mapviewer.qml @@ -194,10 +194,6 @@ Item { addItem(plugins[i]) } - onClicked: { - page.state = "" - } - onExclusiveButtonChanged: createMap(exclusiveButton) } @@ -245,6 +241,10 @@ Item { State{ name: "Distance" PropertyChanges { target: messageDialog; title: "Distance" } + }, + State{ + name: "ProviderError" + PropertyChanges { target: messageDialog; title: "Provider Error" } } ] } @@ -605,6 +605,16 @@ Item { onResetState: {\ page.state = "";\ }\ + onErrorChanged: {\ + if (map.error != Map.NoError) {\ + messageDialog.state = "ProviderError";\ + messageDialog.text = map.errorString + "<br/><br/><b>Try to select other provider</b>";\ + if (map.error == Map.MissingRequiredParameterError) \ + messageDialog.text += "<br/>or see \'mapviewer --help\'\ + how to pass plugin parameters.";\ + page.state = "Message";\ + }\ + }\ }',page) diff --git a/src/imports/location/declarativeplaces/qdeclarativesearchresultmodel.cpp b/src/imports/location/declarativeplaces/qdeclarativesearchresultmodel.cpp index fe70509b..b5a65e91 100644 --- a/src/imports/location/declarativeplaces/qdeclarativesearchresultmodel.cpp +++ b/src/imports/location/declarativeplaces/qdeclarativesearchresultmodel.cpp @@ -315,8 +315,8 @@ QT_USE_NAMESPACE /*! \qmlmethod string PlaceSearchModel::errorString() const - This read-only property holds the textual presentation of latest place search model error. - If no error has occurred or if the model was cleared an empty string is returned. + This read-only property holds the textual presentation of the latest place search model error. + If no error has occurred or if the model was cleared, an empty string is returned. An empty string may also be returned if an error occurred which has no associated textual representation. diff --git a/src/imports/location/declarativeplaces/qdeclarativesearchsuggestionmodel.cpp b/src/imports/location/declarativeplaces/qdeclarativesearchsuggestionmodel.cpp index 2f83e2f9..74238a52 100644 --- a/src/imports/location/declarativeplaces/qdeclarativesearchsuggestionmodel.cpp +++ b/src/imports/location/declarativeplaces/qdeclarativesearchsuggestionmodel.cpp @@ -208,7 +208,7 @@ QT_USE_NAMESPACE /*! \qmlmethod string QtLocation::PlaceSearchSuggestionModel::errorString() const - This read-only property holds the textual presentation of latest search suggestion model error. + This read-only property holds the textual presentation of the latest search suggestion model error. If no error has occurred, or if the model was cleared, an empty string is returned. An empty string may also be returned if an error occurred which has no associated diff --git a/src/imports/location/declarativeplaces/qdeclarativesupportedcategoriesmodel.cpp b/src/imports/location/declarativeplaces/qdeclarativesupportedcategoriesmodel.cpp index 6654512b..2ff2ff5a 100644 --- a/src/imports/location/declarativeplaces/qdeclarativesupportedcategoriesmodel.cpp +++ b/src/imports/location/declarativeplaces/qdeclarativesupportedcategoriesmodel.cpp @@ -110,7 +110,7 @@ QT_USE_NAMESPACE /*! \qmlmethod string QtLocation::CategoryModel::errorString() const - This read-only property holds the textual presentation of latest category model error. + This read-only property holds the textual presentation of the latest category model error. If no error has occurred, an empty string is returned. An empty string may also be returned if an error occurred which has no associated diff --git a/src/imports/location/qdeclarativegeocodemodel.cpp b/src/imports/location/qdeclarativegeocodemodel.cpp index df3f17fb..6a6ca9f7 100644 --- a/src/imports/location/qdeclarativegeocodemodel.cpp +++ b/src/imports/location/qdeclarativegeocodemodel.cpp @@ -442,7 +442,7 @@ void QDeclarativeGeocodeModel::setError(GeocodeError error) /*! \qmlproperty string QtLocation::GeocodeModel::errorString - This read-only property holds the textual presentation of latest geocoding error. + This read-only property holds the textual presentation of the latest geocoding error. If no error has occurred or the model has been reset, an empty string is returned. An empty string may also be returned if an error occurred which has no associated diff --git a/src/imports/location/qdeclarativegeomap.cpp b/src/imports/location/qdeclarativegeomap.cpp index bbdf7810..699eeb2b 100644 --- a/src/imports/location/qdeclarativegeomap.cpp +++ b/src/imports/location/qdeclarativegeomap.cpp @@ -184,7 +184,8 @@ QDeclarativeGeoMap::QDeclarativeGeoMap(QQuickItem *parent) componentCompleted_(false), mappingManagerInitialized_(false), touchTimer_(-1), - map_(0) + map_(0), + error_(QGeoServiceProvider::NoError) { QLOC_TRACE0; setAcceptHoverEvents(false); @@ -260,6 +261,16 @@ void QDeclarativeGeoMap::onMapChildrenChanged() copyrights->setCopyrightsZ(maxChildZ + 1); } + +void QDeclarativeGeoMap::setError(QGeoServiceProvider::Error error, const QString &errorString) +{ + if (error_ == error && errorString_ == errorString) + return; + error_ = error; + errorString_ = errorString; + emit errorChanged(); +} + /*! \internal */ @@ -268,6 +279,8 @@ void QDeclarativeGeoMap::pluginReady() serviceProvider_ = plugin_->sharedGeoServiceProvider(); mappingManager_ = serviceProvider_->mappingManager(); + setError(serviceProvider_->error(), serviceProvider_->errorString()); + if (!mappingManager_ || serviceProvider_->error() != QGeoServiceProvider::NoError) { qmlInfo(this) << QStringLiteral("Error: Plugin does not support mapping.\nError message:") << serviceProvider_->errorString(); @@ -759,6 +772,44 @@ void QDeclarativeGeoMap::cameraStopped() } /*! + \qmlproperty string QtLocation::Map::errorString + + This read-only property holds the textual presentation of the latest mapping provider error. + If no error has occurred, an empty string is returned. + + An empty string may also be returned if an error occurred which has no associated + textual representation. + + \sa QGeoServiceProvider::errorString() +*/ + +QString QDeclarativeGeoMap::errorString() const +{ + return errorString_; +} + +/*! + \qmlproperty enumeration QtLocation::Map::error + + This read-only property holds the last occurred mapping service provider error. + + \list + \li Map.NoError - No error has occurred. + \li Map.NotSupportedError -The plugin does not support mapping functionality. + \li Map.UnknownParameterError -The plugin did not recognize one of the parameters it was given. + \li Map.MissingRequiredParameterError - The plugin did not find one of the parameters it was expecting. + \li Map.ConnectionError - The plugin could not connect to its backend service or database. + \endlist + + \sa QGeoServiceProvider::Error +*/ + +QGeoServiceProvider::Error QDeclarativeGeoMap::error() const +{ + return error_; +} + +/*! \internal */ void QDeclarativeGeoMap::touchEvent(QTouchEvent *event) diff --git a/src/imports/location/qdeclarativegeomap_p.h b/src/imports/location/qdeclarativegeomap_p.h index e06d9b36..cc3e6311 100644 --- a/src/imports/location/qdeclarativegeomap_p.h +++ b/src/imports/location/qdeclarativegeomap_p.h @@ -44,6 +44,7 @@ #include <QtQuick/QSGTexture> #include <QtQuick/QQuickPaintedItem> #include <QtQml/QQmlParserStatus> +#include "qgeoserviceprovider.h" #include "qdeclarativegeomapitemview_p.h" #include "qdeclarativegeomapgesturearea_p.h" #include "qgeomapcontroller_p.h" @@ -87,7 +88,7 @@ class QDeclarativeGeoMapType; class QDeclarativeGeoMap : public QQuickItem { Q_OBJECT - + Q_ENUMS(QGeoServiceProvider::Error) Q_PROPERTY(QDeclarativeGeoMapGestureArea *gesture READ gesture CONSTANT) Q_PROPERTY(QDeclarativeGeoServiceProvider *plugin READ plugin WRITE setPlugin NOTIFY pluginChanged) Q_PROPERTY(qreal minimumZoomLevel READ minimumZoomLevel WRITE setMinimumZoomLevel NOTIFY minimumZoomLevelChanged) @@ -97,6 +98,8 @@ class QDeclarativeGeoMap : public QQuickItem Q_PROPERTY(QQmlListProperty<QDeclarativeGeoMapType> supportedMapTypes READ supportedMapTypes NOTIFY supportedMapTypesChanged) Q_PROPERTY(QGeoCoordinate center READ center WRITE setCenter NOTIFY centerChanged) Q_PROPERTY(QList<QObject *> mapItems READ mapItems NOTIFY mapItemsChanged) + Q_PROPERTY(QGeoServiceProvider::Error error READ error NOTIFY errorChanged) + Q_PROPERTY(QString errorString READ errorString NOTIFY errorChanged) Q_INTERFACES(QQmlParserStatus) public: @@ -149,6 +152,9 @@ public: Q_INVOKABLE void pan(int dx, int dy); Q_INVOKABLE void cameraStopped(); // optional hint for prefetch + QString errorString() const; + QGeoServiceProvider::Error error() const; + protected: void mousePressEvent(QMouseEvent *event); void mouseMoveEvent(QMouseEvent *event); @@ -169,6 +175,7 @@ Q_SIGNALS: void minimumZoomLevelChanged(); void maximumZoomLevelChanged(); void mapItemsChanged(); + void errorChanged(); private Q_SLOTS: void updateMapDisplay(const QRectF &target); @@ -177,6 +184,9 @@ private Q_SLOTS: void pluginReady(); void onMapChildrenChanged(); +protected: + void setError(QGeoServiceProvider::Error error, const QString &errorString); + private: void setupMapView(QDeclarativeGeoMapItemView *view); void populateMap(); @@ -207,6 +217,10 @@ private: QList<QPointer<QDeclarativeGeoMapItemBase> > mapItems_; QMutex updateMutex_; + + QString errorString_; + QGeoServiceProvider::Error error_; + friend class QDeclarativeGeoMapItem; friend class QDeclarativeGeoMapItemView; friend class QDeclarativeGeoMapGestureArea; diff --git a/src/imports/location/qdeclarativegeoroutemodel.cpp b/src/imports/location/qdeclarativegeoroutemodel.cpp index 8727f65b..f8bd144f 100644 --- a/src/imports/location/qdeclarativegeoroutemodel.cpp +++ b/src/imports/location/qdeclarativegeoroutemodel.cpp @@ -516,7 +516,7 @@ void QDeclarativeGeoRouteModel::setErrorString(const QString &error) /*! \qmlproperty string QtLocation::RouteModel::errorString - This read-only property holds the textual presentation of latest routing error. + This read-only property holds the textual presentation of the latest routing error. If no error has occurred or the model has been reset, an empty string is returned. An empty string may also be returned if an error occurred which has no associated diff --git a/src/location/maps/qgeoserviceprovider.cpp b/src/location/maps/qgeoserviceprovider.cpp index 5b8f8282..b72aed26 100644 --- a/src/location/maps/qgeoserviceprovider.cpp +++ b/src/location/maps/qgeoserviceprovider.cpp @@ -105,25 +105,20 @@ Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader, */ /*! -\enum QGeoServiceProvider::Error - -Describes an error related to the loading and setup of a service provider -plugin. - -\value NoError -No error has occurred. - -\value NotSupportedError -The plugin does not support this functionality. - -\value UnknownParameterError -The plugin did not recognize one of the parameters it was given. - -\value MissingRequiredParameterError -The plugin did not find one of the parameters it was expecting. - -\value ConnectionError -The plugin could not connect to its backend service or database. + \enum QGeoServiceProvider::Error + + Describes an error related to the loading and setup of a service provider plugin. + + \value NoError + No error has occurred. + \value NotSupportedError + The plugin does not support this functionality. + \value UnknownParameterError + The plugin did not recognize one of the parameters it was given. + \value MissingRequiredParameterError + The plugin did not find one of the parameters it was expecting. + \value ConnectionError + The plugin could not connect to its backend service or database. */ /*! diff --git a/src/location/maps/qgeoserviceprovider.h b/src/location/maps/qgeoserviceprovider.h index 3c9b96b5..fe9fce4c 100644 --- a/src/location/maps/qgeoserviceprovider.h +++ b/src/location/maps/qgeoserviceprovider.h @@ -56,7 +56,7 @@ class QGeoServiceProviderPrivate; class Q_LOCATION_EXPORT QGeoServiceProvider : public QObject { Q_OBJECT - + Q_ENUMS(Error) public: enum Error { NoError, diff --git a/tests/auto/declarative_core/tst_plugin_error.qml b/tests/auto/declarative_core/tst_plugin_error.qml new file mode 100644 index 00000000..d88ae0fa --- /dev/null +++ b/tests/auto/declarative_core/tst_plugin_error.qml @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtTest 1.0 +import QtLocation 5.3 + +Item { + + Plugin { id: testPlugin; + name: "qmlgeo.test.plugin" + allowExperimental: true + parameters: [ + // Parms to guide the test plugin + PluginParameter { name: "error"; value: "1"}, + PluginParameter { name: "errorString"; value: "This error was expected. No worries !"} + ] + } + + Map { + id: map + } + + SignalSpy {id: errorSpy; target: map; signalName: "errorChanged"} + + TestCase { + name: "MappingManagerError" + function test_error() { + verify (map.error === Map.NoError); + map.plugin = testPlugin; + verify (map.error === Map.NotSupportedError); + verify (map.errorString == "This error was expected. No worries !"); + compare(errorSpy.count, 1); + } + } +} diff --git a/tests/auto/geotestplugin/qgeoserviceproviderplugin_test.cpp b/tests/auto/geotestplugin/qgeoserviceproviderplugin_test.cpp index 185bf44f..d3e45e41 100644 --- a/tests/auto/geotestplugin/qgeoserviceproviderplugin_test.cpp +++ b/tests/auto/geotestplugin/qgeoserviceproviderplugin_test.cpp @@ -39,6 +39,24 @@ #include <QtPlugin> +namespace +{ + template<class EngineType> + EngineType * createEngine(const QVariantMap ¶meters, QGeoServiceProvider::Error *error, QString *errorString) + { + const QString failError = parameters.value(QStringLiteral("error")).toString(); + const QString failErrorString = parameters.value(QStringLiteral("errorString")).toString(); + + if (!failError.isEmpty()) { + *error = QGeoServiceProvider::Error(failError.toInt()); + *errorString = failErrorString; + return 0; + } else { + return new EngineType(parameters, error, errorString); + } + } +} + QGeoServiceProviderFactoryTest::QGeoServiceProviderFactoryTest() { } @@ -51,7 +69,7 @@ QGeoRoutingManagerEngine* QGeoServiceProviderFactoryTest::createRoutingManagerEn const QVariantMap ¶meters, QGeoServiceProvider::Error *error, QString *errorString) const { - return new QGeoRoutingManagerEngineTest(parameters, error, errorString); + return createEngine<QGeoRoutingManagerEngineTest>(parameters, error, errorString); } @@ -59,7 +77,7 @@ QGeoCodingManagerEngine* QGeoServiceProviderFactoryTest::createGeocodingManagerE const QVariantMap ¶meters, QGeoServiceProvider::Error *error, QString *errorString) const { - return new QGeoCodingManagerEngineTest(parameters, error, errorString); + return createEngine<QGeoCodingManagerEngineTest>(parameters, error, errorString); } @@ -67,7 +85,7 @@ QGeoMappingManagerEngine* QGeoServiceProviderFactoryTest::createMappingManagerEn const QVariantMap ¶meters, QGeoServiceProvider::Error *error, QString *errorString) const { - return new QGeoTiledMappingManagerEngineTest(parameters, error, errorString); + return createEngine<QGeoTiledMappingManagerEngineTest>(parameters, error, errorString); } QPlaceManagerEngine* QGeoServiceProviderFactoryTest::createPlaceManagerEngine( |