diff options
author | Aaron McCarthy <aaron.mccarthy@nokia.com> | 2012-07-27 12:58:48 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-08-24 05:28:08 +0200 |
commit | 1549d59e448550f05c5bd1ea6a9da5d1e78c7f26 (patch) | |
tree | a4163bbe7adcb9eeec31d8d9b12399f2cd3cb5cc /examples/declarative | |
parent | 5c8ad55eefd482bdb91d314502289df82c1bc9ad (diff) | |
download | qtlocation-1549d59e448550f05c5bd1ea6a9da5d1e78c7f26.tar.gz |
Convert Coordinate into a QML coordinate value type.
This replaces the Coordinate QML element with a value type.
A value type is a better fit for a coordinate. It is very similar to
a vector3d except it has an explicit coordinate system and some utility
functions.
Declare QGeoCoordinate as a movable type.
Update documentation.
Change-Id: I758fa9dfd7154a4d60fb791fe553b9fee3164c2c
Reviewed-by: abcd <amos.choy@nokia.com>
Diffstat (limited to 'examples/declarative')
14 files changed, 89 insertions, 148 deletions
diff --git a/examples/declarative/flickr/flickr.qml b/examples/declarative/flickr/flickr.qml index 3ef14b9d..ab36f078 100644 --- a/examples/declarative/flickr/flickr.qml +++ b/examples/declarative/flickr/flickr.qml @@ -54,9 +54,9 @@ Item { Image { source: "flickrmobile/images/stripes.png"; fillMode: Image.Tile; anchors.fill: parent; opacity: 0.3 } Common.RestModel { - id: restModel; - latitude: geoTab.latitude - longitude: geoTab.longitude} + id: restModel + coordinate: geoTab.coordinate + } Item { id: views diff --git a/examples/declarative/flickr/flickrcommon/RestModel.qml b/examples/declarative/flickr/flickrcommon/RestModel.qml index fae0a8c5..0b445615 100644 --- a/examples/declarative/flickr/flickrcommon/RestModel.qml +++ b/examples/declarative/flickr/flickrcommon/RestModel.qml @@ -43,8 +43,7 @@ import QtQuick.XmlListModel 2.0 //! [restmodel] XmlListModel { - property double latitude: 0 - property double longitude: 0 + property variant coordinate source: "http://api.flickr.com/services/rest/?" + "min_taken_date=2000-01-01+0:00:00&" + @@ -53,7 +52,7 @@ XmlListModel { "per_page=30&" + "sort=date-taken-desc&" + "api_key=e36784df8a03fea04c22ed93318b291c&" + - "lat=" + latitude + "&lon=" + longitude; + "lat=" + coordinate.latitude + "&lon=" + coordinate.longitude; query: "/rsp/photos/photo" XmlRole { name: "title"; query: "@title/string()" } @@ -64,48 +63,3 @@ XmlListModel { XmlRole { name: "secret"; query: "@secret/string()" } } //! [restmodel] - -/* - -QString url = "http://farm"; - url.append(child.attribute("farm")); - url.append(".static.flickr.com/"); - url.append(child.attribute("server")); - url.append("/"); - url.append(child.attribute("id")); - url.append("_"); - url.append(child.attribute("secret")); - - -XmlListModel { - property string tags : "" - - function commasep(x) - { - return x.replace(' ',','); - } - - //m_latitude = 61.4500; - //m_longitude = 23.8502; - //urlstring.append("&lat="); - //urlstring.append(QString::number(m_latitude)); - //urlstring.append("&lon="); - - source: "http://api.flickr.com/services/rest/photos_public.gne?"+(tags ? "tags="+commasep(tags)+"&" : "")+"format=rss2" - // +"&lat=61"+"&lon=23" - // original source: "http://api.flickr.com/services/feeds/photos_public.gne?"+(tags ? "tags="+commasep(tags)+"&" : "")+"format=rss2" - query: "/rss/channel/item" - namespaceDeclarations: "declare namespace media=\"http://search.yahoo.com/mrss/\";" - - XmlRole { name: "title"; query: "title/string()" } - XmlRole { name: "imagePath"; query: "media:thumbnail/@url/string()" } - XmlRole { name: "url"; query: "media:content/@url/string()" } - XmlRole { name: "description"; query: "description/string()" } - XmlRole { name: "tags"; query: "media:category/string()" } - XmlRole { name: "photoWidth"; query: "media:content/@width/string()" } - XmlRole { name: "photoHeight"; query: "media:content/@height/string()" } - XmlRole { name: "photoType"; query: "media:content/@type/string()" } - XmlRole { name: "photoAuthor"; query: "author/string()" } - XmlRole { name: "photoDate"; query: "pubDate/string()" } -} -*/ diff --git a/examples/declarative/flickr/flickrmobile/GeoTab.qml b/examples/declarative/flickr/flickrmobile/GeoTab.qml index b5342609..596abccd 100644 --- a/examples/declarative/flickr/flickrmobile/GeoTab.qml +++ b/examples/declarative/flickr/flickrmobile/GeoTab.qml @@ -41,17 +41,19 @@ import QtQuick 2.0 import QtLocation 5.0 - Rectangle { id: container property int maxX: parent.width; property int maxY: parent.height //! [props] - property double latitude - property double longitude - latitude: positionSource.position.coordinate.latitude - longitude: positionSource.position.coordinate.longitude + property variant coordinate //! [props] + Binding { + target: container + property: "coordinate" + value: positionSource.position.coordinate + } + width: 300; height: 130 color: "blue" opacity: 0.7 diff --git a/examples/declarative/mapviewer/content/map/3dItem.qml b/examples/declarative/mapviewer/content/map/3dItem.qml index 866270cd..9506f007 100644 --- a/examples/declarative/mapviewer/content/map/3dItem.qml +++ b/examples/declarative/mapviewer/content/map/3dItem.qml @@ -49,7 +49,6 @@ import Qt3D.Shapes 2.0 MapQuickItem { //to be used inside MapComponent only id: mapItem - coordinate: Coordinate { latitude : 0; longitude : 0 } // zoomLevel: 8 // set this if you want the item to follow zoom level changes function setGeometry(markers, index) { diff --git a/examples/declarative/mapviewer/content/map/CircleItem.qml b/examples/declarative/mapviewer/content/map/CircleItem.qml index ba38b2dc..54b3cf3b 100644 --- a/examples/declarative/mapviewer/content/map/CircleItem.qml +++ b/examples/declarative/mapviewer/content/map/CircleItem.qml @@ -49,7 +49,6 @@ MapCircle { border.width: 5 smooth: true opacity: 0.5 - center: Coordinate{} function setGeometry(markers, index){ center.latitude = markers[index].coordinate.latitude diff --git a/examples/declarative/mapviewer/content/map/ImageItem.qml b/examples/declarative/mapviewer/content/map/ImageItem.qml index 114da856..977c2960 100644 --- a/examples/declarative/mapviewer/content/map/ImageItem.qml +++ b/examples/declarative/mapviewer/content/map/ImageItem.qml @@ -43,8 +43,6 @@ import QtLocation 5.0 MapQuickItem { //to be used inside MapComponent only id: imageItem - coordinate: Coordinate { latitude : 0; longitude : 0 } - MapMouseArea { anchors.fill: parent drag.target: parent diff --git a/examples/declarative/mapviewer/content/map/MapComponent.qml b/examples/declarative/mapviewer/content/map/MapComponent.qml index 07f91b3d..2f810add 100644 --- a/examples/declarative/mapviewer/content/map/MapComponent.qml +++ b/examples/declarative/mapviewer/content/map/MapComponent.qml @@ -45,7 +45,13 @@ import QtLocation.examples 5.0 Map { id: map zoomLevel: (maximumZoomLevel - minimumZoomLevel)/2 - center: nokiaCoordinate + + //! [coord] + center { + latitude: -27.5796 + longitude: 153.1003 + } + //! [coord] // Enable pinch gestures to zoom in and out gesture.flickDeceleration: 3000 @@ -68,14 +74,6 @@ Map { signal showDistance(string distance); signal requestLocale() -//! [coord] - Coordinate { - id: nokiaCoordinate - latitude: -27.5796 - longitude: 153.1003 - } -//! [coord] - /* @todo Binding { target: map @@ -95,7 +93,11 @@ Map { MapCircle { id: poiEightMilePlains - center: Coordinate { latitude: -27.5758; longitude: 153.0881 } + center { + latitude: -27.5758 + longitude: 153.0881 + } + radius: 1800 color: "green" border.width: 2 @@ -111,7 +113,10 @@ Map { styleColor: "#ECECEC" style: Text.Outline } - coordinate: Coordinate { latitude: -27.59; longitude: 153.084 } + coordinate { + latitude: -27.59 + longitude: 153.084 + } anchorPoint.x: 0 anchorPoint.y: 0 } @@ -119,7 +124,10 @@ Map { MapQuickItem { id: poiNokia sourceItem: Rectangle { width: 14; height: 14; color: "#1c94fc"; border.width: 2; border.color: "#242424"; smooth: true; radius: 7 } - coordinate: Coordinate { latitude: -27.5796; longitude: 153.1003 } + coordinate { + latitude: -27.5796 + longitude: 153.1003 + } opacity:0.7 anchorPoint.x: sourceItem.width/2 anchorPoint.y: sourceItem.height/2 @@ -837,7 +845,7 @@ Map { MapMouseArea { id: mouseArea - property Coordinate lastCoordinate: Coordinate { latitude : 0; longitude : 0} + property variant lastCoordinate anchors.fill: parent onPressed : { diff --git a/examples/declarative/mapviewer/content/map/Marker.qml b/examples/declarative/mapviewer/content/map/Marker.qml index 95a77039..f17227a5 100644 --- a/examples/declarative/mapviewer/content/map/Marker.qml +++ b/examples/declarative/mapviewer/content/map/Marker.qml @@ -53,8 +53,6 @@ MapQuickItem { anchorPoint.x: image.width/4 anchorPoint.y: image.height - coordinate: Coordinate { latitude : 0; longitude : 0 } - sourceItem: Image { id: image //! [mqi-anchor] @@ -110,10 +108,7 @@ MapQuickItem { } //! [mqi-closeimage] - Component.onCompleted: { - coordinate.longitude = mouseArea.lastCoordinate.longitude - coordinate.latitude = mouseArea.lastCoordinate.latitude - } + Component.onCompleted: coordinate = mouseArea.lastCoordinate //! [mqi-close] } //! [mqi-close] diff --git a/examples/declarative/mapviewer/content/map/MiniMap.qml b/examples/declarative/mapviewer/content/map/MiniMap.qml index 9aff95bf..3d004d28 100644 --- a/examples/declarative/mapviewer/content/map/MiniMap.qml +++ b/examples/declarative/mapviewer/content/map/MiniMap.qml @@ -70,8 +70,14 @@ Rectangle{ color: "#44ff0000" border.width: 1 border.color: "red" - topLeft: Coordinate{latitude: miniMap.center.latitude + 5; longitude: miniMap.center.longitude - 5} - bottomRight: Coordinate{latitude: miniMap.center.latitude - 5; longitude: miniMap.center.longitude + 5} + topLeft { + latitude: miniMap.center.latitude + 5 + longitude: miniMap.center.longitude - 5 + } + bottomRight { + latitude: miniMap.center.latitude - 5 + longitude: miniMap.center.longitude + 5 + } } } } diff --git a/examples/declarative/mapviewer/content/map/RectangleItem.qml b/examples/declarative/mapviewer/content/map/RectangleItem.qml index f6d6515f..0f0ee661 100644 --- a/examples/declarative/mapviewer/content/map/RectangleItem.qml +++ b/examples/declarative/mapviewer/content/map/RectangleItem.qml @@ -41,13 +41,11 @@ import QtQuick 2.0 import QtLocation 5.0 MapRectangle { - id: mapRectangle + color: mousearea.containsMouse ? "lime" : "red" opacity: 0.5 border.width: 2.0 - bottomRight: Coordinate{} - topLeft: Coordinate{} function setGeometry(markers, index){ topLeft.latitude = Math.max(markers[index].coordinate.latitude, markers[index + 1].coordinate.latitude) diff --git a/examples/declarative/mapviewer/content/map/VideoItem.qml b/examples/declarative/mapviewer/content/map/VideoItem.qml index e6f26723..f02917e4 100644 --- a/examples/declarative/mapviewer/content/map/VideoItem.qml +++ b/examples/declarative/mapviewer/content/map/VideoItem.qml @@ -47,7 +47,6 @@ import QtMultimedia 5.0 MapQuickItem { //to be used inside MapComponent only id: testVideoItem - coordinate: Coordinate { latitude : 0; longitude : 0 } // zoomLevel: 8 // set this if you want the video to follow zoom level changes function setGeometry(markers, index) { diff --git a/examples/declarative/mapviewer/mapviewer.qml b/examples/declarative/mapviewer/mapviewer.qml index 9d4aed93..31db7e11 100644 --- a/examples/declarative/mapviewer/mapviewer.qml +++ b/examples/declarative/mapviewer/mapviewer.qml @@ -50,7 +50,7 @@ Item { height: parent ? parent.height : 640 property variant map property variant minimap - property list<PluginParameter> parameters + property variant parameters Rectangle { id: backgroundRect @@ -95,10 +95,6 @@ Item { y: page.height horizontalOrientation: false - Component.onCompleted: { - update() - } - onClicked: { switch (button) { case "Reverse geocode": { @@ -155,10 +151,6 @@ Item { horizontalOrientation: false exclusive: true - Component.onCompleted: { - update() - } - onClicked: { page.state = "" } @@ -193,16 +185,13 @@ Item { var plugins = getPlugins() for (var i = 0; i<plugins.length; i++) addItem(plugins[i]) - if (plugins.length > 0) exclusiveButton = plugins[0] } onClicked: { page.state = "" } - onExclusiveButtonChanged: { - createMap(exclusiveButton) - } + onExclusiveButtonChanged: createMap(exclusiveButton) } //=====================Dialogs===================== @@ -258,8 +247,9 @@ Item { RouteDialog { id: routeDialog - Coordinate { id: endCoordinate } - Coordinate { id: startCoordinate } + property variant startCoordinate + property variant endCoordinate + //! [routedialog0] Address { id: startAddress } Address { id: endAddress } @@ -269,7 +259,6 @@ Item { GeocodeModel { id: tempGeocodeModel - plugin : map.plugin property int success: 0 onCountChanged: { @@ -316,10 +305,10 @@ Item { tempGeocodeModel.reset() messageDialog.state = "" if (routeDialog.byCoordinates) { - startCoordinate.latitude = routeDialog.startLatitude - startCoordinate.longitude = routeDialog.startLongitude - endCoordinate.latitude = routeDialog.endLatitude - endCoordinate.longitude = routeDialog.endLongitude + startCoordinate = QtLocation.coordinate(parseFloat(routeDialog.startLatitude), + parseFloat(routeDialog.startLongitude)); + endCoordinate = QtLocation.coordinate(parseFloat(routeDialog.endLatitude), + parseFloat(routeDialog.endLongitude)); calculateRoute() } @@ -368,8 +357,7 @@ Item { map.routeModel.update(); // center the map on the start coord - map.center.latitude = startCoordinate.latitude - map.center.longitude = startCoordinate.longitude + map.center = startCoordinate; //! [routerequest1] } //! [routedialog1] @@ -430,16 +418,11 @@ Item { setModel(obj) } - Coordinate { - id: reverseGeocodeCoordinate - } - onGoButtonClicked: { page.state = "" messageDialog.state = "" - reverseGeocodeCoordinate.latitude = dialogModel.get(0).inputText - reverseGeocodeCoordinate.longitude = dialogModel.get(1).inputText - map.geocodeModel.query = reverseGeocodeCoordinate + map.geocodeModel.query = QtLocation.coordinate(parseFloat(dialogModel.get(0).inputText), + parseFloat(dialogModel.get(1).inputText)); map.geocodeModel.update(); } @@ -462,20 +445,14 @@ Item { onGoButtonClicked: { page.state = "" messageDialog.state = "" - var latitude = parseFloat(dialogModel.get(0).inputText) - var longitude = parseFloat(dialogModel.get(1).inputText) - - if (latitude !== "NaN" && longitude !== "NaN") { - - var coordinate = Qt.createQmlObject('import QtLocation 5.0; Coordinate {}', map) - coordinate.latitude = latitude - coordinate.longitude = longitude - - if (coordinate.isValid) { - map.markers[map.currentMarker].coordinate.latitude = latitude - map.markers[map.currentMarker].coordinate.longitude = longitude - map.center.latitude = latitude - map.center.longitude = longitude + var newLat = parseFloat(dialogModel.get(0).inputText) + var newLong = parseFloat(dialogModel.get(1).inputText) + + if (newLat !== "NaN" && newLong !== "NaN") { + var c = QtLocation.coordinate(newLat, newLong); + if (c.isValid) { + map.markers[map.currentMarker].coordinate = c; + map.center = c; } } } @@ -625,7 +602,10 @@ Item { page.state = "";\ }\ }',page) - map.plugin = plugin + map.plugin = plugin; + tempGeocodeModel.plugin = plugin; + mapTypeMenu.update(); + toolsMenu.update(); } } @@ -653,7 +633,10 @@ Item { parameters.push(parameter) } page.parameters=parameters - createMap(map.plugin.name) + if (providerMenu.exclusiveButton !== "") + createMap(providerMenu.exclusiveButton); + else if (providerMenu.children.length > 0) + createMap(providerMenu.children[0].text); } //=====================States of page===================== diff --git a/examples/declarative/places/content/places/MapComponent.qml b/examples/declarative/places/content/places/MapComponent.qml index e8dc165e..62e78a55 100644 --- a/examples/declarative/places/content/places/MapComponent.qml +++ b/examples/declarative/places/content/places/MapComponent.qml @@ -45,7 +45,11 @@ import QtLocation.examples 5.0 Map { id: map zoomLevel: (maximumZoomLevel - minimumZoomLevel)/2 - center: brisbaneCoordinate + center { + // Brisbane + latitude: -27.5 + longitude: 153 + } gesture.flickDeceleration: 3000 gesture.enabled: true @@ -53,12 +57,6 @@ Map { 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] - Coordinate { - id: brisbaneCoordinate - latitude: -27.5 - longitude: 153 - } - PositionSource{ id: positionSource active: followme diff --git a/examples/declarative/places/places.qml b/examples/declarative/places/places.qml index 98be4f8a..35911a4c 100644 --- a/examples/declarative/places/places.qml +++ b/examples/declarative/places/places.qml @@ -205,10 +205,12 @@ Item { onCancelButtonClicked: page.state = "" onGoButtonClicked: { - startLocation.center.latitude = dialogModel.get(0).inputText; - startLocation.center.longitude = dialogModel.get(1).inputText; + var c = QtLocation.coordinate(parseFloat(dialogModel.get(0).inputText), + parseFloat(dialogModel.get(1).inputText)); searchRegion = startLocation; + map.center = c; + if (searchRegionItem) { map.removeMapItem(searchRegionItem); searchRegionItem.destroy(); @@ -240,13 +242,13 @@ Item { onCancelButtonClicked: page.state = "" onGoButtonClicked: { var newRegion = Qt.createQmlObject('import QtLocation 5.0; GeoRectangle {}', page, "GeoCircle"); - newRegion.center.latitude = dialogModel.get(0).inputText; - newRegion.center.longitude = dialogModel.get(1).inputText; + var c = QtLocation.coordinate(parseFloat(dialogModel.get(0).inputText), + parseFloat(dialogModel.get(1).inputText)); + newRegion.center = c; newRegion.width = dialogModel.get(2).inputText; newRegion.height = dialogModel.get(3).inputText; - startLocation.center.latitude = dialogModel.get(0).inputText; - startLocation.center.longitude = dialogModel.get(1).inputText; + map.center = c; searchRegion = newRegion; @@ -285,12 +287,12 @@ Item { onCancelButtonClicked: page.state = "" onGoButtonClicked: { var newRegion = Qt.createQmlObject('import QtLocation 5.0; GeoCircle {}', page, "GeoCircle"); - newRegion.center.latitude = dialogModel.get(0).inputText; - newRegion.center.longitude = dialogModel.get(1).inputText; + var c = QtLocation.coordinate(parseFloat(dialogModel.get(0).inputText), + parseFloat(dialogModel.get(1).inputText)); + newRegion.center = c; newRegion.radius = dialogModel.get(2).inputText; - startLocation.center.latitude = dialogModel.get(0).inputText; - startLocation.center.longitude = dialogModel.get(1).inputText; + map.center = c; searchRegion = newRegion; @@ -352,7 +354,7 @@ Item { Binding { target: startLocation property: "center" - value: map ? map.center : null + value: map ? map.center : QtLocation.coordinate() } //! [PlaceSearchModel model] |