The RouteModel type provides access to routes. More...
Import Statement: | import QtLocation 6.4 |
Since: | QtLocation 5.5 |
The RouteModel type is used as part of a model/view grouping to retrieve geographic routes from a backend provider. Routes include data about driving directions between two points, walking directions with multiple waypoints, and various other similar concepts. It functions much like other Model types in QML (see for example ListModel and XmlListModel), and interacts with views such as MapItemView, and ListView.
Like Map and GeocodeModel, all the data for a RouteModel to work comes from a services plugin. This is contained in the plugin property, and this must be set before the RouteModel can do any useful work.
Once the plugin is set, create a RouteQuery with the appropriate waypoints and other settings, and set the RouteModel's query property. If autoUpdate is enabled, the update will being automatically. Otherwise, the update method may be used. By default, autoUpdate is disabled.
The data stored and returned in the RouteModel consists of Route objects, as a list with the role name "routeData". See the documentation for Route for further details on its structure and contents.
The following snippet is two-part, showing firstly the declaration of objects, and secondly a short piece of procedural code using it. We set the routeModel's autoUpdate property to false, and call update once the query is set up, to avoid useless extra requests halfway through the set up of the query.
Plugin { id: aPlugin name: "osm" } RouteQuery { id: aQuery } RouteModel { id: routeModel plugin: aPlugin query: aQuery autoUpdate: false }
{ aQuery.addWaypoint(...) aQuery.addWaypoint(...) aQuery.travelModes = ... routeModel.update() }
autoUpdate : bool |
This property controls whether the Model automatically updates in response to changes in its attached RouteQuery. The default value of this property is false.
If setting this value to 'true', note that any change at all in the RouteQuery object set in the query property will trigger a new request to be sent. If you are adjusting many properties of the RouteQuery with autoUpdate enabled, this can generate large numbers of useless (and later discarded) requests.
[read-only] count : int |
This property holds how many routes the model currently has. Amongst other uses, you can use this value when accessing routes via the QtLocation::RouteModel::get -method.
[read-only] error : enumeration |
This read-only property holds the latest error value of the routing request.
[read-only] errorString : string |
This read-only property holds the textual presentation of the latest routing error. If no error has occurred 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.
measurementSystem : Locale::MeasurementSystem |
This property holds the measurement system which will be used when calculating the route. This property is changed when the Plugin::locales property of plugin changes.
If setting this property it must be set after the plugin property is set.
plugin : Plugin |
This property holds the plugin that providers the actual routing service. Note that all plugins do not necessarily provide routing (could for example provide only geocoding or maps).
A valid plugin must be set before the RouteModel can perform any useful operations.
See also Plugin.
query : RouteQuery |
This property holds the data of the route request. The primary data are the waypoint coordinates and possible further preferences (means of traveling, things to avoid on route etc).
[read-only] status : enumeration |
This read-only property holds the current status of the model.
void cancel() |
Cancels any outstanding requests and clears errors. Model status will be set to either RouteModel.Null or RouteModel.Ready.
Returns the Route at the specified index. Use the count property to check the amount of routes available. The routes 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.
void reset() |
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
void update() |
Instructs the RouteModel to update its data. This is most useful when autoUpdate is disabled, to force a refresh when the query has been changed.