diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2014-11-03 17:52:04 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-11-03 17:52:04 -0800 |
commit | 0dd87989a878945331ea3266ff0f490f058bfea3 (patch) | |
tree | 5636878028e4140acba7e90f6e4501a6b519022f /qt-ui/divelistview.cpp | |
parent | a3f1dc76816ae385315a91188fdbbcfc2d26d71d (diff) | |
download | subsurface-0dd87989a878945331ea3266ff0f490f058bfea3.tar.gz |
Correctly unselect trips when dive list filters change
Oddly Qt left the trips selected (but all dives where unselected in the
UI). This got our internal state rather confused. With this change we
clean up that mess and go back to just having those dives that were
originally selected and are still visible show up as selected.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/divelistview.cpp')
-rw-r--r-- | qt-ui/divelistview.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp index 98681197c..502cebcbd 100644 --- a/qt-ui/divelistview.cpp +++ b/qt-ui/divelistview.cpp @@ -234,6 +234,29 @@ void DiveListView::selectTrip(dive_trip_t *trip) expand(idx); } +// this is an odd one - when filtering the dive list the selection status of the trips +// is kept - but all other selections are lost. That's gets us into rather inconsistent state +// we call this function which clears the selection state of the trips as well, but does so +// without updating our internal "->selected" state. So once we called this function we can +// go back and select those dives that are still visible under the filter and everything +// works as expected +void DiveListView::clearTripSelection() +{ + // we want to make sure no trips are selected + disconnect(selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SLOT(selectionChanged(QItemSelection, QItemSelection))); + disconnect(selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)), this, SLOT(currentChanged(QModelIndex, QModelIndex))); + + Q_FOREACH (const QModelIndex &index, selectionModel()->selectedRows()) { + dive_trip_t *trip = static_cast<dive_trip_t *>(index.data(DiveTripModel::TRIP_ROLE).value<void *>()); + if (!trip) + continue; + selectionModel()->select(index, QItemSelectionModel::Deselect); + } + + connect(selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SLOT(selectionChanged(QItemSelection, QItemSelection))); + connect(selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)), this, SLOT(currentChanged(QModelIndex, QModelIndex))); +} + void DiveListView::unselectDives() { // make sure we don't try to redraw the dives during the selection change |