diff --git a/src/Model/SedimentLayer/SedimentLayer.py b/src/Model/SedimentLayer/SedimentLayer.py index a18b88fb6f20079254c2cf5f70bf14bb9ac9a3fd..20af62fd7c98d8c1507801f10c47abea79b3768e 100644 --- a/src/Model/SedimentLayer/SedimentLayer.py +++ b/src/Model/SedimentLayer/SedimentLayer.py @@ -284,6 +284,7 @@ class SedimentLayer(SQLSubModel): l = self._layers l[index], l[next] = l[next], l[index] + self._status.modified() def move_down(self, index): @@ -292,4 +293,5 @@ class SedimentLayer(SQLSubModel): l = self._layers l[index], l[prev] = l[prev], l[index] + self._status.modified() diff --git a/src/View/SedimentLayers/Edit/Table.py b/src/View/SedimentLayers/Edit/Table.py index 32790f1bebd1279a1cdd12aa2108fd297b802927..47a870099ac720beaab549f00b9c71f0024b62d1 100644 --- a/src/View/SedimentLayers/Edit/Table.py +++ b/src/View/SedimentLayers/Edit/Table.py @@ -124,7 +124,7 @@ class TableModel(QAbstractTableModel): self.beginMoveRows(parent, row - 1, row - 1, parent, target) - self._undo_stack.push( + self._undo.push( MoveCommand( self._sl, "up", row ) @@ -133,7 +133,7 @@ class TableModel(QAbstractTableModel): self.endMoveRows() self.layoutChanged.emit() - def move_down(self, index, parent=QModelIndex()): + def move_down(self, row, parent=QModelIndex()): if row > len(self._sl): return @@ -141,7 +141,7 @@ class TableModel(QAbstractTableModel): self.beginMoveRows(parent, row + 1, row + 1, parent, target) - self._undo_stack.push( + self._undo.push( MoveCommand( self._sl, "down", row ) diff --git a/src/View/SedimentLayers/Edit/Window.py b/src/View/SedimentLayers/Edit/Window.py index a95e4ff08e372061d96887b825d61d1ce3926206..965895d24c176f76d42a78b02041560b85ab0681 100644 --- a/src/View/SedimentLayers/Edit/Window.py +++ b/src/View/SedimentLayers/Edit/Window.py @@ -91,7 +91,9 @@ class EditSedimentLayersWindow(ASubMainWindow, ListedSubWindow): self.canvas.setObjectName("canvas") self.plot_layout = self.find(QVBoxLayout, "verticalLayout") self.plot_layout.addWidget(self.canvas) + self._set_plot() + def _set_plot(self): self.plot = Plot( canvas = self.canvas, data = self._sl, @@ -104,14 +106,17 @@ class EditSedimentLayersWindow(ASubMainWindow, ListedSubWindow): def setup_connections(self): self.find(QAction, "action_add").triggered.connect(self.add) self.find(QAction, "action_del").triggered.connect(self.delete) - self.find(QAction, "action_move_up").triggered.connect(self.delete) - self.find(QAction, "action_move_down").triggered.connect(self.delete) + self.find(QAction, "action_move_up").triggered.connect(self.move_up) + self.find(QAction, "action_move_down").triggered.connect(self.move_down) self.undo_sc.activated.connect(self.undo) self.redo_sc.activated.connect(self.redo) self.copy_sc.activated.connect(self.copy) self.paste_sc.activated.connect(self.paste) + self._table.dataChanged.connect(self._set_plot) + self._table.layoutChanged.connect(self._set_plot) + def index_selected_rows(self): table = self.find(QTableView, f"tableView") return list( @@ -138,6 +143,20 @@ class EditSedimentLayersWindow(ASubMainWindow, ListedSubWindow): self._table.delete(rows) + def move_up(self): + rows = self.index_selected_rows() + if len(rows) == 0: + return + + self._table.move_up(rows[0]) + + def move_down(self): + rows = self.index_selected_rows() + if len(rows) == 0: + return + + self._table.move_down(rows[0]) + def copy(self): logger.info("TODO: copy") diff --git a/src/View/SedimentLayers/Window.py b/src/View/SedimentLayers/Window.py index b04c073d97591cf4df341865bfaa9ad995fb7485..f8b9d2d2676b50b88fbb0de095d9291efdf2f240 100644 --- a/src/View/SedimentLayers/Window.py +++ b/src/View/SedimentLayers/Window.py @@ -27,6 +27,8 @@ from PyQt5.QtWidgets import ( from View.SedimentLayers.UndoCommand import * from View.SedimentLayers.Table import * +from View.SedimentLayers.Edit.Plot import Plot + from View.Plot.MplCanvas import MplCanvas from View.SedimentLayers.translate import * @@ -85,15 +87,6 @@ class SedimentLayersWindow(ASubMainWindow, ListedSubWindow): self.plot_layout = self.find(QVBoxLayout, "verticalLayout") self.plot_layout.addWidget(self.canvas) - # self.plot = PlotKPC( - # canvas = self.canvas, - # data = self._reach.reach, - # toolbar = None, - # display_current = False - # ) - # self.plot.draw() - - def setup_connections(self): self.find(QAction, "action_add").triggered.connect(self.add) self.find(QAction, "action_del").triggered.connect(self.delete) @@ -104,6 +97,29 @@ class SedimentLayersWindow(ASubMainWindow, ListedSubWindow): self.copy_sc.activated.connect(self.copy) self.paste_sc.activated.connect(self.paste) + table = self.find(QTableView, f"tableView") + table.selectionModel()\ + .selectionChanged\ + .connect(self._set_current_sl) + + self._table.dataChanged\ + .connect(self._set_current_sl) + + def _set_current_sl(self): + rows = self.index_selected_rows() + + if len(rows) == 0: + return + + self.plot = Plot( + canvas = self.canvas, + data = self._sediment_layers.get(rows[0]), + toolbar = None, + display_current = False + ) + self.plot.draw() + + def index_selected_rows(self): table = self.find(QTableView, f"tableView") return list(