diff options
author | Michal Klocek <michal.klocek@theqtcompany.com> | 2015-06-04 19:57:06 +0200 |
---|---|---|
committer | Michal Klocek <michal.klocek@theqtcompany.com> | 2015-06-11 06:51:58 +0000 |
commit | e6d3af5d1c39925b3028542fddb062b333375045 (patch) | |
tree | b41030327045b7354f9d08ef5d5a018baecc2834 /src/imports/location/qdeclarativegeocodemodel.cpp | |
parent | e8b225cbcc2249f545a98e94ba36b7aa159a4aba (diff) |
Improve error handling in map, geo and route models
Current error handling is misleading and most of the error messages
are logged only to the console. Moreover error messages are too general.
For example 'plugin does not support mapping' is reported when
provider credentials are missing. Emitting onErrorChanged
and onErrorStringChanged does not work correctly, ie. check for
errorString in onErrorChanged ends up in not up to date error message.
Replace logging to console with setting an error on given component.
Use setError instead of qWarning and use one single setter
for errorType and errorString. Combine geocode error reporting
with geoprovider errors. Combine route error reporting with
geoprovider errors. Update unit tests. Move geocode unit test
to _core since it is not a _ui test.
Change-Id: Ia02b1bf4d88f48b963ada75fa7ed74598713c97f
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src/imports/location/qdeclarativegeocodemodel.cpp')
-rw-r--r-- | src/imports/location/qdeclarativegeocodemodel.cpp | 49 |
1 files changed, 22 insertions, 27 deletions
diff --git a/src/imports/location/qdeclarativegeocodemodel.cpp b/src/imports/location/qdeclarativegeocodemodel.cpp index 4c043d49..d2599747 100644 --- a/src/imports/location/qdeclarativegeocodemodel.cpp +++ b/src/imports/location/qdeclarativegeocodemodel.cpp @@ -150,7 +150,7 @@ void QDeclarativeGeocodeModel::update() return; if (!plugin_) { - qmlInfo(this) << QStringLiteral("Cannot geocode, plugin not set."); + setError(NotSupportedError, tr("Cannot geocode, plugin not set.")); return; } @@ -160,17 +160,16 @@ void QDeclarativeGeocodeModel::update() QGeoCodingManager *geocodingManager = serviceProvider->geocodingManager(); if (!geocodingManager) { - qmlInfo(this) << QStringLiteral("Cannot geocode, geocode manager not set."); + setError(NotSupportedError, tr("Cannot geocode, geocode manager not set.")); return; } if (!coordinate_.isValid() && (!address_ || address_->address().isEmpty()) && (searchString_.isEmpty())) { - qmlInfo(this) << QStringLiteral("Cannot geocode, valid query not set."); + setError(ParseError, tr("Cannot geocode, valid query not set.")); return; } abortRequest(); // abort possible previous requests - setErrorString(""); // clear previous error string - setError(NoError); + setError(NoError, QString()); if (coordinate_.isValid()) { setStatus(QDeclarativeGeocodeModel::Loading); @@ -291,11 +290,18 @@ void QDeclarativeGeocodeModel::pluginReady() { QGeoServiceProvider *serviceProvider = plugin_->sharedGeoServiceProvider(); QGeoCodingManager *geocodingManager = serviceProvider->geocodingManager(); - if (!geocodingManager || serviceProvider->error() != QGeoServiceProvider::NoError) { - qmlInfo(this) << QStringLiteral("Error: Plugin does not support (reverse) geocoding.\nError message:") - << serviceProvider->errorString(); + + if (serviceProvider->error() != QGeoServiceProvider::NoError) { + setError(GeocodeError(serviceProvider->error() + NotSupportedError - 1), + serviceProvider->errorString()); + return; + } + + if (!geocodingManager) { + setError(NotSupportedError,tr("Plugin does not support (reverse) geocoding.")); return; } + connect(geocodingManager, SIGNAL(finished(QGeoCodeReply*)), this, SLOT(geocodeFinished(QGeoCodeReply*))); connect(geocodingManager, SIGNAL(error(QGeoCodeReply*,QGeoCodeReply::Error,QString)), @@ -362,8 +368,7 @@ void QDeclarativeGeocodeModel::geocodeFinished(QGeoCodeReply *reply) return; int oldCount = declarativeLocations_.count(); setLocations(reply->locations()); - setErrorString(""); - setError(NoError); + setError(NoError, QString()); setStatus(QDeclarativeGeocodeModel::Ready); reply->deleteLater(); reply_ = 0; @@ -389,8 +394,7 @@ void QDeclarativeGeocodeModel::geocodeError(QGeoCodeReply *reply, emit locationsChanged(); emit countChanged(); } - setErrorString(errorString); - setError(static_cast<QDeclarativeGeocodeModel::GeocodeError>(error)); + setError(static_cast<QDeclarativeGeocodeModel::GeocodeError>(error), errorString); setStatus(QDeclarativeGeocodeModel::Error); reply->deleteLater(); reply_ = 0; @@ -443,11 +447,12 @@ QDeclarativeGeocodeModel::GeocodeError QDeclarativeGeocodeModel::error() const return error_; } -void QDeclarativeGeocodeModel::setError(GeocodeError error) +void QDeclarativeGeocodeModel::setError(GeocodeError error, const QString &errorString) { - if (error_ == error) + if (error_ == error && errorString_ == errorString) return; error_ = error; + errorString_ = errorString; emit errorChanged(); } @@ -466,14 +471,6 @@ QString QDeclarativeGeocodeModel::errorString() const return errorString_; } -void QDeclarativeGeocodeModel::setErrorString(const QString &error) -{ - if (errorString_ == error) - return; - errorString_ = error; - emit errorStringChanged(); -} - /*! \internal */ @@ -515,7 +512,7 @@ int QDeclarativeGeocodeModel::count() const QDeclarativeGeoLocation *QDeclarativeGeocodeModel::get(int index) { if (index < 0 || index >= declarativeLocations_.count()) { - qmlInfo(this) << QStringLiteral("Index '%1' out of range").arg(index); + setError(UnsupportedOptionError, QCoreApplication::translate(CONTEXT_NAME, INDEX_OUT_OF_RANGE).arg(index)); return 0; } return declarativeLocations_.at(index); @@ -592,8 +589,7 @@ void QDeclarativeGeocodeModel::reset() endResetModel(); abortRequest(); - setErrorString(QString()); - setError(NoError); + setError(NoError, QString()); setStatus(QDeclarativeGeocodeModel::Null); } @@ -606,8 +602,7 @@ void QDeclarativeGeocodeModel::reset() void QDeclarativeGeocodeModel::cancel() { abortRequest(); - setErrorString(QString()); - setError(NoError); + setError(NoError, QString()); setStatus(declarativeLocations_.isEmpty() ? Null : Ready); } |