Commit 7bfa7f5e authored by Volker Krause's avatar Volker Krause
Browse files

Add standalone test for the vehicle layout page

This works by loading offline data rather than doing an online query of
a suitable train booking, which is far more convenient for testing.
parent b17a78c3
......@@ -3,3 +3,6 @@
add_executable(pkpassviewer pkpassviewer.cpp pkpassviewer.qrc)
target_link_libraries(pkpassviewer itinerary)
add_executable(vehiclelayoutviewer vehiclelayoutviewer.cpp vehiclelayoutviewer.qrc)
target_link_libraries(vehiclelayoutviewer itinerary)
{
"scheduledDepartureTime": "1970-01-01T00:00:00",
"stopPoint": {
"identifier": {
"ibnr": "8507000"
},
"latitude": 46.949005126953125,
"locality": "Bern",
"longitude": 7.439121246337891,
"name": "Bern HB",
"timezone": "Europe/Zurich",
"type": "Stop"
},
"route": {
"line": {
"mode": "LongDistanceTrain",
"name": "IC 8"
}
},
"platformLayout": {
"length": 1,
"sections": [
{
"begin": 0,
"end": 0.10979928821325302,
"name": "H"
},
{
"begin": 0.10979928821325302,
"end": 0.22963400185108185,
"name": "G"
},
{
"begin": 0.22963400185108185,
"end": 0.4096812307834625,
"name": "F"
},
{
"begin": 0.4096812307834625,
"end": 0.46989375352859497,
"name": "E"
},
{
"begin": 0.46989375352859497,
"end": 0.5802833437919617,
"name": "D"
},
{
"begin": 0.5802833437919617,
"end": 0.7001180648803711,
"name": "C"
},
{
"begin": 0.7001180648803711,
"end": 0.8199527859687805,
"name": "B"
},
{
"begin": 0.8199527859687805,
"end": 1,
"name": "A"
}
]
},
"vehicleLayout": {
"direction": "UnknownDirection",
"sections": [
{
"classes": "UnknownClass",
"connectedSides": "Front|Back",
"deckCount": 1,
"features": "NoFeatures",
"platformPositionBegin": -1,
"platformPositionEnd": -1,
"platformSectionName": "A",
"type": "Engine"
},
{
"classes": "FirstClass",
"connectedSides": "Front|Back",
"deckCount": 1,
"features": "WheelchairAccessible",
"name": "1",
"platformPositionBegin": -1,
"platformPositionEnd": -1,
"platformSectionName": "B",
"type": "PassengerCar"
},
{
"classes": "FirstClass",
"connectedSides": "Front|Back",
"deckCount": 1,
"features": "NoFeatures",
"name": "3",
"platformPositionBegin": -1,
"platformPositionEnd": -1,
"platformSectionName": "B",
"type": "PassengerCar"
},
{
"classes": "FirstClass",
"connectedSides": "Front|Back",
"deckCount": 1,
"features": "NoFeatures",
"name": "2",
"platformPositionBegin": -1,
"platformPositionEnd": -1,
"platformSectionName": "C",
"type": "PassengerCar"
},
{
"classes": "SecondClass",
"connectedSides": "Front|Back",
"deckCount": 1,
"features": "NoFeatures",
"name": "4",
"platformPositionBegin": -1,
"platformPositionEnd": -1,
"platformSectionName": "C",
"type": "PassengerCar"
},
{
"classes": "SecondClass",
"connectedSides": "Front|Back",
"deckCount": 1,
"features": "NoFeatures",
"name": "6",
"platformPositionBegin": -1,
"platformPositionEnd": -1,
"platformSectionName": "D",
"type": "PassengerCar"
},
{
"classes": "SecondClass",
"connectedSides": "Front|Back",
"deckCount": 1,
"features": "NoFeatures",
"name": "7",
"platformPositionBegin": -1,
"platformPositionEnd": -1,
"platformSectionName": "D",
"type": "PassengerCar"
},
{
"classes": "SecondClass",
"connectedSides": "Front|Back",
"deckCount": 1,
"features": "NoFeatures",
"name": "8",
"platformPositionBegin": -1,
"platformPositionEnd": -1,
"platformSectionName": "E",
"type": "PassengerCar"
},
{
"classes": "SecondClass",
"connectedSides": "Front|Back",
"deckCount": 1,
"features": "NoFeatures",
"name": "5",
"platformPositionBegin": -1,
"platformPositionEnd": -1,
"platformSectionName": "F",
"type": "PassengerCar"
},
{
"classes": "UnknownClass",
"connectedSides": "Front|Back",
"deckCount": 1,
"features": "BikeStorage",
"name": "9",
"platformPositionBegin": -1,
"platformPositionEnd": -1,
"platformSectionName": "F",
"type": "PassengerCar"
}
]
}
}
/*
SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "publictransport.h"
#include <KPublicTransport/Stopover>
#include <KLocalizedContext>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QDebug>
#include <QFile>
#include <QGuiApplication>
#include <QJsonDocument>
#include <QJsonObject>
#include <QUrl>
int main(int argc, char **argv)
{
QCoreApplication::setApplicationName(QStringLiteral("vehiclelayoutviewer"));
QCoreApplication::setOrganizationName(QStringLiteral("KDE"));
QCoreApplication::setOrganizationDomain(QStringLiteral("kde.org"));
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
QGuiApplication app(argc, argv);
if (app.arguments().size() <= 1) {
qCritical("Missing command line argument!");
exit(1);
}
QFile file(app.arguments().at(1));
if (!file.open(QFile::ReadOnly)) {
qCritical("Failed to open file!");
exit(1);
}
const auto stopover = KPublicTransport::Stopover::fromJson(QJsonDocument::fromJson(file.readAll()).object());
qmlRegisterSingletonType("org.kde.itinerary", 1, 0, "PublicTransport", [](QQmlEngine*, QJSEngine *engine) -> QJSValue { \
return engine->toScriptValue(PublicTransport()); \
});
QQmlApplicationEngine engine;
engine.rootContext()->setContextObject(new KLocalizedContext(&engine));
engine.rootContext()->setContextProperty(QStringLiteral("_stopover"), stopover);
engine.load(QStringLiteral("qrc:/vehiclelayoutviewer.qml"));
return app.exec();
}
/*
SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
import QtQuick 2.5
import QtQuick.Layouts 1.1
import QtQuick.Controls 2.1 as QQC2
import org.kde.kirigami 2.12 as Kirigami
import org.kde.kpublictransport 1.0 as KPT
import "." as App
Kirigami.ApplicationWindow {
title: "Vehicle Layout Viewer"
reachableModeEnabled: false
width: 480
height: 720
pageStack.initialPage: layoutPage
KPT.Manager {
id: ptMgr;
}
Component {
id: layoutPage
App.VehicleLayoutPage {
stopover: _stopover
publicTransportManager: ptMgr
}
}
}
<!--
SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: CC0-1.0
-->
<RCC>
<qresource prefix="/">
<file>vehiclelayoutviewer.qml</file>
<file alias="VehicleLayoutPage.qml">../src/app/VehicleLayoutPage.qml</file>
</qresource>
</RCC>
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