From 601ef73b5dd4a8fdbf4877d9e83880500ed5693f Mon Sep 17 00:00:00 2001 From: Theophile Terraz Date: Thu, 6 Jun 2024 14:30:15 +0200 Subject: [PATCH] implement rectangular selection in profile window --- src/View/Geometry/Profile/Plot.py | 40 +++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/src/View/Geometry/Profile/Plot.py b/src/View/Geometry/Profile/Plot.py index 5f488592..eb664ea4 100644 --- a/src/View/Geometry/Profile/Plot.py +++ b/src/View/Geometry/Profile/Plot.py @@ -24,7 +24,7 @@ from tools import timer, trace from View.Tools.PamhyrPlot import PamhyrPlot from PyQt5.QtCore import ( - Qt, QCoreApplication, QItemSelectionModel + Qt, QCoreApplication, QItemSelectionModel, QItemSelection, QItemSelectionRange ) from PyQt5.QtWidgets import QApplication @@ -82,7 +82,7 @@ class Plot(PamhyrPlot): ind, point = self._closer_point(event) self.highlight = ([point], hyd) - self._select_in_table(ind) + self._select_in_table([ind]) self.update() return @@ -135,7 +135,10 @@ class Plot(PamhyrPlot): self._table.setFocus() selection = self._table.selectionModel() - index = self._table.model().index(ind, 0) + index = QItemSelection() + if len(ind) > 0: + for i in ind: + index.append(QItemSelectionRange(self._table.model().index(i, 0))) selection.select( index, QItemSelectionModel.Rows | @@ -143,7 +146,8 @@ class Plot(PamhyrPlot): QItemSelectionModel.Select ) - self._table.scrollTo(index) + if len(ind) > 0: + self._table.scrollTo(self._table.model().index(ind[-1], 0)) self._table.blockSignals(False) def _closer_point(self, event): @@ -181,6 +185,34 @@ class Plot(PamhyrPlot): def _get_z_from_click(self, event): return event.ydata + def rect_select_callback(self, eclick, erelease): + + _, hyd = self.highlight + + x1, y1 = eclick.xdata, eclick.ydata + x2, y2 = erelease.xdata, erelease.ydata + + inds, points = self._points_in_rectangle(x1, y1, x2, y2) + + self.highlight = (points, hyd) + + self._select_in_table(inds) + + self.update() + return + + def _points_in_rectangle(self, x1, y1, x2, y2): + # TODO: use lambdas + listi = [] + listp = [] + station = self.data._get_station(self.data.points) + for i, p in enumerate(self.data.points): + if (min(x1,x2)