Warning, /libraries/kpublictransport/tests/departurequery.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: "Departure Query"
0018
0019 width: 540
0020 height: 800
0021
0022 pageStack.initialPage: departureQueryPage
0023
0024 globalDrawer: Kirigami.GlobalDrawer {
0025 actions: [
0026 Kirigami.Action {
0027 text: "Save..."
0028 icon.name: "document-save"
0029 onTriggered: fileDialog.open();
0030 },
0031 Kirigami.Action {
0032 icon.name: "help-about-symbolic"
0033 text: "Data Sources"
0034 enabled: departureModel.attributions.length > 0
0035 onTriggered: aboutSheet.open();
0036 },
0037 Kirigami.Action {
0038 icon.name: "settings-configure"
0039 text: "Backends"
0040 onTriggered: pageStack.push(backendPage)
0041 }
0042 ]
0043 }
0044
0045 Dialogs.FileDialog {
0046 id: fileDialog
0047 title: "Save Departure Data"
0048 fileMode: Dialog.FileDialog.SaveFile
0049 nameFilters: ["JSON files (*.json)"]
0050 onAccepted: ExampleUtil.saveTo(departureModel, fileDialog.selectedFile);
0051 }
0052
0053 TestLocationsModel { id: exampleModel }
0054 AttributionSheet {
0055 id: aboutSheet
0056 attributions: departureModel.attributions
0057 }
0058 LocationDetailsSheet { id: locationDetailsSheet }
0059
0060 Manager {
0061 id: ptMgr;
0062 }
0063
0064 Settings {
0065 id: settings
0066 property alias allowInsecureBackends: ptMgr.allowInsecureBackends
0067 property alias enabledBackends: ptMgr.enabledBackends
0068 property alias disabledBackends: ptMgr.disabledBackends
0069 }
0070
0071 StopoverQueryModel {
0072 id: departureModel
0073 manager: ptMgr
0074 }
0075
0076 Component {
0077 id: vehicleLayoutPage
0078 VehicleLayoutPage {
0079 publicTransportManager: ptMgr
0080 }
0081 }
0082
0083 Component {
0084 id: indoorMapPage
0085 IndoorMapPage {}
0086 }
0087
0088 Component {
0089 id: departureDelegate
0090 QQC2.ItemDelegate {
0091 enabled: departure.disruptionEffect != Disruption.NoService
0092 highlighted: false
0093 width: ListView.view.width
0094 contentItem: RowLayout {
0095 id: delegateLayout
0096
0097 Kirigami.Icon {
0098 id: icon
0099 source: departure.route.line.hasLogo ? departure.route.line.logo : departure.route.line.modeLogo
0100 width: height
0101 height: Kirigami.Units.iconSizes.large
0102 visible: source != ""
0103 }
0104
0105 Rectangle {
0106 id: colorBar
0107 width: Kirigami.Units.largeSpacing
0108 color: departure.route.line.hasColor ? departure.route.line.color : "transparent"
0109 Layout.fillHeight: true
0110 visible: icon.source == ""
0111 }
0112
0113 QQC2.Label {
0114 text: {
0115 switch (departure.route.line.mode) {
0116 case Line.Air: return "✈️";
0117 case Line.Boat: return "🛥️";
0118 case Line.Bus: return "🚍";
0119 case Line.BusRapidTransit: return "🚌";
0120 case Line.Coach: return "🚌";
0121 case Line.Ferry: return "⛴️";
0122 case Line.Funicular: return "🚞";
0123 case Line.LocalTrain: return "🚆";
0124 case Line.LongDistanceTrain: return "🚄";
0125 case Line.Metro: return "🚇";
0126 case Line.RailShuttle: return "🚅";
0127 case Line.RapidTransit: return "🚊";
0128 case Line.Shuttle: return "🚐";
0129 case Line.Taxi: return "🚕";
0130 case Line.Train: return "🚆";
0131 case Line.Tramway: return "🚈";
0132 case Line.RideShare: return "🚗";
0133 default: return "?";
0134 }
0135 }
0136 font.pointSize: Kirigami.Theme.defaultFont.pointSize * 2
0137 visible: icon.source == ""
0138 }
0139
0140 ColumnLayout {
0141 Layout.fillWidth: true
0142 QQC2.Label {
0143 Layout.fillWidth: true
0144 text: {
0145 if (departure.route.name !== "") {
0146 return departure.route.line.modeString + " " + departure.route.line.name + " (" + departure.route.name
0147 + ") to <a href=\"#dest\">" + departure.route.direction + "</a>"
0148 }
0149 return departure.route.line.modeString + " " + departure.route.line.name
0150 + " to <a href=\"#dest\">" + departure.route.direction + "</a>";
0151 }
0152 onLinkActivated: {
0153 locationDetailsSheet.location = departure.route.destination;
0154 locationDetailsSheet.open();
0155 }
0156 }
0157 RowLayout {
0158 QQC2.Label {
0159 text: "Arrival: " + departure.scheduledArrivalTime.toTimeString()
0160 }
0161 QQC2.Label {
0162 text: (departure.arrivalDelay >= 0 ? "+" : "") + departure.arrivalDelay
0163 color: departure.arrivalDelay > 1 ? Kirigami.Theme.negativeTextColor : Kirigami.Theme.positiveTextColor
0164 visible: departure.hasExpectedArrivalTime
0165 }
0166 QQC2.Label {
0167 text: "Departure: " + departure.scheduledDepartureTime.toTimeString()
0168 }
0169 QQC2.Label {
0170 text: (departure.departureDelay >= 0 ? "+" : "") + departure.departureDelay
0171 color: departure.departureDelay > 1 ? Kirigami.Theme.negativeTextColor : Kirigami.Theme.positiveTextColor
0172 visible: departure.hasExpectedDepartureTime
0173 }
0174 QQC2.Label {
0175 text: "<a href=\"#layout\">vehicle</a>"
0176 visible: departure.route.line.mode == Line.LongDistanceTrain || departure.route.line.mode == Line.Train || departure.route.name !== ""
0177 onLinkActivated: applicationWindow().pageStack.push(vehicleLayoutPage, {"departure": departure });
0178 Layout.fillWidth: true
0179 horizontalAlignment: Text.Right
0180 }
0181 }
0182 RowLayout {
0183 QQC2.Label {
0184 text: "From: <a href=\"#from\">" + departure.stopPoint.name + "</a>"
0185 onLinkActivated: {
0186 locationDetailsSheet.location = departure.stopPoint;
0187 locationDetailsSheet.open();
0188 }
0189 }
0190 QQC2.Label {
0191 visible: departure.scheduledPlatform != ""
0192 text: "Platform: " + departure.scheduledPlatform + (platformChange.visible ? " -> " : "")
0193 color: (!platformChange.visible && departure.hasExpectedPlatform) ? Kirigami.Theme.positiveTextColor : Kirigami.Theme.textColor
0194 }
0195 QQC2.Label {
0196 id: platformChange
0197 text: departure.expectedPlatform
0198 visible: departure.hasExpectedPlatform && departure.scheduledPlatform != departure.expectedPlatform
0199 color: Kirigami.Theme.negativeTextColor
0200 }
0201 }
0202 RowLayout {
0203 visible: departure.loadInformation.length > 0
0204 QQC2.Label {
0205 text: "Load: ";
0206 }
0207 Repeater {
0208 model: departure.loadInformation
0209 RowLayout {
0210 QQC2.Label {
0211 text: {
0212 switch (modelData.load) {
0213 case Load.Low: return "Low";
0214 case Load.Medium: return "Medium";
0215 case Load.High: return "High";
0216 case Load.Full: return "Full";
0217 default: return "?"
0218 }
0219 }
0220 color: {
0221 switch (modelData.load) {
0222 case Load.Low: return Kirigami.Theme.positiveTextColor;
0223 case Load.Medium: return Kirigami.Theme.neutralTextColor;
0224 case Load.High:
0225 case Load.Full:
0226 return Kirigami.Theme.negativeTextColor;
0227 default:
0228 return Kirigami.Theme.textColor;
0229 }
0230 }
0231 }
0232 QQC2.Label {
0233 text: "(class " + modelData.seatingClass + ")"
0234 visible: modelData.seatingClass != ""
0235 }
0236 }
0237 }
0238 }
0239 QQC2.Label {
0240 text: departure.notes.join("<br/>")
0241 visible: departure.notes.length > 0
0242 font.italic: true
0243 textFormat: Text.RichText
0244 }
0245 }
0246 }
0247 }
0248 }
0249
0250 Component {
0251 id: backendPage
0252 BackendPage {
0253 publicTransportManager: ptMgr
0254 }
0255 }
0256
0257 Component {
0258 id: departureQueryPage
0259 Kirigami.Page {
0260 Settings {
0261 id: settings
0262 property alias queryArrivals: arrivalBox.checked
0263 property alias singleBackend: backendBox.checked
0264 property alias backend: backendSelector.currentIndex
0265 property alias maxResults: maxResults.text
0266 }
0267
0268 ColumnLayout {
0269 anchors.fill: parent
0270
0271 QQC2.CheckBox {
0272 id: arrivalBox
0273 text: checked ? "Arrival" : "Departure"
0274 }
0275
0276 QQC2.CheckBox {
0277 text: "Allow insecure backends"
0278 checked: ptMgr.allowInsecureBackends
0279 onToggled: ptMgr.allowInsecureBackends = checked
0280 }
0281
0282 RowLayout {
0283 QQC2.CheckBox {
0284 id: backendBox
0285 text: "Select Backend:"
0286 }
0287 QQC2.ComboBox {
0288 id: backendSelector
0289 Layout.fillWidth: true
0290 textRole: "identifier"
0291 model: BackendModel {
0292 manager: ptMgr
0293 }
0294 enabled: backendBox.checked
0295 }
0296 }
0297 RowLayout {
0298 QQC2.Label { text: "Results:" }
0299 QQC2.TextField {
0300 id: maxResults
0301 text: "10"
0302 }
0303 }
0304
0305 QQC2.ComboBox {
0306 id: exampleSelector
0307 Layout.fillWidth: true
0308 model: exampleModel
0309 textRole: "label"
0310 onCurrentIndexChanged: {
0311 var obj = exampleModel.get(currentIndex);
0312 nameQuery.text = obj.name == "" ? obj.label : obj.name;
0313 lonQuery.text = obj.lon;
0314 latQuery.text = obj.lat;
0315 }
0316 }
0317
0318 RowLayout {
0319 Layout.fillWidth: true
0320 QQC2.TextField {
0321 Layout.fillWidth: true
0322 id: nameQuery
0323 }
0324 QQC2.TextField {
0325 id: lonQuery
0326 Layout.preferredWidth: 100
0327 }
0328 QQC2.TextField {
0329 id: latQuery
0330 Layout.preferredWidth: 100
0331 }
0332 }
0333
0334 QQC2.ComboBox {
0335 id: lineModeSelector
0336 Layout.fillWidth: true
0337 model: [ "All", "Only long distance", "Local public transport", "Local trains only", "Rapit transit/metro/tram", "Bus" ]
0338 property var currentMode: {
0339 switch (currentIndex) {
0340 case 1: return [Line.LongDistanceTrain, Line.Train];
0341 case 2: return [Line.LocalTrain, Line.RapidTransit, Line.Metro, Line.Tramway, Line.Funicular, Line.Bus];
0342 case 3: return [Line.LocalTrain];
0343 case 4: return [Line.RapidTransit, Line.Metro, Line.Tramway, Line.Funicular];
0344 case 5: return [Line.Bus];
0345 }
0346 return [];
0347 }
0348 }
0349
0350 RowLayout {
0351 Layout.fillWidth: true
0352 QQC2.Button {
0353 text: "Query"
0354 onClicked: {
0355 var stop = departureModel.request.stop;
0356 stop.latitude = latQuery.text;
0357 stop.longitude = lonQuery.text;
0358 stop.name = nameQuery.text;
0359 departureModel.request.stop = stop;
0360 departureModel.request.mode = arrivalBox.checked ? StopoverRequest.QueryArrival : StopoverRequest.QueryDeparture;
0361 departureModel.request.backends = backendBox.checked ? [ backendSelector.currentText ] : [];
0362 departureModel.request.downloadAssets = true;
0363 departureModel.request.maximumResults = maxResults.text;
0364 departureModel.request.lineModes = lineModeSelector.currentMode
0365 }
0366 }
0367 QQC2.Button {
0368 text: "Query Name"
0369 onClicked: {
0370 var stop = departureModel.request.stop;
0371 stop.latitude = NaN;
0372 stop.longitude = NaN;
0373 stop.name = nameQuery.text;
0374 departureModel.request.stop = stop;
0375 departureModel.request.mode = arrivalBox.checked ? StopoverRequest.QueryArrival : StopoverRequest.QueryDeparture;
0376 departureModel.request.backends = backendBox.checked ? [ backendSelector.currentText ] : [];
0377 departureModel.request.downloadAssets = true;
0378 departureModel.request.lineModes = lineModeSelector.currentMode
0379 departureModel.request.maximumResults = maxResults.text;
0380 }
0381 }
0382 QQC2.Button {
0383 text: "Query Coord"
0384 onClicked: {
0385 var stop = departureModel.request.stop;
0386 stop.latitude = latQuery.text;
0387 stop.longitude = lonQuery.text;
0388 stop.name = "";
0389 departureModel.request.stop = stop;
0390 departureModel.request.mode = arrivalBox.checked ? StopoverRequest.QueryArrival : StopoverRequest.QueryDeparture;
0391 departureModel.request.backends = backendBox.checked ? [ backendSelector.currentText ] : [];
0392 departureModel.request.downloadAssets = true;
0393 departureModel.request.maximumResults = maxResults.text;
0394 departureModel.request.lineModes = lineModeSelector.currentMode
0395 }
0396 }
0397 QQC2.Button {
0398 text: "Earlier"
0399 enabled: departureModel.canQueryPrevious
0400 onClicked: departureModel.queryPrevious()
0401 }
0402 QQC2.Button {
0403 text: "Later"
0404 enabled: departureModel.canQueryNext
0405 onClicked: departureModel.queryNext()
0406 }
0407 }
0408
0409 ListView {
0410 Layout.fillHeight: true
0411 Layout.fillWidth: true
0412 model: departureModel
0413 clip: true
0414 delegate: departureDelegate
0415
0416 QQC2.BusyIndicator {
0417 anchors.centerIn: parent
0418 running: departureModel.loading
0419 }
0420
0421 QQC2.Label {
0422 anchors.centerIn: parent
0423 width: parent.width
0424 text: departureModel.errorMessage
0425 color: Kirigami.Theme.negativeTextColor
0426 wrapMode: Text.Wrap
0427 }
0428 }
0429
0430 }
0431 }
0432 }
0433 }