From f8355021e7817dddf43b9fe8a16fe12ad6dfc6bb Mon Sep 17 00:00:00 2001
From: Pierre-Antoine Rouby <pierre-antoine.rouby@inrae.fr>
Date: Thu, 4 May 2023 10:22:39 +0200
Subject: [PATCH] BC: Edit: Fix update plot.

---
 src/View/BoundaryCondition/Edit/Plot.py   | 12 ++++++++----
 src/View/BoundaryCondition/Edit/Window.py | 15 +++++++++++++++
 2 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/src/View/BoundaryCondition/Edit/Plot.py b/src/View/BoundaryCondition/Edit/Plot.py
index be3ad854..39af012c 100644
--- a/src/View/BoundaryCondition/Edit/Plot.py
+++ b/src/View/BoundaryCondition/Edit/Plot.py
@@ -35,7 +35,7 @@ class Plot(APlot):
             x, y,
             color='r', lw=1.,
             markersize=5, marker='+',
-            picker=30
+            picker=30,
         )
 
         # Plot label
@@ -47,9 +47,10 @@ class Plot(APlot):
             table_headers[header[1]], color='black', fontsize=10
         )
 
+        self.canvas.axes.autoscale_view(True, True, True)
         self.canvas.figure.tight_layout()
         self.canvas.figure.canvas.draw_idle()
-        self.toolbar.update()
+        #self.toolbar.update()
 
         self._init = True
 
@@ -59,9 +60,12 @@ class Plot(APlot):
             self.draw()
             return
 
-        # if ind is not None:
+        x = list(map(lambda v: v[0], self.data.data))
+        y = list(map(lambda v: v[1], self.data.data))
 
-        # else:
+        self._line.set_data(x, y)
 
+        self.canvas.axes.relim()
+        self.canvas.axes.autoscale()
         self.canvas.figure.tight_layout()
         self.canvas.figure.canvas.draw_idle()
diff --git a/src/View/BoundaryCondition/Edit/Window.py b/src/View/BoundaryCondition/Edit/Window.py
index 4a2bbc55..1b2e554c 100644
--- a/src/View/BoundaryCondition/Edit/Window.py
+++ b/src/View/BoundaryCondition/Edit/Window.py
@@ -95,6 +95,11 @@ class EditBoundaryConditionWindow(ASubMainWindow, ListedSubWindow):
         self.copy_sc.activated.connect(self.copy)
         self.paste_sc.activated.connect(self.paste)
 
+        self._table.dataChanged.connect(self.update)
+
+    def update(self):
+        self.plot.update()
+
     def index_selected_row(self):
         table = self.find(QTableView, "tableView")
         return table.selectionModel()\
@@ -121,33 +126,43 @@ class EditBoundaryConditionWindow(ASubMainWindow, ListedSubWindow):
         else:
             self._table.add(rows[0])
 
+        self.plot.update()
+
     def delete(self):
         rows = self.index_selected_rows()
         if len(rows) == 0:
             return
 
         self._table.delete(rows)
+        self.plot.update()
 
     def sort(self):
         self._table.sort(False)
+        self.plot.update()
 
     def move_up(self):
         row = self.index_selected_row()
         self._table.move_up(row)
+        self.plot.update()
 
     def move_down(self):
         row = self.index_selected_row()
         self._table.move_down(row)
+        self.plot.update()
 
 
     def copy(self):
         print("TODO")
+        self.plot.update()
 
     def paste(self):
         print("TODO")
+        self.plot.update()
 
     def undo(self):
         self._table.undo()
+        self.plot.update()
 
     def redo(self):
         self._table.redo()
+        self.plot.update()
-- 
GitLab