Commit ce215d90 authored by Volker Krause's avatar Volker Krause

Show departure delays in the timeline

This still misses proper change notification via the timeline model, so
it's not reacting to updates yet.
parent a0d0ee9e
......@@ -24,6 +24,7 @@ import "." as App
App.TimelineDelegate {
id: root
property var departure: _liveDataManager.departure(resIds[0])
headerIconSource: "qrc:///images/train.svg"
headerItem: RowLayout {
......@@ -38,6 +39,11 @@ App.TimelineDelegate {
color: Kirigami.Theme.textColor
font.pointSize: Kirigami.Theme.defaultFont.pointSize * root.headerFontScale
}
QQC2.Label {
text: (departure.delay >= 0 ? "+" : "") + departure.delay
color: (departure.delay > 1) ? Kirigami.Theme.negativeTextColor : Kirigami.Theme.positiveTextColor
visible: departure.hasExpectedTime
}
}
contentItem: ColumnLayout {
......
......@@ -72,6 +72,10 @@ void LiveDataManager::setPkPassManager(PkPassManager *pkPassMgr)
m_pkPassMgr = pkPassMgr;
}
QVariant LiveDataManager::departure(const QString &resId)
{
return QVariant::fromValue(m_departures.value(resId));
}
void LiveDataManager::checkForUpdates()
{
......@@ -136,7 +140,7 @@ void LiveDataManager::checkTrainTrip(const TrainTrip& trip, const QString& resId
req.setDateTime(trip.departureTime());
auto reply = m_ptMgr->queryDeparture(req);
connect(reply, &Reply::finished, this, [this, trip, reply]() {
connect(reply, &Reply::finished, this, [this, trip, resId, reply]() {
reply->deleteLater();
if (reply->error() != Reply::NoError) {
qCDebug(Log) << reply->error() << reply->errorString();
......@@ -149,7 +153,11 @@ void LiveDataManager::checkTrainTrip(const TrainTrip& trip, const QString& resId
continue;
}
qCDebug(Log) << "Found departure information:" << dep.route().line().name() << dep.expectedPlatform() << dep.expectedTime();
m_departures.insert(resId, dep);
emit departureUpdated(resId);
break;
}
});
}
#include "moc_livedatamanager.cpp"
......@@ -18,6 +18,7 @@
#ifndef LIVEDATAMANAGER_H
#define LIVEDATAMANAGER_H
#include <QHash>
#include <QObject>
#include <memory>
......@@ -28,6 +29,7 @@ class TrainTrip;
}
namespace KPublicTransport {
class Departure;
class Manager;
}
......@@ -45,10 +47,15 @@ public:
void setReservationManager(ReservationManager *resMgr);
void setPkPassManager(PkPassManager *pkPassMgr);
Q_INVOKABLE QVariant departure(const QString &resId);
public slots:
/** Checks all applicable elements for updates. */
void checkForUpdates();
signals:
void departureUpdated(const QString &resId);
private:
void checkTrainTrip(const KItinerary::TrainTrip &trip, const QString &resId);
......@@ -56,6 +63,7 @@ private:
PkPassManager *m_pkPassMgr;
std::unique_ptr<KPublicTransport::Manager> m_ptMgr;
std::vector<QString> m_reservations;
QHash <QString, KPublicTransport::Departure> m_departures;
};
#endif // LIVEDATAMANAGER_H
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