Warning, /libraries/kpublictransport/tests/locationquery.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 SPDX-FileCopyrightText: 2018 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 import QtCore 0008 import QtQuick 0009 import QtQuick.Layouts 0010 import QtQuick.Controls as QQC2 0011 import QtQuick.Dialogs as Dialogs 0012 import org.kde.kirigami as Kirigami 0013 import org.kde.kpublictransport 0014 import org.kde.example 0015 0016 Kirigami.ApplicationWindow { 0017 title: "Location Query" 0018 0019 width: 540 0020 height: 720 0021 0022 pageStack.initialPage: locationQueryPage 0023 0024 Manager { 0025 id: ptMgr 0026 } 0027 Settings { 0028 id: settings 0029 property alias allowInsecureBackends: ptMgr.allowInsecureBackends 0030 property alias enabledBackends: ptMgr.enabledBackends 0031 property alias disabledBackends: ptMgr.disabledBackends 0032 } 0033 0034 LocationQueryModel { 0035 id: locationModel 0036 manager: ptMgr 0037 } 0038 0039 TestLocationsModel { id: exampleModel } 0040 AttributionSheet { 0041 id: aboutSheet 0042 attributions: locationModel.attributions 0043 } 0044 0045 globalDrawer: Kirigami.GlobalDrawer { 0046 actions: [ 0047 Kirigami.Action { 0048 text: "Save..." 0049 icon.name: "document-save" 0050 onTriggered: fileDialog.open(); 0051 }, 0052 Kirigami.Action { 0053 icon.name: "help-about-symbolic" 0054 text: "Data Sources" 0055 enabled: locationModel.attributions.length > 0 0056 onTriggered: aboutSheet.open(); 0057 }, 0058 Kirigami.Action { 0059 icon.name: "settings-configure" 0060 text: "Backends" 0061 onTriggered: pageStack.push(backendPage) 0062 } 0063 ] 0064 } 0065 0066 Dialogs.FileDialog { 0067 id: fileDialog 0068 title: "Save Departure Data" 0069 fileMode: Dialogs.FileDialog.SaveFile 0070 nameFilters: ["JSON files (*.json)"] 0071 onAccepted: ExampleUtil.saveTo(locationModel, fileDialog.selectedFile); 0072 } 0073 0074 function vehicleTypeIcon(type) 0075 { 0076 var s = ""; 0077 if (type & RentalVehicle.Bicycle) 0078 s += "🚲"; 0079 if (type & RentalVehicle.ElectricKickScooter) 0080 s += "🛴"; 0081 if (type & RentalVehicle.ElectricMoped) 0082 s += "🛵"; 0083 if (type & RentalVehicle.Car) 0084 s += "🚗"; 0085 if (type & RentalVehicle.Pedelec) 0086 s += "⚡🚲"; 0087 return s ? s : "🚲"; 0088 } 0089 0090 Component { 0091 id: locationDelegate 0092 Kirigami.SwipeListItem { 0093 actions: [ 0094 Kirigami.Action { 0095 icon.name: "map-globe" 0096 text: "View on OSM" 0097 onTriggered: Qt.openUrlExternally("https://www.openstreetmap.org/#map=18/" + location.latitude + "/" + location.longitude) 0098 }, 0099 Kirigami.Action { 0100 icon.name: "map-symbolic" 0101 text: "Indoor Map" 0102 onTriggered: pageStack.push(indoorMapPage, {coordinate: Qt.point(location.longitude, location.latitude)}) 0103 } 0104 ] 0105 contentItem: ColumnLayout { 0106 id: delegateLayout 0107 Layout.fillWidth: true 0108 QQC2.Label { 0109 text: { 0110 switch (location.type) { 0111 case Location.Stop: return "🚏 " + location.name; 0112 case Location.RentedVehicleStation: 0113 return '🚏' + vehicleTypeIcon(location.rentalVehicleStation.supportedVehicleTypes) + ' ' + location.name; 0114 case Location.RentedVehicle: 0115 return vehicleTypeIcon(location.rentalVehicle.type) + ' ' + location.name; 0116 case Location.Equipment: 0117 switch (location.equipment.type) { 0118 case Equipment.Elevator: 0119 return '🛗 ' + location.name; 0120 case Equipment.Escalator: 0121 return '↗ ' + location.name; 0122 default: 0123 return '? ' + location.name; 0124 } 0125 case Location.CarpoolPickupDropoff: 0126 return '🚘 ' + location.name; 0127 case Location.Place: return location.name; 0128 } 0129 } 0130 color: { 0131 if (location.type == Location.Equipment) { 0132 switch (location.equipment.disruptionEffect) { 0133 case Disruption.NormalService: 0134 return Kirigami.Theme.positiveTextColor; 0135 case Disruption.NoService: 0136 return Kirigami.Theme.negativeTextColor; 0137 } 0138 } 0139 return Kirigami.Theme.textColor; 0140 } 0141 } 0142 QQC2.Label { 0143 text: location.streetAddress 0144 visible: location.streetAddress.length > 0 0145 } 0146 QQC2.Label { 0147 text: "ZIP: " + location.postalCode + " City: " + location.locality 0148 visible: location.postalCode.length > 0 || location.locality.length > 0 0149 } 0150 QQC2.Label { 0151 text: "Region: " + location.region + " Country: " + location.country 0152 visible: location.region.length > 0 || location.country.length > 0 0153 } 0154 QQC2.Label { 0155 text: "Lat: " + location.latitude + " Lon: " + location.longitude 0156 } 0157 QQC2.Label { 0158 text: location.rentalVehicleStation.network.name + " (" + location.rentalVehicleStation.availableVehicles 0159 + "/" + location.rentalVehicleStation.capacity + ")" 0160 visible: location.rentalVehicleStation.isValid 0161 } 0162 QQC2.Label { 0163 text: location.equipment ? location.equipment.notes.join("<br/>") : '' 0164 visible: text != '' 0165 font.italic: true 0166 textFormat: Text.RichText 0167 } 0168 QQC2.Label { 0169 text: "Identifiers: " + ExampleUtil.locationIds(location) 0170 } 0171 } 0172 } 0173 } 0174 0175 Component { 0176 id: backendPage 0177 BackendPage { 0178 publicTransportManager: ptMgr 0179 } 0180 } 0181 0182 Component { 0183 id: indoorMapPage 0184 IndoorMapPage {} 0185 } 0186 0187 Component { 0188 id: locationQueryPage 0189 Kirigami.Page { 0190 Settings { 0191 id: settings 0192 property alias singleBackend: backendBox.checked 0193 property alias backend: backendSelector.currentIndex 0194 property alias maxResults: maxResults.text 0195 property alias maxDistance: maxDist.text 0196 property alias includeStops: includeStops.checked 0197 property alias includeRentals: includeRentals.checked 0198 property alias includeEquipment: includeEquipment.checked 0199 } 0200 0201 ColumnLayout { 0202 anchors.fill: parent 0203 0204 QQC2.CheckBox { 0205 text: "Allow insecure backends" 0206 checked: ptMgr.allowInsecureBackends 0207 onToggled: ptMgr.allowInsecureBackends = checked 0208 } 0209 0210 RowLayout { 0211 QQC2.CheckBox { 0212 id: backendBox 0213 text: "Select Backend:" 0214 } 0215 QQC2.ComboBox { 0216 id: backendSelector 0217 Layout.fillWidth: true 0218 textRole: "identifier" 0219 model: BackendModel { 0220 manager: ptMgr 0221 } 0222 enabled: backendBox.checked 0223 } 0224 } 0225 0226 RowLayout { 0227 QQC2.Label { text: "Results:" } 0228 QQC2.TextField { 0229 id: maxResults 0230 text: "10" 0231 } 0232 QQC2.Label { text: "Distance:" } 0233 QQC2.TextField { 0234 id: maxDist 0235 text: "1000" 0236 } 0237 } 0238 0239 RowLayout { 0240 QQC2.CheckBox { 0241 id: includeStops 0242 checked: true 0243 text: "Public Transport Stops" 0244 } 0245 QQC2.CheckBox { 0246 id: includeRentals 0247 checked: true 0248 text: "Rental Vehicles" 0249 } 0250 QQC2.CheckBox { 0251 id: includeEquipment 0252 checked: true 0253 text: "Elevators" 0254 } 0255 } 0256 0257 QQC2.ComboBox { 0258 id: exampleSelector 0259 Layout.fillWidth: true 0260 model: exampleModel 0261 textRole: "label" 0262 onCurrentIndexChanged: { 0263 var obj = exampleModel.get(currentIndex); 0264 nameQuery.text = obj.name == "" ? obj.label : obj.name; 0265 latQuery.text = obj.lat; 0266 lonQuery.text = obj.lon; 0267 } 0268 } 0269 0270 RowLayout { 0271 Layout.fillWidth: true 0272 QQC2.TextField { 0273 Layout.fillWidth: true 0274 id: nameQuery 0275 } 0276 QQC2.Button { 0277 text: "Query" 0278 onClicked: { 0279 locationModel.request.latitude = NaN; 0280 locationModel.request.longitude = NaN; 0281 locationModel.request.name = nameQuery.text; 0282 locationModel.request.backends = backendBox.checked ? [ backendSelector.currentText ] : []; 0283 locationModel.request.maximumResults = maxResults.text; 0284 locationModel.request.maximumDistance = maxDist.text; 0285 locationModel.request.types = (includeStops.checked ? Location.Stop : Location.Place) 0286 | (includeRentals.checked ? (Location.RentedVehicleStation | Location.RentedVehicle) : Location.Place) 0287 | (includeEquipment.checked ? Location.Equipment : Location.Place); 0288 } 0289 } 0290 } 0291 0292 RowLayout { 0293 Layout.fillWidth: true 0294 QQC2.TextField { 0295 id: latQuery 0296 } 0297 QQC2.TextField { 0298 id: lonQuery 0299 } 0300 QQC2.Button { 0301 text: "Query" 0302 onClicked: { 0303 locationModel.request.latitude = latQuery.text; 0304 locationModel.request.longitude = lonQuery.text; 0305 locationModel.request.name = ""; 0306 locationModel.request.backends = backendBox.checked ? [ backendSelector.currentText ] : []; 0307 locationModel.request.maximumResults = maxResults.text; 0308 locationModel.request.maximumDistance = maxDist.text; 0309 locationModel.request.types = (includeStops.checked ? Location.Stop : Location.Place) 0310 | (includeRentals.checked ? (Location.RentedVehicleStation | Location.RentedVehicle) : Location.Place) 0311 | (includeEquipment.checked ? Location.Equipment : Location.Place); 0312 } 0313 } 0314 } 0315 0316 ListView { 0317 Layout.fillHeight: true 0318 Layout.fillWidth: true 0319 model: locationModel 0320 clip: true 0321 delegate: locationDelegate 0322 0323 QQC2.BusyIndicator { 0324 anchors.centerIn: parent 0325 running: locationModel.loading 0326 } 0327 0328 QQC2.Label { 0329 anchors.centerIn: parent 0330 width: parent.width 0331 text: locationModel.errorMessage 0332 color: Kirigami.Theme.negativeTextColor 0333 wrapMode: Text.Wrap 0334 } 0335 } 0336 0337 } 0338 } 0339 } 0340 }