diff --git a/src/View/SedimentLayers/Reach/SLDialog.py b/src/View/SedimentLayers/Reach/SLDialog.py new file mode 100644 index 00000000..ed4d3248 --- /dev/null +++ b/src/View/SedimentLayers/Reach/SLDialog.py @@ -0,0 +1,58 @@ +# -*- coding: utf-8 -*- + +from View.ASubWindow import ASubWindow +from View.ListedSubWindow import ListedSubWindow + +from PyQt5.QtGui import ( + QKeySequence, +) + +from PyQt5.QtCore import ( + Qt, QVariant, QAbstractTableModel, +) + +from PyQt5.QtWidgets import ( + QDialogButtonBox, QComboBox, QUndoStack, QShortcut, + QDoubleSpinBox, +) + +from View.SedimentLayers.Reach.translate import * + +_translate = QCoreApplication.translate + +class SLDialog(ASubWindow, ListedSubWindow): + def __init__(self, title="SL", study=None, parent=None): + self._study = study + + super(SLDialog, self).__init__( + name=title, ui="SLDialog", parent=parent + ) + + self.setup_combobox() + + self.value = None + + def setup_combobox(self): + self.combobox_add_items( + "comboBox", + [_translate("SedimentLayers", "Not defined")] + + list( + map( + lambda sl: str(sl), + self._study.river.sediment_layers.sediment_layers + ) + ) + ) + + @property + def sl(self): + return next( + filter( + lambda sl: str(sl) == self.value, + self._study.river.sediment_layers.sediment_layers + ) + ) + + def accept(self): + self.value = self.get_combobox_text("comboBox") + super().accept() diff --git a/src/View/SedimentLayers/Reach/Table.py b/src/View/SedimentLayers/Reach/Table.py index d9cac095..8fdb8d7e 100644 --- a/src/View/SedimentLayers/Reach/Table.py +++ b/src/View/SedimentLayers/Reach/Table.py @@ -142,6 +142,14 @@ class TableModel(QAbstractTableModel): self.dataChanged.emit(index, index) return True + def apply_sl_each_profile(self, sl): + self._undo.push( + ApplySLCommand( + self._reach, sl + ) + ) + self.layoutChanged.emit() + def undo(self): self._undo.undo() self.layoutChanged.emit() diff --git a/src/View/SedimentLayers/Reach/UndoCommand.py b/src/View/SedimentLayers/Reach/UndoCommand.py index 82ba3764..17e1f0f1 100644 --- a/src/View/SedimentLayers/Reach/UndoCommand.py +++ b/src/View/SedimentLayers/Reach/UndoCommand.py @@ -30,3 +30,22 @@ class SetSLCommand(QUndoCommand): def redo(self): self._reach.profile(self._index).sl = self._new + + +class ApplySLCommand(QUndoCommand): + def __init__(self, reach, new_value): + QUndoCommand.__init__(self) + + self._reach = reach + self._old = [] + for profile in self._reach.profiles: + self._old.append(profile.sl) + self._new = new_value + + def undo(self): + for i, profile in enumerate(self._reach.profiles): + profile.sl = self._old[i] + + def redo(self): + for profile in self._reach.profiles: + profile.sl = self._new diff --git a/src/View/SedimentLayers/Reach/Window.py b/src/View/SedimentLayers/Reach/Window.py index 4d155cec..01f36348 100644 --- a/src/View/SedimentLayers/Reach/Window.py +++ b/src/View/SedimentLayers/Reach/Window.py @@ -27,6 +27,7 @@ from PyQt5.QtWidgets import ( from View.SedimentLayers.Reach.UndoCommand import * from View.SedimentLayers.Reach.Table import * from View.SedimentLayers.Reach.Plot import Plot +from View.SedimentLayers.Reach.SLDialog import SLDialog from View.Plot.MplCanvas import MplCanvas from View.SedimentLayers.Reach.translate import * @@ -111,6 +112,13 @@ class ReachSedimentLayersWindow(ASubMainWindow, ListedSubWindow): def setup_connections(self): self.find(QAction, "action_edit").triggered.connect(self.edit_profile) + self.find(QPushButton, "pushButton_edit")\ + .clicked\ + .connect(self.edit_sl) + self.find(QPushButton, "pushButton_apply")\ + .clicked\ + .connect(self.apply_sl_each_profile) + self.undo_sc.activated.connect(self.undo) self.redo_sc.activated.connect(self.redo) self.copy_sc.activated.connect(self.copy) @@ -140,6 +148,15 @@ class ReachSedimentLayersWindow(ASubMainWindow, ListedSubWindow): def redo(self): self._table.redo() + def apply_sl_each_profile(self): + slw = SLDialog( + study = self._study, + parent = self + ) + if slw.exec(): + sl = slw.sl + self._table.apply_sl_each_profile(sl) + def edit_profile(self): rows = self.index_selected_rows() @@ -150,3 +167,11 @@ class ReachSedimentLayersWindow(ASubMainWindow, ListedSubWindow): parent = self ) slw.show() + + + def edit_sl(self): + slw = SedimentLayersWindow( + study = self._study, + parent = self + ) + slw.show() diff --git a/src/View/ui/ReachSedimentLayers.ui b/src/View/ui/ReachSedimentLayers.ui index a1beb8ca..dfe39a82 100644 --- a/src/View/ui/ReachSedimentLayers.ui +++ b/src/View/ui/ReachSedimentLayers.ui @@ -26,14 +26,14 @@ - + Edit sediment layers list - + Apply sediment layers on all reach diff --git a/src/View/ui/SLDialog.ui b/src/View/ui/SLDialog.ui new file mode 100644 index 00000000..8681418b --- /dev/null +++ b/src/View/ui/SLDialog.ui @@ -0,0 +1,67 @@ + + + Dialog + + + + 0 + 0 + 194 + 76 + + + + Dialog + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + Dialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + Dialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + +