mirror of
https://gitlab.com/pamhyr/pamhyr2.git
synced 2026-10-30 03:20:41 +01:00
update model + view to display only BCAdisTS related to pollutant, and not the global list, todo: reconnect add/del buttons
This commit is contained in:
1 parent
c498ed2d96
commit
a68270ff67
6 files changed
+66
-61
No files matched your search
@@ -112,18 +112,21 @@ class ComboBoxDelegate(QItemDelegate):
|
||||
|
||||
|
||||
class TableModel(PamhyrTableModel):
|
||||
def __init__(self, pollutant=None, bc_list=None, trad=None, **kwargs):
|
||||
def __init__(self, bc_list=None, pollutant_bc_list=None, trad=None, **kwargs):
|
||||
self._trad = trad
|
||||
self._bc_list = bc_list
|
||||
self._pollutant = pollutant
|
||||
self._pollutant = pollutant_bc_list.id
|
||||
self._pollutant_bc_list = pollutant_bc_list
|
||||
|
||||
super(TableModel, self).__init__(trad=trad, **kwargs)
|
||||
|
||||
def _setup_lst(self):
|
||||
self._lst = self._pollutant_bc_list.boundary_conditions_adists
|
||||
|
||||
def rowCount(self, parent):
|
||||
return len(self._bc_list)
|
||||
return len(self._lst)
|
||||
|
||||
def data(self, index, role):
|
||||
|
||||
if role != Qt.ItemDataRole.DisplayRole:
|
||||
return QVariant()
|
||||
|
||||
@@ -131,12 +134,12 @@ class TableModel(PamhyrTableModel):
|
||||
column = index.column()
|
||||
|
||||
if self._headers[column] == "type":
|
||||
n = self._bc_list.get(row).type
|
||||
n = self._lst[row].type
|
||||
if n is None or n == "":
|
||||
return self._trad["not_associated"]
|
||||
return n
|
||||
elif self._headers[column] == "node":
|
||||
n = self._bc_list.get(row).node
|
||||
n = self._lst[row].node
|
||||
if n is None:
|
||||
return self._trad["not_associated"]
|
||||
tmp = next(filter(lambda x: x.id == n, self._data._nodes), None)
|
||||
@@ -144,18 +147,6 @@ class TableModel(PamhyrTableModel):
|
||||
return tmp.name
|
||||
else:
|
||||
return self._trad["not_associated"]
|
||||
elif self._headers[column] == "pol":
|
||||
n = self._bc_list.get(row).pollutant
|
||||
if n is None or n == "not_associated" or n == "":
|
||||
return self._trad["not_associated"]
|
||||
tmp = next(filter(lambda x: x.id == n,
|
||||
self._data._Pollutants.Pollutants_List
|
||||
),
|
||||
None)
|
||||
if tmp is not None:
|
||||
return tmp.name
|
||||
else:
|
||||
return self._trad["not_associated"]
|
||||
|
||||
return QVariant()
|
||||
|
||||
@@ -179,22 +170,7 @@ class TableModel(PamhyrTableModel):
|
||||
self._bc_list, row, self._data.node(value)
|
||||
)
|
||||
)
|
||||
elif self._headers[column] == "pol":
|
||||
if value == self._trad["not_associated"]:
|
||||
self._undo.push(
|
||||
SetPolCommand(
|
||||
self._bc_list, row, None
|
||||
)
|
||||
)
|
||||
else:
|
||||
pol = next(filter(lambda x: x.name == value,
|
||||
self._data._Pollutants.Pollutants_List)
|
||||
)
|
||||
self._undo.push(
|
||||
SetPolCommand(
|
||||
self._bc_list, row, pol.id
|
||||
)
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
logger.info(e)
|
||||
logger.debug(traceback.format_exc())
|
||||
|
||||
@@ -58,11 +58,21 @@ class BoundaryConditionAdisTSWindow(PamhyrWindow):
|
||||
_pamhyr_ui = "BoundaryConditionsAdisTS"
|
||||
_pamhyr_name = "Boundary conditions AdisTS"
|
||||
|
||||
def __init__(self, study=None, config=None, parent=None):
|
||||
def __init__(self, data=None, pollutant_id=None, study=None, config=None, parent=None):
|
||||
self._data = data
|
||||
self._pollutant_id = pollutant_id
|
||||
|
||||
_pollutants_lst = study._river._Pollutants.Pollutants_List
|
||||
self._pollutant_name = next(
|
||||
(x.name for x in _pollutants_lst if x.id == self._pollutant_id),
|
||||
None
|
||||
)
|
||||
|
||||
trad = BCAdisTSTranslate()
|
||||
name = (
|
||||
trad[self._pamhyr_name] +
|
||||
" - " + study.name
|
||||
" - " + study.name +
|
||||
" - " + self._pollutant_name
|
||||
)
|
||||
|
||||
super(BoundaryConditionAdisTSWindow, self).__init__(
|
||||
@@ -73,7 +83,6 @@ class BoundaryConditionAdisTSWindow(PamhyrWindow):
|
||||
parent=parent
|
||||
)
|
||||
|
||||
self._pollutants_lst = self._study._river._Pollutants
|
||||
self._bcs = self._study.river.boundary_conditions_adists
|
||||
|
||||
self.setup_graph()
|
||||
@@ -95,12 +104,6 @@ class BoundaryConditionAdisTSWindow(PamhyrWindow):
|
||||
mode="node",
|
||||
parent=self
|
||||
)
|
||||
self._delegate_pol = ComboBoxDelegate(
|
||||
trad=self._trad,
|
||||
data=self._study.river,
|
||||
mode="pol",
|
||||
parent=self
|
||||
)
|
||||
|
||||
table = self.find(QTableView, f"tableView")
|
||||
self._table = TableModel(
|
||||
@@ -110,10 +113,10 @@ class BoundaryConditionAdisTSWindow(PamhyrWindow):
|
||||
delegates={
|
||||
"type": self._delegate_type,
|
||||
"node": self._delegate_node,
|
||||
"pol": self._delegate_pol,
|
||||
},
|
||||
trad=self._trad,
|
||||
bc_list=self._study.river.boundary_conditions_adists,
|
||||
pollutant_bc_list=self._data,
|
||||
undo=self._undo_stack,
|
||||
data=self._study.river
|
||||
)
|
||||
@@ -156,7 +159,7 @@ class BoundaryConditionAdisTSWindow(PamhyrWindow):
|
||||
)
|
||||
|
||||
def add(self):
|
||||
self._table.add(len(self._bcs))
|
||||
self._table.add(len(self._data.boundary_conditions_adists))
|
||||
|
||||
def delete(self):
|
||||
rows = self.index_selected_rows()
|
||||
|
||||
@@ -34,5 +34,4 @@ class BCAdisTSTranslate(MainTranslate):
|
||||
self._sub_dict["table_headers"] = {
|
||||
"type": self._dict["type"],
|
||||
"node": _translate("BoundaryCondition", "Node"),
|
||||
"pol": _translate("BoundaryCondition", "Pollutant")
|
||||
}
|
||||
@@ -222,21 +222,32 @@ class PollutantsWindow(PamhyrWindow):
|
||||
initial.show()
|
||||
|
||||
def boundary_conditions(self):
|
||||
|
||||
if self.sub_window_exists(
|
||||
BoundaryConditionAdisTSWindow,
|
||||
data=[self._study, None]
|
||||
):
|
||||
bound = self.get_sub_window(
|
||||
BoundaryConditionAdisTSWindow,
|
||||
data=[self._study, None]
|
||||
)
|
||||
rows = self.index_selected_rows()
|
||||
if len(rows) == 0:
|
||||
return
|
||||
|
||||
bound = BoundaryConditionAdisTSWindow(
|
||||
study=self._study, parent=self
|
||||
)
|
||||
bound.show()
|
||||
for row in rows:
|
||||
pollutant_id = self._pollutants_lst.get(row).id
|
||||
|
||||
bclist = self._study.river.boundary_conditions_adists.BCs_AdisTS_List
|
||||
bcs_adists = [
|
||||
x for x in bclist
|
||||
if x.pollutant == pollutant_id
|
||||
]
|
||||
self._data = self._study.river.Pollutants.get(row)
|
||||
if self.sub_window_exists(
|
||||
BoundaryConditionAdisTSWindow,
|
||||
data=[self._study, None, bcs_adists]
|
||||
):
|
||||
return
|
||||
|
||||
bound = BoundaryConditionAdisTSWindow(
|
||||
study=self._study,
|
||||
parent=self,
|
||||
data=self._data,
|
||||
pollutant_id=pollutant_id
|
||||
)
|
||||
bound.show()
|
||||
|
||||
def lateral_contrib(self):
|
||||
rows = self.index_selected_rows()
|
||||
|
||||
Reference in new issue
Block a user