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>
This commit is contained in:
Dirk Hohndel 2013-05-03 20:58:44 -07:00
parent 7add8594a7
commit fcd6903621

View file

@ -80,26 +80,20 @@ void MainWindow::on_actionOpen_triggered()
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*>(); /* first deselect the dives that are no longer selected */
//if (dive)
// selected_dive = get_index_for_dive(dive);
Q_FOREACH(const QModelIndex& desselect, oldSelection.indexes()) { Q_FOREACH(const QModelIndex& desselect, oldSelection.indexes()) {
struct dive *d = (struct dive*) desselect.data(TreeItemDT::DIVE_ROLE).value<void*>(); struct dive *d = (struct dive*) desselect.data(TreeItemDT::DIVE_ROLE).value<void*>();
if (!d) if (!d || !d->selected)
continue; continue;
d->selected = false; deselect_dive(get_divenr(d));
} }
/* then select the newly selected dives */
struct dive *lastSelected = 0; Q_FOREACH(const QModelIndex& select, newSelection.indexes()) {
Q_FOREACH(const QModelIndex& select, oldSelection.indexes()){
struct dive *d = (struct dive*) select.data(TreeItemDT::DIVE_ROLE).value<void*>(); struct dive *d = (struct dive*) select.data(TreeItemDT::DIVE_ROLE).value<void*>();
if (!d) if (!d || d->selected)
continue; continue;
d->selected = true; select_dive(get_divenr(d));
lastSelected = d;
} }
select_dive( get_divenr(lastSelected) );
} }
void MainWindow::on_actionSave_triggered() void MainWindow::on_actionSave_triggered()