summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorabcd <amos.choy@nokia.com>2012-07-18 19:13:18 +1000
committerQt by Nokia <qt-info@nokia.com>2012-07-20 09:38:53 +0200
commitfa9c0d906d31dd1f85e235182acfea797eafbf7b (patch)
treeef4cc830f198d331686f136b2bb25c75764a91e7
parent6a80e4afa9e04b64b8dbfdfa2e3d7cd3c8058bbc (diff)
downloadqtlocation-fa9c0d906d31dd1f85e235182acfea797eafbf7b.tar.gz
Fix incorrect warning messages + refactor error handling
There was an assumption in the QML models that if the QGeoServiceProvider::placeManager() returned null, then places was not supported. This is no longer the case as incorrect parmeters may result in null being returned. Previously a warning was output to console. Instead, if possible, we set the error status of the model, and set the error string to the one provided by the QGeoServiceProvider. If it is not possible, such as in the case of the Icon element, a warning is output to console but only if it is deemed necessary. Task-number: QTBUG-26566 Change-Id: I584222af9325ddb8575fa8f77909521c49bc850a Reviewed-by: Aaron McCarthy <aaron.mccarthy@nokia.com>
-rw-r--r--examples/declarative/places/places.qml7
-rw-r--r--src/imports/location/declarativeplaces/qdeclarativecategory.cpp39
-rw-r--r--src/imports/location/declarativeplaces/qdeclarativecategory_p.h2
-rw-r--r--src/imports/location/declarativeplaces/qdeclarativeplace.cpp20
-rw-r--r--src/imports/location/declarativeplaces/qdeclarativeplace_p.h2
-rw-r--r--src/imports/location/declarativeplaces/qdeclarativeplacecontentmodel.cpp4
-rw-r--r--src/imports/location/declarativeplaces/qdeclarativeplaceicon.cpp7
-rw-r--r--src/imports/location/declarativeplaces/qdeclarativesearchmodelbase.cpp15
-rw-r--r--src/imports/location/declarativeplaces/qdeclarativesupportedcategoriesmodel.cpp29
-rw-r--r--src/imports/location/declarativeplaces/qdeclarativesupportedcategoriesmodel_p.h2
-rw-r--r--src/imports/location/error_messages.cpp4
-rw-r--r--src/imports/location/error_messages.h4
-rw-r--r--src/location/maps/qgeoserviceprovider.cpp3
13 files changed, 68 insertions, 70 deletions
diff --git a/examples/declarative/places/places.qml b/examples/declarative/places/places.qml
index eab92a20..98be4f8a 100644
--- a/examples/declarative/places/places.qml
+++ b/examples/declarative/places/places.qml
@@ -407,8 +407,13 @@ Item {
}
onStatusChanged: {
- if (status === PlaceSearchModel.Ready)
+ switch (status) {
+ case PlaceSearchModel.Ready:
searchResultView.showSearchResults();
+ break;
+ case PlaceSearchModel.Error:
+ console.log(errorString());
+ }
}
}
//! [PlaceSearchModel model]
diff --git a/src/imports/location/declarativeplaces/qdeclarativecategory.cpp b/src/imports/location/declarativeplaces/qdeclarativecategory.cpp
index f0412799..39f6ac85 100644
--- a/src/imports/location/declarativeplaces/qdeclarativecategory.cpp
+++ b/src/imports/location/declarativeplaces/qdeclarativecategory.cpp
@@ -150,8 +150,8 @@ void QDeclarativeCategory::pluginReady()
QGeoServiceProvider *serviceProvider = m_plugin->sharedGeoServiceProvider();
QPlaceManager *placeManager = serviceProvider->placeManager();
if (!placeManager || serviceProvider->error() != QGeoServiceProvider::NoError) {
- m_errorString = QCoreApplication::translate(CONTEXT_NAME, PLUGIN_DOESNOT_SUPPORT_PLACES2).arg(m_plugin->name());
- setStatus(Error);
+ setStatus(Error, QCoreApplication::translate(CONTEXT_NAME, PLUGIN_ERROR)
+ .arg(m_plugin->name()).arg(serviceProvider->errorString()));
return;
}
}
@@ -303,6 +303,16 @@ QString QDeclarativeCategory::errorString() const
return m_errorString;
}
+void QDeclarativeCategory::setStatus(Status status, const QString &errorString)
+{
+ Status originalStatus = m_status;
+ m_status = status;
+ m_errorString = errorString;
+
+ if (originalStatus != m_status)
+ emit statusChanged();
+}
+
/*!
\qmlproperty enumeration Category::status
@@ -327,17 +337,6 @@ QString QDeclarativeCategory::errorString() const
performed on the category.
\endtable
*/
-void QDeclarativeCategory::setStatus(Status status)
-{
- if (status != Error)
- m_errorString.clear();
-
- if (m_status != status) {
- m_status = status;
- emit statusChanged();
- }
-}
-
QDeclarativeCategory::Status QDeclarativeCategory::status() const
{
return m_status;
@@ -413,12 +412,12 @@ void QDeclarativeCategory::replyFinished()
setStatus(QDeclarativeCategory::Ready);
} else {
- m_errorString = m_reply->errorString();
+ QString errorString = m_reply->errorString();
m_reply->deleteLater();
m_reply = 0;
- setStatus(QDeclarativeCategory::Error);
+ setStatus(QDeclarativeCategory::Error, errorString);
}
}
@@ -440,21 +439,19 @@ QPlaceManager *QDeclarativeCategory::manager()
}
if (!m_plugin) {
- m_errorString = QCoreApplication::translate(CONTEXT_NAME, PLUGIN_PROPERTY_NOT_SET);
- setStatus(Error);
+ setStatus(Error, QCoreApplication::translate(CONTEXT_NAME, PLUGIN_PROPERTY_NOT_SET));
return 0;
}
QGeoServiceProvider *serviceProvider = m_plugin->sharedGeoServiceProvider();
if (!serviceProvider) {
- m_errorString = QCoreApplication::translate(CONTEXT_NAME, PLUGIN_NOT_VALID);
- setStatus(Error);
+ setStatus(Error, QCoreApplication::translate(CONTEXT_NAME, PLUGIN_NOT_VALID));
return 0;
}
QPlaceManager *placeManager = serviceProvider->placeManager();
if (!placeManager) {
- m_errorString = QCoreApplication::translate(CONTEXT_NAME, PLUGIN_DOESNOT_SUPPORT_PLACES2).arg(m_plugin->name());
- setStatus(Error);
+ setStatus(Error, QCoreApplication::translate(CONTEXT_NAME, PLUGIN_ERROR)
+ .arg(m_plugin->name()).arg(serviceProvider->errorString()));
return 0;
}
diff --git a/src/imports/location/declarativeplaces/qdeclarativecategory_p.h b/src/imports/location/declarativeplaces/qdeclarativecategory_p.h
index a7dae7c6..e9fbb8ce 100644
--- a/src/imports/location/declarativeplaces/qdeclarativecategory_p.h
+++ b/src/imports/location/declarativeplaces/qdeclarativecategory_p.h
@@ -110,7 +110,7 @@ public:
Q_INVOKABLE QString errorString() const;
Status status() const;
- void setStatus(Status status);
+ void setStatus(Status status, const QString &errorString = QString());
Q_INVOKABLE void save(const QString &parentId = QString());
Q_INVOKABLE void remove();
diff --git a/src/imports/location/declarativeplaces/qdeclarativeplace.cpp b/src/imports/location/declarativeplaces/qdeclarativeplace.cpp
index af8758df..832d3e3d 100644
--- a/src/imports/location/declarativeplaces/qdeclarativeplace.cpp
+++ b/src/imports/location/declarativeplaces/qdeclarativeplace.cpp
@@ -249,7 +249,8 @@ void QDeclarativePlace::pluginReady()
QGeoServiceProvider *serviceProvider = m_plugin->sharedGeoServiceProvider();
QPlaceManager *placeManager = serviceProvider->placeManager();
if (!placeManager || serviceProvider->error() != QGeoServiceProvider::NoError) {
- qmlInfo(this) << QCoreApplication::translate(CONTEXT_NAME, PLUGIN_DOESNOT_SUPPORT_PLACES).arg(serviceProvider->errorString());
+ setStatus(Error, QCoreApplication::translate(CONTEXT_NAME, PLUGIN_ERROR)
+ .arg(m_plugin->name()).arg(serviceProvider->errorString()));
return;
}
}
@@ -644,12 +645,14 @@ bool QDeclarativePlace::detailsFetched() const
\snippet snippets/declarative/places.qml Place checkStatus handler
*/
-void QDeclarativePlace::setStatus(Status status)
+void QDeclarativePlace::setStatus(Status status, const QString &errorString)
{
- if (m_status != status) {
- m_status = status;
+ Status originalStatus = m_status;
+ m_status = status;
+ m_errorString = errorString;
+
+ if (originalStatus != m_status)
emit statusChanged();
- }
}
QDeclarativePlace::Status QDeclarativePlace::status() const
@@ -699,12 +702,12 @@ void QDeclarativePlace::finished()
setStatus(QDeclarativePlace::Ready);
} else {
- m_errorString = m_reply->errorString();
+ QString errorString = m_reply->errorString();
m_reply->deleteLater();
m_reply = 0;
- setStatus(QDeclarativePlace::Error);
+ setStatus(QDeclarativePlace::Error, errorString);
}
}
@@ -1207,7 +1210,8 @@ QPlaceManager *QDeclarativePlace::manager()
QPlaceManager *placeManager = serviceProvider->placeManager();
if (!placeManager) {
- qmlInfo(this) << QCoreApplication::translate(CONTEXT_NAME, PLUGIN_DOESNOT_SUPPORT_PLACES2).arg(m_plugin->name());
+ setStatus(Error, QCoreApplication::translate(CONTEXT_NAME, PLUGIN_ERROR)
+ .arg(m_plugin->name()).arg(serviceProvider->errorString()));
return 0;
}
diff --git a/src/imports/location/declarativeplaces/qdeclarativeplace_p.h b/src/imports/location/declarativeplaces/qdeclarativeplace_p.h
index 16fcc3a3..2552d5a1 100644
--- a/src/imports/location/declarativeplaces/qdeclarativeplace_p.h
+++ b/src/imports/location/declarativeplaces/qdeclarativeplace_p.h
@@ -151,7 +151,7 @@ public:
bool detailsFetched() const;
Status status() const;
- void setStatus(Status status);
+ void setStatus(Status status, const QString &errorString = QString());
Q_INVOKABLE void getDetails();
Q_INVOKABLE void save();
diff --git a/src/imports/location/declarativeplaces/qdeclarativeplacecontentmodel.cpp b/src/imports/location/declarativeplaces/qdeclarativeplacecontentmodel.cpp
index c7479c9d..1eb5bcf8 100644
--- a/src/imports/location/declarativeplaces/qdeclarativeplacecontentmodel.cpp
+++ b/src/imports/location/declarativeplaces/qdeclarativeplacecontentmodel.cpp
@@ -285,10 +285,8 @@ void QDeclarativePlaceContentModel::fetchMore(const QModelIndex &parent)
return;
QPlaceManager *placeManager = serviceProvider->placeManager();
- if (!placeManager) {
- qmlInfo(this) << QCoreApplication::translate(CONTEXT_NAME, PLUGIN_DOESNOT_SUPPORT_PLACES2).arg(plugin->name());
+ if (!placeManager)
return;
- }
QPlaceContentRequest request;
request.setContentType(m_type);
diff --git a/src/imports/location/declarativeplaces/qdeclarativeplaceicon.cpp b/src/imports/location/declarativeplaces/qdeclarativeplaceicon.cpp
index 178a44bb..92e61684 100644
--- a/src/imports/location/declarativeplaces/qdeclarativeplaceicon.cpp
+++ b/src/imports/location/declarativeplaces/qdeclarativeplaceicon.cpp
@@ -204,7 +204,8 @@ void QDeclarativePlaceIcon::pluginReady()
QGeoServiceProvider *serviceProvider = m_plugin->sharedGeoServiceProvider();
QPlaceManager *placeManager = serviceProvider->placeManager();
if (!placeManager || serviceProvider->error() != QGeoServiceProvider::NoError) {
- qmlInfo(this) << QCoreApplication::translate(CONTEXT_NAME, PLUGIN_DOESNOT_SUPPORT_PLACES).arg(serviceProvider->errorString());
+ qmlInfo(this) << QCoreApplication::translate(CONTEXT_NAME, PLUGIN_ERROR)
+ .arg(m_plugin->name()).arg(serviceProvider->errorString());
return;
}
}
@@ -226,10 +227,8 @@ QPlaceManager *QDeclarativePlaceIcon::manager() const
QPlaceManager *placeManager = serviceProvider->placeManager();
- if (!placeManager) {
- qmlInfo(this) << QCoreApplication::translate(CONTEXT_NAME, PLUGIN_DOESNOT_SUPPORT_PLACES2).arg(m_plugin->name());
+ if (!placeManager)
return 0;
- }
return placeManager;
}
diff --git a/src/imports/location/declarativeplaces/qdeclarativesearchmodelbase.cpp b/src/imports/location/declarativeplaces/qdeclarativesearchmodelbase.cpp
index b8804fc0..4d7ca557 100644
--- a/src/imports/location/declarativeplaces/qdeclarativesearchmodelbase.cpp
+++ b/src/imports/location/declarativeplaces/qdeclarativesearchmodelbase.cpp
@@ -154,12 +154,12 @@ QDeclarativeSearchModelBase::Status QDeclarativeSearchModelBase::status() const
*/
void QDeclarativeSearchModelBase::setStatus(Status status, const QString &errorString)
{
- if (m_status == status)
- return;
-
+ Status originalStatus = m_status;
m_status = status;
m_errorString = errorString;
- emit statusChanged();
+
+ if (originalStatus != m_status)
+ emit statusChanged();
}
/*!
@@ -168,7 +168,7 @@ void QDeclarativeSearchModelBase::setStatus(Status status, const QString &errorS
void QDeclarativeSearchModelBase::update()
{
if (!m_plugin) {
- qmlInfo(this) << "plugin not set.";
+ setStatus(Error, QCoreApplication::translate(CONTEXT_NAME, PLUGIN_PROPERTY_NOT_SET));
return;
}
@@ -178,7 +178,8 @@ void QDeclarativeSearchModelBase::update()
QPlaceManager *placeManager = serviceProvider->placeManager();
if (!placeManager) {
- qmlInfo(this) << QCoreApplication::translate(CONTEXT_NAME, PLUGIN_DOESNOT_SUPPORT_PLACES2).arg(m_plugin->name());
+ setStatus(Error, QCoreApplication::translate(CONTEXT_NAME, PLUGIN_ERROR)
+ .arg(m_plugin->name()).arg(serviceProvider->errorString()));
return;
}
@@ -187,7 +188,7 @@ void QDeclarativeSearchModelBase::update()
updateSearchRequest();
m_reply = sendQuery(placeManager, m_request);
if (!m_reply) {
- setStatus(Error);
+ setStatus(Error, QCoreApplication::translate(CONTEXT_NAME, UNABLE_TO_MAKE_REQUEST));
return;
}
diff --git a/src/imports/location/declarativeplaces/qdeclarativesupportedcategoriesmodel.cpp b/src/imports/location/declarativeplaces/qdeclarativesupportedcategoriesmodel.cpp
index 3ab93a08..d27559ff 100644
--- a/src/imports/location/declarativeplaces/qdeclarativesupportedcategoriesmodel.cpp
+++ b/src/imports/location/declarativeplaces/qdeclarativesupportedcategoriesmodel.cpp
@@ -476,10 +476,8 @@ void QDeclarativeSupportedCategoriesModel::connectNotificationSignals()
return;
QPlaceManager *placeManager = serviceProvider->placeManager();
- if (!placeManager) {
- qmlInfo(this) << QCoreApplication::translate(CONTEXT_NAME, PLUGIN_DOESNOT_SUPPORT_PLACES2).arg(m_plugin->name());
+ if (!placeManager)
return;
- }
// listen for any category notifications so that we can reupdate the categories
// model.
@@ -512,7 +510,8 @@ void QDeclarativeSupportedCategoriesModel::update()
QPlaceManager *placeManager = serviceProvider->placeManager();
if (!placeManager) {
- qmlInfo(this) << QCoreApplication::translate(CONTEXT_NAME, PLUGIN_DOESNOT_SUPPORT_PLACES2).arg(m_plugin->name());
+ setStatus(Error, QCoreApplication::translate(CONTEXT_NAME, PLUGIN_ERROR)
+ .arg(m_plugin->name()).arg(serviceProvider->errorString()));
return;
}
@@ -522,8 +521,8 @@ void QDeclarativeSupportedCategoriesModel::update()
connect(m_response, SIGNAL(finished()), this, SLOT(replyFinished()));
setStatus(QDeclarativeSupportedCategoriesModel::Loading);
} else {
- setStatus(QDeclarativeSupportedCategoriesModel::Error);
- m_errorString = QCoreApplication::translate(CONTEXT_NAME, CATEGORIES_NOT_INITIALIZED);
+ setStatus(Error, QCoreApplication::translate(CONTEXT_NAME,
+ CATEGORIES_NOT_INITIALIZED));
}
}
}
@@ -541,10 +540,8 @@ void QDeclarativeSupportedCategoriesModel::updateLayout()
return;
QPlaceManager *placeManager = serviceProvider->placeManager();
- if (!placeManager) {
- qmlInfo(this) << QCoreApplication::translate(CONTEXT_NAME, PLUGIN_DOESNOT_SUPPORT_PLACES2).arg(m_plugin->name());
+ if (!placeManager)
return;
- }
beginResetModel();
qDeleteAll(m_categoriesTree);
@@ -584,12 +581,14 @@ QString QDeclarativeSupportedCategoriesModel::errorString() const
performed on the model.
\endtable
*/
-void QDeclarativeSupportedCategoriesModel::setStatus(Status status)
+void QDeclarativeSupportedCategoriesModel::setStatus(Status status, const QString &errorString)
{
- if (m_status != status) {
- m_status = status;
+ Status originalStatus = m_status;
+ m_status = status;
+ m_errorString = errorString;
+
+ if (originalStatus != m_status)
emit statusChanged();
- }
}
QDeclarativeSupportedCategoriesModel::Status QDeclarativeSupportedCategoriesModel::status() const
@@ -697,10 +696,8 @@ QPlaceManager *QDeclarativeSupportedCategoriesModel::manager(bool checkState)
QPlaceManager *placeManager = serviceProvider->placeManager();
- if (!placeManager) {
- qmlInfo(this) << QCoreApplication::translate(CONTEXT_NAME, PLUGIN_DOESNOT_SUPPORT_PLACES2).arg(m_plugin->name());
+ if (!placeManager)
return 0;
- }
return placeManager;
}
diff --git a/src/imports/location/declarativeplaces/qdeclarativesupportedcategoriesmodel_p.h b/src/imports/location/declarativeplaces/qdeclarativesupportedcategoriesmodel_p.h
index c9e677eb..2129e420 100644
--- a/src/imports/location/declarativeplaces/qdeclarativesupportedcategoriesmodel_p.h
+++ b/src/imports/location/declarativeplaces/qdeclarativesupportedcategoriesmodel_p.h
@@ -116,7 +116,7 @@ public:
Q_INVOKABLE QString errorString() const;
Status status() const;
- void setStatus(Status status);
+ void setStatus(Status status, const QString &errorString = QString());
using QAbstractItemModel::dataChanged;
Q_SIGNALS:
diff --git a/src/imports/location/error_messages.cpp b/src/imports/location/error_messages.cpp
index 8567e296..06edc5fe 100644
--- a/src/imports/location/error_messages.cpp
+++ b/src/imports/location/error_messages.cpp
@@ -47,11 +47,10 @@ const char CONTEXT_NAME[] = "QtLocationQML";
const char PLUGIN_DOESNOT_SUPPORT_ROUTING[] = QT_TRANSLATE_NOOP("QtLocationQML", "Error: Plugin does not support routing.\nError message: %1");
const char PLUGIN_DOESNOT_SUPPORT_MAPPING[] = QT_TRANSLATE_NOOP("QtLocationQML", "Error: Plugin does not support mapping.\nError message: %1");
const char PLUGIN_DOESNOT_SUPPORT_GEOCODING[] = QT_TRANSLATE_NOOP("QtLocationQML", "Error: Plugin does not support (reverse) geocoding.\nError message: %1");
-const char PLUGIN_DOESNOT_SUPPORT_PLACES[] = QT_TRANSLATE_NOOP("QtLocationQML", "Error: Plugin does not support places.\nError message: %1");
-const char PLUGIN_DOESNOT_SUPPORT_PLACES2[] = QT_TRANSLATE_NOOP("QtLocationQML", "Plugin %1 does not support places.");
const char NOT_SUPPORTED_BY[] = QT_TRANSLATE_NOOP("QtLocationQML", "%1 not supported by %2 plugin.");
const char PLUGIN_PROPERTY_NOT_SET[] = QT_TRANSLATE_NOOP("QtLocationQML", "Plugin property is not set.");
+const char PLUGIN_ERROR[] = QT_TRANSLATE_NOOP("QtLocationQML", "Plugin Error (%1): %2");
const char PLUGIN_NOT_VALID[] = QT_TRANSLATE_NOOP("QtLocationQML", "Plugin is not valid");
const char PLUGIN_NOT_ASSIGNED_TO_PLACE[] = QT_TRANSLATE_NOOP("QtLocationQML", "Plugin is not assigned to place.");
const char PLUGIN_NOT_ASSIGNED_TO_PLACE_ICON[] = QT_TRANSLATE_NOOP("QtLocationQML", "Plugin is not assigned to place icon.");
@@ -86,5 +85,6 @@ const char CANNOT_ADD_INVALID_WAYPOINT[] = QT_TRANSLATE_NOOP("QtLocationQML", "N
const char CANNOT_REMOVE_WAYPOINT[] = QT_TRANSLATE_NOOP("QtLocationQML", "Cannot remove nonexistent waypoint.");
const char COORD_NOT_BELONG_TO[] = QT_TRANSLATE_NOOP("QtLocationQML", "Coordinate does not belong to %1");
const char MISSED_NMEA_FILE[] = QT_TRANSLATE_NOOP("QtLocationQML", "Nmea file not found.");
+const char UNABLE_TO_MAKE_REQUEST[]= QT_TRANSLATE_NOOP("QtLocationQML", "Unable to create request");
QT_END_NAMESPACE
diff --git a/src/imports/location/error_messages.h b/src/imports/location/error_messages.h
index 2fa536a1..68259cde 100644
--- a/src/imports/location/error_messages.h
+++ b/src/imports/location/error_messages.h
@@ -51,10 +51,9 @@ extern const char CONTEXT_NAME[];
extern const char PLUGIN_DOESNOT_SUPPORT_MAPPING[];
extern const char PLUGIN_DOESNOT_SUPPORT_ROUTING[];
extern const char PLUGIN_DOESNOT_SUPPORT_GEOCODING[];
-extern const char PLUGIN_DOESNOT_SUPPORT_PLACES[];
-extern const char PLUGIN_DOESNOT_SUPPORT_PLACES2[];
extern const char PLUGIN_PROPERTY_NOT_SET[];
+extern const char PLUGIN_ERROR[];
extern const char PLUGIN_NOT_VALID[];
extern const char PLUGIN_NOT_ASSIGNED_TO_PLACE[];
extern const char PLUGIN_NOT_ASSIGNED_TO_PLACE_ICON[];
@@ -88,6 +87,7 @@ extern const char CANNOT_ADD_INVALID_WAYPOINT[];
extern const char CANNOT_REMOVE_WAYPOINT[];
extern const char COORD_NOT_BELONG_TO[];
extern const char MISSED_NMEA_FILE[];
+extern const char UNABLE_TO_MAKE_REQUEST[];
QT_END_NAMESPACE
diff --git a/src/location/maps/qgeoserviceprovider.cpp b/src/location/maps/qgeoserviceprovider.cpp
index d8efea3a..e80d9d58 100644
--- a/src/location/maps/qgeoserviceprovider.cpp
+++ b/src/location/maps/qgeoserviceprovider.cpp
@@ -463,9 +463,6 @@ QGeoRoutingManager *QGeoServiceProvider::routingManager() const
/*!
Returns the QPlaceManager made available by the service provider.
- This function will return 0 if the service provider does not provide
- any place searching services.
-
This function will attempt to construct a QPlaceManager instance
when it is called for the first time. If the attempt is successful the
QPlaceManager will be cached, otherwise each call of this function