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

SL: Add cmd apply for reach.

Showing with 179 additions and 2 deletions
+179 -2
# -*- 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()
......@@ -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()
......
......@@ -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
......@@ -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()
......@@ -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>
......
<?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>
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