summaryrefslogtreecommitdiffstats
path: root/qt-ui
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2014-04-03 10:11:39 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-04-03 10:26:48 -0700
commit3485c6c2609f998b82d56b89e3a12db7dc0c4b05 (patch)
tree11110864527bac59c2b34216be8d35ca09c784f6 /qt-ui
parent141433c3df8f033737942c2fb90dca9fa841a19d (diff)
downloadsubsurface-3485c6c2609f998b82d56b89e3a12db7dc0c4b05.tar.gz
Correctly handle dive selection after editing dives
It's a tricky problem as we need to remember this across a divelist sort (as the user might have edited the date / time). The old code made not one but two incorrect assumptions. a) it assumed that the added or edited (but previously manually added) dive was the last one in the dive list (clearly wrong when adding a dive that has an earlier date) b) it ignored the fact that refreshDisplay() would select the top dive in the list if no dive was selected This patch addresses both of them and makes the code easier to understand. Fixes #480 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui')
-rw-r--r--qt-ui/maintab.cpp18
1 files changed, 12 insertions, 6 deletions
diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index 9ff5e9f31..70a9dc3cf 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -671,24 +671,30 @@ void MainTab::acceptChanges()
int scrolledBy = MainWindow::instance()->dive_list()->verticalScrollBar()->sliderPosition();
resetPallete();
if (editMode == ADD || editMode == MANUALLY_ADDED_DIVE) {
+ // it's tricky to keep the right dive selected;
+ // first remember which one is selected in the current sort order
+ // and unselect all dives
+ int rememberSelected = selected_dive;
MainWindow::instance()->dive_list()->unselectDives();
- struct dive *d = get_dive(dive_table.nr - 1);
- // mark the dive as remembered (abusing the selected flag)
+ struct dive *d = get_dive(rememberSelected);
+ // mark the previously selected dive as remembered (abusing the selected flag)
// and then clear that flag out on the other side of the sort_table()
d->selected = true;
sort_table(&dive_table);
- int i = 0;
- for_each_dive(i, d) {
+ for_each_dive(rememberSelected, d) {
if (d->selected) {
d->selected = false;
break;
}
}
+ // refreshDisplay() will select the top dive if no dive was
+ // selected - but that may not be the right one, so select the one
+ // we remembered instead
+ MainWindow::instance()->dive_list()->selectDive(rememberSelected, true);
+
editMode = NONE;
MainWindow::instance()->refreshDisplay();
- MainWindow::instance()->dive_list()->selectDive(i, true);
MainWindow::instance()->graphics()->replot();
-
} else {
editMode = NONE;
MainWindow::instance()->dive_list()->rememberSelection();