diff options
author | Michal Klocek <michal.klocek@theqtcompany.com> | 2015-02-24 17:31:03 +0100 |
---|---|---|
committer | Michal Klocek <michal.klocek@theqtcompany.com> | 2015-04-14 08:35:54 +0000 |
commit | 8ccac8432b9575e2dbf49e9e887c2581bcee308f (patch) | |
tree | 976d2e36c8f30c6b064ace1f4aeefd355aa66919 /examples | |
parent | 1901c8bc9e1d2a931d541f77b08654b4017f5b5c (diff) | |
download | qtlocation-8ccac8432b9575e2dbf49e9e887c2581bcee308f.tar.gz |
Refactor code and fix documentation for mapviewer example.
Refactor code so the MapComponent holds the most of revelant
code for documenting. Rewrite mapviewer example documentation
so it fits the current code snippets.
Change-Id: Idf468d2025303a42cea6ca8d24ed541c509911c0
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/location/mapviewer/forms/Geocode.qml | 8 | ||||
-rw-r--r-- | examples/location/mapviewer/forms/RouteCoordinate.qml | 5 | ||||
-rw-r--r-- | examples/location/mapviewer/forms/RouteList.qml | 25 | ||||
-rw-r--r-- | examples/location/mapviewer/map/MapComponent.qml | 173 | ||||
-rw-r--r-- | examples/location/mapviewer/mapviewer.qml | 50 |
5 files changed, 133 insertions, 128 deletions
diff --git a/examples/location/mapviewer/forms/Geocode.qml b/examples/location/mapviewer/forms/Geocode.qml index c1d70a45..4484b301 100644 --- a/examples/location/mapviewer/forms/Geocode.qml +++ b/examples/location/mapviewer/forms/Geocode.qml @@ -41,15 +41,12 @@ import QtQuick 2.4 import QtPositioning 5.2 -//Geocode Dialog -//! [geocode0] GeocodeForm { - //! [geocode0] + property variant address signal showPlace(variant address) signal closeForm() - //! [geocode1] goButton.onClicked: { // fill out the Address element address.street = street.text @@ -59,7 +56,6 @@ GeocodeForm { address.postalCode = postalCode.text showPlace(address) } - //! [geocode1] clearButton.onClicked: { street.text = "" @@ -68,7 +64,6 @@ GeocodeForm { country.text = "" postalCode.text = "" } - //! [geocode2] cancelButton.onClicked: { closeForm() @@ -82,6 +77,5 @@ GeocodeForm { postalCode.text = address.postalCode } } -//! [geocode2] diff --git a/examples/location/mapviewer/forms/RouteCoordinate.qml b/examples/location/mapviewer/forms/RouteCoordinate.qml index 9c593e0a..5a42310b 100644 --- a/examples/location/mapviewer/forms/RouteCoordinate.qml +++ b/examples/location/mapviewer/forms/RouteCoordinate.qml @@ -41,15 +41,12 @@ import QtQuick 2.4 import QtPositioning 5.2 -//Route Dialog -//! [routedialog0] RouteCoordinateForm { property variant toCoordinate property variant fromCoordinate signal showRoute(variant startCoordinate,variant endCoordinate) signal closeForm() - //! [routedialog0] goButton.onClicked: { var startCoordinate = QtPositioning.coordinate(parseFloat(fromLatitude.text), parseFloat(fromLongitude.text)); @@ -78,7 +75,5 @@ RouteCoordinateForm { toLatitude.text = "" + toCoordinate.latitude toLongitude.text = "" + toCoordinate.longitude } - //! [routedialog1] } -//! [routedialog1] diff --git a/examples/location/mapviewer/forms/RouteList.qml b/examples/location/mapviewer/forms/RouteList.qml index 200d10dd..a2d7e9df 100644 --- a/examples/location/mapviewer/forms/RouteList.qml +++ b/examples/location/mapviewer/forms/RouteList.qml @@ -42,24 +42,23 @@ import QtQuick 2.4 import QtQuick.Controls 1.3 import "../helper.js" as Helper +//! [routeinfomodel0] ListView { +//! [routeinfomodel0] property variant routeModel property string totalTravelTime property string totalDistance signal closeForm() - +//! [routeinfomodel1] interactive: true - - model: ListModel { id: routeList } - + model: ListModel { id: routeInfoModel } header: RouteListHeader {} - delegate: RouteListDelegate{ routeIndex.text: index + 1 routeInstruction.text: instruction routeDistance.text: distance } - +//! [routeinfomodel1] footer: Button { anchors.horizontalCenter: parent.horizontalCenter text: qsTr("Close") @@ -69,16 +68,20 @@ ListView { } Component.onCompleted: { - routeList.clear() + //! [routeinfomodel2] + routeInfoModel.clear() if (routeModel.count > 0) { for (var i = 0; i < routeModel.get(0).segments.length; i++) { - routeList.append({ - "instruction": routeModel.get(0).segments[i].maneuver.instructionText, - "distance": Helper.formatDistance(routeModel.get(0).segments[i].maneuver.distanceToNextInstruction) - }); + routeInfoModel.append({ + "instruction": routeModel.get(0).segments[i].maneuver.instructionText, + "distance": Helper.formatDistance(routeModel.get(0).segments[i].maneuver.distanceToNextInstruction) + }); } } + //! [routeinfomodel2] totalTravelTime = routeModel.count == 0 ? "" : Helper.formatTime(routeModel.get(0).travelTime) totalDistance = routeModel.count == 0 ? "" : Helper.formatDistance(routeModel.get(0).distance) } +//! [routeinfomodel3] } +//! [routeinfomodel3] diff --git a/examples/location/mapviewer/map/MapComponent.qml b/examples/location/mapviewer/map/MapComponent.qml index e3a0f323..6250f6c7 100644 --- a/examples/location/mapviewer/map/MapComponent.qml +++ b/examples/location/mapviewer/map/MapComponent.qml @@ -46,7 +46,7 @@ import "../helper.js" as Helper //! [top] Map { id: map - //! [top] +//! [top] property variant markers property variant mapItems property int markerCounter: 0 // counter for total amount of markers. Resets to 0 when number of markers = 0 @@ -58,59 +58,9 @@ Map { property int jitterThreshold : 30 property bool followme: false property variant scaleLengths: [5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000, 20000, 50000, 100000, 200000, 500000, 1000000, 2000000] - //! [routemodel0] - property RouteQuery routeQuery: RouteQuery {} - - property RouteModel routeModel: RouteModel { - plugin : map.plugin - query: routeQuery - //! [routemodel0] - - //! [routemodel1] - onStatusChanged: { - if (status == RouteModel.Ready) { - switch (count) { - case 0: - // technically not an error - map.routeError() - break - case 1: - showRouteList() - break - } - } else if (status == RouteModel.Error) { - map.routeError() - } - } - //! [routemodel1] - - //! [routemodel2] - - //! [routemodel2] - //! [routemodel3] - } - //! [routemodel3] - - //! [geocodemodel0] - property GeocodeModel geocodeModel: GeocodeModel { - //! [geocodemodel0] - //! [geocodemodel0 body] - plugin: map.plugin - onStatusChanged: { - if ((status == GeocodeModel.Ready) || (status == GeocodeModel.Error)) - map.geocodeFinished() - } - onLocationsChanged: - { - if (count == 1) { - map.center.latitude = get(0).coordinate.latitude - map.center.longitude = get(0).coordinate.longitude - } - } - //! [geocodemodel0 body] - //! [geocodemodel1] - } - //! [geocodemodel1] + property alias routeQuery: routeQuery + property alias routeModel: routeModel + property alias geocodeModel: geocodeModel signal showGeocodeInfo() signal geocodeFinished() @@ -253,7 +203,8 @@ Map { if (markers.length == 0) markerCounter = 0 } - function calculateRoute(){ + function calculateMarkerRoute() + { routeQuery.clearWaypoints(); for (var i = currentMarker; i< map.markers.length; i++){ routeQuery.addWaypoint(markers[i].coordinate) @@ -264,16 +215,64 @@ Map { routeModel.update(); } - //! [coord] + function calculateCoordinateRoute(startCoordinate, endCoordinate) + { + //! [routerequest0] + // clear away any old data in the query + routeQuery.clearWaypoints(); + + // add the start and end coords as waypoints on the route + routeQuery.addWaypoint(startCoordinate) + routeQuery.addWaypoint(endCoordinate) + routeQuery.travelModes = RouteQuery.CarTravel + routeQuery.routeOptimizations = RouteQuery.FastestRoute + + //! [routerequest0] + + //! [routerequest0 feature weight] + for (var i=0; i<9; i++) { + routeQuery.setFeatureWeight(i, 0) + } + //for (var i=0; i<routeDialog.features.length; i++) { + // map.routeQuery.setFeatureWeight(routeDialog.features[i], RouteQuery.AvoidFeatureWeight) + //} + //! [routerequest0 feature weight] + + //! [routerequest1] + routeModel.update(); + + //! [routerequest1] + //! [routerequest2] + // center the map on the start coord + map.center = startCoordinate; + //! [routerequest2] + } + + function geocode(fromAddress) + { + //! [geocode1] + // send the geocode request + geocodeModel.query = fromAddress + geocodeModel.update() + //! [geocode1] + } + + +//! [coord] + zoomLevel: (maximumZoomLevel - minimumZoomLevel)/2 center { + // The Qt Company in Oslo latitude: 59.9485 longitude: 10.7686 } - //! [coord] +//! [coord] - // Enable pinch gestures to zoom in and out +//! [mapnavigation] + // Enable pan, flick, and pinch gestures to zoom in and out + gesture.activeGestures: MapGestureArea.PanGesture | MapGestureArea.FlickGesture | MapGestureArea.ZoomGesture gesture.flickDeceleration: 3000 gesture.enabled: true +//! [mapnavigation] onCopyrightLinkActivated: Qt.openUrlExternally(link) onCenterChanged:{ @@ -407,6 +406,32 @@ Map { } } + //! [routemodel0] + RouteModel { + id: routeModel + plugin : map.plugin + query: RouteQuery { + id: routeQuery + } + onStatusChanged: { + if (status == RouteModel.Ready) { + switch (count) { + case 0: + // technically not an error + map.routeError() + break + case 1: + map.showRouteList() + break + } + } else if (status == RouteModel.Error) { + map.routeError() + } + } + } + //! [routemodel0] + + //! [routedelegate0] Component { id: routeDelegate @@ -417,7 +442,7 @@ Map { line.width: 5 smooth: true opacity: 0.8 - //! [routedelegate0] + //! [routedelegate0] MouseArea { id: routeMouseArea anchors.fill: parent @@ -450,11 +475,29 @@ Map { } } } + //! [routedelegate1] } - //! [routedelegate1] } //! [routedelegate1] + //! [geocodemodel0] + GeocodeModel { + id: geocodeModel + plugin: map.plugin + onStatusChanged: { + if ((status == GeocodeModel.Ready) || (status == GeocodeModel.Error)) + map.geocodeFinished() + } + onLocationsChanged: + { + if (count == 1) { + map.center.latitude = get(0).coordinate.latitude + map.center.longitude = get(0).coordinate.longitude + } + } + } + //! [geocodemodel0] + //! [pointdel0] Component { id: pointDelegate @@ -500,18 +543,20 @@ Map { } } } - //! [pointdel1] + //! [pointdel1] } } //! [pointdel1] - //! [routeview] + //! [routeview0] MapItemView { model: routeModel delegate: routeDelegate + //! [routeview0] autoFitViewport: true + //! [routeview1] } - //! [routeview] + //! [routeview1] //! [geocodeview] MapItemView { @@ -578,6 +623,6 @@ Map { } } } - //! [end] +//! [end] } //! [end] diff --git a/examples/location/mapviewer/mapviewer.qml b/examples/location/mapviewer/mapviewer.qml index d15058ba..491bc47f 100644 --- a/examples/location/mapviewer/mapviewer.qml +++ b/examples/location/mapviewer/mapviewer.qml @@ -53,8 +53,10 @@ ApplicationWindow { property variant parameters //defaults + //! [routecoordinate] property variant fromCoordinate: QtPositioning.coordinate(59.9483, 10.7695) property variant toCoordinate: QtPositioning.coordinate(59.9645, 10.671) + //! [routecoordinate] function createMap(provider) { @@ -168,6 +170,7 @@ ApplicationWindow { visible: true menuBar: mainMenu + //! [geocode0] Address { id :fromAddress street: "Sandakerveien 116" @@ -176,6 +179,7 @@ ApplicationWindow { state : "" postalCode: "0484" } + //! [geocode0] Address { id: toAddress @@ -198,42 +202,6 @@ ApplicationWindow { } } - //! [routerequest0] - function showRoute(startCoordinate, endCoordinate) - { - // clear away any old data in the query - map.routeQuery.clearWaypoints(); - - // add the start and end coords as waypoints on the route - map.routeQuery.addWaypoint(startCoordinate) - map.routeQuery.addWaypoint(endCoordinate) - map.routeQuery.travelModes = RouteQuery.CarTravel - map.routeQuery.routeOptimizations = RouteQuery.FastestRoute - //! [routerequest0] - - //! [routerequest0 feature weight] - for (var i=0; i<9; i++) { - map.routeQuery.setFeatureWeight(i, 0) - } - //for (var i=0; i<routeDialog.features.length; i++) { - // map.routeQuery.setFeatureWeight(routeDialog.features[i], RouteQuery.AvoidFeatureWeight) - //} - //! [routerequest0 feature weight] - - //! [routerequest1] - map.routeModel.update(); - // center the map on the start coord - map.center = startCoordinate; - //! [routerequest1] - } - - function showPlace(geocode) - { - // send the geocode request - map.geocodeModel.query = geocode - map.geocodeModel.update() - } - function setLanguage(lang) { map.plugin.locales = lang; @@ -277,7 +245,7 @@ ApplicationWindow { properties: { "plugin": map.plugin, "toAddress": toAddress, "fromAddress": fromAddress}}) - stackView.currentItem.showRoute.connect(showRoute) + stackView.currentItem.showRoute.connect(map.calculateCoordinateRoute) stackView.currentItem.showMessage.connect(stackView.showMessage) stackView.currentItem.closeForm.connect(stackView.closeForm) break @@ -285,19 +253,19 @@ ApplicationWindow { stackView.push({ item: Qt.resolvedUrl("forms/RouteCoordinate.qml") , properties: { "toCoordinate": toCoordinate, "fromCoordinate": fromCoordinate}}) - stackView.currentItem.showRoute.connect(showRoute) + stackView.currentItem.showRoute.connect(map.calculateCoordinateRoute) stackView.currentItem.closeForm.connect(stackView.closeForm) break case "Geocode": stackView.push({ item: Qt.resolvedUrl("forms/Geocode.qml") , properties: { "address": fromAddress}}) - stackView.currentItem.showPlace.connect(showPlace) + stackView.currentItem.showPlace.connect(map.geocode) stackView.currentItem.closeForm.connect(stackView.closeForm) break case "RevGeocode": stackView.push({ item: Qt.resolvedUrl("forms/ReverseGeocode.qml") , properties: { "coordinate": fromCoordinate}}) - stackView.currentItem.showPlace.connect(showPlace) + stackView.currentItem.showPlace.connect(map.geocode) stackView.currentItem.closeForm.connect(stackView.closeForm) break case "Language": @@ -405,7 +373,7 @@ ApplicationWindow { break; case "routeToNextPoint": case "routeToNextPoints": - map.calculateRoute() + map.calculateMarkerRoute() break case "distanceToNextPoint": var coordinate1 = map.markers[currentMarker].coordinate; |