aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-02-08 22:05:37 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-02-08 14:06:18 -0800
commit2cea115ddb7528d9e6dd1bf918ebf5c670b82479 (patch)
tree372aec558eb5404d8268ed6f2db7721f8a219a4e
parent1f03a8be81527c2c32e66a169457340283c0e7ce (diff)
downloadsubsurface-2cea115ddb7528d9e6dd1bf918ebf5c670b82479.tar.gz
Dive list: be more careful on when updating the UI after selection
Fix two issues: 1) When narrowing the selection, we didn't get setSelection() calls. Only, when the user released the mouse button was the selection updated. Therefore, hook into the mouse-release- event and update the UI if the selection changed. 2) We updated the ui in setSelection(). However, this was called on mouse-move even if the actual selection didn't change. Therefore, compare selection before and after processing of the event and only refresh the UI if there are changes. Clearly, this can only be a quick stopgap solution and we should find out how to properly hook into the selection change machinery. Though see commit 4928c4ae0421193bbd371cb0924091a970489611 for the reason why we do things as we do them. Fixes #2595 Reported-by: Willem Ferguson <willemferguson@zoology.up.ac.za> Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r--desktop-widgets/divelistview.cpp36
-rw-r--r--desktop-widgets/divelistview.h1
2 files changed, 36 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 &current, 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()
diff --git a/desktop-widgets/divelistview.h b/desktop-widgets/divelistview.h
index ca6c61e9e..20f568479 100644
--- a/desktop-widgets/divelistview.h
+++ b/desktop-widgets/divelistview.h
@@ -65,6 +65,7 @@ slots:
void tripChanged(dive_trip *trip, TripField);
private:
void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags flags) override;
+ void mouseReleaseEvent(QMouseEvent *event) override;
void selectAll() override;
void selectionChangeDone();
DiveTripModelBase::Layout currentLayout;