KOSMIndoorMap

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

KDE's Doxygen guidelines are available online.