mirror of https://gitlab.com/pamhyr/pamhyr2
deal with conflicts between onpick and rect select in Profile plot
parent
fe57890da4
commit
c6b28ba3a0
|
|
@ -202,11 +202,11 @@ class PlotKPZ(PamhyrPlot):
|
||||||
)
|
)
|
||||||
|
|
||||||
def color_hightlight(self):
|
def color_hightlight(self):
|
||||||
rows = list(
|
rows = sorted(list(
|
||||||
set(
|
set(
|
||||||
(i.row() for i in self.parent.tableView.selectedIndexes())
|
(i.row() for i in self.parent.tableView.selectedIndexes())
|
||||||
)
|
)
|
||||||
)
|
))
|
||||||
colors = [self.color_plot for row in range(len(self._data))]
|
colors = [self.color_plot for row in range(len(self._data))]
|
||||||
style = ["-" for row in range(len(self._data))]
|
style = ["-" for row in range(len(self._data))]
|
||||||
if len(rows) >0:
|
if len(rows) >0:
|
||||||
|
|
|
||||||
|
|
@ -193,11 +193,11 @@ class PlotXY(PamhyrPlot):
|
||||||
self.canvas.axes.add_collection(self.line_xy_collection)
|
self.canvas.axes.add_collection(self.line_xy_collection)
|
||||||
|
|
||||||
def color_hightlight(self):
|
def color_hightlight(self):
|
||||||
rows = list(
|
rows = sorted(list(
|
||||||
set(
|
set(
|
||||||
(i.row() for i in self.parent.tableView.selectedIndexes())
|
(i.row() for i in self.parent.tableView.selectedIndexes())
|
||||||
)
|
)
|
||||||
)
|
))
|
||||||
colors = [self.color_plot for row in range(len(self._data))]
|
colors = [self.color_plot for row in range(len(self._data))]
|
||||||
style = ["-" for row in range(len(self._data))]
|
style = ["-" for row in range(len(self._data))]
|
||||||
if len(rows) >0:
|
if len(rows) >0:
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,41 @@ class Plot(PamhyrPlot):
|
||||||
None # Hydrolic values (z, wet_area,
|
None # Hydrolic values (z, wet_area,
|
||||||
# wet_preimeter, water_width)
|
# 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):
|
def onpick(self, event):
|
||||||
if event.mouseevent.inaxes != self.canvas.axes:
|
if event.mouseevent.inaxes != self.canvas.axes:
|
||||||
|
|
@ -82,37 +116,7 @@ class Plot(PamhyrPlot):
|
||||||
if modifiers not in [Qt.ControlModifier, Qt.NoModifier, Qt.ShiftModifier]:
|
if modifiers not in [Qt.ControlModifier, Qt.NoModifier, Qt.ShiftModifier]:
|
||||||
return
|
return
|
||||||
|
|
||||||
points, hyd = self.highlight
|
self._onpickevent = event
|
||||||
|
|
||||||
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()
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def onclick(self, event):
|
def onclick(self, event):
|
||||||
|
|
@ -227,6 +231,7 @@ class Plot(PamhyrPlot):
|
||||||
|
|
||||||
def rect_select_callback(self, eclick, erelease):
|
def rect_select_callback(self, eclick, erelease):
|
||||||
|
|
||||||
|
points, hyd = self.highlight
|
||||||
x1, y1 = eclick.xdata, eclick.ydata
|
x1, y1 = eclick.xdata, eclick.ydata
|
||||||
x2, y2 = erelease.xdata, erelease.ydata
|
x2, y2 = erelease.xdata, erelease.ydata
|
||||||
|
|
||||||
|
|
@ -234,13 +239,12 @@ class Plot(PamhyrPlot):
|
||||||
return
|
return
|
||||||
modifiers = QApplication.keyboardModifiers()
|
modifiers = QApplication.keyboardModifiers()
|
||||||
|
|
||||||
points, hyd = self.highlight
|
|
||||||
|
|
||||||
x1, y1 = eclick.xdata, eclick.ydata
|
x1, y1 = eclick.xdata, eclick.ydata
|
||||||
x2, y2 = erelease.xdata, erelease.ydata
|
x2, y2 = erelease.xdata, erelease.ydata
|
||||||
|
|
||||||
inds, points2 = self._points_in_rectangle(x1, y1, x2, y2)
|
inds, points2 = self._points_in_rectangle(x1, y1, x2, y2)
|
||||||
|
self._onclickevent = None
|
||||||
if modifiers == Qt.ControlModifier:
|
if modifiers == Qt.ControlModifier:
|
||||||
rows = self._parent.index_selected_rows()
|
rows = self._parent.index_selected_rows()
|
||||||
if all(i in rows for i in inds):
|
if all(i in rows for i in inds):
|
||||||
|
|
@ -255,8 +259,6 @@ class Plot(PamhyrPlot):
|
||||||
else:
|
else:
|
||||||
self.highlight = (points2, hyd)
|
self.highlight = (points2, hyd)
|
||||||
self._select_in_table(inds)
|
self._select_in_table(inds)
|
||||||
|
|
||||||
self.update()
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def _points_in_rectangle(self, x1, y1, x2, y2):
|
def _points_in_rectangle(self, x1, y1, x2, y2):
|
||||||
|
|
@ -267,7 +269,7 @@ class Plot(PamhyrPlot):
|
||||||
for i, p in enumerate(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)):
|
if (min(x1,x2)<station[i]<max(x1,x2) and min(y1,y2)<p.z<max(y1,y2)):
|
||||||
listi.append(i)
|
listi.append(i)
|
||||||
listp.append(p)
|
listp.append((station[i], p.z))
|
||||||
return listi, listp
|
return listi, listp
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -359,7 +361,6 @@ class Plot(PamhyrPlot):
|
||||||
x, y,
|
x, y,
|
||||||
color=self.color_plot_highlight,
|
color=self.color_plot_highlight,
|
||||||
lw=1.5, markersize=7, marker='+',
|
lw=1.5, markersize=7, marker='+',
|
||||||
picker=30
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,7 @@ class PamhyrPlot(APlot):
|
||||||
connector = {
|
connector = {
|
||||||
'pick_event': self.onpick,
|
'pick_event': self.onpick,
|
||||||
'button_press_event': self.onclick,
|
'button_press_event': self.onclick,
|
||||||
|
'button_release_event': self.onrelease,
|
||||||
}
|
}
|
||||||
|
|
||||||
for event in connector:
|
for event in connector:
|
||||||
|
|
@ -109,8 +110,8 @@ class PamhyrPlot(APlot):
|
||||||
onselect=self.rect_select_callback,
|
onselect=self.rect_select_callback,
|
||||||
useblit=True,
|
useblit=True,
|
||||||
button=[1], # don't use middle nor right button
|
button=[1], # don't use middle nor right button
|
||||||
minspanx=1.0,
|
minspanx=2.0,
|
||||||
minspany=1.0,
|
minspany=2.0,
|
||||||
spancoords='pixels',
|
spancoords='pixels',
|
||||||
interactive=False)
|
interactive=False)
|
||||||
|
|
||||||
|
|
@ -245,6 +246,9 @@ class PamhyrPlot(APlot):
|
||||||
def onclick(self, event):
|
def onclick(self, event):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def onrelease(self, event):
|
||||||
|
return
|
||||||
|
|
||||||
def rect_select_callback(self, eclick, erelease):
|
def rect_select_callback(self, eclick, erelease):
|
||||||
'eclick and erelease are the press and release events'
|
'eclick and erelease are the press and release events'
|
||||||
x1, y1 = eclick.xdata, eclick.ydata
|
x1, y1 = eclick.xdata, eclick.ydata
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue