diff options
author | juhvu <qt-info@nokia.com> | 2011-08-24 14:55:51 +1000 |
---|---|---|
committer | David Laing <david.laing@nokia.com> | 2011-08-24 07:41:25 +0200 |
commit | ccaf530d04860a7a11ff57b1113c6d819df5b4dd (patch) | |
tree | 8aa3f2a272c6a3e92c851782fc274ccddc817ffc | |
parent | b8e49782715d73bcdee1374073d938898a4c3cde (diff) | |
download | qtlocation-ccaf530d04860a7a11ff57b1113c6d819df5b4dd.tar.gz |
First pass on QML geocoding docs (no examples).
Change-Id: I156054bfd9296d180559c61de61baccba3cf33aa
Reviewed-on: http://codereview.qt.nokia.com/3442
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: David Laing <david.laing@nokia.com>
-rw-r--r-- | src/imports/location/qdeclarativegeocodemodel.cpp | 193 | ||||
-rw-r--r-- | src/imports/location/qdeclarativegeocodemodel_p.h | 26 | ||||
-rw-r--r-- | src/imports/location/qdeclarativegeomaneuver.cpp | 98 | ||||
-rw-r--r-- | src/imports/location/qdeclarativegeomaneuver_p.h | 4 | ||||
-rw-r--r-- | src/imports/location/qdeclarativegeoroute.cpp | 64 | ||||
-rw-r--r-- | src/imports/location/qdeclarativegeoroutemodel.cpp | 8 | ||||
-rw-r--r-- | src/imports/location/qdeclarativegeoroutesegment.cpp | 59 | ||||
-rw-r--r-- | tests/auto/declarative/tst_map_geocoding.qml | 66 | ||||
-rw-r--r-- | tests/auto/declarative/tst_map_routing.qml | 1 |
9 files changed, 474 insertions, 45 deletions
diff --git a/src/imports/location/qdeclarativegeocodemodel.cpp b/src/imports/location/qdeclarativegeocodemodel.cpp index 4eadc0dc..8f391800 100644 --- a/src/imports/location/qdeclarativegeocodemodel.cpp +++ b/src/imports/location/qdeclarativegeocodemodel.cpp @@ -49,6 +49,23 @@ QT_BEGIN_NAMESPACE +/*! + \qmlclass GeocodeModel + + \brief The GeocodeModel element provides support for searching operations related + to geographic information. + \ingroup qml-geocoding + \since 5.0 + + The GeocodeModel is a model used to perform geocoding. This includes both geocoding + (address to coordinate) and reverse geocoding (coordinate to address). + The geocoding result provider is determined by the \l plugin. The geocoding data is set + in \l query. + + The model provides a single data role, the "locationData" role which + is a \l Location element. +*/ + QDeclarativeGeocodeModel::QDeclarativeGeocodeModel(QObject* parent) : QAbstractListModel(parent), autoUpdate_(false), @@ -57,6 +74,7 @@ QDeclarativeGeocodeModel::QDeclarativeGeocodeModel(QObject* parent) plugin_(0), boundingArea_(0), status_(QDeclarativeGeocodeModel::Null), + error_(QDeclarativeGeocodeModel::NoError), coordinate_(0), address_(0), limit_(-1), @@ -64,7 +82,7 @@ QDeclarativeGeocodeModel::QDeclarativeGeocodeModel(QObject* parent) { QHash<int, QByteArray> roleNames; roleNames = QAbstractItemModel::roleNames(); - roleNames.insert(LocationRole, "location"); + roleNames.insert(LocationRole, "locationData"); setRoleNames(roleNames); } @@ -119,7 +137,8 @@ void QDeclarativeGeocodeModel::update() return; } abortRequest(); // abort possible previous requests - setError(""); // clear previous error string + setErrorString(""); // clear previous error string + setError(NoError); if (coordinate_) { setStatus(QDeclarativeGeocodeModel::Loading); @@ -210,6 +229,16 @@ void QDeclarativeGeocodeModel::setPlugin(QDeclarativeGeoServiceProvider *plugin) this, SLOT(geocodeError(QGeocodeReply*,QGeocodeReply::Error,QString))); } +/*! + \qmlproperty Plugin GeocodeModel::plugin + + This property holds the plugin that providers the actual geocoding service. + Note that all plugins do not necessarily provide routing (could e.g. provide + only routing or maps). + + \sa Plugin +*/ + QDeclarativeGeoServiceProvider* QDeclarativeGeocodeModel::plugin() const { return plugin_; @@ -231,6 +260,17 @@ void QDeclarativeGeocodeModel::setBounds(QObject* bounds) emit boundsChanged(); } +/*! + \qmlproperty bounding area GeocodeModel::bounds + + This property holds the bounding area used to limit the results to those + within the area. his is particularly useful if query is only partially filled out, + as the service will attempt to (reverse) geocode all matches for the specified data. + + Accepted element types are \l BoundingBox and \l BoundingCircle. + +*/ + QObject* QDeclarativeGeocodeModel::bounds() const { return boundingArea_; @@ -243,7 +283,8 @@ void QDeclarativeGeocodeModel::geocodeFinished(QGeocodeReply *reply) } int oldCount = declarativeLocations_.count(); setLocations(reply->locations()); - setError(""); + setErrorString(""); + setError(NoError); setStatus(QDeclarativeGeocodeModel::Ready); reply->deleteLater(); reply_ = 0; @@ -264,12 +305,26 @@ void QDeclarativeGeocodeModel::geocodeError(QGeocodeReply *reply, emit locationsChanged(); emit countChanged(); } - setError(errorString); + setErrorString(errorString); + setError(static_cast<QDeclarativeGeocodeModel::GeocodeError>(error)); setStatus(QDeclarativeGeocodeModel::Error); reply->deleteLater(); reply_ = 0; } +/*! + \qmlproperty enumeration GeocodeModel::status + + This read-only property holds the current status of the model. + + \list + \o GeocodeModel.Null - No geocode requests have been issued or \l reset has been called. + \o GeocodeModel.Ready - Geocode request(s) have finished successfully. + \o GeocodeModel.Loading - Geocode request has been issued but not yet finished + \o GeocodeModel.Error - Geocoding error has occured, details are in \l error and \l errorString + \endlist +*/ + QDeclarativeGeocodeModel::Status QDeclarativeGeocodeModel::status() const { return status_; @@ -283,19 +338,58 @@ void QDeclarativeGeocodeModel::setStatus(QDeclarativeGeocodeModel::Status status emit statusChanged(); } -QString QDeclarativeGeocodeModel::error() const +/*! + \qmlproperty enumeration GeocodeModel::error + + This read-only property holds the latest error value of the geocoding request. + + \list + \o GeocodeModel.NoError - No error has occurred + \o GeocodeModel.EngineNotSetError - The plugin/service provider used does not support (reverse) geocoding + \o GeocodeModel.CommunicationError - An error occurred while communicating with the service provider + \o GeocodeModel.ParseError - The response from the service provider was in an unrecognizable format + \o GeocodeModel.UnsupportedOptionError - The requested operation or one of the options for the operation are not supported by the service provider. + \o GeocodeModel.CombinationError - An error occurred while results where being combined from multiple sources + \o GeocodeModel.UnknownError - An error occurred which does not fit into any of the other categories + \endlist +*/ + +QDeclarativeGeocodeModel::GeocodeError QDeclarativeGeocodeModel::error() const { return error_; } -void QDeclarativeGeocodeModel::setError(const QString &error) -{ +void QDeclarativeGeocodeModel::setError(GeocodeError error) +{ if (error_ == error) return; error_ = error; emit errorChanged(); } +/*! + \qmlproperty string GeocodeModel::errorString + + This read-only property holds the textual presentation of latest geocoding error. + If no error has occured 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 + textual representation. +*/ + +QString QDeclarativeGeocodeModel::errorString() const +{ + return errorString_; +} + +void QDeclarativeGeocodeModel::setErrorString(const QString &error) +{ + if (errorString_ == error) + return; + errorString_ = error; + emit errorStringChanged(); +} + void QDeclarativeGeocodeModel::setLocations(const QList<QGeoLocation> &locations) { beginResetModel(); @@ -308,12 +402,30 @@ void QDeclarativeGeocodeModel::setLocations(const QList<QGeoLocation> &locations endResetModel(); } +/*! + \qmlproperty int GeocodeModel::count + + This property holds how many locations the model currently has + Amongst other uses, you can use this value when accessing locations + via the GeocodeModel::get -method. +*/ + int QDeclarativeGeocodeModel::count() const { return declarativeLocations_.count(); } -Q_INVOKABLE QDeclarativeGeoLocation* QDeclarativeGeocodeModel::get(int index) +/*! + \qmlmethod GeocodeModel::get(int) + + Returns the Location at given index. Use \l count property to check the + amount of locations available. The locations are indexed from zero, so the accessible range + is 0...(count - 1). + + If you access out of bounds, a zero (null object) is returned and a warning is issued. +*/ + +QDeclarativeGeoLocation* QDeclarativeGeocodeModel::get(int index) { if (index < 0 || index >= declarativeLocations_.count()) { qmlInfo(this) << tr("Error, too big or small index in get(): ") << index; @@ -322,6 +434,16 @@ Q_INVOKABLE QDeclarativeGeoLocation* QDeclarativeGeocodeModel::get(int index) return declarativeLocations_.at(index); } +/*! + \qmlproperty int GeocodeModel::limit + + This property holds the maximum number of results. The \l limit and \l offset values only + applicable with free string geocoding (i.e. they are not considered when using addresses + or coordinates in the search query). + + If limit is -1 the entire result set will be returned, otherwise at most limit results will be returned. + The limit and \l offset results can be used together to implement paging. +*/ int QDeclarativeGeocodeModel::limit() const { @@ -339,6 +461,16 @@ void QDeclarativeGeocodeModel::setLimit(int limit) emit limitChanged(); } +/*! + \qmlproperty int GeocodeModel::offset + + This property tells not to return the first 'offset' number of the results. The \l limit + and \l offset values are only applicable with free string geocoding (i.e. they are not considered + when using addresses or coordinates in the search query). + + The \l limit and offset results can be used together to implement paging. +*/ + int QDeclarativeGeocodeModel::offset() const { return offset_; @@ -355,8 +487,14 @@ void QDeclarativeGeocodeModel::setOffset(int offset) emit offsetChanged(); } +/*! + \qmlmethod GeocodeModel::clear() -Q_INVOKABLE void QDeclarativeGeocodeModel::clear() + Clears the location data of the model. Any outstanding requests or + errors remain intact. +*/ + +void QDeclarativeGeocodeModel::clear() { bool hasChanged = !declarativeLocations_.isEmpty(); setLocations(QList<QGeoLocation>()); @@ -364,14 +502,37 @@ Q_INVOKABLE void QDeclarativeGeocodeModel::clear() emit countChanged(); } -Q_INVOKABLE void QDeclarativeGeocodeModel::reset() +/*! + \qmlmethod GeocodeModel::reset() + + Resets the model. All location data is cleared, any outstanding requests + are aborted and possible errors are cleared. Model status will be set + to GeocodeModel.Null +*/ + +void QDeclarativeGeocodeModel::reset() { clear(); abortRequest(); - setError(""); + setErrorString(""); + setError(NoError); setStatus(QDeclarativeGeocodeModel::Null); } +/*! + \qmlproperty QVariant GeocodeModel::query + + This property holds the data of the geocoding request. + The property accepts three types of queries, which determines both the data and + the type of action to be performed: + + \list + \o Address - Geocoding (address to coordinate) + \o Coordinate - Reverse geocoding (coordinate to address) + \o string - Geocoding (address to coordinate) + \endlist +*/ + QVariant QDeclarativeGeocodeModel::query() const { return queryVariant_; @@ -427,6 +588,16 @@ void QDeclarativeGeocodeModel::setQuery(const QVariant& query) update(); } +/*! + \qmlproperty bool GeocodeModel::autoUpdate + + This property instructs how the model should react on query changes - + should it automatically update the model or do nothing. + + Caution: If setting this value to 'true', take also care that your application + does not accidentally trigger huge amounts of unnecessary geocoding requests. + In another words, be aware where in your application the query might change. +*/ bool QDeclarativeGeocodeModel::autoUpdate() const { diff --git a/src/imports/location/qdeclarativegeocodemodel_p.h b/src/imports/location/qdeclarativegeocodemodel_p.h index 5071fa3c..c8d2b7ea 100644 --- a/src/imports/location/qdeclarativegeocodemodel_p.h +++ b/src/imports/location/qdeclarativegeocodemodel_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -63,16 +63,18 @@ class QDeclarativeGeocodeModel : public QAbstractListModel, public QDeclarativeP { Q_OBJECT Q_ENUMS(Status) + Q_ENUMS(GeocodeError) Q_PROPERTY(QDeclarativeGeoServiceProvider *plugin READ plugin WRITE setPlugin NOTIFY pluginChanged) Q_PROPERTY(bool autoUpdate READ autoUpdate WRITE setAutoUpdate NOTIFY autoUpdateChanged) Q_PROPERTY(Status status READ status NOTIFY statusChanged) - Q_PROPERTY(QString error READ error NOTIFY errorChanged) + Q_PROPERTY(QString errorString READ errorString NOTIFY errorStringChanged) Q_PROPERTY(int count READ count NOTIFY countChanged) Q_PROPERTY(int limit READ limit WRITE setLimit NOTIFY limitChanged) Q_PROPERTY(int offset READ offset WRITE setOffset NOTIFY offsetChanged) Q_PROPERTY(QVariant query READ query WRITE setQuery NOTIFY queryChanged) Q_PROPERTY(QObject* bounds READ bounds WRITE setBounds NOTIFY boundsChanged) + Q_PROPERTY(GeocodeError error READ error NOTIFY errorChanged) Q_INTERFACES(QDeclarativeParserStatus) public: @@ -83,6 +85,16 @@ public: Error }; + enum GeocodeError { + NoError = QGeocodeReply::NoError, + EngineNotSetError = QGeocodeReply::EngineNotSetError, + CommunicationError = QGeocodeReply::CommunicationError, + ParseError = QGeocodeReply::ParseError, + UnsupportedOptionError = QGeocodeReply::UnsupportedOptionError, + CombinationError = QGeocodeReply::CombinationError, + UnknownError = QGeocodeReply::UnknownError + }; + enum Roles { LocationRole = Qt::UserRole + 1 }; @@ -105,7 +117,8 @@ public: QObject* bounds() const; Status status() const; - QString error() const; + QString errorString() const; + GeocodeError error() const; bool autoUpdate() const; void setAutoUpdate(bool update); @@ -127,6 +140,7 @@ Q_SIGNALS: void countChanged(); void pluginChanged(); void statusChanged(); + void errorStringChanged(); void errorChanged(); void locationsChanged(); void autoUpdateChanged(); @@ -148,7 +162,8 @@ protected Q_SLOTS: protected: QGeocodingManager* searchManager(); void setStatus(Status status); - void setError(const QString &error); + void setErrorString(const QString &error); + void setError(GeocodeError error); bool autoUpdate_; bool complete_; @@ -166,7 +181,8 @@ private: QList<QDeclarativeGeoLocation*> declarativeLocations_; Status status_; - QString error_; + QString errorString_; + GeocodeError error_; QVariant queryVariant_; QDeclarativeCoordinate* coordinate_; QDeclarativeGeoAddress* address_; diff --git a/src/imports/location/qdeclarativegeomaneuver.cpp b/src/imports/location/qdeclarativegeomaneuver.cpp index cff58c51..8bed3f29 100644 --- a/src/imports/location/qdeclarativegeomaneuver.cpp +++ b/src/imports/location/qdeclarativegeomaneuver.cpp @@ -43,6 +43,23 @@ QT_BEGIN_NAMESPACE +/*! + \qmlclass RouteManeuver + + \brief The RouteManeuver element represents the information relevant to the + point at which two RouteSegments meet. + \ingroup qml-routing + \since 5.0 + + RouteSegment instances can be thought of as edges on a routing + graph, with RouteManeuver instances as optional labels attached to the + vertices of the graph. + + The most interesting information held in a RouteManeuver instance is + normally the textual navigation to provide and the position at which to + provide it, accessible by \l instructionText and \l position respectively. +*/ + QDeclarativeGeoManeuver::QDeclarativeGeoManeuver(QObject *parent) : QObject(parent) { @@ -60,41 +77,122 @@ QDeclarativeGeoManeuver::QDeclarativeGeoManeuver(const QGeoManeuver &maneuver, Q QDeclarativeGeoManeuver::~QDeclarativeGeoManeuver() {} +/*! + \qmlproperty bool RouteManeuver::valid + + This read-only property holds whether this maneuver is valid or not. + + Invalid maneuvers are used when there is no information + that needs to be attached to the endpoint of a QGeoRouteSegment instance. +*/ + bool QDeclarativeGeoManeuver::valid() const { return maneuver_.isValid(); } +/*! + \qmlproperty Coordinate RouteManeuver::position + + This read-only property holds where the \l instructionText should be displayed. + +*/ + QDeclarativeCoordinate* QDeclarativeGeoManeuver::position() const { return position_; } +/*! + \qmlproperty string RouteManeuver::instructionText + + This read-only property holds textual navigation instruction. +*/ + QString QDeclarativeGeoManeuver::instructionText() const { return maneuver_.instructionText(); } +/*! + \qmlproperty enumeration RouteManeuver::direction + + Describes the change in direction associated with the instruction text + that is associated with a RouteManeuver. + + \list + \o RouteModel.NoDirection - There is no direction associated with the instruction text + \o RouteModel.DirectionForward - The instruction indicates that the direction of travel does not need to change + \o RouteModel.DirectionBearRight - The instruction indicates that the direction of travel should bear to the right + \o RouteModel.DirectionLightRight - The instruction indicates that a light turn to the right is required + \o RouteModel.DirectionRight - The instruction indicates that a turn to the right is required + \o RouteModel.DirectionHardRight - The instruction indicates that a hard turn to the right is required + \o RouteModel.DirectionUTurnRight - The instruction indicates that a u-turn to the right is required + \o RouteModel.DirectionUTurnLeft - The instruction indicates that a u-turn to the left is required + \o RouteModel.DirectionHardLeft - The instruction indicates that a hard turn to the left is required + \o RouteModel.DirectionLeft - The instruction indicates that a turn to the left is required + \o RouteModel.DirectionLightLeft - The instruction indicates that a light turn to the left is required + \o RouteModel.DirectionBearLeft - The instruction indicates that the direction of travel should bear to the left + \endlist +*/ + QDeclarativeGeoManeuver::Direction QDeclarativeGeoManeuver::direction() const { return QDeclarativeGeoManeuver::Direction(maneuver_.direction()); } +/*! + \qmlproperty int RouteManeuver::timeToNextInstruction + + This read-only property holds the estimated time it will take to travel + from the point at which the associated instruction was issued and the + point that the next instruction should be issued, in seconds. +*/ + int QDeclarativeGeoManeuver::timeToNextInstruction() const { return maneuver_.timeToNextInstruction(); } +/*! + \qmlproperty qreal RouteManeuver::distanceToNextInstruction + + This read-only property holds the distance, in metres, between the point at which + the associated instruction was issued and the point that the next instruction should + be issued. +*/ + qreal QDeclarativeGeoManeuver::distanceToNextInstruction() const { return maneuver_.distanceToNextInstruction(); } +/*! + \qmlproperty Coordinate RouteManeuver::waypoint + + This property holds the waypoint associated with this maneuver. + All maneuvers do not have a waypoint associated with them, this + can be checked with \l waypointValid. + +*/ + QDeclarativeCoordinate* QDeclarativeGeoManeuver::waypoint() const { return waypoint_; } +/*! + \qmlproperty bool RouteManeuver::waypointValid + + This read-only property holds whether this the \l waypoint associated with this + maneuver is valid. +*/ + +bool QDeclarativeGeoManeuver::waypointValid() const +{ + return waypoint_->coordinate().isValid(); +} + #include "moc_qdeclarativegeomaneuver_p.cpp" QT_END_NAMESPACE diff --git a/src/imports/location/qdeclarativegeomaneuver_p.h b/src/imports/location/qdeclarativegeomaneuver_p.h index 9025c0b3..654f4924 100644 --- a/src/imports/location/qdeclarativegeomaneuver_p.h +++ b/src/imports/location/qdeclarativegeomaneuver_p.h @@ -55,13 +55,14 @@ class QDeclarativeGeoManeuver : public QObject Q_OBJECT Q_ENUMS(Direction) - Q_PROPERTY(bool valid READ valid) + Q_PROPERTY(bool valid READ valid CONSTANT) Q_PROPERTY(QDeclarativeCoordinate* position READ position CONSTANT) Q_PROPERTY(QString instructionText READ instructionText CONSTANT) Q_PROPERTY(Direction direction READ direction CONSTANT) Q_PROPERTY(int timeToNextInstruction READ timeToNextInstruction CONSTANT) Q_PROPERTY(qreal distanceToNextInstruction READ distanceToNextInstruction CONSTANT) Q_PROPERTY(QDeclarativeCoordinate* waypoint READ waypoint CONSTANT) + Q_PROPERTY(bool waypointValid READ waypointValid CONSTANT) public: enum Direction { @@ -84,6 +85,7 @@ public: ~QDeclarativeGeoManeuver(); bool valid() const; + bool waypointValid() const; QDeclarativeCoordinate* position() const; QString instructionText() const; diff --git a/src/imports/location/qdeclarativegeoroute.cpp b/src/imports/location/qdeclarativegeoroute.cpp index 66c2ee19..4e2c9179 100644 --- a/src/imports/location/qdeclarativegeoroute.cpp +++ b/src/imports/location/qdeclarativegeoroute.cpp @@ -43,6 +43,23 @@ QT_BEGIN_NAMESPACE +/*! + \qmlclass Route + + \brief The Route element represents one geographical route. + \ingroup qml-routing + \since 5.0 + + A Route element contains high level information about a route, such + as the length the route, the estimated travel time for the route, + and enough information to render a basic image of the route on a map. + + The QGeoRoute object also contains a list of \l RouteSegment elements which + describe subsections of the route in greater detail. + + The primary means of acquiring Route elements is \l RouteModel. +*/ + QDeclarativeGeoRoute::QDeclarativeGeoRoute(QObject *parent) : QObject(parent) { @@ -73,21 +90,56 @@ void QDeclarativeGeoRoute::init() } } +/*! + \qmlproperty BoundingBox Route::bounds + + Read-only property which holds a bounding box which encompasses the entire route. + +*/ + QDeclarativeGeoBoundingBox* QDeclarativeGeoRoute::bounds() const { return bounds_; } +/*! + \qmlproperty int Route::travelTime + + Read-only property which holds the estimated amount of time it will take to + traverse this route, in seconds. + +*/ + int QDeclarativeGeoRoute::travelTime() const { return route_.travelTime(); } +/*! + \qmlproperty int Route::distance + + Read-only property which holds distance covered by this route, in metres. +*/ + qreal QDeclarativeGeoRoute::distance() const { return route_.distance(); } +/* + \qmlproperty QDeclarativeListProperty<Coordinate> Route::path + + Read-only property which holds the geographical coordinates of this route. + Coordinates are listed in the order in which they would be traversed by someone + traveling along this segment of the route. + + To access individual segments you can use standard list accessors: 'path.length' + indicates the number of elements and 'path[index starting from zero]' gives + the actual element. + + \sa Coordinate +*/ + QDeclarativeListProperty<QDeclarativeCoordinate> QDeclarativeGeoRoute::path() { return QDeclarativeListProperty<QDeclarativeCoordinate>(this, @@ -118,6 +170,18 @@ void QDeclarativeGeoRoute::path_clear(QDeclarativeListProperty<QDeclarativeCoord static_cast<QDeclarativeGeoRoute*>(prop->object)->path_.clear(); } +/* + \qmlproperty QDeclarativeListProperty<RouteSegment> Route::segments + + Read-only property which holds the list of \l RouteSegment elements of this route. + + To access individual segments you can use standard list accessors: 'segments.length' + indicates the number of elements and 'segments[index starting from zero]' gives + the actual element. + + \sa RouteSegment +*/ + QDeclarativeListProperty<QDeclarativeGeoRouteSegment> QDeclarativeGeoRoute::segments() { return QDeclarativeListProperty<QDeclarativeGeoRouteSegment>(this, diff --git a/src/imports/location/qdeclarativegeoroutemodel.cpp b/src/imports/location/qdeclarativegeoroutemodel.cpp index e12b7090..89ffd289 100644 --- a/src/imports/location/qdeclarativegeoroutemodel.cpp +++ b/src/imports/location/qdeclarativegeoroutemodel.cpp @@ -48,7 +48,6 @@ QT_BEGIN_NAMESPACE - /*! \qmlclass RouteModel @@ -63,7 +62,6 @@ QT_BEGIN_NAMESPACE returns a Route object. */ - QDeclarativeGeoRouteModel::QDeclarativeGeoRouteModel(QObject *parent) : QAbstractListModel(parent), complete_(false), @@ -129,7 +127,7 @@ void QDeclarativeGeoRouteModel::clear() Resets the model. All route data is cleared, any outstanding requests are aborted and possible errors are cleared. Model status will be set - to RouteModel.Null. + to RouteModel.Null */ void QDeclarativeGeoRouteModel::reset() @@ -343,8 +341,8 @@ void QDeclarativeGeoRouteModel::setErrorString(const QString &error) This read-only property holds the textual presentation of latest routing error. If no error has occured or the model has been reset, an empty string is returned. - It is possible that an error occurred which has no associated textual representation, - in which case this will also return an empty string. + An empty string may also be returned if an error occurred which has no associated + textual representation. */ QString QDeclarativeGeoRouteModel::errorString() const diff --git a/src/imports/location/qdeclarativegeoroutesegment.cpp b/src/imports/location/qdeclarativegeoroutesegment.cpp index d5379941..bc7f301c 100644 --- a/src/imports/location/qdeclarativegeoroutesegment.cpp +++ b/src/imports/location/qdeclarativegeoroutesegment.cpp @@ -43,6 +43,25 @@ QT_BEGIN_NAMESPACE +/*! + \qmlclass RouteSegment + + \brief The RouteSegment element represents a segment of a Route. + \ingroup qml-routing + \since 5.0 + + A RouteSegment instance has information about the physcial layout + of the route segment, the length of the route and estimated time required + to traverse the route segment and optional RouteManeuvers associated with + the end of the route segment. + + RouteSegment instances can be thought of as edges on a routing + graph, with RouteManeuver instances as optional labels attached to the + vertices of the graph. + + The primary means of acquiring Route elements is via Routes via \l RouteModel. +*/ + QDeclarativeGeoRouteSegment::QDeclarativeGeoRouteSegment(QObject *parent) : QObject(parent) { @@ -62,21 +81,59 @@ QDeclarativeGeoRouteSegment::QDeclarativeGeoRouteSegment(const QGeoRouteSegment QDeclarativeGeoRouteSegment::~QDeclarativeGeoRouteSegment() {} +/*! + \qmlproperty int RouteSegment::travelTime + + Read-only property which holds the estimated amount of time it will take to + traverse this segment, in seconds. + +*/ + int QDeclarativeGeoRouteSegment::travelTime() const { return segment_.travelTime(); } +/*! + \qmlproperty int RouteSegment::distance + + Read-only property which holds the distance covered by this segment of the route, in metres. + +*/ + qreal QDeclarativeGeoRouteSegment::distance() const { return segment_.distance(); } +/*! + \qmlproperty int RouteSegment::maneuver + + Read-only property which holds the manevuer for this route segment. + + Will return invalid maneuver if no information has been attached to the endpoint + of this route segment. +*/ + QDeclarativeGeoManeuver* QDeclarativeGeoRouteSegment::maneuver() const { return maneuver_; } +/* + \qmlproperty QDeclarativeListProperty<Coordinate> RouteSegment::path + + Read-only property which holds the geographical coordinates of this segment. + Coordinates are listed in the order in which they would be traversed by someone + traveling along this segment of the route. + + To access individual segments you can use standard list accessors: 'path.length' + indicates the number of elements and 'path[index starting from zero]' gives + the actual element. + + \sa Coordinate +*/ + QDeclarativeListProperty<QDeclarativeCoordinate> QDeclarativeGeoRouteSegment::path() { return QDeclarativeListProperty<QDeclarativeCoordinate>(this, @@ -89,7 +146,6 @@ QDeclarativeListProperty<QDeclarativeCoordinate> QDeclarativeGeoRouteSegment::pa void QDeclarativeGeoRouteSegment::path_append(QDeclarativeListProperty<QDeclarativeCoordinate> *prop, QDeclarativeCoordinate *coordinate) { - //static_cast<QDeclarativeGeoRouteSegment*>(prop->object)->segment_.path().append(coordinate->coordinate()); static_cast<QDeclarativeGeoRouteSegment*>(prop->object)->path_.append(coordinate); } @@ -105,7 +161,6 @@ QDeclarativeCoordinate* QDeclarativeGeoRouteSegment::path_at(QDeclarativeListPro void QDeclarativeGeoRouteSegment::path_clear(QDeclarativeListProperty<QDeclarativeCoordinate> *prop) { - //static_cast<QDeclarativeGeoRouteSegment*>(prop->object)->segment_.path().clear(); static_cast<QDeclarativeGeoRouteSegment*>(prop->object)->path_.clear(); } diff --git a/tests/auto/declarative/tst_map_geocoding.qml b/tests/auto/declarative/tst_map_geocoding.qml index 124cb3a1..39452aad 100644 --- a/tests/auto/declarative/tst_map_geocoding.qml +++ b/tests/auto/declarative/tst_map_geocoding.qml @@ -146,7 +146,8 @@ Item { compare (emptyModel.status, RouteModel.Null) // error - compare (emptyModel.error, "") + compare (emptyModel.errorString, "") + compare (emptyModel.error, GeocodeModel.NoError) // count compare( emptyModel.count, 0) @@ -252,6 +253,7 @@ Item { SignalSpy {id: locationsSlackSpy; target: slackModel; signalName: "locationsChanged"} SignalSpy {id: countSlackSpy; target: slackModel; signalName: "countChanged"} SignalSpy {id: querySlackSpy; target: slackModel; signalName: "queryChanged"} + SignalSpy {id: errorStringSlackSpy; target: slackModel; signalName: "errorStringChanged"} SignalSpy {id: errorSlackSpy; target: slackModel; signalName: "errorChanged"} SignalSpy {id: pluginSlackSpy; target: slackModel; signalName: "pluginChanged"} @@ -260,6 +262,7 @@ Item { SignalSpy {id: countImmediateSpy; target: immediateModel; signalName: "countChanged"} SignalSpy {id: queryImmediateSpy; target: immediateModel; signalName: "queryChanged"} SignalSpy {id: statusImmediateSpy; target: immediateModel; signalName: "statusChanged"} + SignalSpy {id: errorStringImmediateSpy; target: immediateModel; signalName: "errorStringChanged"} SignalSpy {id: errorImmediateSpy; target: immediateModel; signalName: "errorChanged"} GeocodeModel {id: automaticModel; plugin: autoPlugin; query: automaticAddress1; autoUpdate: true} @@ -272,6 +275,7 @@ Item { locationsSlackSpy.clear() countSlackSpy.clear() querySlackSpy.clear() + errorStringSlackSpy.clear() errorSlackSpy.clear() slackModel.limit = -1 slackModel.offset = 0 @@ -281,6 +285,7 @@ Item { locationsImmediateSpy.clear() countImmediateSpy.clear() queryImmediateSpy.clear() + errorStringImmediateSpy.clear() errorImmediateSpy.clear() statusImmediateSpy.clear() immediateModel.limit = -1 @@ -290,12 +295,14 @@ Item { clear_immediate_model(); immediateModel.query = errorAddress1 immediateModel.update() - compare (immediateModel.error, errorAddress1.street) + compare (immediateModel.errorString, errorAddress1.street) + compare (immediateModel.error, RouteModel.CommunicationError) compare (immediateModel.count, 0) compare (statusImmediateSpy.count, 2) compare (immediateModel.status, GeocodeModel.Error) immediateModel.reset() - compare (immediateModel.error, "") + compare (immediateModel.errorString, "") + compare (immediateModel.error, GeocodeModel.NoError) compare (immediateModel.status, GeocodeModel.Null) // Check that ongoing req is aborted clear_slack_model() @@ -343,8 +350,9 @@ Item { clear_immediate_model() immediateModel.query = errorAddress1 immediateModel.update() - compare (errorImmediateSpy.count, 1) - compare (immediateModel.error, errorAddress1.street) + compare (errorStringImmediateSpy.count, 1) + compare (immediateModel.errorString, errorAddress1.street) + compare (immediateModel.error, GeocodeModel.CommunicationError) // county of the address (2) compare (immediateModel.count, 0) compare (statusImmediateSpy.count, 2) compare (immediateModel.status, GeocodeModel.Error) @@ -353,17 +361,22 @@ Item { slackModel.query = errorAddress1 errorAddress1.street = "error code 2" slackModel.update() + compare (errorStringSlackSpy.count, 0) compare (errorSlackSpy.count, 0) + tryCompare (errorStringSlackSpy, "count", 1) tryCompare (errorSlackSpy, "count", 1) - compare (slackModel.error, errorAddress1.street) + compare (slackModel.errorString, errorAddress1.street) + compare (slackModel.error, GeocodeModel.CommunicationError) compare (slackModel.count, 0) // Check that we recover slackModel.query = address1 slackModel.update() tryCompare(countSlackSpy, "count", 1) compare (slackModel.count, 2) + compare (errorStringSlackSpy.count, 2) compare (errorSlackSpy.count, 2) - compare (slackModel.error, "") + compare (slackModel.errorString, "") + compare (slackModel.error, GeocodeModel.NoError) } function test_error_reverse_geocode() { @@ -371,11 +384,12 @@ Item { clear_immediate_model() immediateModel.query = errorCoordinate1 immediateModel.update() - if (immediateModel.error != "") - compare (errorImmediateSpy.count, 2) // the previous error is cleared upon update() + if (immediateModel.errorString != "") + compare (errorStringImmediateSpy.count, 2) // the previous error is cleared upon update() else compare (errorImmediateSpy.count, 1) - compare (immediateModel.error, "error") + compare (immediateModel.errorString, "error") + compare (immediateModel.error, GeocodeModel.ParseError) compare (immediateModel.count, 0) compare (statusImmediateSpy.count, 2) compare (immediateModel.status, GeocodeModel.Error) @@ -383,20 +397,24 @@ Item { clear_slack_model() slackModel.query = errorCoordinate1 slackModel.update() + compare (errorStringSlackSpy.count, 0) compare (errorSlackSpy.count, 0) - if (slackModel.error != "") - tryCompare (errorSlackSpy, "count", 2) + if (slackModel.errorString != "") + tryCompare (errorStringSlackSpy, "count", 2) else - tryCompare (errorSlackSpy, "count", 1) - compare (slackModel.error, "error") + tryCompare (errorStringSlackSpy, "count", 1) + compare (slackModel.errorString, "error") + compare (slackModel.error, GeocodeModel.ParseError) compare (slackModel.count, 0) // Check that we recover slackModel.query = rcoordinate1 slackModel.update() tryCompare(countSlackSpy, "count", 1) compare (slackModel.count, 2) + compare (errorStringSlackSpy.count, 2) compare (errorSlackSpy.count, 2) - compare (slackModel.error, "") + compare (slackModel.errorString, "") + compare (slackModel.error, GeocodeModel.NoError) } function test_basic_address_geocode() { testQuerySpy.clear() @@ -405,13 +423,15 @@ Item { testModel.clear() countSpy.clear() compare (locationsSpy.count, 0) - compare (testModel.error, "") + compare (testModel.errorString, "") + compare (testModel.error, GeocodeModel.NoError) compare (testModel.count, 0) testModel.query = address1 compare (testQuerySpy.count, 1) testModel.update() tryCompare (locationsSpy, "count", 1) // 5 sec - compare (testModel.error, "") + compare (testModel.errorString, "") + compare (testModel.error, GeocodeModel.NoError) compare (testModel.count, 2) compare (testQuerySpy.count, 1) compare (testStatusSpy.count, 2) @@ -427,7 +447,8 @@ Item { testModel.clear() countSpy.clear() compare (locationsSpy.count, 0) - compare (testModel.error, "") + compare (testModel.errorString, "") + compare (testModel.error, GeocodeModel.NoError) compare (testModel.count, 0) testModel.limit = 5 // number of places echoed back testModel.offset = 10 // 'county' set in the places @@ -446,7 +467,8 @@ Item { tryCompare (locationsSpy, "count", 2) // 5 sec tryCompare(countSpy, "count", 2) tryCompare(testModel, "count", 0) - compare(testModel.error, "2") + compare(testModel.errorString, "2") + compare (testModel.error, GeocodeModel.CommunicationError) testModel.clear() tryCompare(countSpy, "count", 2) compare (testModel.count, 0) @@ -565,7 +587,8 @@ Item { locationsSpy.clear() testStatusSpy.clear() countSpy.clear() - compare (testModel.error, "") + compare (testModel.errorString, "") + compare (testModel.error, GeocodeModel.NoError) compare (testModel.count, 0) compare (testQuerySpy.count, 0) testModel.query = rcoordinate1 @@ -573,7 +596,8 @@ Item { testModel.update() tryCompare (locationsSpy, "count", 1) // 5 sec tryCompare(countSpy, "count", 1) - compare (testModel.error, "") + compare (testModel.errorString, "") + compare (testModel.error, GeocodeModel.NoError) compare (testModel.count, 2) testModel.clear() tryCompare(countSpy, "count", 2) diff --git a/tests/auto/declarative/tst_map_routing.qml b/tests/auto/declarative/tst_map_routing.qml index 4343abe2..d404ae5f 100644 --- a/tests/auto/declarative/tst_map_routing.qml +++ b/tests/auto/declarative/tst_map_routing.qml @@ -124,6 +124,7 @@ Item { compare(emptySegment.path.length, 0) compare(emptySegment.maneuver.valid, emptyManeuver.valid) compare(emptySegment.maneuver.instructionText, emptyManeuver.instructionText) + compare(emptySegment.maneuver.waypointValid, emptyManeuver.waypointValid) } function test_maneuver_defaults() { compare(emptyManeuver.valid, false) |