diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2013-05-03 20:58:44 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-05-03 20:58:44 -0700 |
commit | fcd6903621da975a83bfb6c9a9769221c4203ad9 (patch) | |
tree | dde5f73347ddd7914388b99246980e976d0f29dd /qt-ui | |
parent | 7add8594a71db739d86966ea2bc1e15aa7a6674f (diff) | |
download | subsurface-fcd6903621da975a83bfb6c9a9769221c4203ad9.tar.gz |
Small changes to the selection logic
Now it correctly uses the existing helper functions and keeps our idea of
the selection consistent.
There is a small behavioral change compared to the Gtk code. Range
selections no longer have the last dive clicked on as selected_dive but
instead the dive with the highest index that was selected. I don't think
that is a major issue for anyone.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui')
-rw-r--r-- | qt-ui/mainwindow.cpp | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index 3b0981d21..3f545171e 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -78,28 +78,22 @@ void MainWindow::on_actionOpen_triggered() ui->ListWidget->sortByColumn(0, Qt::DescendingOrder); } -void MainWindow::dive_selection_changed(const QItemSelection& newSelection, const QItemSelection& oldSelection) +void MainWindow::dive_selection_changed(const QItemSelection& newSelection, const QItemSelection& oldSelection) { - // struct dive *dive = (struct dive*) index.model()->data(index, TreeItemDT::DIVE_ROLE).value<void*>(); - //if (dive) - // selected_dive = get_index_for_dive(dive); - Q_FOREACH(const QModelIndex& desselect, oldSelection.indexes()){ + /* first deselect the dives that are no longer selected */ + Q_FOREACH(const QModelIndex& desselect, oldSelection.indexes()) { struct dive *d = (struct dive*) desselect.data(TreeItemDT::DIVE_ROLE).value<void*>(); - if (!d) + if (!d || !d->selected) continue; - d->selected = false; + deselect_dive(get_divenr(d)); } - - struct dive *lastSelected = 0; - Q_FOREACH(const QModelIndex& select, oldSelection.indexes()){ + /* then select the newly selected dives */ + Q_FOREACH(const QModelIndex& select, newSelection.indexes()) { struct dive *d = (struct dive*) select.data(TreeItemDT::DIVE_ROLE).value<void*>(); - if (!d) + if (!d || d->selected) continue; - d->selected = true; - lastSelected = d; + select_dive(get_divenr(d)); } - - select_dive( get_divenr(lastSelected) ); } void MainWindow::on_actionSave_triggered() |