Commit a0d0ee9e authored by Volker Krause's avatar Volker Krause
Browse files

Add convenience property for computing the delay

parent 4d0b5e95
......@@ -63,6 +63,14 @@ bool Departure::hasExpectedTime() const
return d->expectedTime.isValid();
}
int Departure::delay() const
{
if (hasExpectedTime()) {
return d->scheduledTime.secsTo(d->expectedTime) / 60;
}
return 0;
}
QString Departure::scheduledPlatform() const
{
return d->scheduledPlatform;
......
......@@ -55,12 +55,16 @@ class Departure
/** The stop point of this departure. */
Q_PROPERTY(KPublicTransport::Location stopPoint READ stopPoint WRITE setStopPoint)
/** Difference to schedule in minutes. */
Q_PROPERTY(int delay READ delay)
public:
QDateTime scheduledTime() const;
void setScheduledTime(const QDateTime &scheduledTime);
QDateTime expectedTime() const;
void setExpectedTime(const QDateTime &expectedTime);
bool hasExpectedTime() const;
int delay() const;
QString scheduledPlatform() const;
void setScheduledPlatform(const QString &platform);
......
......@@ -104,9 +104,8 @@ Kirigami.ApplicationWindow {
text: "Departure: " + modelData.scheduledTime.toTimeString()
}
QQC2.Label {
property int diff: (modelData.expectedTime.getTime() - modelData.scheduledTime.getTime()) / 60000
text: (diff >= 0 ? "+" : "") + diff
color: diff > 1 ? Kirigami.Theme.negativeTextColor : Kirigami.Theme.positiveTextColor
text: (modelData.delay >= 0 ? "+" : "") + modelData.delay
color: modelData.delay > 1 ? Kirigami.Theme.negativeTextColor : Kirigami.Theme.positiveTextColor
visible: modelData.hasExpectedTime
}
}
......
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