Commit f92e0d3b authored by Volker Krause's avatar Volker Krause

Fix change notification for the previous location property

Too aggressive now, but at least we are not getting outdated information
anymore.
parent 8b872f92
......@@ -64,7 +64,7 @@ private Q_SLOTS:
QCOMPARE(controller.progress(), 0.0f);
}
void testController()
void testProgress()
{
ReservationManager mgr;
clearReservations(&mgr);
......@@ -96,6 +96,49 @@ private Q_SLOTS:
QCOMPARE(controller.progress(), 0.5f);
QCOMPARE(currentSpy.size(), 1);
}
void testPreviousLocation()
{
ReservationManager mgr;
clearReservations(&mgr);
TimelineDelegateController controller;
controller.setReservationManager(&mgr);
{
TrainTrip trip;
trip.setTrainNumber(QStringLiteral("TGV 1235"));
trip.setDepartureTime(QDateTime::currentDateTime().addDays(2));
TrainReservation res;
res.setReservationNumber(QStringLiteral("XXX007"));
res.setReservationFor(trip);
mgr.addReservation(res);
}
QCOMPARE(mgr.batches().size(), 1);
const auto batchId = mgr.batches().at(0);
controller.setBatchId(batchId);
QCOMPARE(controller.previousLocation(), QVariant());
TrainStation arrStation;
arrStation.setName(QStringLiteral("My Station"));
TrainTrip prevTrip;
prevTrip.setTrainNumber(QStringLiteral("ICE 1234"));
prevTrip.setDepartureTime(QDateTime::currentDateTime().addDays(1));
prevTrip.setArrivalTime(QDateTime::currentDateTime().addDays(1));
prevTrip.setArrivalStation(arrStation);
TrainReservation prevRes;
prevRes.setReservationNumber(QStringLiteral("XXX007"));
prevRes.setReservationFor(prevTrip);
QSignalSpy changeSpy(&controller, &TimelineDelegateController::previousLocationChanged);
mgr.addReservation(prevRes);
QCOMPARE(changeSpy.size(), 1);
QVERIFY(!controller.previousLocation().isNull());
QCOMPARE(controller.previousLocation().value<TrainStation>().name(), QLatin1String("My Station"));
}
};
QTEST_GUILESS_MAIN(TimelineDelegateControllerTest)
......
......@@ -68,9 +68,13 @@ void TimelineDelegateController::setReservationManager(QObject *resMgr)
emit contentChanged();
emit departureChanged();
emit arrivalChanged();
emit previousLocationChanged();
connect(m_resMgr, &ReservationManager::batchChanged, this, &TimelineDelegateController::batchChanged);
connect(m_resMgr, &ReservationManager::batchContentChanged, this, &TimelineDelegateController::batchChanged);
// ### could be done more efficiently
connect(m_resMgr, &ReservationManager::batchAdded, this, &TimelineDelegateController::previousLocationChanged);
connect(m_resMgr, &ReservationManager::batchRemoved, this, &TimelineDelegateController::previousLocationChanged);
checkForUpdate(m_batchId);
}
......@@ -121,6 +125,7 @@ void TimelineDelegateController::setBatchId(const QString &batchId)
emit contentChanged();
emit departureChanged();
emit arrivalChanged();
emit previousLocationChanged();
checkForUpdate(batchId);
}
......@@ -275,6 +280,7 @@ void TimelineDelegateController::batchChanged(const QString& batchId)
emit contentChanged();
emit arrivalChanged();
emit departureChanged();
emit previousLocationChanged();
}
QVariant TimelineDelegateController::previousLocation() const
......
......@@ -45,7 +45,7 @@ class TimelineDelegateController : public QObject
/** The location we are in before this element begins.
* This is only relevant for future elements, past elements, or elements without a non-current predecessor return nothing here.
*/
Q_PROPERTY(QVariant previousLocation READ previousLocation NOTIFY contentChanged) // TODO technically we need to update this too when a new reservation was inserted before this
Q_PROPERTY(QVariant previousLocation READ previousLocation NOTIFY previousLocationChanged)
Q_PROPERTY(KPublicTransport::Departure arrival READ arrival NOTIFY arrivalChanged)
Q_PROPERTY(KPublicTransport::Departure departure READ departure NOTIFY departureChanged)
......@@ -77,6 +77,7 @@ Q_SIGNALS:
void progressChanged();
void arrivalChanged();
void departureChanged();
void previousLocationChanged();
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