mirror of https://gitlab.com/pamhyr/pamhyr2
fix tab elts related to pollutants, and fix add/del functionnality for LateralContributionAdisTS
parent
b3d631943c
commit
2db1f4c7f7
|
|
@ -65,7 +65,8 @@ class BoundaryConditionAdisTSWindow(PamhyrWindow):
|
||||||
trad = BCAdisTSTranslate()
|
trad = BCAdisTSTranslate()
|
||||||
|
|
||||||
self._pollutant_name = next(
|
self._pollutant_name = next(
|
||||||
(x.name for x in study._river._Pollutants.Pollutants_List if x.id == self._pollutant_id),
|
(x.name for x in study._river._Pollutants.Pollutants_List
|
||||||
|
if x.id == self._pollutant_id),
|
||||||
None
|
None
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -68,14 +68,16 @@ class InitialConditionsAdisTSWindow(PamhyrWindow):
|
||||||
_pamhyr_ui = "InitialConditionsAdisTS"
|
_pamhyr_ui = "InitialConditionsAdisTS"
|
||||||
_pamhyr_name = "Initial condition AdisTS"
|
_pamhyr_name = "Initial condition AdisTS"
|
||||||
|
|
||||||
def __init__(self, data=None, pollutant_id=None, study=None, config=None, parent=None):
|
def __init__(self, data=None, pollutant_id=None, study=None,
|
||||||
|
config=None, parent=None):
|
||||||
self._data = []
|
self._data = []
|
||||||
self._data.append(data)
|
self._data.append(data)
|
||||||
self._pollutant_id = pollutant_id
|
self._pollutant_id = pollutant_id
|
||||||
trad = IcAdisTSTranslate()
|
trad = IcAdisTSTranslate()
|
||||||
|
|
||||||
self._pollutant_name = next(
|
self._pollutant_name = next(
|
||||||
(x.name for x in study._river._Pollutants.Pollutants_List if x.id == self._pollutant_id),
|
(x.name for x in study._river._Pollutants.Pollutants_List
|
||||||
|
if x.id == self._pollutant_id),
|
||||||
None
|
None
|
||||||
)
|
)
|
||||||
name = (
|
name = (
|
||||||
|
|
|
||||||
|
|
@ -116,10 +116,22 @@ class TableModel(PamhyrTableModel):
|
||||||
self._pollutant = pollutant
|
self._pollutant = pollutant
|
||||||
|
|
||||||
super(TableModel, self).__init__(trad=trad, **kwargs)
|
super(TableModel, self).__init__(trad=trad, **kwargs)
|
||||||
|
self._setup_lst()
|
||||||
|
|
||||||
def _setup_lst(self):
|
def _setup_lst(self):
|
||||||
self._lst = self._data.lateral_contributions_adists.lst
|
if self._lcs_list is not None:
|
||||||
self._tab = self._opt_data
|
self._lcs_pol_list = [
|
||||||
|
lcs for lcs in self._lcs_list.lst
|
||||||
|
if lcs.pollutant == self._pollutant
|
||||||
|
]
|
||||||
|
|
||||||
|
self._lst = list(
|
||||||
|
filter(
|
||||||
|
lambda x: x._deleted is False,
|
||||||
|
self._lcs_pol_list
|
||||||
|
)
|
||||||
|
)
|
||||||
|
# self._tab = self._opt_data
|
||||||
self._long_types = self._trad.get_dict("long_types")
|
self._long_types = self._trad.get_dict("long_types")
|
||||||
|
|
||||||
def rowCount(self, parent):
|
def rowCount(self, parent):
|
||||||
|
|
@ -190,17 +202,43 @@ class TableModel(PamhyrTableModel):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self._setup_lst()
|
||||||
self.endInsertRows()
|
self.endInsertRows()
|
||||||
self.layoutChanged.emit()
|
self.layoutChanged.emit()
|
||||||
|
|
||||||
def delete(self, rows, parent=QModelIndex()):
|
def delete(self, rows, parent=QModelIndex()):
|
||||||
self.beginRemoveRows(parent, rows[0], rows[-1])
|
self.beginRemoveRows(parent, rows[0], rows[-1])
|
||||||
|
|
||||||
|
global_rows = list(
|
||||||
|
map(self._global_row, rows)
|
||||||
|
)
|
||||||
self._undo.push(
|
self._undo.push(
|
||||||
DelCommand(
|
DelCommand(
|
||||||
self._lst, rows
|
self._lcs_list, global_rows
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self._setup_lst()
|
||||||
self.endRemoveRows()
|
self.endRemoveRows()
|
||||||
self.layoutChanged.emit()
|
self.layoutChanged.emit()
|
||||||
|
|
||||||
|
def undo(self):
|
||||||
|
self._undo.undo()
|
||||||
|
self._setup_lst()
|
||||||
|
self.layoutChanged.emit()
|
||||||
|
|
||||||
|
def redo(self):
|
||||||
|
self._undo.redo()
|
||||||
|
self._setup_lst()
|
||||||
|
self.layoutChanged.emit()
|
||||||
|
|
||||||
|
def get(self, row):
|
||||||
|
if row < 0 or row >= len(self._lst):
|
||||||
|
return None
|
||||||
|
return self._lst[row]
|
||||||
|
|
||||||
|
def _global_row(self, row):
|
||||||
|
bc = self.get(row)
|
||||||
|
if bc is None:
|
||||||
|
return None
|
||||||
|
return self._lcs_list.index(bc)
|
||||||
|
|
|
||||||
|
|
@ -91,13 +91,13 @@ class AddCommand(QUndoCommand):
|
||||||
self._new = None
|
self._new = None
|
||||||
|
|
||||||
def undo(self):
|
def undo(self):
|
||||||
del self._lcs[self._index]
|
self._lcs.delete_i(self._index)
|
||||||
|
|
||||||
def redo(self):
|
def redo(self):
|
||||||
if self._new is None:
|
if self._new is None:
|
||||||
self._new = self._lcs.new(self._index, self._pollutant)
|
self._new = self._lcs.new(self._index, self._pollutant)
|
||||||
else:
|
else:
|
||||||
self._lcs_lst.insert(self._index, self._new)
|
self._lcs.insert(self._index, self._new)
|
||||||
|
|
||||||
|
|
||||||
class DelCommand(QUndoCommand):
|
class DelCommand(QUndoCommand):
|
||||||
|
|
@ -107,15 +107,14 @@ class DelCommand(QUndoCommand):
|
||||||
self._lcs = lcs
|
self._lcs = lcs
|
||||||
self._rows = rows
|
self._rows = rows
|
||||||
|
|
||||||
self._bc = []
|
self._lc = []
|
||||||
for row in rows:
|
for row in rows:
|
||||||
self._bc.append((row, self._lcs[row]))
|
self._lc.append((row, self._lcs.get(row)))
|
||||||
self._bc.sort()
|
self._lc.sort()
|
||||||
|
|
||||||
def undo(self):
|
def undo(self):
|
||||||
for row, el in self._bc:
|
for row, el in self._lc:
|
||||||
self._lcs.insert(row, el)
|
self._lcs.insert(row, el)
|
||||||
|
|
||||||
def redo(self):
|
def redo(self):
|
||||||
for row in self._rows:
|
self._lcs.delete_i(self._rows)
|
||||||
del self._lcs[row]
|
|
||||||
|
|
|
||||||
|
|
@ -57,11 +57,24 @@ class LateralContributionAdisTSWindow(PamhyrWindow):
|
||||||
_pamhyr_ui = "LateralContributionsAdisTS"
|
_pamhyr_ui = "LateralContributionsAdisTS"
|
||||||
_pamhyr_name = "Lateral contribution AdisTS"
|
_pamhyr_name = "Lateral contribution AdisTS"
|
||||||
|
|
||||||
def __init__(self, study=None, pollutant=None, config=None, parent=None):
|
def __init__(self, data=None, study=None, pollutant_id=None,
|
||||||
|
config=None, parent=None):
|
||||||
|
self._pollutant = pollutant_id
|
||||||
|
self._study = study
|
||||||
|
self._data = data
|
||||||
trad = LCTranslate()
|
trad = LCTranslate()
|
||||||
name = trad[self._pamhyr_name] + " - " + study.name
|
|
||||||
|
|
||||||
self._pollutant = pollutant
|
self._pollutant_name = next(
|
||||||
|
(x.name for x in study._river._Pollutants.Pollutants_List
|
||||||
|
if x.id == self._pollutant),
|
||||||
|
None
|
||||||
|
)
|
||||||
|
|
||||||
|
name = (
|
||||||
|
trad[self._pamhyr_name] +
|
||||||
|
" - " + study.name +
|
||||||
|
" - " + self._pollutant_name
|
||||||
|
)
|
||||||
|
|
||||||
super(LateralContributionAdisTSWindow, self).__init__(
|
super(LateralContributionAdisTSWindow, self).__init__(
|
||||||
title=name,
|
title=name,
|
||||||
|
|
@ -110,7 +123,7 @@ class LateralContributionAdisTSWindow(PamhyrWindow):
|
||||||
data=self._study.river,
|
data=self._study.river,
|
||||||
undo=self._undo_stack,
|
undo=self._undo_stack,
|
||||||
trad=self._trad,
|
trad=self._trad,
|
||||||
opt_data="liquid",
|
# opt_data="liquid",
|
||||||
pollutant=self._pollutant,
|
pollutant=self._pollutant,
|
||||||
lcs_list=self._lcs,
|
lcs_list=self._lcs,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -258,6 +258,9 @@ class PollutantsWindow(PamhyrWindow):
|
||||||
|
|
||||||
pollutant_id = self._pollutants_lst.get(rows[0]).id
|
pollutant_id = self._pollutants_lst.get(rows[0]).id
|
||||||
|
|
||||||
|
lclist = self._study.river.lateral_contributions_adists.Lat_Cont_List
|
||||||
|
lcs_adists = [x for x in lclist if x.pollutant == pollutant_id]
|
||||||
|
|
||||||
if self.sub_window_exists(
|
if self.sub_window_exists(
|
||||||
LateralContributionAdisTSWindow,
|
LateralContributionAdisTSWindow,
|
||||||
data=[self._study, pollutant_id, None]
|
data=[self._study, pollutant_id, None]
|
||||||
|
|
@ -266,8 +269,9 @@ class PollutantsWindow(PamhyrWindow):
|
||||||
|
|
||||||
lateral = LateralContributionAdisTSWindow(
|
lateral = LateralContributionAdisTSWindow(
|
||||||
study=self._study,
|
study=self._study,
|
||||||
pollutant=pollutant_id,
|
parent=self,
|
||||||
parent=self
|
data=lcs_adists,
|
||||||
|
pollutant_id=pollutant_id,
|
||||||
)
|
)
|
||||||
lateral.show()
|
lateral.show()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue