adists_num
Youcef AOUAD 2024-06-13 14:35:40 +02:00
parent f917dd9284
commit 716d0af96f
6 changed files with 50 additions and 33 deletions

View File

@ -96,8 +96,6 @@ class InitialConditionsAdisTS(SQLSubModel):
"FROM initial_conditions_adists"
)
print("db load ic adists : ", table)
if table is not None:
for row in table:
IC_id = row[0]
@ -259,16 +257,13 @@ class InitialConditionsAdisTS(SQLSubModel):
self._status.modified()
def delete_i(self, indexes):
data = list(
map(
lambda x: x[1],
filter(
lambda x: x[0] in indexes,
enumerate(self._data)
)
)
)
self.delete(data)
for ind in indexes:
del self._data[ind]
self._status.modified()
def insert(self, index, data):
self._data.insert(index, data)
self._status.modified()

View File

@ -98,6 +98,7 @@ class ICAdisTSSpec(SQLSubModel):
)
for row in table:
id = row[0]
name = row[2]
reach = row[3]
start_kp = row[4]
@ -109,7 +110,24 @@ class ICAdisTSSpec(SQLSubModel):
rate = row[10]
enabled = (row[11] == 1)
new_spec = [name, reach, start_kp, end_kp, concentration, eg, em, ed, rate, enabled]
#new_spec = [name, reach, start_kp, end_kp, concentration, eg, em, ed, rate, enabled]
new_spec = cls(
id=id,
name=name,
status=data['status']
)
new_spec.reach = reach
new_spec.start_kp = start_kp
new_spec.end_kp = end_kp
new_spec.concentration = concentration
new_spec.eg = eg
new_spec.em = em
new_spec.ed = ed
new_spec.rate = rate
new_spec.enabled = enabled
new.append(new_spec)
return new

View File

@ -116,11 +116,12 @@ class InitialConditionTableModel(PamhyrTableModel):
self._data = data
print("init table model : ", self._river)
def _setup_lst(self):
self._lst = self._data._data
def rowCount(self, parent):
return len(self._lst)
def data(self, index, role):
if role != Qt.ItemDataRole.DisplayRole:
return QVariant()
@ -135,7 +136,6 @@ class InitialConditionTableModel(PamhyrTableModel):
return n
elif self._headers[column] is "reach":
n = self._lst[row].reach
print(n)
if n is None:
return self._trad['not_associated']
return next(filter(lambda edge: edge.id == n, self._river.edges())).name

View File

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

View File

@ -71,7 +71,6 @@ class InitialConditionsAdisTSWindow(PamhyrWindow):
def __init__(self, data=None, study=None, config=None, parent=None):
self._data = []
self._data.append(data)
print(self._data[0]._data)
trad = IcAdisTSTranslate()
name = (
@ -131,8 +130,8 @@ class InitialConditionsAdisTSWindow(PamhyrWindow):
toolBar.addAction(action_add)
toolBar.addAction(action_delete)
table_spec = QTableView()
layout.addWidget(table_spec)
self.table_spec = QTableView()
layout.addWidget(self.table_spec)
self._delegate_reach = ComboBoxDelegate(
trad=self._trad,
@ -150,7 +149,7 @@ class InitialConditionsAdisTSWindow(PamhyrWindow):
)
self._table_spec = InitialConditionTableModel(
table_view=table_spec,
table_view=self.table_spec,
table_headers=self._trad.get_dict("table_headers_spec"),
editable_headers=["name", "reach", "start_kp", "end_kp", "concentration", "eg", "em", "ed", "rate"],
delegates={
@ -164,13 +163,13 @@ class InitialConditionsAdisTSWindow(PamhyrWindow):
river=self._study.river
)
table_spec.setModel(self._table_spec)
table_spec.setSelectionBehavior(QAbstractItemView.SelectRows)
table_spec.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
table_spec.setAlternatingRowColors(True)
self.table_spec.setModel(self._table_spec)
self.table_spec.setSelectionBehavior(QAbstractItemView.SelectRows)
self.table_spec.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
self.table_spec.setAlternatingRowColors(True)
selectionModel = table_spec.selectionModel()
index = table_spec.model().index(0, 0)
selectionModel = self.table_spec.selectionModel()
index = self.table_spec.model().index(0, 0)
selectionModel.select(
index,
@ -178,10 +177,11 @@ class InitialConditionsAdisTSWindow(PamhyrWindow):
QItemSelectionModel.ClearAndSelect |
QItemSelectionModel.Select
)
table_spec.scrollTo(index)
self.table_spec.scrollTo(index)
def index_selected_row(self):
table = self.find(QTableView, f"tableView")
#table = self.find(QTableView, f"tableView")
table = self.table_spec
rows = table.selectionModel()\
.selectedRows()
@ -191,7 +191,8 @@ class InitialConditionsAdisTSWindow(PamhyrWindow):
return rows[0].row()
def index_selected_rows(self):
table = self.find(QTableView, f"tableView")
#table = self.find(QTableView, f"tableView")
table = self.table_spec
return list(
# Delete duplicate
set(