View main window: keep zoom on the geographical graph after a change in the geometry

dev_dylan
Dylan Jeannin 2026-09-08 14:02:53 +02:00
parent fc40552d68
commit bcc9dd1a0d
1 changed files with 16 additions and 0 deletions

View File

@ -27,6 +27,7 @@ class WidgetGraph(QWidget):
self._study = study self._study = study
self._trad = trad self._trad = trad
self._plot_river = None
layout = QHBoxLayout(self) layout = QHBoxLayout(self)
self._splitter = QSplitter(Qt.Horizontal, self) self._splitter = QSplitter(Qt.Horizontal, self)
@ -87,6 +88,14 @@ class WidgetGraph(QWidget):
) )
def update(self): def update(self):
river = self._study.river if self._study is not None else None
view = None
if river is not None and river is self._plot_river:
axes = self.canvas.axes
if axes.has_data():
view = (axes.get_xlim(), axes.get_ylim(),
axes.get_aspect(), axes.get_adjustable())
self._update_graph_title() self._update_graph_title()
if (self._graph_widget is not None if (self._graph_widget is not None
and (self._study is None and (self._study is None
@ -121,3 +130,10 @@ class WidgetGraph(QWidget):
parent=self parent=self
) )
self.plot.update() self.plot.update()
self._plot_river = river
if view is not None:
x_limits, y_limits, aspect, adjustable = view
self.canvas.axes.set_aspect(aspect, adjustable=adjustable)
self.canvas.axes.set_xlim(x_limits)
self.canvas.axes.set_ylim(y_limits)
self.canvas.draw_idle()