diff options
-rw-r--r-- | examples/location/mapviewer/RouteList.qml | 118 | ||||
-rw-r--r-- | examples/location/mapviewer/RouteListDelegate.qml | 82 | ||||
-rw-r--r-- | examples/location/mapviewer/RouteListHeader.qml | 86 | ||||
-rw-r--r-- | examples/location/mapviewer/content/map/MapComponent.qml | 166 | ||||
-rw-r--r-- | examples/location/mapviewer/mapviewer.qml | 20 | ||||
-rw-r--r-- | examples/location/mapviewer/mapviewerwrapper.qrc | 3 |
6 files changed, 308 insertions, 167 deletions
diff --git a/examples/location/mapviewer/RouteList.qml b/examples/location/mapviewer/RouteList.qml new file mode 100644 index 00000000..ff32d747 --- /dev/null +++ b/examples/location/mapviewer/RouteList.qml @@ -0,0 +1,118 @@ +/**************************************************************************** +** +** 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 + +ListView { + property variant routeModel + property string totalTravelTime + property string totalDistance + + signal closeForm() + + id: listView + interactive: true + + model: ListModel { id: routeList } + + header: RouteListHeader {} + + delegate: RouteListDelegate{ + routeIndex.text: index + 1 + routeInstruction.text: instruction + routeDistance.text: distance + } + + footer: Button { + anchors.horizontalCenter: parent.horizontalCenter + text: qsTr("Close") + onClicked: { + closeForm() + } + } + + Component.onCompleted: { + routeList.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": formatDistance(routeModel.get(0).segments[i].maneuver.distanceToNextInstruction) + }); + } + } + totalTravelTime = routeModel.count == 0 ? "" : formatTime(routeModel.get(0).travelTime) + totalDistance = routeModel.count == 0 ? "" : formatDistance(routeModel.get(0).distance) + } + + function formatTime(sec){ + var value = sec + var seconds = value % 60 + value /= 60 + value = (value > 1) ? Math.round(value) : 0 + var minutes = value % 60 + value /= 60 + value = (value > 1) ? Math.round(value) : 0 + var hours = value + if (hours > 0) value = hours + "h:"+ minutes + "m" + else value = minutes + "min" + return value + } + + function formatDistance(meters) + { + var dist = Math.round(meters) + if (dist > 1000 ){ + if (dist > 100000){ + dist = Math.round(dist / 1000) + } + else{ + dist = Math.round(dist / 100) + dist = dist / 10 + } + dist = dist + " km" + } + else{ + dist = dist + " m" + } + return dist + } +} diff --git a/examples/location/mapviewer/RouteListDelegate.qml b/examples/location/mapviewer/RouteListDelegate.qml new file mode 100644 index 00000000..5b68269a --- /dev/null +++ b/examples/location/mapviewer/RouteListDelegate.qml @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** 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 +import QtQuick.Layouts 1.1 + +Item { + id: root + width: parent.width + height: indexLabel.height * 2 + + property bool checked: false + property alias routeInstruction: instructionLabel + property alias routeDistance: distanceLabel + property alias routeIndex: indexLabel + + RowLayout { + spacing: 10 + anchors.left: parent.left + anchors.leftMargin: 30 + anchors.verticalCenter: parent.verticalCenter + Label { + id: indexLabel + } + Label { + id: instructionLabel + wrapMode: Text.Wrap + } + Label { + id: distanceLabel + } + } + + Rectangle { + anchors.left: parent.left + anchors.right: parent.right + anchors.margins: 15 + height: 1 + color: "#f36910" + } +} + + + diff --git a/examples/location/mapviewer/RouteListHeader.qml b/examples/location/mapviewer/RouteListHeader.qml new file mode 100644 index 00000000..96e065e0 --- /dev/null +++ b/examples/location/mapviewer/RouteListHeader.qml @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** 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 + +Item { + + width: parent.width + height: tabTitle.height * 3.0 + property alias travelTime: travelTimeLabel + property alias distance: distanceLabel + + Rectangle { + id: tabRectangle + y: tabTitle.height + height: tabTitle.height * 2 - 1 + color: "#f36910" + anchors.left: parent.left + anchors.right: parent.right + + Label { + id: tabTitle + color: "#ffffff" + text: qsTr("Route Information") + anchors.verticalCenter: parent.verticalCenter + anchors.horizontalCenter: parent.horizontalCenter + } + + Label { + id: travelTimeLabel + text: totalTravelTime + color: "#ffffff" + font.bold: true + anchors.left: parent.left + anchors.verticalCenter: parent.verticalCenter + } + + Label { + id: distanceLabel + text: totalDistance + color: "#ffffff" + font.bold: true + anchors.right: parent.right + anchors.verticalCenter: parent.verticalCenter + } + + } +} diff --git a/examples/location/mapviewer/content/map/MapComponent.qml b/examples/location/mapviewer/content/map/MapComponent.qml index e559ba3a..9db45134 100644 --- a/examples/location/mapviewer/content/map/MapComponent.qml +++ b/examples/location/mapviewer/content/map/MapComponent.qml @@ -67,6 +67,7 @@ Map { signal showMarkerMenu(variant coordinate) signal showRouteMenu(variant coordinate) signal showPointMenu(variant coordinate) + signal showRouteList() property int lastX : -1 property int lastY : -1 @@ -183,24 +184,21 @@ Map { if (status == RouteModel.Ready) { switch (count) { case 0: - clearAll() // technically not an error + // technically not an error map.routeError() break case 1: - routeInfoModel.update() + showRouteList() break } } else if (status == RouteModel.Error) { - clearAll() map.routeError() } } //! [routemodel1] //! [routemodel2] - function clearAll() { - routeInfoModel.update() - } + //! [routemodel2] //! [routemodel3] } @@ -337,97 +335,6 @@ Map { } //! [pointdel1] -//! [routeinfodel0] - Component { - id: routeInfoDelegate - Row { - spacing: 10 -//! [routeinfodel0] - Text { - id: indexText - text: index + 1 - color: "#242424" - font.bold: true - font.pixelSize: 14 - } -//! [routeinfodel1] - Text { - id: instructionText - text: instruction - color: "#242424" - wrapMode: Text.Wrap -//! [routeinfodel1] - width: textArea.width - indexText.width - distanceText.width - spacing*4 -//! [routeinfodel2] - font.pixelSize: 14 - } - Text { - id: distanceText - text: distance - color: "#242424" - font.bold: true - font.pixelSize: 14 - } - } - } -//! [routeinfodel2] - - Component{ - id: routeInfoHeader - Item { - width: textArea.width - height: travelTime.height + line.anchors.topMargin + line.height - Text { - id: travelTime - text: routeInfoModel.travelTime - color: "#242424" - font.bold: true - font.pixelSize: 14 - anchors.left: parent.left - } - Text { - id: distance - text: routeInfoModel.distance - color: "#242424" - font.bold: true - font.pixelSize: 14 - anchors.right: parent.right - } - Rectangle { - id: line - color: "#242424" - width: parent.width - height: 2 - anchors.left: parent.left - anchors.topMargin: 1 - anchors.top: distance.bottom - } - } - } - -//! [routeinfomodel] - ListModel { - id: routeInfoModel - - property string travelTime - property string distance - - function update() { - clear() - if (routeModel.count > 0) { - for (var i = 0; i < routeModel.get(0).segments.length; i++) { - append({ - "instruction": routeModel.get(0).segments[i].maneuver.instructionText, - "distance": formatDistance(routeModel.get(0).segments[i].maneuver.distanceToNextInstruction) - }); - } - } - travelTime = routeModel.count == 0 ? "" : formatTime(routeModel.get(0).travelTime) - distance = routeModel.count == 0 ? "" : formatDistance(routeModel.get(0).distance) - } - } -//! [routeinfomodel] - //! [routeview] MapItemView { model: routeModel @@ -443,66 +350,6 @@ Map { } //! [geocodeview] - Item { - id: infoTab - parent: scale.parent - z: map.z + 2 - height: parent.height - 180 - width: parent.width - x: -5 - infoRect.width - y: 60 - visible: (routeInfoModel.count > 0) - Image { - id: catchImage - source: "../../resources/catch.png" - anchors.verticalCenter: parent.verticalCenter - anchors.right: parent.right - MouseArea { - anchors.fill: parent - onClicked: { - if (infoTab.x == -5) infoTab.x -= infoRect.width - else infoTab.x = -5 - map.state = "" - } - } - } - - Behavior on x { - PropertyAnimation { properties: "x"; duration: 300; easing.type: Easing.InOutQuad } - } - - Rectangle { - id: infoRect - width: parent.width - catchImage.sourceSize.width - height: parent.height - color: "#ECECEC" - opacity: 1 - radius: 5 - MouseArea { - anchors.fill: parent - hoverEnabled: false - } - Item { - id: textArea - anchors.left: parent.left - anchors.leftMargin: 10 - anchors.top: parent.top - anchors.topMargin: 10 - width: parent.width -15 - height: parent.height - 20 - ListView { - id: routeInfoView - model: routeInfoModel - delegate: routeInfoDelegate - header: routeInfoHeader - anchors.fill: parent - clip: true - } - } - } - } - - Item {//scale id: scale parent: zoomSlider.parent @@ -813,11 +660,6 @@ Map { return dist } - function clearRoute() { - routeModel.reset() - routeInfoModel.update() - } - //! [end] } //! [end] diff --git a/examples/location/mapviewer/mapviewer.qml b/examples/location/mapviewer/mapviewer.qml index 1472b77f..64de94be 100644 --- a/examples/location/mapviewer/mapviewer.qml +++ b/examples/location/mapviewer/mapviewer.qml @@ -188,7 +188,6 @@ ApplicationWindow { map.routeModel.update(); // center the map on the start coord map.center = startCoordinate; - stackView.pop(page); //! [routerequest1] } @@ -222,6 +221,14 @@ ApplicationWindow { stackView.pop(page) } + function showRouteListPage() { + stackView.push({ item: Qt.resolvedUrl("RouteList.qml") , + properties: { + "routeModel" : map.routeModel + }}) + stackView.currentItem.closeForm.connect(closeForm) + } + function geocodeMessage(){ var street, district, city, county, state, countryCode, country, postalCode, latitude, longitude, text latitude = Math.round(map.geocodeModel.get(0).coordinate.latitude * 10000) / 10000 @@ -315,6 +322,9 @@ ApplicationWindow { onShowPointMenu: {\ itemPopupMenu.show("Point",coordinate);\ }\ + onShowRouteList: {\ + showRouteListPage(); + }\ }',page) map.plugin = plugin; map.zoomLevel = (map.maximumZoomLevel - map.minimumZoomLevel)/2 @@ -457,13 +467,13 @@ ApplicationWindow { onItemClicked: { stackView.pop(page) switch (item) { - case "infoRoute": - //ignore till next commit + case "showRouteInfo": + showRouteListPage() break; case "deleteRoute": - map.clearRoute() + map.routeModel.reset(); break; - case "infoPoint": + case "showPointInfo": map.showGeocodeInfo() break; case "deletePoint": diff --git a/examples/location/mapviewer/mapviewerwrapper.qrc b/examples/location/mapviewer/mapviewerwrapper.qrc index 5ee8d029..aceba310 100644 --- a/examples/location/mapviewer/mapviewerwrapper.qrc +++ b/examples/location/mapviewer/mapviewerwrapper.qrc @@ -26,5 +26,8 @@ <file>MarkerPopupMenu.qml</file> <file>ItemPopupMenu.qml</file> <file>Locale.qml</file> + <file>RouteList.qml</file> + <file>RouteListDelegate.qml</file> + <file>RouteListHeader.qml</file> </qresource> </RCC> |