diff options
author | Frederik Gladhorn <frederik.gladhorn@digia.com> | 2014-03-24 16:07:08 +0100 |
---|---|---|
committer | Frederik Gladhorn <frederik.gladhorn@digia.com> | 2014-03-24 16:07:09 +0100 |
commit | 4efdf073e7d76dafaac05cf8ccfccefff2734efb (patch) | |
tree | 8f3f38932758689847c861dade294b0772253131 /src | |
parent | 979a0406f0013560efbdcc486b32ba93ce8c946f (diff) | |
parent | a13d8e8862402a144ace00e409341185783927df (diff) | |
download | qtlocation-4efdf073e7d76dafaac05cf8ccfccefff2734efb.tar.gz |
Merge remote-tracking branch 'origin/stable' into dev
Change-Id: I77d4df804eb31a2b63c9d664d63baec840225abd
Diffstat (limited to 'src')
15 files changed, 223 insertions, 162 deletions
diff --git a/src/imports/location/declarativeplaces/qdeclarativeplaceattribute.cpp b/src/imports/location/declarativeplaces/qdeclarativeplaceattribute.cpp index 0edd0d1c..fdb893dc 100644 --- a/src/imports/location/declarativeplaces/qdeclarativeplaceattribute.cpp +++ b/src/imports/location/declarativeplaces/qdeclarativeplaceattribute.cpp @@ -113,10 +113,12 @@ */ /*! - \qmlsignal void ExtendedAttributes::onValueChanged(string key, variant value) + \qmlsignal void ExtendedAttributes::valueChanged(string key, variant value) - This signal is raised when the set of attributes changes. \a key is the key + This signal is emitted when the set of attributes changes. \a key is the key corresponding to the \a value that was changed. + + The corresponding handler is \c onValueChanged. */ /*! diff --git a/src/imports/location/declarativeplaces/qdeclarativesearchresultmodel.cpp b/src/imports/location/declarativeplaces/qdeclarativesearchresultmodel.cpp index ed97e93e..8378b33b 100644 --- a/src/imports/location/declarativeplaces/qdeclarativesearchresultmodel.cpp +++ b/src/imports/location/declarativeplaces/qdeclarativesearchresultmodel.cpp @@ -908,11 +908,13 @@ int QDeclarativeSearchResultModel::getRow(const QString &placeId) const /*! \qmlsignal PlaceSearchResultModel::dataChanged() - Indicates that significant changes have been made to the underlying datastore. + This signal is emitted when significant changes have been made to the underlying datastore. Applications should act on this signal at their own discretion. The data provided by the model could be out of date and so the model should be reupdated sometime, however an immediate reupdate may be disconcerting to users if the results change without any action on their part. + + The corresponding handler is \c onDataChanged. */ diff --git a/src/imports/location/declarativeplaces/qdeclarativesupportedcategoriesmodel.cpp b/src/imports/location/declarativeplaces/qdeclarativesupportedcategoriesmodel.cpp index 7d50af7e..c2d765e4 100644 --- a/src/imports/location/declarativeplaces/qdeclarativesupportedcategoriesmodel.cpp +++ b/src/imports/location/declarativeplaces/qdeclarativesupportedcategoriesmodel.cpp @@ -671,10 +671,12 @@ int QDeclarativeSupportedCategoriesModel::rowToAddChild(PlaceCategoryNode *node, /*! \qmlsignal CategoryModel::dataChanged() - Indicates that significant changes have been made to the underlying datastore. + This signal is emitted when significant changes have been made to the underlying datastore. Applications should act on this signal at their own discretion. The data provided by the model could be out of date and so the model should be reupdated sometime, however an immediate reupdate may be disconcerting to users if the categories change without any action on their part. + + The corresponding handler is \c onDataChanged. */ diff --git a/src/imports/location/qdeclarativegeomapgesturearea.cpp b/src/imports/location/qdeclarativegeomapgesturearea.cpp index 9adc422d..336f922f 100644 --- a/src/imports/location/qdeclarativegeomapgesturearea.cpp +++ b/src/imports/location/qdeclarativegeomapgesturearea.cpp @@ -263,7 +263,9 @@ QT_BEGIN_NAMESPACE /*! \qmlsignal QtLocation::MapGestureArea::pinchStarted(PinchEvent event) - Raised when a pinch gesture is started. + This signal is emitted when a pinch gesture is started. + + The corresponding handler is \c onPinchStarted. \sa pinchUpdated, pinchFinished */ @@ -271,8 +273,10 @@ QT_BEGIN_NAMESPACE /*! \qmlsignal QtLocation::MapGestureArea::pinchUpdated(PinchEvent event) - Once a pinch has begun this event gets raised as the user moves her fingers - across the map. + This signal is emitted as the user's fingers move across the map, + after the the \l pinchStarted signal is emitted. + + The corresponding handler is \c onPinchUpdated. \sa pinchStarted, pinchFinished */ @@ -280,7 +284,9 @@ QT_BEGIN_NAMESPACE /*! \qmlsignal QtLocation::MapGestureArea::pinchFinished(PinchEvent event) - The end of a pinch gesture is signaled by this event. + This signal is emitted at the end of a pinch gesture. + + The corresponding handler is \c onPinchFinished. \sa pinchStarted, pinchUpdated */ @@ -288,35 +294,43 @@ QT_BEGIN_NAMESPACE /*! \qmlsignal QtLocation::MapGestureArea::panStarted() - This handler is called when the view begins moving due to user + This signal is emitted when the view begins moving due to user interaction. Typically this means that the user is dragging a finger - or a mouse with one of more mouse buttons pressed - on the map. + + The corresponding handler is \c onPanStarted. */ /*! \qmlsignal QtLocation::MapGestureArea::panFinished() - This handler is called when the view stops moving due to user - interaction. If a flick was generated, this handler will - be triggered once the flick stops. If a flick was not - generated, the handler will be triggered when the + This signal is emitted when the view stops moving due to user + interaction. If a flick was generated, this signal is + emitted when the flick stops. If a flick was not + generated, this signal is emitted when the user stops dragging - that is a mouse or touch release. + The corresponding handler is \c onPanFinished. + */ /*! \qmlsignal QtLocation::MapGestureArea::flickStarted() - This handler is called when the view is flicked. A flick + This signal is emitted when the view is flicked. A flick starts from the point that the mouse or touch is released, while still in motion. + + The corresponding handler is \c onFlichStarted. */ /*! \qmlsignal QtLocation::MapGestureArea::flickFinished() - This handler is called when the view stops moving due to a flick. + This signal is emitted when the view stops moving due to a flick. The order of panFinished() and flickFinished() is not specified. + + The corresponding handler is \c onFlickFinished. */ QDeclarativeGeoMapGestureArea::QDeclarativeGeoMapGestureArea(QDeclarativeGeoMap *map, QObject *parent) diff --git a/src/location/maps/qgeocameratiles.cpp b/src/location/maps/qgeocameratiles.cpp index 0d5a5626..2700c1dd 100644 --- a/src/location/maps/qgeocameratiles.cpp +++ b/src/location/maps/qgeocameratiles.cpp @@ -294,11 +294,9 @@ QSet<QGeoTileSpec> QGeoCameraTiles::tiles() const } QGeoCameraTilesPrivate::QGeoCameraTilesPrivate() - : tileSize_(0), - maxZoom_(0), - intZoomLevel_(0), - sideLength_(0), - mapVersion_(-1) {} +: mapVersion_(-1), tileSize_(0), maxZoom_(0), intZoomLevel_(0), sideLength_(0) +{ +} QGeoCameraTilesPrivate::~QGeoCameraTilesPrivate() {} diff --git a/src/plugins/geoservices/nokia/qgeocodereply_nokia.cpp b/src/plugins/geoservices/nokia/qgeocodereply_nokia.cpp index cb76fbca..f1d0f4d4 100644 --- a/src/plugins/geoservices/nokia/qgeocodereply_nokia.cpp +++ b/src/plugins/geoservices/nokia/qgeocodereply_nokia.cpp @@ -48,25 +48,24 @@ #include "qgeocodereply_nokia.h" #include "qgeocodexmlparser.h" +#include "qgeoerror_messages.h" #include <QtPositioning/QGeoShape> +#include <QtCore/QCoreApplication> + +Q_DECLARE_METATYPE(QList<QGeoLocation>) QT_BEGIN_NAMESPACE QGeoCodeReplyNokia::QGeoCodeReplyNokia(QNetworkReply *reply, int limit, int offset, const QGeoShape &viewport, QObject *parent) - : QGeoCodeReply(parent), - m_reply(reply) +: QGeoCodeReply(parent), m_reply(reply), m_parsing(false) { - connect(m_reply, - SIGNAL(finished()), - this, - SLOT(networkFinished())); + qRegisterMetaType<QList<QGeoLocation> >(); - connect(m_reply, - SIGNAL(error(QNetworkReply::NetworkError)), - this, - SLOT(networkError(QNetworkReply::NetworkError))); + connect(m_reply, SIGNAL(finished()), this, SLOT(networkFinished())); + connect(m_reply, SIGNAL(error(QNetworkReply::NetworkError)), + this, SLOT(networkError(QNetworkReply::NetworkError))); setLimit(limit); setOffset(offset); @@ -75,18 +74,19 @@ QGeoCodeReplyNokia::QGeoCodeReplyNokia(QNetworkReply *reply, int limit, int offs QGeoCodeReplyNokia::~QGeoCodeReplyNokia() { - //TODO: possible mem leak -> m_reply->deleteLater() ? + abort(); } void QGeoCodeReplyNokia::abort() { - if (!m_reply) + if (!m_reply && !m_parsing) return; m_reply->abort(); m_reply->deleteLater(); m_reply = 0; + m_parsing = false; } void QGeoCodeReplyNokia::networkFinished() @@ -94,29 +94,17 @@ void QGeoCodeReplyNokia::networkFinished() if (!m_reply) return; - if (m_reply->error() != QNetworkReply::NoError) { - // Removed because this is already done in networkError, which previously caused _two_ errors to be raised for every error. - //setError(QGeoCodeReply::CommunicationError, m_reply->errorString()); - //m_reply->deleteLater(); - //m_reply = 0; + if (m_reply->error() != QNetworkReply::NoError) return; - } - - QGeoCodeXmlParser parser; - if (parser.parse(m_reply)) { - QList<QGeoLocation> locations = parser.results(); - QGeoShape bounds = viewport(); - if (bounds.isValid()) { - for (int i = locations.size() - 1; i >= 0; --i) { - if (!bounds.contains(locations[i].coordinate())) - locations.removeAt(i); - } - } - setLocations(locations); - setFinished(true); - } else { - setError(QGeoCodeReply::ParseError, parser.errorString()); - } + + QGeoCodeXmlParser *parser = new QGeoCodeXmlParser; + parser->setBounds(viewport()); + connect(parser, SIGNAL(results(QList<QGeoLocation>)), + this, SLOT(appendResults(QList<QGeoLocation>))); + connect(parser, SIGNAL(error(QString)), this, SLOT(parseError(QString))); + + m_parsing = true; + parser->parse(m_reply->readAll()); m_reply->deleteLater(); m_reply = 0; @@ -135,4 +123,23 @@ void QGeoCodeReplyNokia::networkError(QNetworkReply::NetworkError error) m_reply = 0; } +void QGeoCodeReplyNokia::appendResults(const QList<QGeoLocation> &locations) +{ + if (!m_parsing) + return; + + m_parsing = false; + setLocations(locations); + setFinished(true); +} + +void QGeoCodeReplyNokia::parseError(const QString &errorString) +{ + Q_UNUSED(errorString) + + setError(QGeoCodeReply::ParseError, + QCoreApplication::translate(NOKIA_PLUGIN_CONTEXT_NAME, RESPONSE_NOT_RECOGNIZABLE)); + abort(); +} + QT_END_NAMESPACE diff --git a/src/plugins/geoservices/nokia/qgeocodereply_nokia.h b/src/plugins/geoservices/nokia/qgeocodereply_nokia.h index 6b72cd40..af3f4dec 100644 --- a/src/plugins/geoservices/nokia/qgeocodereply_nokia.h +++ b/src/plugins/geoservices/nokia/qgeocodereply_nokia.h @@ -66,9 +66,12 @@ public: private Q_SLOTS: void networkFinished(); void networkError(QNetworkReply::NetworkError error); + void appendResults(const QList<QGeoLocation> &locations); + void parseError(const QString &errorString); private: QNetworkReply *m_reply; + bool m_parsing; }; QT_END_NAMESPACE diff --git a/src/plugins/geoservices/nokia/qgeocodexmlparser.cpp b/src/plugins/geoservices/nokia/qgeocodexmlparser.cpp index b9dbd934..d19246ff 100644 --- a/src/plugins/geoservices/nokia/qgeocodexmlparser.cpp +++ b/src/plugins/geoservices/nokia/qgeocodexmlparser.cpp @@ -48,10 +48,9 @@ #include "qgeocodexmlparser.h" -#include <QXmlStreamReader> -#include <QIODevice> - -#include <qgeolocation.h> +#include <QtCore/QXmlStreamReader> +#include <QtCore/QThreadPool> +#include <QtPositioning/QGeoLocation> #include <QtPositioning/QGeoAddress> #include <QtPositioning/QGeoCoordinate> #include <QtPositioning/QGeoRectangle> @@ -66,28 +65,28 @@ QGeoCodeXmlParser::~QGeoCodeXmlParser() { } -bool QGeoCodeXmlParser::parse(QIODevice *source) +void QGeoCodeXmlParser::setBounds(const QGeoShape &bounds) { - m_reader.reset(new QXmlStreamReader(source)); - - if (!parseRootElement()) { - m_errorString = m_reader->errorString(); - return false; - } - - m_errorString = ""; - - return true; + m_bounds = bounds; } -QList<QGeoLocation> QGeoCodeXmlParser::results() const +void QGeoCodeXmlParser::parse(const QByteArray &data) { - return m_results; + m_data = data; + QThreadPool::globalInstance()->start(this); } -QString QGeoCodeXmlParser::errorString() const +void QGeoCodeXmlParser::run() { - return m_errorString; + m_reader = new QXmlStreamReader(m_data); + + if (!parseRootElement()) + emit error(m_reader->errorString()); + else + emit results(m_results); + + delete m_reader; + m_reader = 0; } bool QGeoCodeXmlParser::parseRootElement() @@ -137,7 +136,8 @@ bool QGeoCodeXmlParser::parseRootElement() if (!parsePlace(&location)) return false; - m_results.append(location); + if (!m_bounds.isValid() || m_bounds.contains(location.coordinate())) + m_results.append(location); } else { m_reader->raiseError(QString("The element \"places\" did not expect a child element named \"%1\".").arg(m_reader->name().toString())); return false; diff --git a/src/plugins/geoservices/nokia/qgeocodexmlparser.h b/src/plugins/geoservices/nokia/qgeocodexmlparser.h index 8eeb6cc3..67c9da9e 100644 --- a/src/plugins/geoservices/nokia/qgeocodexmlparser.h +++ b/src/plugins/geoservices/nokia/qgeocodexmlparser.h @@ -49,29 +49,35 @@ #ifndef QGEOCODEXMLPARSER_H #define QGEOCODEXMLPARSER_H -#include <QString> -#include <QList> -#include <QScopedPointer> +#include <QtCore/QObject> +#include <QtCore/QRunnable> +#include <QtCore/QString> +#include <QtCore/QList> +#include <QtPositioning/QGeoShape> QT_BEGIN_NAMESPACE -class QIODevice; class QGeoLocation; class QGeoAddress; class QGeoRectangle; class QGeoCoordinate; class QXmlStreamReader; -class QGeoCodeXmlParser +class QGeoCodeXmlParser : public QObject, public QRunnable { + Q_OBJECT + public: QGeoCodeXmlParser(); ~QGeoCodeXmlParser(); - bool parse(QIODevice *source); + void setBounds(const QGeoShape &bounds); + void parse(const QByteArray &data); + void run(); - QList<QGeoLocation> results() const; - QString errorString() const; +signals: + void results(const QList<QGeoLocation> &locations); + void error(const QString &errorString); private: bool parseRootElement(); @@ -81,7 +87,9 @@ private: bool parseBoundingBox(QGeoRectangle *bounds); bool parseCoordinate(QGeoCoordinate *coordinate, const QString &elementName); - QScopedPointer<QXmlStreamReader> m_reader; + QGeoShape m_bounds; + QByteArray m_data; + QXmlStreamReader *m_reader; QList<QGeoLocation> m_results; QString m_errorString; diff --git a/src/plugins/geoservices/nokia/qgeoerror_messages.cpp b/src/plugins/geoservices/nokia/qgeoerror_messages.cpp index 05cb93fa..5995876b 100644 --- a/src/plugins/geoservices/nokia/qgeoerror_messages.cpp +++ b/src/plugins/geoservices/nokia/qgeoerror_messages.cpp @@ -59,5 +59,6 @@ const char REMOVING_CATEGORY_NOT_SUPPORTED[] = QT_TRANSLATE_NOOP("QtLocationQML" const char PARSE_ERROR[] = QT_TRANSLATE_NOOP("QtLocationQML", "Error parsing response."); const char NETWORK_ERROR[] = QT_TRANSLATE_NOOP("QtLocationQML", "Network error."); const char CANCEL_ERROR[] = QT_TRANSLATE_NOOP("QtLocationQML", "Request was canceled."); +const char RESPONSE_NOT_RECOGNIZABLE[] = QT_TRANSLATE_NOOP("QtLocationQML", "The response from the service was not in a recognizable format."); QT_END_NAMESPACE diff --git a/src/plugins/geoservices/nokia/qgeoerror_messages.h b/src/plugins/geoservices/nokia/qgeoerror_messages.h index 03a85dc0..b1227629 100644 --- a/src/plugins/geoservices/nokia/qgeoerror_messages.h +++ b/src/plugins/geoservices/nokia/qgeoerror_messages.h @@ -63,6 +63,7 @@ extern const char REMOVING_CATEGORY_NOT_SUPPORTED[]; extern const char PARSE_ERROR[]; extern const char NETWORK_ERROR[]; extern const char CANCEL_ERROR[]; +extern const char RESPONSE_NOT_RECOGNIZABLE[]; QT_END_NAMESPACE diff --git a/src/plugins/geoservices/nokia/qgeoroutereply_nokia.cpp b/src/plugins/geoservices/nokia/qgeoroutereply_nokia.cpp index 2245b208..861436c5 100644 --- a/src/plugins/geoservices/nokia/qgeoroutereply_nokia.cpp +++ b/src/plugins/geoservices/nokia/qgeoroutereply_nokia.cpp @@ -48,25 +48,27 @@ #include "qgeoroutereply_nokia.h" #include "qgeoroutexmlparser.h" +#include "qgeoerror_messages.h" #include <qgeorouterequest.h> +#include <QtCore/QCoreApplication> + +Q_DECLARE_METATYPE(QList<QGeoRoute>) + QT_BEGIN_NAMESPACE -QGeoRouteReplyNokia::QGeoRouteReplyNokia(const QGeoRouteRequest &request, const QList<QNetworkReply*> &replies, QObject *parent) - : QGeoRouteReply(request, parent), - m_replies(replies) +QGeoRouteReplyNokia::QGeoRouteReplyNokia(const QGeoRouteRequest &request, + const QList<QNetworkReply *> &replies, + QObject *parent) +: QGeoRouteReply(request, parent), m_replies(replies), m_parsers(0) { + qRegisterMetaType<QList<QGeoRoute> >(); + foreach (QNetworkReply *reply, m_replies) { - connect(reply, - SIGNAL(finished()), - this, - SLOT(networkFinished())); - - connect(reply, - SIGNAL(error(QNetworkReply::NetworkError)), - this, - SLOT(networkError(QNetworkReply::NetworkError))); + connect(reply, SIGNAL(finished()), this, SLOT(networkFinished())); + connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), + this, SLOT(networkError(QNetworkReply::NetworkError))); } } @@ -77,7 +79,7 @@ QGeoRouteReplyNokia::~QGeoRouteReplyNokia() void QGeoRouteReplyNokia::abort() { - if (m_replies.isEmpty()) + if (m_replies.isEmpty() && !m_parsers) return; foreach (QNetworkReply *reply, m_replies) { @@ -85,6 +87,7 @@ void QGeoRouteReplyNokia::abort() reply->deleteLater(); } m_replies.clear(); + m_parsers = 0; } void QGeoRouteReplyNokia::networkFinished() @@ -93,53 +96,65 @@ void QGeoRouteReplyNokia::networkFinished() if (!reply) return; - if (reply->error() != QNetworkReply::NoError) { - // Removed because this is already done in networkError, which previously caused _two_ errors to be raised for every error. - //setError(QGeoRouteReply::CommunicationError, m_reply->errorString()); - //m_reply->deleteLater(); - //m_reply = 0; + if (reply->error() != QNetworkReply::NoError) return; - } - QGeoRouteXmlParser parser(request()); - if (parser.parse(reply)) { - addRoutes(parser.results()); - reply->deleteLater(); - m_replies.removeOne(reply); - if (m_replies.isEmpty()) - setFinished(true); - } else { - // add a qWarning with the actual parser.errorString() - setError(QGeoRouteReply::ParseError, "The response from the service was not in a recognisable format."); - abort(); - } + QGeoRouteXmlParser *parser = new QGeoRouteXmlParser(request()); + connect(parser, SIGNAL(results(QList<QGeoRoute>)), + this, SLOT(appendResults(QList<QGeoRoute>))); + connect(parser, SIGNAL(error(QString)), this, SLOT(parserError(QString))); + + ++m_parsers; + parser->parse(reply->readAll()); + + m_replies.removeOne(reply); + reply->deleteLater(); } void QGeoRouteReplyNokia::networkError(QNetworkReply::NetworkError error) { - Q_UNUSED(error) - QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender()); if (!reply) return; - bool resolvedError = false; - if (QNetworkReply::UnknownContentError == error) { - QGeoRouteXmlParser parser(request()); - if (parser.parse(reply)) { - addRoutes(parser.results()); - reply->deleteLater(); - m_replies.removeOne(reply); - resolvedError = true; - if (m_replies.isEmpty()) - setFinished(true); - } - } + if (error == QNetworkReply::UnknownContentError) { + QGeoRouteXmlParser *parser = new QGeoRouteXmlParser(request()); + connect(parser, SIGNAL(results(QList<QGeoRoute>)), + this, SLOT(appendResults(QList<QGeoRoute>))); + connect(parser, SIGNAL(error(QString)), this, SLOT(parserError(QString))); + + ++m_parsers; + parser->parse(reply->readAll()); - if (!resolvedError) { + m_replies.removeOne(reply); + reply->deleteLater(); + } else { setError(QGeoRouteReply::CommunicationError, reply->errorString()); abort(); } } +void QGeoRouteReplyNokia::appendResults(const QList<QGeoRoute> &routes) +{ + if (!m_parsers) + return; + + --m_parsers; + addRoutes(routes); + + if (!m_parsers && m_replies.isEmpty()) + setFinished(true); +} + +void QGeoRouteReplyNokia::parserError(const QString &errorString) +{ + Q_UNUSED(errorString) + + --m_parsers; + + setError(QGeoRouteReply::ParseError, + QCoreApplication::translate(NOKIA_PLUGIN_CONTEXT_NAME, RESPONSE_NOT_RECOGNIZABLE)); + abort(); +} + QT_END_NAMESPACE diff --git a/src/plugins/geoservices/nokia/qgeoroutereply_nokia.h b/src/plugins/geoservices/nokia/qgeoroutereply_nokia.h index 911e1920..d1684e83 100644 --- a/src/plugins/geoservices/nokia/qgeoroutereply_nokia.h +++ b/src/plugins/geoservices/nokia/qgeoroutereply_nokia.h @@ -54,6 +54,8 @@ QT_BEGIN_NAMESPACE +class QGeoRouteXmlParser; + class QGeoRouteReplyNokia : public QGeoRouteReply { Q_OBJECT @@ -66,9 +68,12 @@ public: private Q_SLOTS: void networkFinished(); void networkError(QNetworkReply::NetworkError error); + void appendResults(const QList<QGeoRoute> &routes); + void parserError(const QString &errorString); private: - QList<QNetworkReply*> m_replies; + QList<QNetworkReply *> m_replies; + int m_parsers; }; QT_END_NAMESPACE diff --git a/src/plugins/geoservices/nokia/qgeoroutexmlparser.cpp b/src/plugins/geoservices/nokia/qgeoroutexmlparser.cpp index 60840ec6..e032f8d3 100644 --- a/src/plugins/geoservices/nokia/qgeoroutexmlparser.cpp +++ b/src/plugins/geoservices/nokia/qgeoroutexmlparser.cpp @@ -49,12 +49,12 @@ #include "qgeoroutexmlparser.h" #include <QXmlStreamReader> -#include <QIODevice> #include <QStringList> #include <QString> +#include <QtCore/QThreadPool> -#include <qgeoroute.h> #include <QtPositioning/QGeoRectangle> +#include <QtLocation/QGeoRoute> QT_BEGIN_NAMESPACE @@ -74,28 +74,23 @@ QGeoRouteXmlParser::~QGeoRouteXmlParser() { } -bool QGeoRouteXmlParser::parse(QIODevice *source) +void QGeoRouteXmlParser::parse(const QByteArray &data) { - m_reader.reset(new QXmlStreamReader(source)); - - if (!parseRootElement()) { - m_errorString = m_reader->errorString(); - return false; - } - - m_errorString = ""; - - return true; + m_data = data; + QThreadPool::globalInstance()->start(this); } -QList<QGeoRoute> QGeoRouteXmlParser::results() const +void QGeoRouteXmlParser::run() { - return m_results; -} + m_reader = new QXmlStreamReader(m_data); -QString QGeoRouteXmlParser::errorString() const -{ - return m_errorString; + if (!parseRootElement()) + emit error(m_reader->errorString()); + else + emit results(m_results); + + delete m_reader; + m_reader = 0; } bool QGeoRouteXmlParser::parseRootElement() diff --git a/src/plugins/geoservices/nokia/qgeoroutexmlparser.h b/src/plugins/geoservices/nokia/qgeoroutexmlparser.h index 466bca5e..7e6307e7 100644 --- a/src/plugins/geoservices/nokia/qgeoroutexmlparser.h +++ b/src/plugins/geoservices/nokia/qgeoroutexmlparser.h @@ -49,16 +49,17 @@ #ifndef QROUTEXMLPARSER_H #define QROUTEXMLPARSER_H -#include <QList> -#include <QString> -#include <QScopedPointer> +#include <QtCore/QObject> +#include <QtCore/QRunnable> +#include <QtCore/QString> +#include <QtCore/QList> -#include <qgeoroutesegment.h> -#include <qgeorouterequest.h> -#include <qgeomaneuver.h> +#include <QtLocation/QGeoRouteRequest> +#include <QtLocation/QGeoRouteSegment> +#include <QtLocation/QGeoManeuver> QT_BEGIN_NAMESPACE -class QIODevice; + class QXmlStreamReader; class QGeoRoute; class QGeoCoordinate; @@ -92,15 +93,20 @@ public: int baseTime; }; -class QGeoRouteXmlParser +class QGeoRouteXmlParser : public QObject, public QRunnable { + Q_OBJECT + public: QGeoRouteXmlParser(const QGeoRouteRequest &request); ~QGeoRouteXmlParser(); - bool parse(QIODevice *source); - QList<QGeoRoute> results() const; - QString errorString() const; + void parse(const QByteArray &data); + void run(); + +signals: + void results(const QList<QGeoRoute> &routes); + void error(const QString &errorString); private: bool parseRootElement(); @@ -119,12 +125,14 @@ private: bool parseDynamicSpeedInfo(QGeoDynamicSpeedInfoContainer &speedInfo); QGeoRouteRequest m_request; - QScopedPointer<QXmlStreamReader> m_reader; + QByteArray m_data; + QXmlStreamReader *m_reader; + QList<QGeoRoute> m_results; - QString m_errorString; QList<QGeoManeuverContainer> m_maneuvers; QList<QGeoRouteSegmentContainer> m_segments; }; QT_END_NAMESPACE + #endif |