mirror of https://gitlab.com/pamhyr/pamhyr2
HS: Create a enabled undo command.
parent
ac2a2002b7
commit
1ab1cb37b0
|
|
@ -38,7 +38,7 @@ from View.Tools.PamhyrTable import PamhyrTableModel
|
|||
|
||||
from View.HydraulicStructures.UndoCommand import (
|
||||
SetNameCommand, SetReachCommand, SetKpCommand,
|
||||
AddCommand, DelCommand,
|
||||
SetEnabledCommand, AddCommand, DelCommand,
|
||||
)
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
|
@ -189,6 +189,14 @@ class TableModel(PamhyrTableModel):
|
|||
self.endRemoveRows()
|
||||
self.layoutChanged.emit()
|
||||
|
||||
def enabled(self, row, enabled, parent=QModelIndex()):
|
||||
self._undo.push(
|
||||
SetEnabledCommand(
|
||||
self._lst, row, enabled
|
||||
)
|
||||
)
|
||||
self.layoutChanged.emit()
|
||||
|
||||
def undo(self):
|
||||
self._undo.undo()
|
||||
self.layoutChanged.emit()
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import logging
|
||||
|
||||
from copy import deepcopy
|
||||
from tools import trace, timer
|
||||
|
||||
|
|
@ -23,6 +25,8 @@ from PyQt5.QtWidgets import (
|
|||
QMessageBox, QUndoCommand, QUndoStack,
|
||||
)
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
class SetNameCommand(QUndoCommand):
|
||||
def __init__(self, h_s_lst, index, new_value):
|
||||
|
|
@ -78,6 +82,23 @@ class SetKpCommand(QUndoCommand):
|
|||
self._h_s_lst.get(self._index).input_kp = self._new
|
||||
|
||||
|
||||
class SetEnabledCommand(QUndoCommand):
|
||||
def __init__(self, h_s_lst, index, enabled):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._h_s_lst = h_s_lst
|
||||
self._index = index
|
||||
self._old = not enabled
|
||||
self._new = enabled
|
||||
|
||||
def undo(self):
|
||||
logger.info(f"Undo {self._new} -> {self._old}")
|
||||
self._h_s_lst.get(self._index).enabled = self._old
|
||||
|
||||
def redo(self):
|
||||
logger.info(f"Undo {self._old} -> {self._new}")
|
||||
self._h_s_lst.get(self._index).enabled = self._new
|
||||
|
||||
class AddCommand(QUndoCommand):
|
||||
def __init__(self, h_s_lst, index):
|
||||
QUndoCommand.__init__(self)
|
||||
|
|
|
|||
|
|
@ -161,7 +161,7 @@ class HydraulicStructuresWindow(PamhyrWindow):
|
|||
self.find(QAction, "action_add").triggered.connect(self.add)
|
||||
self.find(QAction, "action_delete").triggered.connect(self.delete)
|
||||
#self.find(QAction, "action_edit").triggered.connect(self.edit)
|
||||
self._checkbox.stateChanged.connect(self._set_structure_state)
|
||||
self._checkbox.clicked.connect(self._set_structure_state)
|
||||
|
||||
table = self.find(QTableView, "tableView")
|
||||
table.selectionModel()\
|
||||
|
|
@ -173,8 +173,8 @@ class HydraulicStructuresWindow(PamhyrWindow):
|
|||
|
||||
def index_selected(self):
|
||||
table = self.find(QTableView, "tableView")
|
||||
r = table.selectionModel()\
|
||||
.selectedRows()
|
||||
r = table.selectionModel().selectedRows()
|
||||
|
||||
if len(r)>0:
|
||||
return r[0]
|
||||
else:
|
||||
|
|
@ -182,8 +182,8 @@ class HydraulicStructuresWindow(PamhyrWindow):
|
|||
|
||||
def index_selected_row(self):
|
||||
table = self.find(QTableView, "tableView")
|
||||
r = table.selectionModel()\
|
||||
.selectedRows()
|
||||
r = table.selectionModel().selectedRows()
|
||||
|
||||
if len(r)>0:
|
||||
return r[0].row()
|
||||
else:
|
||||
|
|
@ -256,10 +256,11 @@ class HydraulicStructuresWindow(PamhyrWindow):
|
|||
|
||||
def _set_structure_state(self):
|
||||
row = self.index_selected_row()
|
||||
if row is None:
|
||||
self._checkbox.setEnabled(False)
|
||||
else:
|
||||
self._hs_lst.get(row).enabled = self._checkbox.isChecked()
|
||||
if row is not None:
|
||||
self._table.enabled(
|
||||
row,
|
||||
self._checkbox.isChecked()
|
||||
)
|
||||
|
||||
def update(self):
|
||||
self._set_checkbox_state()
|
||||
|
|
|
|||
Loading…
Reference in New Issue