mirror of https://gitlab.com/pamhyr/pamhyr2
update model + view to display only BCAdisTS related to pollutant, and not the global list, todo: reconnect add/del buttons
parent
63836527c7
commit
23361d142e
|
|
@ -312,6 +312,7 @@ class BoundaryConditionAdisTS(SQLSubModel):
|
|||
status = data['status']
|
||||
nodes = data['nodes']
|
||||
scenario = data["scenario"]
|
||||
pollutant = data["pollutant"]
|
||||
loaded = data['loaded_pid']
|
||||
|
||||
if scenario is None:
|
||||
|
|
@ -321,7 +322,8 @@ class BoundaryConditionAdisTS(SQLSubModel):
|
|||
"SELECT pamhyr_id, deleted, pollutant, type, node, scenario " +
|
||||
"FROM boundary_condition_adists " +
|
||||
f"WHERE scenario = {scenario.id} " +
|
||||
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))}) "
|
||||
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))}) " +
|
||||
f"AND pollutant = {pollutant.id} "
|
||||
)
|
||||
|
||||
if table is not None:
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ from tools import (
|
|||
from Model.Tools.PamhyrDB import SQLSubModel
|
||||
from Model.Except import NotImplementedMethodeError
|
||||
from Model.Scenario import Scenario
|
||||
from Model.BoundaryConditionsAdisTS.BoundaryConditionAdisTS import BoundaryConditionAdisTS
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
|
@ -275,7 +276,8 @@ class PollutantCharacteristics(SQLSubModel):
|
|||
|
||||
|
||||
class Pollutants(SQLSubModel):
|
||||
_sub_classes = [PollutantCharacteristics]
|
||||
_sub_classes = [PollutantCharacteristics,
|
||||
BoundaryConditionAdisTS]
|
||||
|
||||
def __init__(self, id: int = -1, name: str = "",
|
||||
status=None, owner_scenario=-1):
|
||||
|
|
@ -293,6 +295,11 @@ class Pollutants(SQLSubModel):
|
|||
self._enabled = True
|
||||
|
||||
self._data = []
|
||||
self._boundary_conditions_adists = []
|
||||
|
||||
@property
|
||||
def boundary_conditions_adists(self):
|
||||
return self._boundary_conditions_adists
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
|
@ -415,6 +422,10 @@ class Pollutants(SQLSubModel):
|
|||
new_pollutant._data = PollutantCharacteristics._db_load(
|
||||
execute, data=data
|
||||
)
|
||||
|
||||
new_pollutant._boundary_conditions_adists = BoundaryConditionAdisTS._db_load(
|
||||
execute, data=data
|
||||
)
|
||||
|
||||
loaded.add(pid)
|
||||
new.append(new_pollutant)
|
||||
|
|
@ -455,6 +466,9 @@ class Pollutants(SQLSubModel):
|
|||
for d in self._data:
|
||||
ok &= d._db_save(execute, data)
|
||||
|
||||
for bc in self._boundary_conditions_adists:
|
||||
ok &= bc._db_save(execute, data)
|
||||
|
||||
return ok
|
||||
|
||||
def _data_traversal(self,
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Reference in New Issue