diff options
author | Michal Klocek <michal.klocek@theqtcompany.com> | 2015-02-11 19:03:23 +0100 |
---|---|---|
committer | Michal Klocek <michal.klocek@theqtcompany.com> | 2015-04-13 14:54:36 +0000 |
commit | 19d8a8514ae875b0fc4b5e7e7a08b5db74a457ce (patch) | |
tree | 7a2c41806934a89baf365006c346cd172c9c0c65 /examples | |
parent | 6cd56cd2a431238f67544f62fd541c55ba9ecda1 (diff) | |
download | qtlocation-19d8a8514ae875b0fc4b5e7e7a08b5db74a457ce.tar.gz |
Replace route and point menus in mapviewer example.
Use qtquickcontroles based one.
Change-Id: I02f657cbb2b3f2728edd3287b0d7edf793c20aa7
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/location/mapviewer/ItemPopupMenu.qml | 53 | ||||
-rw-r--r-- | examples/location/mapviewer/content/map/MapComponent.qml | 105 | ||||
-rw-r--r-- | examples/location/mapviewer/mapviewer.qml | 42 | ||||
-rw-r--r-- | examples/location/mapviewer/mapviewerwrapper.qrc | 1 |
4 files changed, 110 insertions, 91 deletions
diff --git a/examples/location/mapviewer/ItemPopupMenu.qml b/examples/location/mapviewer/ItemPopupMenu.qml new file mode 100644 index 00000000..6b604aaa --- /dev/null +++ b/examples/location/mapviewer/ItemPopupMenu.qml @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.4 +import QtQuick.Controls 1.3 + +Menu { + property variant type + signal itemClicked(string item) + + function update() { + clear() + addItem(qsTr("Info")).triggered.connect(function(){itemClicked("show" + type + "Info")}) + addItem(qsTr("Delete")).triggered.connect(function(){itemClicked("delete" + type )}) + } +} diff --git a/examples/location/mapviewer/content/map/MapComponent.qml b/examples/location/mapviewer/content/map/MapComponent.qml index 001dddc7..e559ba3a 100644 --- a/examples/location/mapviewer/content/map/MapComponent.qml +++ b/examples/location/mapviewer/content/map/MapComponent.qml @@ -41,7 +41,6 @@ import QtQuick 2.4 import QtQuick.Controls 1.3 import QtLocation 5.3 import QtPositioning 5.2 -import QtLocation.examples 5.0 as OwnControls //! [top] Map { @@ -64,9 +63,10 @@ Map { property variant mapItems property int markerCounter: 0 // counter for total amount of markers. Resets to 0 when number of markers = 0 property int currentMarker - signal resetState() signal showMainMenu(variant coordinate) signal showMarkerMenu(variant coordinate) + signal showRouteMenu(variant coordinate) + signal showPointMenu(variant coordinate) property int lastX : -1 property int lastY : -1 @@ -167,7 +167,6 @@ Map { onValueChanged: { map.zoomLevel = value map.state="" - map.resetState() } } @@ -244,8 +243,8 @@ Map { id: routeDelegate MapRoute { + id: route route: routeData - line.color: routeMouseArea.containsMouse ? "lime" : "red" line.width: 5 smooth: true @@ -255,19 +254,18 @@ Map { id: routeMouseArea anchors.fill: parent hoverEnabled: false + property variant lastCoordinate onPressed : { - map.resetState(); - map.state = "" map.lastX = mouse.x + parent.x map.lastY = mouse.y + parent.y map.pressX = mouse.x + parent.x map.pressY = mouse.y + parent.y + lastCoordinate = map.toCoordinate(Qt.point(mouse.x, mouse.y)) } onPositionChanged: { - if (map.state != "RoutePopupMenu" || - Math.abs(map.pressX - parent.x- mouse.x ) > map.jitterThreshold || + if (Math.abs(map.pressX - parent.x- mouse.x ) > map.jitterThreshold || Math.abs(map.pressY - parent.y -mouse.y ) > map.jitterThreshold) { map.state = "" } @@ -280,7 +278,7 @@ Map { onPressAndHold:{ if (Math.abs(map.pressX - parent.x- mouse.x ) < map.jitterThreshold && Math.abs(map.pressY - parent.y - mouse.y ) < map.jitterThreshold) { - map.state = "RoutePopupMenu" + showRouteMenu(lastCoordinate); } } } @@ -294,6 +292,7 @@ Map { id: pointDelegate MapCircle { + id: point radius: 1000 color: circleMouseArea.containsMouse ? "lime" : "red" opacity: 0.6 @@ -303,19 +302,18 @@ Map { anchors.fill:parent id: circleMouseArea hoverEnabled: false + property variant lastCoordinate onPressed : { - map.resetState(); - map.state = "" map.lastX = mouse.x + parent.x map.lastY = mouse.y + parent.y map.pressX = mouse.x + parent.x map.pressY = mouse.y + parent.y + lastCoordinate = map.toCoordinate(Qt.point(mouse.x, mouse.y)) } onPositionChanged: { - if (map.state != "PointPopupMenu" || - Math.abs(map.pressX - parent.x- mouse.x ) > map.jitterThreshold || + if (Math.abs(map.pressX - parent.x- mouse.x ) > map.jitterThreshold || Math.abs(map.pressY - parent.y -mouse.y ) > map.jitterThreshold) { map.state = "" if (pressed) parent.radius = parent.center.distanceTo( @@ -330,7 +328,7 @@ Map { onPressAndHold:{ if (Math.abs(map.pressX - parent.x- mouse.x ) < map.jitterThreshold && Math.abs(map.pressY - parent.y - mouse.y ) < map.jitterThreshold) { - map.state = "PointPopupMenu" + showPointMenu(lastCoordinate); } } } @@ -578,62 +576,6 @@ Map { scaleTimer.restart() } - OwnControls.Menu { - id: routeMenu - horizontalOrientation: false - autoWidth: true - z: map.z + 4 - opacity: 0 - - width: 150 - x: 0 - y: 0 - - onClicked: { - switch (button) { - case "Delete": {//delete route - routeModel.reset() - routeInfoModel.update() - break; - } - } - map.state = "" - } - Component.onCompleted: { - addItem("Delete") - } - } - - OwnControls.Menu { - id: pointMenu - horizontalOrientation: false - autoWidth: true - z: map.z + 4 - opacity: 0 - - width: 150 - x: 0 - y: 0 - - onClicked: { - switch (button) { - case "Info": { - map.showGeocodeInfo() - break; - } - case "Delete": { - geocodeModel.reset() - break; - } - } - map.state = "" - } - Component.onCompleted: { - addItem("Info") - addItem("Delete") - } - } - Rectangle { id: infoLabel width: backgroundRect.width + 10 @@ -671,8 +613,6 @@ Map { anchors.fill: parent onPressed : { - map.resetState(); - map.state = "" map.lastX = mouse.x map.lastY = mouse.y map.pressX = mouse.x @@ -712,7 +652,6 @@ Map { if (Math.abs(map.pressX - mouse.x ) < map.jitterThreshold && Math.abs(map.pressY - mouse.y ) < map.jitterThreshold) { showMainMenu(lastCoordinate); - map.state = "" } } } @@ -874,21 +813,11 @@ Map { return dist } - // states of map - states: [ - State { - name: "RoutePopupMenu" - PropertyChanges { target: routeMenu; opacity: 1} - PropertyChanges { target: routeMenu; x: ((map.lastX + routeMenu.width > map.width) ? map.width - routeMenu.width : map.lastX)} - PropertyChanges { target: routeMenu; y: ((map.lastY + routeMenu.height > map.height - 40) ? map.height - routeMenu.height - 40 : map.lastY)} - }, - State { - name: "PointPopupMenu" - PropertyChanges { target: pointMenu; opacity: 1} - PropertyChanges { target: pointMenu; x: ((map.lastX + pointMenu.width > map.width) ? map.width - pointMenu.width : map.lastX)} - PropertyChanges { target: pointMenu; y: ((map.lastY + pointMenu.height > map.height - 40) ? map.height - pointMenu.height - 40 : map.lastY)} - } - ] + function clearRoute() { + routeModel.reset() + routeInfoModel.update() + } + //! [end] } //! [end] diff --git a/examples/location/mapviewer/mapviewer.qml b/examples/location/mapviewer/mapviewer.qml index e2b41611..1472b77f 100644 --- a/examples/location/mapviewer/mapviewer.qml +++ b/examples/location/mapviewer/mapviewer.qml @@ -293,9 +293,6 @@ ApplicationWindow { onShowGeocodeInfo:{\ showMessage(qsTr("Location"),geocodeMessage(),page);\ }\ - onResetState: {\ - page.state = "";\ - }\ onErrorChanged: {\ if (map.error != Map.NoError) {\ var title = qsTr("ProviderError");\ @@ -312,6 +309,12 @@ ApplicationWindow { onShowMarkerMenu: {\ markerPopupMenu.show(coordinate);\ }\ + onShowRouteMenu: {\ + itemPopupMenu.show("Route",coordinate);\ + }\ + onShowPointMenu: {\ + itemPopupMenu.show("Point",coordinate);\ + }\ }',page) map.plugin = plugin; map.zoomLevel = (map.maximumZoomLevel - map.minimumZoomLevel)/2 @@ -440,6 +443,39 @@ ApplicationWindow { } + ItemPopupMenu { + + id: itemPopupMenu + + function show(type,coordinate) { + stackView.pop(page) + itemPopupMenu.type = type + itemPopupMenu.update() + itemPopupMenu.popup() + } + + onItemClicked: { + stackView.pop(page) + switch (item) { + case "infoRoute": + //ignore till next commit + break; + case "deleteRoute": + map.clearRoute() + break; + case "infoPoint": + map.showGeocodeInfo() + break; + case "deletePoint": + map.geocodeModel.reset() + break; + default: + console.log("Unsupported operation") + } + } + + } + StackView { id: stackView diff --git a/examples/location/mapviewer/mapviewerwrapper.qrc b/examples/location/mapviewer/mapviewerwrapper.qrc index b5fcc9ac..5ee8d029 100644 --- a/examples/location/mapviewer/mapviewerwrapper.qrc +++ b/examples/location/mapviewer/mapviewerwrapper.qrc @@ -24,6 +24,7 @@ <file>ReverseGeocode.qml</file> <file>MapPopupMenu.qml</file> <file>MarkerPopupMenu.qml</file> + <file>ItemPopupMenu.qml</file> <file>Locale.qml</file> </qresource> </RCC> |