From fcd6903621da975a83bfb6c9a9769221c4203ad9 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Fri, 3 May 2013 20:58:44 -0700 Subject: [PATCH] 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 --- qt-ui/mainwindow.cpp | 24 +++++++++--------------- 1 file 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(); - //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(); - 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(); - 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()