mirror of https://gitlab.com/pamhyr/pamhyr2
SL: Add cmd apply for reach.
parent
ebd05768a4
commit
edc99230d7
|
|
@ -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()
|
||||||
|
|
@ -142,6 +142,14 @@ class TableModel(QAbstractTableModel):
|
||||||
self.dataChanged.emit(index, index)
|
self.dataChanged.emit(index, index)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def apply_sl_each_profile(self, sl):
|
||||||
|
self._undo.push(
|
||||||
|
ApplySLCommand(
|
||||||
|
self._reach, sl
|
||||||
|
)
|
||||||
|
)
|
||||||
|
self.layoutChanged.emit()
|
||||||
|
|
||||||
def undo(self):
|
def undo(self):
|
||||||
self._undo.undo()
|
self._undo.undo()
|
||||||
self.layoutChanged.emit()
|
self.layoutChanged.emit()
|
||||||
|
|
|
||||||
|
|
@ -30,3 +30,22 @@ class SetSLCommand(QUndoCommand):
|
||||||
|
|
||||||
def redo(self):
|
def redo(self):
|
||||||
self._reach.profile(self._index).sl = self._new
|
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.UndoCommand import *
|
||||||
from View.SedimentLayers.Reach.Table import *
|
from View.SedimentLayers.Reach.Table import *
|
||||||
from View.SedimentLayers.Reach.Plot import Plot
|
from View.SedimentLayers.Reach.Plot import Plot
|
||||||
|
from View.SedimentLayers.Reach.SLDialog import SLDialog
|
||||||
|
|
||||||
from View.Plot.MplCanvas import MplCanvas
|
from View.Plot.MplCanvas import MplCanvas
|
||||||
from View.SedimentLayers.Reach.translate import *
|
from View.SedimentLayers.Reach.translate import *
|
||||||
|
|
@ -111,6 +112,13 @@ class ReachSedimentLayersWindow(ASubMainWindow, ListedSubWindow):
|
||||||
def setup_connections(self):
|
def setup_connections(self):
|
||||||
self.find(QAction, "action_edit").triggered.connect(self.edit_profile)
|
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.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)
|
||||||
|
|
@ -140,6 +148,15 @@ class ReachSedimentLayersWindow(ASubMainWindow, ListedSubWindow):
|
||||||
def redo(self):
|
def redo(self):
|
||||||
self._table.redo()
|
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):
|
def edit_profile(self):
|
||||||
rows = self.index_selected_rows()
|
rows = self.index_selected_rows()
|
||||||
|
|
||||||
|
|
@ -150,3 +167,11 @@ class ReachSedimentLayersWindow(ASubMainWindow, ListedSubWindow):
|
||||||
parent = self
|
parent = self
|
||||||
)
|
)
|
||||||
slw.show()
|
slw.show()
|
||||||
|
|
||||||
|
|
||||||
|
def edit_sl(self):
|
||||||
|
slw = SedimentLayersWindow(
|
||||||
|
study = self._study,
|
||||||
|
parent = self
|
||||||
|
)
|
||||||
|
slw.show()
|
||||||
|
|
|
||||||
|
|
@ -26,14 +26,14 @@
|
||||||
<widget class="QTableView" name="tableView"/>
|
<widget class="QTableView" name="tableView"/>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="pushButton">
|
<widget class="QPushButton" name="pushButton_edit">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Edit sediment layers list</string>
|
<string>Edit sediment layers list</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="pushButton_2">
|
<widget class="QPushButton" name="pushButton_apply">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Apply sediment layers on all reach</string>
|
<string>Apply sediment layers on all reach</string>
|
||||||
</property>
|
</property>
|
||||||
|
|
|
||||||
|
|
@ -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>
|
||||||
Loading…
Reference in New Issue