Commit b0810f6e authored by Pierre-Antoine Rouby's avatar Pierre-Antoine Rouby
Browse files

SL: Fix move on edit window and some minor fix.

Showing with 51 additions and 14 deletions
+51 -14
......@@ -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()
......@@ -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
)
......
......@@ -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")
......
......@@ -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(
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment