Commit ef3047a8 authored by Volker Krause's avatar Volker Krause

Improve the journey selector

parent c1ed1c47
......@@ -282,4 +282,9 @@ int Journey::duration() const
return scheduledDepartureTime().secsTo(scheduledArrivalTime());
}
int Journey::numberOfChanges() const
{
return std::count_if(d->sections.begin(), d->sections.end(), [](const auto &section) { return section.mode() == JourneySection::PublicTransport; });
}
#include "moc_journey.cpp"
......@@ -152,6 +152,9 @@ class Journey
Q_PROPERTY(QDateTime scheduledArrivalTime READ scheduledArrivalTime STORED false)
/** Duration of the entire journey in seconds. */
Q_PROPERTY(int duration READ duration STORED false)
/** Number of changes on this journey. */
Q_PROPERTY(int numberOfChanges READ numberOfChanges STORED false)
public:
/** The journey sections. */
const std::vector<JourneySection>& sections() const;
......@@ -163,6 +166,7 @@ public:
QDateTime scheduledDepartureTime() const;
QDateTime scheduledArrivalTime() const;
int duration() const;
int numberOfChanges() const;
private:
QVariantList sectionsVariant() const;
};
......
......@@ -28,6 +28,7 @@
#include <QApplication>
#include <QDateTime>
#include <QDebug>
#include <QLocale>
#include <QNetworkAccessManager>
#include <QUrl>
......@@ -70,14 +71,13 @@ public:
std::transform(res.begin(), res.end(), std::back_inserter(l), [](const auto &journey) { return QVariant::fromValue(journey); });
engine->rootContext()->setContextProperty(QStringLiteral("_journeys"), l);
QStringList journeyTitles;
for (const auto &journey : res) {
qDebug() << journey.sections().size();
for (const auto &section : journey.sections()) {
qDebug() << " From" << section.from().name() << section.scheduledDepartureTime();
qDebug() << " Mode" << section.mode() << section.route().line().name() << section.route().direction() << section.route().line().modeString();
qDebug() << " To" << section.to().name() << section.scheduledArrivalTime();
}
const QString t = QLocale().toString(journey.scheduledDepartureTime(), QLocale::ShortFormat) + QLatin1String(" (") +
QString::number(journey.duration()/60) + QLatin1String("min) - ") + QString::number(journey.numberOfChanges()) + QLatin1String(" change(s)");
journeyTitles.push_back(t);
}
engine->rootContext()->setContextProperty(QStringLiteral("_journeyTitles"), journeyTitles);
} else {
m_errorMsg = reply->errorString();
emit errorMessageChanged();
......
......@@ -243,7 +243,7 @@ Kirigami.ApplicationWindow {
QQC2.ComboBox {
id: journeySelector
Layout.fillWidth: true
model: _journeys
model: _journeyTitles
}
ListView {
......
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