mirror of https://gitlab.com/pamhyr/pamhyr2
WeatherParameters: Correct add and implement del function on tab_spec
parent
a01e47f205
commit
5dcc82d81e
|
|
@ -68,8 +68,8 @@ class ComboBoxDelegate(QItemDelegate):
|
||||||
self.editor = QComboBox(parent)
|
self.editor = QComboBox(parent)
|
||||||
|
|
||||||
if self._mode == "rk":
|
if self._mode == "rk":
|
||||||
wp = None
|
wp = index.model().get(index.row())
|
||||||
if self._weather_param_lst is not None:
|
if wp is None and self._weather_param_lst is not None:
|
||||||
wp = self._weather_param_lst.get(index.row())
|
wp = self._weather_param_lst.get(index.row())
|
||||||
if wp is None or wp.reach is None:
|
if wp is None or wp.reach is None:
|
||||||
self.editor.addItems(
|
self.editor.addItems(
|
||||||
|
|
@ -102,8 +102,8 @@ class ComboBoxDelegate(QItemDelegate):
|
||||||
|
|
||||||
if self._mode == "rk":
|
if self._mode == "rk":
|
||||||
value = None
|
value = None
|
||||||
wp = None
|
wp = index.model().get(index.row())
|
||||||
if self._weather_param_lst is not None:
|
if wp is None and self._weather_param_lst is not None:
|
||||||
wp = self._weather_param_lst.get(index.row())
|
wp = self._weather_param_lst.get(index.row())
|
||||||
if wp is not None and wp.reach is not None:
|
if wp is not None and wp.reach is not None:
|
||||||
profiles = list(
|
profiles = list(
|
||||||
|
|
@ -152,6 +152,22 @@ class WeatherParametersTableModel(PamhyrTableModel):
|
||||||
self._setup_lst()
|
self._setup_lst()
|
||||||
self.layoutChanged.emit()
|
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):
|
||||||
|
wp = self.get(row)
|
||||||
|
if wp is None:
|
||||||
|
return None
|
||||||
|
return self._data.index(wp)
|
||||||
|
|
||||||
|
def _global_insert_row(self, row):
|
||||||
|
if row < len(self._lst):
|
||||||
|
return self._global_row(row)
|
||||||
|
return len(self._data)
|
||||||
|
|
||||||
def rowCount(self, parent):
|
def rowCount(self, parent):
|
||||||
return len(self._lst)
|
return len(self._lst)
|
||||||
|
|
||||||
|
|
@ -191,32 +207,36 @@ class WeatherParametersTableModel(PamhyrTableModel):
|
||||||
column = index.column()
|
column = index.column()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
global_row = self._global_row(row)
|
||||||
|
if global_row is None:
|
||||||
|
return False
|
||||||
|
|
||||||
if self._headers[column] == "start_rk":
|
if self._headers[column] == "start_rk":
|
||||||
_edge = self._data.get(row).reach
|
_edge = self._data.get(global_row).reach
|
||||||
_begin_rk = next(
|
_begin_rk = next(
|
||||||
p for p in _edge.reach.profiles
|
p for p in _edge.reach.profiles
|
||||||
if p.pamhyr_id == value
|
if p.pamhyr_id == value
|
||||||
)
|
)
|
||||||
self._undo.push(
|
self._undo.push(
|
||||||
SetBeginCommand(
|
SetBeginCommand(
|
||||||
self._data, row, _begin_rk
|
self._data, global_row, _begin_rk
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
elif self._headers[column] == "end_rk":
|
elif self._headers[column] == "end_rk":
|
||||||
_edge = self._data.get(row).reach
|
_edge = self._data.get(global_row).reach
|
||||||
_end_rk = next(
|
_end_rk = next(
|
||||||
p for p in _edge.reach.profiles
|
p for p in _edge.reach.profiles
|
||||||
if p.pamhyr_id == value
|
if p.pamhyr_id == value
|
||||||
)
|
)
|
||||||
self._undo.push(
|
self._undo.push(
|
||||||
SetEndCommand(
|
SetEndCommand(
|
||||||
self._data, row, _end_rk
|
self._data, global_row, _end_rk
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
elif self._headers[column] == "reach":
|
elif self._headers[column] == "reach":
|
||||||
self._undo.push(
|
self._undo.push(
|
||||||
SetEdgeCommand(
|
SetEdgeCommand(
|
||||||
self._data, row, self._river.edge(value)
|
self._data, global_row, self._river.edge(value)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
@ -227,11 +247,12 @@ class WeatherParametersTableModel(PamhyrTableModel):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def add(self, row, parent=QModelIndex()):
|
def add(self, row, parent=QModelIndex()):
|
||||||
self.beginInsertRows(parent, row, row - 1)
|
self.beginInsertRows(parent, row, row)
|
||||||
|
|
||||||
self._undo.push(
|
self._undo.push(
|
||||||
AddCommand(
|
AddCommand(
|
||||||
self._data, self._type, self._lst, row
|
self._data, self._type, self._lst,
|
||||||
|
self._global_insert_row(row)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -241,15 +262,17 @@ class WeatherParametersTableModel(PamhyrTableModel):
|
||||||
|
|
||||||
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])
|
||||||
|
|
||||||
data_rows = {
|
data_rows = {
|
||||||
id(ica): i for i, ica in enumerate(self._data._data)
|
id(wp): i for i, wp in enumerate(self._data.lst)
|
||||||
}
|
}
|
||||||
self._undo.push(
|
self._undo.push(
|
||||||
DelCommand(
|
DelCommand(
|
||||||
self._data,
|
wps=self._data,
|
||||||
self._data._data,
|
rows=[
|
||||||
[data_rows[id(self._lst[row])] for row in rows]
|
data_rows[id(self._lst[row])]
|
||||||
|
for row in rows
|
||||||
|
if 0 <= row < len(self._lst)
|
||||||
|
]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -150,21 +150,20 @@ class AddCommand(QUndoCommand):
|
||||||
|
|
||||||
|
|
||||||
class DelCommand(QUndoCommand):
|
class DelCommand(QUndoCommand):
|
||||||
def __init__(self, data, wps_spec, rows):
|
def __init__(self, wps, rows):
|
||||||
QUndoCommand.__init__(self)
|
QUndoCommand.__init__(self)
|
||||||
|
|
||||||
self._data = data
|
self._wps = wps
|
||||||
self._wps_spec = wps_spec
|
|
||||||
self._rows = rows
|
self._rows = rows
|
||||||
|
|
||||||
self._ic = []
|
self._wp = []
|
||||||
for row in rows:
|
for row in rows:
|
||||||
self._ic.append((row, self._wps_spec[row]))
|
self._wp.append(self._wps.get(row))
|
||||||
self._ic.sort()
|
|
||||||
|
|
||||||
def undo(self):
|
def undo(self):
|
||||||
for row, el in self._ic:
|
for el in self._wp:
|
||||||
self._data.insert(row, el)
|
el.set_as_not_deleted()
|
||||||
|
|
||||||
def redo(self):
|
def redo(self):
|
||||||
self._data.delete_i(self._rows)
|
for el in self._wp:
|
||||||
|
el.set_as_deleted()
|
||||||
|
|
|
||||||
|
|
@ -238,6 +238,18 @@ class WeatherParametersWindow(PamhyrWindow):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def index_selected_rows_spec(self):
|
||||||
|
table = self.table_spec
|
||||||
|
return list(
|
||||||
|
# Delete duplicate
|
||||||
|
set(
|
||||||
|
map(
|
||||||
|
lambda i: i.row(),
|
||||||
|
table.selectedIndexes()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
def move_up(self):
|
def move_up(self):
|
||||||
row = self.index_selected_row()
|
row = self.index_selected_row()
|
||||||
self._table.move_up(row)
|
self._table.move_up(row)
|
||||||
|
|
@ -326,7 +338,7 @@ class WeatherParametersWindow(PamhyrWindow):
|
||||||
self._table_spec.add(rows[0])
|
self._table_spec.add(rows[0])
|
||||||
|
|
||||||
def delete(self):
|
def delete(self):
|
||||||
rows = self.index_selected_rows()
|
rows = self.index_selected_rows_spec()
|
||||||
if len(rows) == 0:
|
if len(rows) == 0:
|
||||||
return
|
return
|
||||||
self._table_spec.delete(rows)
|
self._table_spec.delete(rows)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue