Warning, /libraries/kosmindoormap/src/app/SelectLocationSheet.qml is written in an unsupported language. File is not indexed.
0001 /*
0002 SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
0003
0004 SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006
0007 import QtQuick
0008 import QtQuick.Layouts
0009 import QtQuick.Controls as QQC2
0010 import org.kde.kirigami as Kirigami
0011 import org.kde.kpublictransport as PublicTransport
0012 import org.kde.kosmindoormap
0013 import org.kde.kosmindoormap.kpublictransport
0014
0015 Kirigami.OverlaySheet {
0016 id: root
0017 property point coordinate;
0018 property var publicTransportManager
0019
0020 signal coordinateSelected()
0021
0022 header: Kirigami.Heading {
0023 text: "Select Location"
0024 }
0025
0026 ColumnLayout {
0027 Kirigami.Heading {
0028 text: "Examples"
0029 level: 4
0030 }
0031
0032 ExampleLocationModel { id: exampleModel }
0033
0034 QQC2.ComboBox {
0035 id: exampleBox
0036 Layout.fillWidth: true
0037 model: exampleModel
0038 popup.z: 999 // workaround for ending up below the overlay sheet
0039 textRole: "label"
0040 onCurrentIndexChanged: {
0041 var obj = exampleModel.get(currentIndex);
0042 root.coordinate.y = obj.lat;
0043 root.coordinate.x = obj.lon;
0044 }
0045 }
0046
0047 Kirigami.Heading {
0048 text: "Coordinate"
0049 level: 4
0050 }
0051
0052 RowLayout {
0053 QQC2.TextField {
0054 id: coordField
0055 placeholderText: "<latitude>, <longitude>"
0056 Layout.fillWidth: true
0057 onEditingFinished: function() {
0058 parseCoordinate();
0059 }
0060 function parseCoordinate() {
0061 var c = coordField.text.match(/([\d\.-]+)[,;/ ]+([\d\.-]*)/);
0062 if (c) {
0063 root.coordinate.y = c[1];
0064 root.coordinate.x = c[2];
0065 }
0066 }
0067 }
0068 QQC2.ToolButton {
0069 icon.name: "edit-clear-symbolic"
0070 onClicked: function() {
0071 coordField.clear();
0072 coordField.parseCoordinate();
0073 }
0074 }
0075 QQC2.ToolButton {
0076 icon.name: "edit-paste-symbolic"
0077 onClicked: function() {
0078 coordField.clear();
0079 coordField.paste();
0080 coordField.parseCoordinate();
0081 }
0082 }
0083 }
0084
0085 Kirigami.Heading {
0086 text: "Name"
0087 level: 4
0088 }
0089
0090 QQC2.TextField {
0091 id: nameField
0092 placeholderText: "train station name"
0093 Layout.fillWidth: true
0094 onEditingFinished: function() {
0095 locationModel.request.name = nameField.text;
0096 locationModel.request.backends = [ "un_navitia", "de_db" ];
0097 locationModel.request.maximumResults = 10;
0098 locationModel.request.types = PublicTransport.Location.Stop;
0099 }
0100 }
0101 PublicTransport.LocationQueryModel {
0102 id: locationModel
0103 manager: root.publicTransportManager
0104 }
0105 ListView {
0106 id: nameSearchResultView
0107 Layout.fillWidth: true
0108 clip: true
0109 implicitHeight: contentHeight
0110 model: locationModel
0111 delegate: QQC2.ItemDelegate {
0112 width: ListView.view.width
0113 contentItem: Kirigami.TitleSubtitle {
0114 title: location.name
0115 }
0116 }
0117 onCurrentIndexChanged: function() {
0118 var loc = locationModel.data(locationModel.index(nameSearchResultView.currentIndex, 0), PublicTransport.LocationQueryModel.LocationRole);
0119 if (loc != undefined) {
0120 root.coordinate.x = loc.longitude;
0121 root.coordinate.y = loc.latitude;
0122 }
0123 }
0124 }
0125 }
0126
0127 footer: QQC2.Button {
0128 text: "Show"
0129 enabled: root.coordinate.x != 0.0 && root.coordinate.x != NaN && root.coordinate.y != 0.0 && root.coordinate != NaN
0130 onClicked: {
0131 console.log(root.coordinate);
0132 root.close();
0133 coordinateSelected();
0134 }
0135 }
0136 }