From 0d98da52610161ecbafd50afacbff20996756264 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Wed, 1 Aug 2018 10:47:09 +0200 Subject: Dive list: remember selected dives Don't delesect dives, when unregistering them from the backend. If a previously selected dive is added, select it in the dive-list. For this purpose introduce a SELECTED_ROLE to query the DiveTripModel for selected dives. Unfortunately, when adding multiple selected dives, current_dive_changed is called for each of them, making this very slow. This will have to be fixed in subsequent commits. Signed-off-by: Berthold Stoeger --- desktop-widgets/divelistview.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'desktop-widgets') diff --git a/desktop-widgets/divelistview.cpp b/desktop-widgets/divelistview.cpp index e8c6ea0dc..ebeb1f6ef 100644 --- a/desktop-widgets/divelistview.cpp +++ b/desktop-widgets/divelistview.cpp @@ -181,10 +181,19 @@ void DiveListView::rowsInserted(const QModelIndex &parent, int start, int end) // First, let the QTreeView do its thing. QTreeView::rowsInserted(parent, start, end); + QAbstractItemModel *m = model(); + QItemSelectionModel *s = selectionModel(); + + // Check whether any of the items is selected + for (int i = start; i <= end; ++i) { + QModelIndex index = m->index(i, 0, parent); + if (m->data(index, DiveTripModel::SELECTED_ROLE).toBool()) + s->select(index, QItemSelectionModel::Select | QItemSelectionModel::Rows); + } + // Now check for each inserted row whether this is a trip and expand the first column if (parent.isValid()) // Trips don't have a parent return; - QAbstractItemModel *m = model(); for (int i = start; i <= end; ++i) { if (m->rowCount(m->index(i, 0)) != 0) setFirstColumnSpanned(i, QModelIndex(), true); -- cgit v1.2.3-70-g09d2