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.Dialog {
16 id: root
17 property point coordinate;
18 property var publicTransportManager
19
20 signal coordinateSelected()
21
22 title: i18nc("@title:dialog", "Select Location")
23
24 width: Math.min(applicationWindow().width, Kirigami.Units.gridUnit * 24)
25
26 leftPadding: Kirigami.Units.largeSpacing
27 topPadding: Kirigami.Units.largeSpacing
28 rightPadding: Kirigami.Units.largeSpacing
29 bottomPadding: Kirigami.Units.largeSpacing
30
31 contentItem: ColumnLayout {
32 Kirigami.Heading {
33 text: "Examples"
34 level: 4
35 }
36
37 ExampleLocationModel { id: exampleModel }
38
39 QQC2.ComboBox {
40 id: exampleBox
41 Layout.fillWidth: true
42 model: exampleModel
43 popup.z: 999 // workaround for ending up below the overlay sheet
44 textRole: "label"
45 onCurrentIndexChanged: {
46 var obj = exampleModel.get(currentIndex);
47 root.coordinate.y = obj.lat;
48 root.coordinate.x = obj.lon;
49 }
50 }
51
52 Kirigami.Heading {
53 text: "Coordinate"
54 level: 4
55 }
56
57 RowLayout {
58 QQC2.TextField {
59 id: coordField
60 placeholderText: "<latitude>, <longitude>"
61 Layout.fillWidth: true
62 onEditingFinished: function() {
63 parseCoordinate();
64 }
65 function parseCoordinate() {
66 var c = coordField.text.match(/([\d\.-]+)[,;/ ]+([\d\.-]*)/);
67 if (c) {
68 root.coordinate.y = c[1];
69 root.coordinate.x = c[2];
70 }
71 }
72 }
73 QQC2.ToolButton {
74 icon.name: "edit-clear-symbolic"
75 onClicked: function() {
76 coordField.clear();
77 coordField.parseCoordinate();
78 }
79 }
80 QQC2.ToolButton {
81 icon.name: "edit-paste-symbolic"
82 onClicked: function() {
83 coordField.clear();
84 coordField.paste();
85 coordField.parseCoordinate();
86 }
87 }
88 }
89
90 Kirigami.Heading {
91 text: "Name"
92 level: 4
93 }
94
95 QQC2.TextField {
96 id: nameField
97 placeholderText: "train station name"
98 Layout.fillWidth: true
99 onEditingFinished: function() {
100 locationModel.request.name = nameField.text;
101 locationModel.request.backends = [ "un_navitia", "de_db" ];
102 locationModel.request.maximumResults = 10;
103 locationModel.request.types = PublicTransport.Location.Stop;
104 }
105 }
106 PublicTransport.LocationQueryModel {
107 id: locationModel
108 manager: root.publicTransportManager
109 }
110 ListView {
111 id: nameSearchResultView
112 Layout.fillWidth: true
113 clip: true
114 implicitHeight: contentHeight
115 model: locationModel
116 delegate: QQC2.ItemDelegate {
117 width: ListView.view.width
118 contentItem: Kirigami.TitleSubtitle {
119 title: location.name
120 }
121 }
122 onCurrentIndexChanged: function() {
123 var loc = locationModel.data(locationModel.index(nameSearchResultView.currentIndex, 0), PublicTransport.LocationQueryModel.LocationRole);
124 if (loc != undefined) {
125 root.coordinate.x = loc.longitude;
126 root.coordinate.y = loc.latitude;
127 }
128 }
129 }
130 }
131
132 customFooterActions: [
133 Kirigami.Action {
134 text: "Show"
135 enabled: root.coordinate.x != 0.0 && root.coordinate.x != NaN && root.coordinate.y != 0.0 && root.coordinate != NaN
136 onTriggered: {
137 console.log(root.coordinate);
138 root.close();
139 coordinateSelected();
140 }
141 }
142 ]
143
144}
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 Fri Jul 26 2024 11:57:46 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.