implement rectangular selection in profile window

0.0.9
Theophile Terraz 2024-06-06 14:30:15 +02:00
parent e4f8bc347d
commit 601ef73b5d
1 changed files with 36 additions and 4 deletions

View File

@ -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)<station[i]<max(x1,x2) and min(y1,y2)<p.z<max(y1,y2)):
listi.append(i)
listp.append(p)
return listi, listp
def _compute_hydrolics(self, z):
profile = self.data