diff options
Diffstat (limited to 'desktop-widgets/divelistview.cpp')
-rw-r--r-- | desktop-widgets/divelistview.cpp | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/desktop-widgets/divelistview.cpp b/desktop-widgets/divelistview.cpp index 6cb4a81c3..4af42e713 100644 --- a/desktop-widgets/divelistview.cpp +++ b/desktop-widgets/divelistview.cpp @@ -533,10 +533,44 @@ void DiveListView::currentChanged(const QModelIndex ¤t, const QModelIndex& scrollTo(current); } +void DiveListView::mouseReleaseEvent(QMouseEvent *event) +{ + // Oy vey. We hook into QTreeView's setSelection() to update the UI + // after selection changes. However, there is a case when this doesn't + // work: when narrowing the selection. If multiple dives are selected, + // and the user clicks on one of them, the selection is unchanged. + // Only on mouse-release the selection is changed, but then + // setSelection() is not called. + // Notably, this happens when the user selects a trip and the clicks + // on a dive in the same trip. + // To solve this, we hook into the mouseReleseEvent here and detect + // selection changes changes by comparing the selection before and after + // processing of the event. + // We really should find another way to solve this. + QModelIndexList selectionBefore = selectionModel()->selectedRows(); + QTreeView::mouseReleaseEvent(event); + QModelIndexList selectionAfter = selectionModel()->selectedRows(); + if (selectionBefore != selectionAfter) + selectionChangeDone(); +} + void DiveListView::setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags flags) { + // We hook into QTreeView's setSelection() to update the UI + // after selection changes. However, we must be careful: + // when the user clicks on an already selected dive, this is called + // with the QItemSelectionModel::NoUpdate flags. In this case, just + // route through. Moreover, we get setSelection() calls on every + // mouseMove event. To avoid excessive reloading of the UI check + // if the selection changed by comparing before and after processing + // the selection. + if (flags == QItemSelectionModel::NoUpdate) + return QTreeView::setSelection(rect, flags); + QModelIndexList selectionBefore = selectionModel()->selectedRows(); QTreeView::setSelection(rect, flags); - selectionChangeDone(); + QModelIndexList selectionAfter = selectionModel()->selectedRows(); + if (selectionBefore != selectionAfter) + selectionChangeDone(); } void DiveListView::selectAll() |