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

mesh
Pierre-Antoine Rouby 2023-07-25 15:43:02 +02:00
parent ef398c78b1
commit b0810f6eed
4 changed files with 51 additions and 14 deletions

View File

@ -284,6 +284,7 @@ class SedimentLayer(SQLSubModel):
l = self._layers l = self._layers
l[index], l[next] = l[next], l[index] l[index], l[next] = l[next], l[index]
self._status.modified() self._status.modified()
def move_down(self, index): def move_down(self, index):
@ -292,4 +293,5 @@ class SedimentLayer(SQLSubModel):
l = self._layers l = self._layers
l[index], l[prev] = l[prev], l[index] l[index], l[prev] = l[prev], l[index]
self._status.modified() self._status.modified()

View File

@ -124,7 +124,7 @@ class TableModel(QAbstractTableModel):
self.beginMoveRows(parent, row - 1, row - 1, parent, target) self.beginMoveRows(parent, row - 1, row - 1, parent, target)
self._undo_stack.push( self._undo.push(
MoveCommand( MoveCommand(
self._sl, "up", row self._sl, "up", row
) )
@ -133,7 +133,7 @@ class TableModel(QAbstractTableModel):
self.endMoveRows() self.endMoveRows()
self.layoutChanged.emit() self.layoutChanged.emit()
def move_down(self, index, parent=QModelIndex()): def move_down(self, row, parent=QModelIndex()):
if row > len(self._sl): if row > len(self._sl):
return return
@ -141,7 +141,7 @@ class TableModel(QAbstractTableModel):
self.beginMoveRows(parent, row + 1, row + 1, parent, target) self.beginMoveRows(parent, row + 1, row + 1, parent, target)
self._undo_stack.push( self._undo.push(
MoveCommand( MoveCommand(
self._sl, "down", row self._sl, "down", row
) )

View File

@ -91,7 +91,9 @@ class EditSedimentLayersWindow(ASubMainWindow, ListedSubWindow):
self.canvas.setObjectName("canvas") self.canvas.setObjectName("canvas")
self.plot_layout = self.find(QVBoxLayout, "verticalLayout") self.plot_layout = self.find(QVBoxLayout, "verticalLayout")
self.plot_layout.addWidget(self.canvas) self.plot_layout.addWidget(self.canvas)
self._set_plot()
def _set_plot(self):
self.plot = Plot( self.plot = Plot(
canvas = self.canvas, canvas = self.canvas,
data = self._sl, data = self._sl,
@ -104,14 +106,17 @@ class EditSedimentLayersWindow(ASubMainWindow, ListedSubWindow):
def setup_connections(self): def setup_connections(self):
self.find(QAction, "action_add").triggered.connect(self.add) self.find(QAction, "action_add").triggered.connect(self.add)
self.find(QAction, "action_del").triggered.connect(self.delete) self.find(QAction, "action_del").triggered.connect(self.delete)
self.find(QAction, "action_move_up").triggered.connect(self.delete) self.find(QAction, "action_move_up").triggered.connect(self.move_up)
self.find(QAction, "action_move_down").triggered.connect(self.delete) self.find(QAction, "action_move_down").triggered.connect(self.move_down)
self.undo_sc.activated.connect(self.undo) self.undo_sc.activated.connect(self.undo)
self.redo_sc.activated.connect(self.redo) self.redo_sc.activated.connect(self.redo)
self.copy_sc.activated.connect(self.copy) self.copy_sc.activated.connect(self.copy)
self.paste_sc.activated.connect(self.paste) 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): def index_selected_rows(self):
table = self.find(QTableView, f"tableView") table = self.find(QTableView, f"tableView")
return list( return list(
@ -138,6 +143,20 @@ class EditSedimentLayersWindow(ASubMainWindow, ListedSubWindow):
self._table.delete(rows) 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): def copy(self):
logger.info("TODO: copy") logger.info("TODO: copy")

View File

@ -27,6 +27,8 @@ from PyQt5.QtWidgets import (
from View.SedimentLayers.UndoCommand import * from View.SedimentLayers.UndoCommand import *
from View.SedimentLayers.Table import * from View.SedimentLayers.Table import *
from View.SedimentLayers.Edit.Plot import Plot
from View.Plot.MplCanvas import MplCanvas from View.Plot.MplCanvas import MplCanvas
from View.SedimentLayers.translate import * from View.SedimentLayers.translate import *
@ -85,15 +87,6 @@ class SedimentLayersWindow(ASubMainWindow, ListedSubWindow):
self.plot_layout = self.find(QVBoxLayout, "verticalLayout") self.plot_layout = self.find(QVBoxLayout, "verticalLayout")
self.plot_layout.addWidget(self.canvas) 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): def setup_connections(self):
self.find(QAction, "action_add").triggered.connect(self.add) self.find(QAction, "action_add").triggered.connect(self.add)
self.find(QAction, "action_del").triggered.connect(self.delete) 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.copy_sc.activated.connect(self.copy)
self.paste_sc.activated.connect(self.paste) 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): def index_selected_rows(self):
table = self.find(QTableView, f"tableView") table = self.find(QTableView, f"tableView")
return list( return list(