INISPEC DEL

adists_num
Youcef AOUAD 2024-06-12 16:56:05 +02:00
parent cd68bebf03
commit f917dd9284
3 changed files with 34 additions and 7 deletions

View File

@ -37,6 +37,7 @@ from View.Tools.PamhyrTable import PamhyrTableModel
from View.InitialConditionsAdisTS.UndoCommand import (
SetCommand, AddCommand, SetCommandSpec,
DelCommand,
)
logger = logging.getLogger()
@ -129,7 +130,7 @@ class InitialConditionTableModel(PamhyrTableModel):
if self._headers[column] is "name":
n = self._lst[row].name
if n is None:
if n is None or n == "":
return self._trad['not_associated']
return n
elif self._headers[column] is "reach":

View File

@ -168,4 +168,22 @@ class AddCommand(QUndoCommand):
self._new = self._data.new(self._index)
else:
self._ics_spec.insert(self._index, self._new)
class DelCommand(QUndoCommand):
def __init__(self, data, ics_spec, rows):
QUndoCommand.__init__(self)
self._ics_spec = ics_spec
self._rows = rows
self._ic = []
for row in rows:
self._ic.append((row, self._ics_spec.get(row)))
self._ic.sort()
def undo(self):
for row, el in self._ic:
self._ics_spec.insert(row, el)
def redo(self):
self._ics_spec.delete_i(self._rows)

View File

@ -30,7 +30,7 @@ from PyQt5.QtGui import (
from PyQt5.QtCore import (
Qt, QVariant, QAbstractTableModel,
QCoreApplication, QModelIndex, pyqtSlot,
QRect,
QRect, QItemSelectionModel,
)
from PyQt5.QtWidgets import (
@ -92,8 +92,6 @@ class InitialConditionsAdisTSWindow(PamhyrWindow):
self._ics_adists_lst = study.river.initial_conditions_adists
print("setup tables")
self.setup_table()
self.ui.setWindowTitle(self._title)
@ -151,8 +149,6 @@ class InitialConditionsAdisTSWindow(PamhyrWindow):
mode="kp"
)
print("hello table", self._study.river)
self._table_spec = InitialConditionTableModel(
table_view=table_spec,
table_headers=self._trad.get_dict("table_headers_spec"),
@ -173,6 +169,17 @@ class InitialConditionsAdisTSWindow(PamhyrWindow):
table_spec.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
table_spec.setAlternatingRowColors(True)
selectionModel = table_spec.selectionModel()
index = table_spec.model().index(0, 0)
selectionModel.select(
index,
QItemSelectionModel.Rows |
QItemSelectionModel.ClearAndSelect |
QItemSelectionModel.Select
)
table_spec.scrollTo(index)
def index_selected_row(self):
table = self.find(QTableView, f"tableView")
rows = table.selectionModel()\
@ -260,7 +267,6 @@ class InitialConditionsAdisTSWindow(PamhyrWindow):
self._update()
def add(self):
print("Hello")
rows = self.index_selected_rows()
if len(self._data[0]._data) == 0 or len(rows) == 0:
self._table_spec.add(0)
@ -268,7 +274,9 @@ class InitialConditionsAdisTSWindow(PamhyrWindow):
self._table_spec.add(rows[0])
def delete(self):
print("del")
rows = self.index_selected_rows()
if len(rows) == 0:
print("len 0")
return
self._table_spec.delete(rows)