diff --git a/src/View/SedimentLayers/Reach/SLDialog.py b/src/View/SedimentLayers/Reach/SLDialog.py new file mode 100644 index 0000000000000000000000000000000000000000..ed4d32481292ad455c1441df8d1fd232768bc2da --- /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 d9cac0956fbd980aae6094d01d3367c402fadeda..8fdb8d7e87099902ccab21d6799edf3a1f65e8ae 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 82ba3764e15606d1fa2cdeb720883600269c06bc..17e1f0f1d308855606e2e8a0b972dc57b48d3983 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 4d155cec80f726cf5ef84d9519e12723f4e379aa..01f363483e82ebfc229639d470b5053ff44468df 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 a1beb8caa877c20aef815a81b511a79a34cefcb7..dfe39a823d819abf8351e0cf9cc490438fb209be 100644 --- a/src/View/ui/ReachSedimentLayers.ui +++ b/src/View/ui/ReachSedimentLayers.ui @@ -26,14 +26,14 @@ <widget class="QTableView" name="tableView"/> </item> <item> - <widget class="QPushButton" name="pushButton"> + <widget class="QPushButton" name="pushButton_edit"> <property name="text"> <string>Edit sediment layers list</string> </property> </widget> </item> <item> - <widget class="QPushButton" name="pushButton_2"> + <widget class="QPushButton" name="pushButton_apply"> <property name="text"> <string>Apply sediment layers on all reach</string> </property> diff --git a/src/View/ui/SLDialog.ui b/src/View/ui/SLDialog.ui new file mode 100644 index 0000000000000000000000000000000000000000..8681418bd621fdbbf0016add2de546e03f1fc947 --- /dev/null +++ b/src/View/ui/SLDialog.ui @@ -0,0 +1,67 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>Dialog</class> + <widget class="QDialog" name="Dialog"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>194</width> + <height>76</height> + </rect> + </property> + <property name="windowTitle"> + <string>Dialog</string> + </property> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0"> + <widget class="QComboBox" name="comboBox"/> + </item> + <item row="1" column="0"> + <widget class="QDialogButtonBox" name="buttonBox"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="standardButtons"> + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections> + <connection> + <sender>buttonBox</sender> + <signal>accepted()</signal> + <receiver>Dialog</receiver> + <slot>accept()</slot> + <hints> + <hint type="sourcelabel"> + <x>248</x> + <y>254</y> + </hint> + <hint type="destinationlabel"> + <x>157</x> + <y>274</y> + </hint> + </hints> + </connection> + <connection> + <sender>buttonBox</sender> + <signal>rejected()</signal> + <receiver>Dialog</receiver> + <slot>reject()</slot> + <hints> + <hint type="sourcelabel"> + <x>316</x> + <y>260</y> + </hint> + <hint type="destinationlabel"> + <x>286</x> + <y>274</y> + </hint> + </hints> + </connection> + </connections> +</ui>