diff --git a/src/View/Geometry/PlotKPZ.py b/src/View/Geometry/PlotKPZ.py index 142cc7d0..7d7921a5 100644 --- a/src/View/Geometry/PlotKPZ.py +++ b/src/View/Geometry/PlotKPZ.py @@ -202,11 +202,11 @@ class PlotKPZ(PamhyrPlot): ) def color_hightlight(self): - rows = list( + rows = sorted(list( set( (i.row() for i in self.parent.tableView.selectedIndexes()) ) - ) + )) colors = [self.color_plot for row in range(len(self._data))] style = ["-" for row in range(len(self._data))] if len(rows) >0: diff --git a/src/View/Geometry/PlotXY.py b/src/View/Geometry/PlotXY.py index ea50eff3..a96fd45b 100644 --- a/src/View/Geometry/PlotXY.py +++ b/src/View/Geometry/PlotXY.py @@ -193,11 +193,11 @@ class PlotXY(PamhyrPlot): self.canvas.axes.add_collection(self.line_xy_collection) def color_hightlight(self): - rows = list( + rows = sorted(list( set( (i.row() for i in self.parent.tableView.selectedIndexes()) ) - ) + )) colors = [self.color_plot for row in range(len(self._data))] style = ["-" for row in range(len(self._data))] if len(rows) >0: diff --git a/src/View/Geometry/Profile/Plot.py b/src/View/Geometry/Profile/Plot.py index 8c9fadce..f8ced64e 100644 --- a/src/View/Geometry/Profile/Plot.py +++ b/src/View/Geometry/Profile/Plot.py @@ -70,7 +70,41 @@ class Plot(PamhyrPlot): None # Hydrolic values (z, wet_area, # wet_preimeter, water_width) ) - self.events = [] + self._onpickevent = None + + def onrelease(self, event): + # we need to do that to prevent conflicst between onpick and rect_select_callback + modifiers = QApplication.keyboardModifiers() + points, hyd = self.highlight + if self._onpickevent is not None: + ind, point = self._closest_point(self._onpickevent) + if modifiers == Qt.ControlModifier: + rows = self._parent.index_selected_rows() + if ind in rows: + rows.remove(ind) + del(points[ind]) + self.highlight = (points, hyd) + self._select_in_table(rows) + else: + self.highlight = (points+[point], hyd) + self._select_in_table(rows+[ind]) + elif modifiers == Qt.ShiftModifier: + rows = self._parent.index_selected_rows() + if len(rows)>0: + i1 = min(rows[0], rows[-1], ind) + i2 = max(rows[0], rows[-1], ind) + p = [[self.data.points[i].x,self.data.points[i].y] for i in range(i1, i2)] + else: + i1 = ind + i2 = ind + p = [point] + self.highlight = (p, hyd) + self._select_range_in_table(i1, i2) + else: + self.highlight = ([point], hyd) + self._select_in_table([ind]) + + self._onpickevent = None def onpick(self, event): if event.mouseevent.inaxes != self.canvas.axes: @@ -82,37 +116,7 @@ class Plot(PamhyrPlot): if modifiers not in [Qt.ControlModifier, Qt.NoModifier, Qt.ShiftModifier]: return - points, hyd = self.highlight - - ind, point = self._closest_point(event) - - if modifiers == Qt.ControlModifier: - rows = self._parent.index_selected_rows() - if ind in rows: - rows.remove(ind) - del(points[ind]) - self.highlight = (points, hyd) - self._select_in_table(rows) - else: - self.highlight = (points+[point], hyd) - self._select_in_table(rows+[ind]) - elif modifiers == Qt.ShiftModifier: - rows = self._parent.index_selected_rows() - if len(rows)>0: - i1 = min(rows[0], rows[-1], ind) - i2 = max(rows[0], rows[-1], ind) - p = [[self.data.points[i].x,self.data.points[i].y] for i in range(i1, i2)] - else: - i1 = ind - i2 = ind - p = [point] - self.highlight = (p, hyd) - self._select_range_in_table(i1, i2) - else: - self.highlight = ([point], hyd) - self._select_in_table([ind]) - - self.update() + self._onpickevent = event return def onclick(self, event): @@ -227,6 +231,7 @@ class Plot(PamhyrPlot): def rect_select_callback(self, eclick, erelease): + points, hyd = self.highlight x1, y1 = eclick.xdata, eclick.ydata x2, y2 = erelease.xdata, erelease.ydata @@ -234,13 +239,12 @@ class Plot(PamhyrPlot): return modifiers = QApplication.keyboardModifiers() - points, hyd = self.highlight x1, y1 = eclick.xdata, eclick.ydata x2, y2 = erelease.xdata, erelease.ydata inds, points2 = self._points_in_rectangle(x1, y1, x2, y2) - + self._onclickevent = None if modifiers == Qt.ControlModifier: rows = self._parent.index_selected_rows() if all(i in rows for i in inds): @@ -255,8 +259,6 @@ class Plot(PamhyrPlot): else: self.highlight = (points2, hyd) self._select_in_table(inds) - - self.update() return def _points_in_rectangle(self, x1, y1, x2, y2): @@ -267,7 +269,7 @@ class Plot(PamhyrPlot): for i, p in enumerate(self.data.points): if (min(x1,x2)