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

Pick a better departure time for manual trips following an existing item

If this follows a timeboxed/non-cancelled element, use the end time of
that as the starting point.
parent 6b017655
......@@ -42,18 +42,26 @@ Kirigami.ScrollablePage {
row = listView.indexAt(0, i);
}
const idx = listView.model.index(row, 0);
var dt = listView.model.data(idx, TimelineModel.StartDateTimeRole);
const HOUR = 60 * 60 * 1000;
var roundInterval = HOUR;
var dt;
if (listView.model.data(idx, TimelineModel.IsTimeboxedRole) && !listView.model.data(idx, TimelineModel.IsCanceledRole)) {
dt = listView.model.data(idx, TimelineModel.EndDateTimeRole);
roundInterval = 5 * 60 * 1000;
} else {
dt = listView.model.data(idx, TimelineModel.StartDateTimeRole);
}
// clamp to future times and round to the next plausible hour
const now = new Date();
if (!dt || dt.getTime() < now.getTime()) {
dt = now;
}
const HOUR = 60 * 60 * 1000;
if (dt.getTime() % HOUR == 0 && dt.getHours() == 0) {
dt.setTime(dt.getTime() + HOUR * 8);
} else {
dt.setTime(dt.getTime() + HOUR - (dt.getTime() % HOUR));
dt.setTime(dt.getTime() + roundInterval - (dt.getTime() % roundInterval));
}
// determine where we are at that time
......
......@@ -247,6 +247,12 @@ QVariant TimelineModel::data(const QModelIndex& index, int role) const
break;
case StartDateTimeRole:
return elem.dt;
case EndDateTimeRole:
return elem.endDateTime();
case IsTimeboxedRole:
return elem.isTimeBoxed();
case IsCanceledRole:
return elem.isCanceled();
}
return {};
}
......
......@@ -40,6 +40,9 @@ public:
TripGroupRole,
TransferRole,
StartDateTimeRole,
EndDateTimeRole,
IsTimeboxedRole,
IsCanceledRole,
};
Q_ENUM(Role)
......
Supports Markdown
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