Commit e5e72dd7 authored by Volker Krause's avatar Volker Krause
Browse files

Allow to search for alternatives for the current leg only

This was previously only offering to search for the entire remaining
journey, which is not always desirable.
parent ed5cbe9f
Pipeline #164980 passed with stage
in 1 minute and 55 seconds
......@@ -56,7 +56,8 @@ private Q_SLOTS:
QCOMPARE(controller.effectiveEndTime(), QDateTime());
QCOMPARE(controller.isLocationChange(), false);
QCOMPARE(controller.isPublicTransport(), false);
QVERIFY(!controller.journeyRequest().isValid());
QVERIFY(!controller.journeyRequestFull().isValid());
QVERIFY(!controller.journeyRequestOne().isValid());
QCOMPARE(controller.isCanceled(), false);
controller.setBatchId(QStringLiteral("foo"));
......@@ -170,19 +171,28 @@ private Q_SLOTS:
controller.setReservationManager(&mgr);
controller.setBatchId(mgr.batches().at(0)); // flight
controller.setLiveDataManager(&ldm);
QVERIFY(!controller.journeyRequest().isValid());
QVERIFY(!controller.journeyRequestFull().isValid());
QVERIFY(!controller.journeyRequestOne().isValid());
controller.setBatchId(mgr.batches().at(1)); // first train segment
QCOMPARE(controller.isLocationChange(), true);
QCOMPARE(controller.isPublicTransport(), true);
auto jnyReq = controller.journeyRequest();
auto jnyReq = controller.journeyRequestFull();
QCOMPARE(jnyReq.isValid(), true);
QCOMPARE(jnyReq.from().name(), QStringLiteral("Zürich Flughafen"));
QCOMPARE(jnyReq.to().name(), QLatin1String("Randa"));
jnyReq = controller.journeyRequestOne();
QCOMPARE(jnyReq.isValid(), true);
QCOMPARE(jnyReq.from().name(), QStringLiteral("Zürich Flughafen"));
QCOMPARE(jnyReq.to().name(), QLatin1String("Visp"));
controller.setBatchId(mgr.batches().at(2)); // second train segment
jnyReq = controller.journeyRequest();
jnyReq = controller.journeyRequestFull();
QCOMPARE(jnyReq.isValid(), true);
QCOMPARE(jnyReq.from().name(), QLatin1String("Visp"));
QCOMPARE(jnyReq.to().name(), QLatin1String("Randa"));
jnyReq = controller.journeyRequestOne();
QCOMPARE(jnyReq.isValid(), true);
QCOMPARE(jnyReq.from().name(), QLatin1String("Visp"));
QCOMPARE(jnyReq.to().name(), QLatin1String("Randa"));
......@@ -212,7 +222,7 @@ private Q_SLOTS:
// apply alternative with 3 segments to test segment insertion
const auto jny3 = KPublicTransport::Journey::fromJson(QJsonDocument::fromJson(readFile(QLatin1String(SOURCE_DIR "/data/publictransport/randa-zrh-3-sections.json"))).object());
controller.applyJourney(QVariant::fromValue(jny3));
controller.applyJourney(QVariant::fromValue(jny3), true);
QCOMPARE(mgr.batches().size(), batchCount + 1);
QCOMPARE(addSpy.size(), 3);
QCOMPARE(updateSpy.size(), 0); // as we move beyond other elements, we get add/remove rather than updated here
......@@ -225,7 +235,7 @@ private Q_SLOTS:
updateSpy.clear();
rmSpy.clear();
const auto jny2 = KPublicTransport::Journey::fromJson(QJsonDocument::fromJson(readFile(QLatin1String(SOURCE_DIR "/data/publictransport/randa-zrh-2-sections.json"))).object());
controller.applyJourney(QVariant::fromValue(jny2));
controller.applyJourney(QVariant::fromValue(jny2), true);
QCOMPARE(mgr.batches().size(), batchCount);
QCOMPARE(addSpy.size(), 2);
QCOMPARE(updateSpy.size(), 0);
......
......@@ -18,10 +18,41 @@ App.JourneyQueryPage {
property QtObject controller;
title: i18n("Alternative Connections")
journeyRequest: controller.journeyRequest
journeyRequest: controller.journeyRequestFull
onJourneyChanged: replaceWarningSheet.sheetOpen = true
QQC2.ActionGroup { id: journeyActionGroup }
Component {
id: fullJourneyAction
Kirigami.Action {
text: i18nc("to travel destination", "To %1", controller.journeyRequestFull.to.name)
checkable: true
checked: controller.journeyRequestFull.to.name == root.journeyRequest.to.name
iconName: "go-next-symbolic"
visible: controller.journeyRequestFull.to.name != controller.journeyRequestOne.to.name
QQC2.ActionGroup.group: journeyActionGroup
onTriggered: root.journeyRequest = controller.journeyRequestFull
}
}
Component {
id: oneJourneyAction
Kirigami.Action {
text: i18nc("to travel destination", "To %1", controller.journeyRequestOne.to.name)
checkable: true
checked: controller.journeyRequestOne.to.name == root.journeyRequest.to.name
iconName: "go-next-symbolic"
visible: controller.journeyRequestFull.to.name != controller.journeyRequestOne.to.name
QQC2.ActionGroup.group: journeyActionGroup
onTriggered: root.journeyRequest = controller.journeyRequestOne
}
}
Component.onCompleted: {
actions.contextualActions.push(fullJourneyAction.createObject(root));
actions.contextualActions.push(oneJourneyAction.createObject(root));
}
Kirigami.OverlaySheet {
id: replaceWarningSheet
......@@ -40,7 +71,7 @@ App.JourneyQueryPage {
text: i18n("Replace")
icon.name: "document-save"
onClicked: {
controller.applyJourney(root.journey);
controller.applyJourney(root.journey, root.journeyRequest.to.name == controller.journeyRequestFull.to.name);
applicationWindow().pageStack.pop();
}
}
......
......@@ -401,7 +401,7 @@ static bool isLayover(const QVariant &res1, const QVariant &res2)
return LocationUtil::isSameLocation(LocationUtil::arrivalLocation(res1), LocationUtil::departureLocation(res2), LocationUtil::WalkingDistance);
}
KPublicTransport::JourneyRequest TimelineDelegateController::journeyRequest() const
KPublicTransport::JourneyRequest TimelineDelegateController::journeyRequestOne() const
{
if (!m_resMgr || m_batchId.isEmpty() || !m_liveDataMgr) {
return {};
......@@ -421,9 +421,18 @@ KPublicTransport::JourneyRequest TimelineDelegateController::journeyRequest() co
req.setIncludeIntermediateStops(true);
req.setIncludePaths(true);
PublicTransport::selectBackends(req, m_liveDataMgr->publicTransportManager(), res);
return req;
}
KPublicTransport::JourneyRequest TimelineDelegateController::journeyRequestFull() const
{
auto req = journeyRequestOne();
if (!req.isValid()) {
return {};
}
// find full journey by looking at subsequent elements
auto prevRes = res;
auto prevRes = m_resMgr->reservation(m_batchId);
auto prevBatchId = m_batchId;
while (true) {
auto endBatchId = m_resMgr->nextBatch(prevBatchId);
......@@ -440,7 +449,7 @@ KPublicTransport::JourneyRequest TimelineDelegateController::journeyRequest() co
return req;
}
void TimelineDelegateController::applyJourney(const QVariant &journey)
void TimelineDelegateController::applyJourney(const QVariant &journey, bool includeFollowing)
{
if (!m_resMgr || m_batchId.isEmpty()) {
return;
......@@ -457,7 +466,7 @@ void TimelineDelegateController::applyJourney(const QVariant &journey)
// find all batches we are replying here (same logic as in journeyRequest)
std::vector<QString> oldBatches({m_batchId});
{
if (includeFollowing) {
auto prevRes = m_resMgr->reservation(m_batchId);
auto prevBatchId = m_batchId;
while (true) {
......
......@@ -60,7 +60,11 @@ class TimelineDelegateController : public QObject
/** A KPublicTransport::JourneyRequest for the current journey.
* This includes the current element as well as any immediately connected following elements.
*/
Q_PROPERTY(KPublicTransport::JourneyRequest journeyRequest READ journeyRequest NOTIFY contentChanged) // TODO technically notification also depends on other elements, so similar to previousLocationChanged
Q_PROPERTY(KPublicTransport::JourneyRequest journeyRequestFull READ journeyRequestFull NOTIFY contentChanged) // TODO technically notification also depends on other elements, so similar to previousLocationChanged
/** A KPublicTransport::JourneyRequest for the current element.
* This does not include any connected following elements.
*/
Q_PROPERTY(KPublicTransport::JourneyRequest journeyRequestOne READ journeyRequestOne NOTIFY contentChanged)
/** Inbound connection is unlikely to work. */
Q_PROPERTY(bool connectionWarning READ connectionWarning NOTIFY connectionWarningChanged)
......@@ -99,8 +103,9 @@ public:
bool isLocationChange() const;
bool isPublicTransport() const;
KPublicTransport::JourneyRequest journeyRequest() const;
Q_INVOKABLE void applyJourney(const QVariant &journey);
KPublicTransport::JourneyRequest journeyRequestFull() const;
KPublicTransport::JourneyRequest journeyRequestOne() const;
Q_INVOKABLE void applyJourney(const QVariant &journey, bool includeFollowing);
bool connectionWarning() const;
bool isCanceled() const;
......
Supports Markdown
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