Commit 4212069e authored by Volker Krause's avatar Volker Krause
Browse files

Also allow to save the results in the location query example

Useful for debugging.
parent af66c29c
......@@ -162,4 +162,10 @@ QHash<int, QByteArray> LocationQueryModel::roleNames() const
return r;
}
const std::vector<Location>& LocationQueryModel::locations() const
{
Q_D(const LocationQueryModel);
return d->m_locations;
}
#include "moc_locationquerymodel.moc"
......@@ -43,6 +43,9 @@ public:
QVariant data(const QModelIndex &index, int role) const override;
QHash<int, QByteArray> roleNames() const override;
/** The current model content. */
const std::vector<Location>& locations() const;
Q_SIGNALS:
void requestChanged();
......
......@@ -10,6 +10,7 @@
#include <KPublicTransport/Journey>
#include <KPublicTransport/JourneyQueryModel>
#include <KPublicTransport/Location>
#include <KPublicTransport/LocationQueryModel>
#include <KPublicTransport/Stopover>
#include <KPublicTransport/StopoverQueryModel>
......@@ -38,6 +39,8 @@ public:
f.write(QJsonDocument(Journey::toJson(qobject_cast<JourneyQueryModel*>(model)->journeys())).toJson());
} else if (qobject_cast<StopoverQueryModel*>(model)) {
f.write(QJsonDocument(Stopover::toJson(qobject_cast<StopoverQueryModel*>(model)->departures())).toJson());
} else if (qobject_cast<LocationQueryModel*>(model)) {
f.write(QJsonDocument(Location::toJson(qobject_cast<LocationQueryModel*>(model)->locations())).toJson());
}
}
......
......@@ -7,6 +7,7 @@
import QtQuick 2.5
import QtQuick.Layouts 1.1
import QtQuick.Controls 2.1 as QQC2
import Qt.labs.platform 1.0 as Platform
import Qt.labs.settings 1.0
import org.kde.kirigami 2.12 as Kirigami
import org.kde.kpublictransport 1.0
......@@ -44,6 +45,11 @@ Kirigami.ApplicationWindow {
globalDrawer: Kirigami.GlobalDrawer {
actions: [
Kirigami.Action {
text: "Save..."
iconName: "document-save"
onTriggered: fileDialog.open();
},
Kirigami.Action {
iconName: "help-about-symbolic"
text: "Data Sources"
......@@ -58,6 +64,14 @@ Kirigami.ApplicationWindow {
]
}
Platform.FileDialog {
id: fileDialog
title: "Save Departure Data"
fileMode: Platform.FileDialog.SaveFile
nameFilters: ["JSON files (*.json)"]
onAccepted: ExampleUtil.saveTo(locationModel, fileDialog.file);
}
function vehicleTypeIcon(type)
{
switch (type) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment