diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2018-08-01 10:47:09 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-10-11 16:22:27 -0700 |
commit | 0d98da52610161ecbafd50afacbff20996756264 (patch) | |
tree | 686947161c92eb96329512af1dcc4d4a18af4fef /desktop-widgets | |
parent | 96d87273995a6af35d90efb1190ff653e4c03d02 (diff) | |
download | subsurface-0d98da52610161ecbafd50afacbff20996756264.tar.gz |
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 <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets')
-rw-r--r-- | desktop-widgets/divelistview.cpp | 11 |
1 files changed, 10 insertions, 1 deletions
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); |