summaryrefslogtreecommitdiffstats
path: root/qt-ui/divelistview.cpp
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2013-11-14 17:52:03 +0900
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-11-14 17:58:14 +0900
commitdfd17c7a7fd1f5dd85f61a6feef96c616e02cfcb (patch)
tree1a319e3029bd13436ae266f7f1658a8ccd9bb92f /qt-ui/divelistview.cpp
parent179615f3a9a7a657f9039e124865b2f449ddb703 (diff)
downloadsubsurface-dfd17c7a7fd1f5dd85f61a6feef96c616e02cfcb.tar.gz
Maintain the selection when aborting "dive add"
We remember what was selected before and restore it. Maybe there's a more "Qt way" of doing this, but my implementation appears to work :-) Also remove unconditional debug output that snuck into an earlier commit. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/divelistview.cpp')
-rw-r--r--qt-ui/divelistview.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp
index 34df44bf1..f2ca6a399 100644
--- a/qt-ui/divelistview.cpp
+++ b/qt-ui/divelistview.cpp
@@ -112,6 +112,30 @@ void DiveListView::fixMessyQtModelBehaviour()
}
}
+// this only remembers dives that were selected, not trips
+void DiveListView::rememberSelection()
+{
+ selectedDives.clear();
+ QItemSelection selection = selectionModel()->selection();
+ Q_FOREACH(const QModelIndex& index , selection.indexes()) {
+ if (index.column() != 0) // We only care about the dives, so, let's stick to rows and discard columns.
+ continue;
+ struct dive *d = (struct dive *) index.data(DiveTripModel::DIVE_ROLE).value<void*>();
+ if (d)
+ selectedDives.push_front(get_divenr(d));
+ }
+}
+
+void DiveListView::restoreSelection()
+{
+ unselectDives();
+ Q_FOREACH(int i, selectedDives) {
+ struct dive *d = get_dive(i);
+ if (d)
+ selectDive(d);
+ }
+}
+
void DiveListView::unselectDives()
{
selectionModel()->clearSelection();