KOSMIndoorMap

SelectLocationSheet.qml
1 /*
2  SPDX-FileCopyrightText: 2021 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 import QtQuick 2.12
8 import QtQuick.Layouts 1.1
9 import QtQuick.Controls 2.1 as QQC2
10 import Qt.labs.platform 1.0 as QPlatform
11 import org.kde.kirigami 2.0 as Kirigami
12 import org.kde.kpublictransport 1.0 as PublicTransport
13 import org.kde.kosmindoormap 1.0
14 import org.kde.kosmindoormap.kpublictransport 1.0
15 
16 Kirigami.OverlaySheet {
17  id: root
18  property point coordinate;
19  property var publicTransportManager
20 
21  signal coordinateSelected()
22 
23  header: Kirigami.Heading {
24  text: "Select Location"
25  }
26 
27  ColumnLayout {
28  Kirigami.Heading {
29  text: "Examples"
30  level: 4
31  }
32 
33  ExampleLocationModel { id: exampleModel }
34 
35  QQC2.ComboBox {
36  id: exampleBox
37  Layout.fillWidth: true
38  model: exampleModel
39  popup.z: 999 // workaround for ending up below the overlay sheet
40  textRole: "label"
41  onCurrentIndexChanged: {
42  var obj = exampleModel.get(currentIndex);
43  root.coordinate.y = obj.lat;
44  root.coordinate.x = obj.lon;
45  }
46  }
47 
48  Kirigami.Heading {
49  text: "Coordinate"
50  level: 4
51  }
52 
53  RowLayout {
54  QQC2.TextField {
55  id: coordField
56  placeholderText: "<latitude>, <longitude>"
57  Layout.fillWidth: true
58  onEditingFinished: function() {
59  parseCoordinate();
60  }
61  function parseCoordinate() {
62  var c = coordField.text.match(/([\d\.-]+)[,;/ ]+([\d\.-]*)/);
63  if (c) {
64  root.coordinate.y = c[1];
65  root.coordinate.x = c[2];
66  }
67  }
68  }
69  QQC2.ToolButton {
70  icon.name: "edit-clear-symbolic"
71  onClicked: function() {
72  coordField.clear();
73  coordField.parseCoordinate();
74  }
75  }
76  QQC2.ToolButton {
77  icon.name: "edit-paste-symbolic"
78  onClicked: function() {
79  coordField.clear();
80  coordField.paste();
81  coordField.parseCoordinate();
82  }
83  }
84  }
85 
86  Kirigami.Heading {
87  text: "Name"
88  level: 4
89  }
90 
91  QQC2.TextField {
92  id: nameField
93  placeholderText: "train station name"
94  Layout.fillWidth: true
95  onEditingFinished: function() {
96  locationModel.request.name = nameField.text;
97  locationModel.request.backends = [ "un_navitia", "de_db" ];
98  locationModel.request.maximumResults = 10;
99  locationModel.request.types = PublicTransport.Location.Stop;
100  }
101  }
102  PublicTransport.LocationQueryModel {
103  id: locationModel
104  manager: root.publicTransportManager
105  }
106  ListView {
107  id: nameSearchResultView
108  Layout.fillWidth: true
109  clip: true
110  implicitHeight: contentHeight
111  model: locationModel
112  delegate: Kirigami.BasicListItem {
113  label: location.name
114  }
115 
116  onCurrentIndexChanged: function() {
117  var loc = locationModel.data(locationModel.index(nameSearchResultView.currentIndex, 0), PublicTransport.LocationQueryModel.LocationRole);
118  if (loc != undefined) {
119  root.coordinate.x = loc.longitude;
120  root.coordinate.y = loc.latitude;
121  }
122  }
123  }
124  }
125 
126  footer: QQC2.Button {
127  text: "Show"
128  enabled: root.coordinate.x != 0.0 && root.coordinate.x != NaN && root.coordinate.y != 0.0 && root.coordinate != NaN
129  onClicked: {
130  console.log(root.coordinate);
131  root.sheetOpen = false;
132  coordinateSelected();
133  }
134  }
135 }
QVariant location(const QVariant &res)
QStringView level(QStringView ifopt)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Oct 25 2021 23:04:00 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.