Commit 26357b5e authored by Volker Krause's avatar Volker Krause
Browse files

Scroll timeline view to the current date

parent 721861e0
......@@ -31,9 +31,9 @@ Kirigami.ScrollablePage {
actions {
contextualActions: [
Kirigami.Action {
text: qsTr("Delete Pass")
iconName: "edit-delete"
onTriggered: print("TODO")
text: qsTr("Today")
iconName: "view-calendar"
onTriggered: listView.positionViewAtIndex(_timelineModel.todayRow, ListView.Beginning);
}
]
}
......@@ -70,6 +70,7 @@ Kirigami.ScrollablePage {
}
ListView {
id: listView
model: _timelineModel
spacing: 5
......@@ -118,4 +119,6 @@ Kirigami.ScrollablePage {
section.criteria: ViewSection.FullString
section.labelPositioning: ViewSection.CurrentLabelAtStart | ViewSection.InlineLabels
}
Component.onCompleted: listView.positionViewAtIndex(_timelineModel.todayRow, ListView.Beginning);
}
......@@ -115,6 +115,7 @@ void TimelineModel::setReservationManager(ReservationManager* mgr)
connect(mgr, &ReservationManager::reservationUpdated, this, &TimelineModel::reservationUpdated);
connect(mgr, &ReservationManager::reservationRemoved, this, &TimelineModel::reservationRemoved);
endResetModel();
emit todayRowChanged();
}
int TimelineModel::rowCount(const QModelIndex& parent) const
......@@ -182,6 +183,11 @@ QHash<int, QByteArray> TimelineModel::roleNames() const
return names;
}
int TimelineModel::todayRow() const
{
return m_reservationIds.indexOf({});
}
void TimelineModel::reservationAdded(const QString &resId)
{
auto it = std::lower_bound(m_reservationIds.begin(), m_reservationIds.end(), resId, [this](const QString &lhs, const QString &rhs) {
......@@ -191,6 +197,7 @@ void TimelineModel::reservationAdded(const QString &resId)
beginInsertRows({}, index, index);
m_reservationIds.insert(it, resId);
endInsertRows();
emit todayRowChanged();
}
void TimelineModel::reservationUpdated(const QString &resId)
......@@ -211,4 +218,5 @@ void TimelineModel::reservationRemoved(const QString &resId)
beginRemoveRows({}, index, index);
m_reservationIds.remove(index);
endRemoveRows();
emit todayRowChanged();
}
......@@ -26,6 +26,8 @@ class ReservationManager;
class TimelineModel : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(int todayRow READ todayRow NOTIFY todayRowChanged)
public:
enum Role {
PassRole = Qt::UserRole + 1,
......@@ -56,6 +58,11 @@ public:
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
QHash<int, QByteArray> roleNames() const override;
int todayRow() const;
signals:
void todayRowChanged();
private:
void reservationAdded(const QString &resId);
void reservationUpdated(const QString &resId);
......
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