Commit 00bb17d6 authored by Volker Krause's avatar Volker Krause

Fix timeline delegate not updating on live data changes

parent 098b3fc8
......@@ -48,6 +48,8 @@ Kirigami.AbstractCard {
reservationManager: _reservationManager
liveDataManager: _liveDataManager
}
property alias arrival: controller.arrival
property alias departure: controller.departure
header: Rectangle {
id: headerBackground
......
......@@ -25,9 +25,6 @@ import "." as App
App.TimelineDelegate {
id: root
property var arrival: _liveDataManager.arrival(batchId)
property var departure: _liveDataManager.departure(batchId)
headerIconSource: departure.route.line.mode == Line.Unknown ? "qrc:///images/train.svg" : PublicTransport.lineModeIcon(departure.route.line.mode)
headerItem: RowLayout {
QQC2.Label {
......
......@@ -237,6 +237,8 @@ void LiveDataManager::updateArrivalData(const KPublicTransport::Departure &arr,
}
}
emit arrivalUpdated(resId);
// check if something changed relevant for notifications
if (oldArr.arrivalDelay() == arr.arrivalDelay() && oldArr.expectedPlatform() == arr.expectedPlatform()) {
return;
......@@ -252,8 +254,6 @@ void LiveDataManager::updateArrivalData(const KPublicTransport::Departure &arr,
QLatin1String("clock"));
}
#endif
emit departureUpdated(resId);
}
void LiveDataManager::updateDepartureData(const KPublicTransport::Departure &dep, const QString &resId)
......@@ -282,6 +282,8 @@ void LiveDataManager::updateDepartureData(const KPublicTransport::Departure &dep
}
}
emit departureUpdated(resId);
// check if something changed relevant for notification
if (oldDep.departureDelay() == dep.departureDelay() && oldDep.expectedPlatform() == dep.expectedPlatform()) {
return;
......@@ -304,8 +306,6 @@ void LiveDataManager::updateDepartureData(const KPublicTransport::Departure &dep
QLatin1String("clock"));
}
#endif
emit departureUpdated(resId);
}
void LiveDataManager::removeArrivalData(const QString &resId)
......
......@@ -65,6 +65,8 @@ void TimelineDelegateController::setReservationManager(QObject *resMgr)
m_resMgr = qobject_cast<ReservationManager*>(resMgr);
emit setupChanged();
emit departureChanged();
emit arrivalChanged();
connect(m_resMgr, &ReservationManager::batchChanged, this, &TimelineDelegateController::checkForUpdate);
connect(m_resMgr, &ReservationManager::batchContentChanged, this, &TimelineDelegateController::checkForUpdate);
......@@ -85,9 +87,21 @@ void TimelineDelegateController::setLiveDataManager(QObject* liveDataMgr)
m_liveDataMgr = qobject_cast<LiveDataManager*>(liveDataMgr);
emit setupChanged();
emit departureChanged();
emit arrivalChanged();
connect(m_liveDataMgr, &LiveDataManager::arrivalUpdated, this, &TimelineDelegateController::checkForUpdate);
connect(m_liveDataMgr, &LiveDataManager::departureUpdated, this, &TimelineDelegateController::checkForUpdate);
connect(m_liveDataMgr, &LiveDataManager::arrivalUpdated, this, [this](const auto &batchId) {
if (batchId == m_batchId) {
emit arrivalChanged();
}
});
connect(m_liveDataMgr, &LiveDataManager::departureUpdated, this, [this](const auto &batchId) {
if (batchId == m_batchId) {
emit departureChanged();
}
});
checkForUpdate(m_batchId);
}
......@@ -104,6 +118,8 @@ void TimelineDelegateController::setBatchId(const QString &batchId)
m_batchId = batchId;
emit contentChanged();
emit departureChanged();
emit arrivalChanged();
checkForUpdate(batchId);
}
......@@ -164,6 +180,22 @@ float TimelineDelegateController::progress() const
return std::min(std::max(0.0f, (float)progress / (float)tripLength), 1.0f);
}
KPublicTransport::Departure TimelineDelegateController::arrival() const
{
if (!m_liveDataMgr || m_batchId.isEmpty()) {
return {};
}
return m_liveDataMgr->arrival(m_batchId).value<KPublicTransport::Departure>();
}
KPublicTransport::Departure TimelineDelegateController::departure() const
{
if (!m_liveDataMgr || m_batchId.isEmpty()) {
return {};
}
return m_liveDataMgr->departure(m_batchId).value<KPublicTransport::Departure>();
}
void TimelineDelegateController::checkForUpdate(const QString& batchId)
{
if (!m_resMgr || m_batchId.isEmpty()) {
......
......@@ -18,6 +18,8 @@
#ifndef TIMELINEDELEGATECONTROLLER_H
#define TIMELINEDELEGATECONTROLLER_H
#include <KPublicTransport/Departure>
#include <QObject>
#include <QVariant>
......@@ -40,6 +42,9 @@ class TimelineDelegateController : public QObject
Q_PROPERTY(bool isCurrent READ isCurrent NOTIFY currentChanged)
Q_PROPERTY(float progress READ progress NOTIFY progressChanged)
Q_PROPERTY(KPublicTransport::Departure arrival READ arrival NOTIFY arrivalChanged)
Q_PROPERTY(KPublicTransport::Departure departure READ departure NOTIFY departureChanged)
public:
TimelineDelegateController(QObject *parent = nullptr);
~TimelineDelegateController();
......@@ -55,11 +60,16 @@ public:
bool isCurrent() const;
float progress() const;
KPublicTransport::Departure arrival() const;
KPublicTransport::Departure departure() const;
Q_SIGNALS:
void setupChanged();
void contentChanged();
void currentChanged();
void progressChanged();
void arrivalChanged();
void departureChanged();
private:
void setCurrent(bool current, const QVariant &res = {});
......
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