summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@theqtcompany.com>2015-08-25 14:22:16 +0200
committerAlex Blasche <alexander.blasche@theqtcompany.com>2015-08-28 12:46:07 +0000
commitfd3ea87861b281a54c1888a0a044517cf86f9692 (patch)
tree41b79f1944943165f5fa3632e9850cf5d24f6645
parent7b9390bd139c8e6314bcf3167f3d0538b9f7708b (diff)
Update Error enums for GeoCode & Route model types
1.) Remove not required/duplicated enums 2.) Add docs for new enum values 3.) Sorted the enums by alphabet (except for NoErrror) 4.) Other minor spelling corrections 5.) Update and expand tests Change-Id: I83bf9e5e40f1237ead45320d020b315b39442946 Reviewed-by: Aaron McCarthy <mccarthy.aaron@gmail.com>
-rw-r--r--src/imports/location/plugins.qmltypes12
-rw-r--r--src/imports/location/qdeclarativegeocodemodel.cpp43
-rw-r--r--src/imports/location/qdeclarativegeocodemodel_p.h17
-rw-r--r--src/imports/location/qdeclarativegeomap.cpp3
-rw-r--r--src/imports/location/qdeclarativegeoroutemodel.cpp41
-rw-r--r--src/imports/location/qdeclarativegeoroutemodel_p.h11
-rw-r--r--src/location/maps/qgeocodingmanager.cpp9
-rw-r--r--tests/auto/declarative_core/tst_geocoding.qml27
-rw-r--r--tests/auto/declarative_core/tst_routing.qml25
9 files changed, 105 insertions, 83 deletions
diff --git a/src/imports/location/plugins.qmltypes b/src/imports/location/plugins.qmltypes
index 3871feaa..105e8713 100644
--- a/src/imports/location/plugins.qmltypes
+++ b/src/imports/location/plugins.qmltypes
@@ -577,10 +577,8 @@ Module {
"ParseError": 3,
"UnsupportedOptionError": 4,
"UnknownError": 5,
- "NotSupportedError": 101,
- "UnknownParameterError": 102,
- "MissingRequiredParameterError": 103,
- "ConnectionError": 104
+ "UnknownParameterError": 100,
+ "MissingRequiredParameterError": 101
}
}
Property { name: "plugin"; type: "QDeclarativeGeoServiceProvider"; isPointer: true }
@@ -984,10 +982,8 @@ Module {
"UnsupportedOptionError": 4,
"CombinationError": 5,
"UnknownError": 6,
- "NotSupportedError": 101,
- "UnknownParameterError": 102,
- "MissingRequiredParameterError": 103,
- "ConnectionError": 104
+ "UnknownParameterError": 100,
+ "MissingRequiredParameterError": 101
}
}
Property { name: "plugin"; type: "QDeclarativeGeoServiceProvider"; isPointer: true }
diff --git a/src/imports/location/qdeclarativegeocodemodel.cpp b/src/imports/location/qdeclarativegeocodemodel.cpp
index d2599747..d8ff4e85 100644
--- a/src/imports/location/qdeclarativegeocodemodel.cpp
+++ b/src/imports/location/qdeclarativegeocodemodel.cpp
@@ -150,7 +150,7 @@ void QDeclarativeGeocodeModel::update()
return;
if (!plugin_) {
- setError(NotSupportedError, tr("Cannot geocode, plugin not set."));
+ setError(EngineNotSetError, tr("Cannot geocode, plugin not set."));
return;
}
@@ -160,7 +160,7 @@ void QDeclarativeGeocodeModel::update()
QGeoCodingManager *geocodingManager = serviceProvider->geocodingManager();
if (!geocodingManager) {
- setError(NotSupportedError, tr("Cannot geocode, geocode manager not set."));
+ setError(EngineNotSetError, tr("Cannot geocode, geocode manager not set."));
return;
}
if (!coordinate_.isValid() && (!address_ || address_->address().isEmpty()) &&
@@ -292,13 +292,26 @@ void QDeclarativeGeocodeModel::pluginReady()
QGeoCodingManager *geocodingManager = serviceProvider->geocodingManager();
if (serviceProvider->error() != QGeoServiceProvider::NoError) {
- setError(GeocodeError(serviceProvider->error() + NotSupportedError - 1),
- serviceProvider->errorString());
+ QDeclarativeGeocodeModel::GeocodeError newError = UnknownError;
+ switch (serviceProvider->error()) {
+ case QGeoServiceProvider::NotSupportedError:
+ newError = EngineNotSetError; break;
+ case QGeoServiceProvider::UnknownParameterError:
+ newError = UnknownParameterError; break;
+ case QGeoServiceProvider::MissingRequiredParameterError:
+ newError = MissingRequiredParameterError; break;
+ case QGeoServiceProvider::ConnectionError:
+ newError = CommunicationError; break;
+ default:
+ break;
+ }
+
+ setError(newError, serviceProvider->errorString());
return;
}
if (!geocodingManager) {
- setError(NotSupportedError,tr("Plugin does not support (reverse) geocoding."));
+ setError(EngineNotSetError,tr("Plugin does not support (reverse) geocoding."));
return;
}
@@ -432,13 +445,17 @@ void QDeclarativeGeocodeModel::setStatus(QDeclarativeGeocodeModel::Status status
This read-only property holds the latest error value of the geocoding request.
\list
- \li GeocodeModel.NoError - No error has occurred
- \li GeocodeModel.EngineNotSetError - The plugin/service provider used does not support (reverse) geocoding
- \li GeocodeModel.CommunicationError - An error occurred while communicating with the service provider
- \li GeocodeModel.ParseError - The response from the service provider was in an unrecognizable format
- \li GeocodeModel.UnsupportedOptionError - The requested operation or one of the options for the operation are not supported by the service provider.
- \li GeocodeModel.CombinationError - An error occurred while results where being combined from multiple sources
- \li GeocodeModel.UnknownError - An error occurred which does not fit into any of the other categories
+ \li GeocodeModel.NoError - No error has occurred.
+ \li GeocodeModel.CombinationError - An error occurred while results where being combined from multiple sources.
+ \li GeocodeModel.CommunicationError - An error occurred while communicating with the service provider.
+ \li GeocodeModel.EngineNotSetError - The model's plugin property was not set or there is no geocoding manager associated with the plugin.
+ \li GeocodeModel.MissingRequiredParameterError - A required parameter was not specified.
+ \li GeocodeModel.ParseError - The response from the service provider was in an unrecognizable format.
+ \li GeocodeModel.UnknownError - An error occurred which does not fit into any of the other categories.
+ \li GeocodeModel.UnknownParameterError - The plugin did not recognize one of the parameters it was given.
+ \li GeocodeModel.UnsupportedOptionError - The requested operation is not supported by the geocoding provider.
+ This may happen when the loaded engine does not support a particular geocoding request
+ such as reverse geocoding.
\endlist
*/
@@ -512,7 +529,7 @@ int QDeclarativeGeocodeModel::count() const
QDeclarativeGeoLocation *QDeclarativeGeocodeModel::get(int index)
{
if (index < 0 || index >= declarativeLocations_.count()) {
- setError(UnsupportedOptionError, QCoreApplication::translate(CONTEXT_NAME, INDEX_OUT_OF_RANGE).arg(index));
+ qmlInfo(this) << QStringLiteral("Index '%1' out of range").arg(index);
return 0;
}
return declarativeLocations_.at(index);
diff --git a/src/imports/location/qdeclarativegeocodemodel_p.h b/src/imports/location/qdeclarativegeocodemodel_p.h
index 5d6b27a7..cb610bb0 100644
--- a/src/imports/location/qdeclarativegeocodemodel_p.h
+++ b/src/imports/location/qdeclarativegeocodemodel_p.h
@@ -82,18 +82,17 @@ public:
enum GeocodeError {
NoError = QGeoCodeReply::NoError,
- EngineNotSetError = QGeoCodeReply::EngineNotSetError,
- CommunicationError = QGeoCodeReply::CommunicationError,
+ EngineNotSetError = QGeoCodeReply::EngineNotSetError, //TODO Qt6 consider merge with NotSupportedError
+ CommunicationError = QGeoCodeReply::CommunicationError, //TODO Qt6 merge with Map's ConnectionError
ParseError = QGeoCodeReply::ParseError,
- UnsupportedOptionError = QGeoCodeReply::UnsupportedOptionError,
+ UnsupportedOptionError = QGeoCodeReply::UnsupportedOptionError, //TODO Qt6 consider rename UnsupportedOperationError
CombinationError = QGeoCodeReply::CombinationError,
UnknownError = QGeoCodeReply::UnknownError,
- //here we leave gap for future model errors
- //now geo service provider errors
- NotSupportedError = 100 + QGeoServiceProvider::NotSupportedError,
- UnknownParameterError = 100 + QGeoServiceProvider::UnknownParameterError,
- MissingRequiredParameterError = 100 + QGeoServiceProvider::MissingRequiredParameterError,
- ConnectionError = 100 + QGeoServiceProvider::ConnectionError
+ //we leave gap for future QGeoCodeReply errors
+
+ //QGeoServiceProvider related errors start here
+ UnknownParameterError = 100,
+ MissingRequiredParameterError
};
enum Roles {
diff --git a/src/imports/location/qdeclarativegeomap.cpp b/src/imports/location/qdeclarativegeomap.cpp
index cf492977..87023708 100644
--- a/src/imports/location/qdeclarativegeomap.cpp
+++ b/src/imports/location/qdeclarativegeomap.cpp
@@ -283,6 +283,7 @@ void QDeclarativeGeoMap::pluginReady()
}
if (!m_mappingManager) {
+ //TODO Should really be EngineNotSetError (see QML GeoCodeModel)
setError(QGeoServiceProvider::NotSupportedError, tr("Plugin does not support mapping."));
return;
}
@@ -917,7 +918,7 @@ QString QDeclarativeGeoMap::errorString() const
\list
\li Map.NoError - No error has occurred.
- \li Map.NotSupportedError -The plugin does not support mapping functionality.
+ \li Map.NotSupportedError -The maps plugin property was not set or there is no mapping manager associated with the plugin.
\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.
diff --git a/src/imports/location/qdeclarativegeoroutemodel.cpp b/src/imports/location/qdeclarativegeoroutemodel.cpp
index 87023c15..0c64c23a 100644
--- a/src/imports/location/qdeclarativegeoroutemodel.cpp
+++ b/src/imports/location/qdeclarativegeoroutemodel.cpp
@@ -212,7 +212,7 @@ void QDeclarativeGeoRouteModel::abortRequest()
QDeclarativeGeoRoute *QDeclarativeGeoRouteModel::get(int index)
{
if (index < 0 || index >= routes_.count()) {
- setError(UnsupportedOptionError, QCoreApplication::translate(CONTEXT_NAME, INDEX_OUT_OF_RANGE).arg(index));
+ qmlInfo(this) << QStringLiteral("Index '%1' out of range").arg(index);
return 0;
}
return routes_.at(index);
@@ -307,13 +307,26 @@ void QDeclarativeGeoRouteModel::pluginReady()
QGeoRoutingManager *routingManager = serviceProvider->routingManager();
if (serviceProvider->error() != QGeoServiceProvider::NoError) {
- setError(RouteError(serviceProvider->error() + NotSupportedError -1),
- serviceProvider->errorString());
+ QDeclarativeGeoRouteModel::RouteError newError = UnknownError;
+ switch (serviceProvider->error()) {
+ case QGeoServiceProvider::NotSupportedError:
+ newError = EngineNotSetError; break;
+ case QGeoServiceProvider::UnknownParameterError:
+ newError = UnknownParameterError; break;
+ case QGeoServiceProvider::MissingRequiredParameterError:
+ newError = MissingRequiredParameterError; break;
+ case QGeoServiceProvider::ConnectionError:
+ newError = CommunicationError; break;
+ default:
+ break;
+ }
+
+ setError(newError, serviceProvider->errorString());
return;
}
if (!routingManager) {
- setError(NotSupportedError, tr("Plugin does not support routing."));
+ setError(EngineNotSetError, tr("Plugin does not support routing."));
return;
}
@@ -519,12 +532,16 @@ QString QDeclarativeGeoRouteModel::errorString() const
This read-only property holds the latest error value of the routing request.
\list
- \li RouteModel.NoError - No error has occurred
- \li RouteModel.EngineNotSetError - The plugin/service provider used does not support routing
- \li RouteModel.CommunicationError - An error occurred while communicating with the service provider
- \li RouteModel.ParseError - The response from the service provider was in an unrecognizable format
- \li RouteModel.UnsupportedOptionError - The requested operation or one of the options for the operation are not supported by the service provider.
- \li RouteModel.UnknownError - An error occurred which does not fit into any of the other categories
+ \li RouteModel.NoError - No error has occurred.
+ \li RouteModel.CommunicationError - An error occurred while communicating with the service provider.
+ \li RouteModel.EngineNotSetError - The model's plugin property was not set or there is no routing manager associated with the plugin.
+ \li RouteModel.MissingRequiredParameterError - A required parameter was not specified.
+ \li RouteModel.ParseError - The response from the service provider was in an unrecognizable format.
+ \li RouteModel.UnknownError - An error occurred which does not fit into any of the other categories.
+ \li RouteModel.UnknownParameterError - The plugin did not recognize one of the parameters it was given.
+ \li RouteModel.UnsupportedOptionError - The requested operation is not supported by the routing provider.
+ This may happen when the loaded engine does not support a particular
+ type of routing request.
\endlist
*/
@@ -555,7 +572,7 @@ void QDeclarativeGeoRouteModel::update()
return;
if (!plugin_) {
- setError(NotSupportedError, tr("Cannot route, plugin not set."));
+ setError(EngineNotSetError, tr("Cannot route, plugin not set."));
return;
}
@@ -565,7 +582,7 @@ void QDeclarativeGeoRouteModel::update()
QGeoRoutingManager *routingManager = serviceProvider->routingManager();
if (!routingManager) {
- setError(NotSupportedError, tr("Cannot route, route manager not set."));
+ setError(EngineNotSetError, tr("Cannot route, route manager not set."));
return;
}
if (!routeQuery_) {
diff --git a/src/imports/location/qdeclarativegeoroutemodel_p.h b/src/imports/location/qdeclarativegeoroutemodel_p.h
index 363c3bc5..35cfe004 100644
--- a/src/imports/location/qdeclarativegeoroutemodel_p.h
+++ b/src/imports/location/qdeclarativegeoroutemodel_p.h
@@ -95,12 +95,11 @@ public:
ParseError = QGeoRouteReply::ParseError,
UnsupportedOptionError = QGeoRouteReply::UnsupportedOptionError,
UnknownError = QGeoRouteReply::UnknownError,
- //here we leave gap for future model errors
- //now geo service provider errors
- NotSupportedError = 100 + QGeoServiceProvider::NotSupportedError,
- UnknownParameterError = 100 + QGeoServiceProvider::UnknownParameterError,
- MissingRequiredParameterError = 100 + QGeoServiceProvider::MissingRequiredParameterError,
- ConnectionError = 100 + QGeoServiceProvider::ConnectionError
+ //we leave gap for future QGeoRouteReply errors
+
+ //QGeoServiceProvider related errors start here
+ UnknownParameterError = 100,
+ MissingRequiredParameterError
};
explicit QDeclarativeGeoRouteModel(QObject *parent = 0);
diff --git a/src/location/maps/qgeocodingmanager.cpp b/src/location/maps/qgeocodingmanager.cpp
index a84686e3..284adde3 100644
--- a/src/location/maps/qgeocodingmanager.cpp
+++ b/src/location/maps/qgeocodingmanager.cpp
@@ -170,9 +170,6 @@ int QGeoCodingManager::managerVersion() const
*/
QGeoCodeReply *QGeoCodingManager::geocode(const QGeoAddress &address, const QGeoShape &bounds)
{
-// if (!d_ptr->engine)
-// return new QGeoCodeReply(QGeoCodeReply::EngineNotSetError, "The geocoding manager was not created with a valid engine.", this);
-
return d_ptr->engine->geocode(address, bounds);
}
@@ -215,9 +212,6 @@ QGeoCodeReply *QGeoCodingManager::geocode(const QGeoAddress &address, const QGeo
*/
QGeoCodeReply *QGeoCodingManager::reverseGeocode(const QGeoCoordinate &coordinate, const QGeoShape &bounds)
{
-// if (!d_ptr->engine)
-// return new QGeoCodeReply(QGeoCodeReply::EngineNotSetError, "The geocoding manager was not created with a valid engine.", this);
-
return d_ptr->engine->reverseGeocode(coordinate, bounds);
}
@@ -255,9 +249,6 @@ QGeoCodeReply *QGeoCodingManager::geocode(const QString &address,
int offset,
const QGeoShape &bounds)
{
-// if (!d_ptr->engine)
-// return new QGeoCodeReply(QGeoCodeReply::EngineNotSetError, "The geocoding manager was not created with a valid engine.", this);
-
QGeoCodeReply *reply = d_ptr->engine->geocode(address,
limit,
offset,
diff --git a/tests/auto/declarative_core/tst_geocoding.qml b/tests/auto/declarative_core/tst_geocoding.qml
index 577a9110..984fde65 100644
--- a/tests/auto/declarative_core/tst_geocoding.qml
+++ b/tests/auto/declarative_core/tst_geocoding.qml
@@ -177,16 +177,24 @@ Item {
compare(pluginSpy.count, 2)
}
// Test that model acts gracefully when plugin is not set or is invalid
- // (does not support routing)
+ // (does not support geocoding)
GeocodeModel {id: errorModel; plugin: errorPlugin}
+ GeocodeModel {id: errorModelNoPlugin}
SignalSpy {id: countInvalidSpy; target: errorModel; signalName: "countChanged"}
SignalSpy {id: errorSpy; target: errorModel; signalName: "errorChanged"}
function test_error_plugin() {
- compare(errorModel.error,GeocodeModel.NotSupportedError)
+ // test plugin not set
+ compare(errorModelNoPlugin.error,GeocodeModel.NoError)
+ errorModelNoPlugin.update()
+ compare(errorModelNoPlugin.error,GeocodeModel.EngineNotSetError)
+ console.log(errorModelNoPlugin.errorString)
+
+ //plugin set but otherwise not offering anything
+ compare(errorModel.error,GeocodeModel.EngineNotSetError)
compare(errorModel.errorString,"This error was expected. No worries !")
errorSpy.clear()
errorModel.update()
- compare(errorModel.error,GeocodeModel.NotSupportedError)
+ compare(errorModel.error,GeocodeModel.EngineNotSetError)
compare(errorModel.errorString,qsTr("Cannot geocode, geocode manager not set."))
compare(errorSpy.count, 1)
errorSpy.clear()
@@ -201,19 +209,12 @@ Item {
compare(errorSpy.count, 0)
errorSpy.clear()
errorModel.update()
- compare(errorModel.error,GeocodeModel.NotSupportedError)
+ compare(errorModel.error,GeocodeModel.EngineNotSetError)
compare(errorModel.errorString,qsTr("Cannot geocode, geocode manager not set."))
compare(errorSpy.count, 1)
errorSpy.clear()
- errorModel.get(-1)
- compare(errorModel.error,GeocodeModel.UnsupportedOptionError)
- compare(errorModel.errorString,qsTr("Index '-1' out of range"))
- compare(errorSpy.count, 1)
- errorSpy.clear()
- errorModel.get(1)
- compare(errorModel.error,GeocodeModel.UnsupportedOptionError)
- compare(errorModel.errorString,qsTr("Index '1' out of range"))
- compare(errorSpy.count, 1)
+ var location = errorModel.get(-1)
+ compare(location, null)
}
}
diff --git a/tests/auto/declarative_core/tst_routing.qml b/tests/auto/declarative_core/tst_routing.qml
index 96a4a10f..f29c7dd3 100644
--- a/tests/auto/declarative_core/tst_routing.qml
+++ b/tests/auto/declarative_core/tst_routing.qml
@@ -446,14 +446,22 @@ Item {
// Test that model acts gracefully when plugin is not set or is invalid
// (does not support routing)
RouteModel {id: errorModel; plugin: errorPlugin}
+ RouteModel {id: errorModelNoPlugin}
SignalSpy {id: countInvalidSpy; target: errorModel; signalName: "countChanged"}
SignalSpy {id: errorSpy; target: errorModel; signalName: "errorChanged"}
function test_error_plugin() {
- compare(errorModel.error,RouteModel.NotSupportedError)
+ // test plugin not set
+ compare(errorModelNoPlugin.error,RouteModel.NoError)
+ errorModelNoPlugin.update()
+ compare(errorModelNoPlugin.error,RouteModel.EngineNotSetError)
+ console.log(errorModelNoPlugin.errorString)
+
+ //plugin set but otherwise not offering anything
+ compare(errorModel.error,RouteModel.EngineNotSetError)
compare(errorModel.errorString,"This error was expected. No worries !")
errorSpy.clear()
errorModel.update()
- compare(errorModel.error,RouteModel.NotSupportedError)
+ compare(errorModel.error,RouteModel.EngineNotSetError)
compare(errorModel.errorString,qsTr("Cannot route, route manager not set."))
compare(errorSpy.count, 1)
errorSpy.clear()
@@ -468,19 +476,12 @@ Item {
compare(errorSpy.count, 0)
errorSpy.clear()
errorModel.update()
- compare(errorModel.error,RouteModel.NotSupportedError)
+ compare(errorModel.error,RouteModel.EngineNotSetError)
compare(errorModel.errorString,qsTr("Cannot route, route manager not set."))
compare(errorSpy.count, 1)
errorSpy.clear()
- errorModel.get(-1)
- compare(errorModel.error,RouteModel.UnsupportedOptionError)
- compare(errorModel.errorString,qsTr("Index '-1' out of range"))
- compare(errorSpy.count, 1)
- errorSpy.clear()
- errorModel.get(1)
- compare(errorModel.error,RouteModel.UnsupportedOptionError)
- compare(errorModel.errorString,qsTr("Index '1' out of range"))
- compare(errorSpy.count, 1)
+ var data = errorModel.get(-1)
+ compare(data, null)
}
}