Commit dc261e25 authored by Volker Krause's avatar Volker Krause

Add a method to determine the location we will be prior to a given element

This will be used for navigation actions for future elements, for example
to show the way from the arriving airport to your hotel, rather than from
your current position at home to the hotel at the destination.
parent 1d21e11a
......@@ -455,3 +455,13 @@ void ReservationManager::removeFromBatch(const QString &resId, const QString &ba
storeBatch(batchId);
}
}
QString ReservationManager::previousBatch(const QString &batchId) const
{
// ### this can be optimized by relying on m_batches being sorted by start date
const auto it = std::find(m_batches.begin(), m_batches.end(), batchId);
if (it == m_batches.end() || it == m_batches.begin()) {
return {};
}
return *(it - 1);
}
......@@ -61,6 +61,10 @@ public:
QString batchForReservation(const QString &resId) const;
Q_INVOKABLE QStringList reservationsForBatch(const QString &batchId) const;
Q_INVOKABLE void removeBatch(const QString &batchId);
/** Returns the batch happening prior to @p batchId, if any. */
QString previousBatch(const QString &batchId) const;
Q_SIGNALS:
void reservationAdded(const QString &id);
void reservationChanged(const QString &id);
......
......@@ -276,3 +276,28 @@ void TimelineDelegateController::batchChanged(const QString& batchId)
emit arrivalChanged();
emit departureChanged();
}
QVariant TimelineDelegateController::previousLocation() const
{
if (m_batchId.isEmpty() || !m_resMgr) {
return {};
}
const auto prevBatch = m_resMgr->previousBatch(m_batchId);
if (prevBatch.isEmpty()) {
return {};
}
const auto res = m_resMgr->reservation(prevBatch);
const auto endTime = SortUtil::endtDateTime(res);
if (endTime < QDateTime::currentDateTime()) { // TODO take live data into account (also for notification!)
// past event, we can use GPS rather than predict our location from the itinerary
return {};
}
if (LocationUtil::isLocationChange(res)) {
return LocationUtil::arrivalLocation(res);
} else {
return LocationUtil::location(res);
}
}
......@@ -42,6 +42,11 @@ class TimelineDelegateController : public QObject
Q_PROPERTY(bool isCurrent READ isCurrent NOTIFY currentChanged)
Q_PROPERTY(float progress READ progress NOTIFY progressChanged)
/** 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(KPublicTransport::Departure arrival READ arrival NOTIFY arrivalChanged)
Q_PROPERTY(KPublicTransport::Departure departure READ departure NOTIFY departureChanged)
......@@ -60,6 +65,8 @@ public:
bool isCurrent() const;
float progress() const;
QVariant previousLocation() const;
KPublicTransport::Departure arrival() const;
KPublicTransport::Departure departure() const;
......
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