mirror of https://gitlab.com/pamhyr/pamhyr2
Pollutants: Fixed pollutant deletion removing the absolute index instead of the relative index
parent
63b5cbaba7
commit
ddbaa0fb94
|
|
@ -48,7 +48,12 @@ _translate = QCoreApplication.translate
|
|||
|
||||
class TableModel(PamhyrTableModel):
|
||||
def _setup_lst(self):
|
||||
self._lst = self._data._Pollutants
|
||||
self._lst = list(
|
||||
filter(
|
||||
lambda dif: dif._deleted is False,
|
||||
self._data._Pollutants._lst
|
||||
)
|
||||
)
|
||||
|
||||
def rowCount(self, parent):
|
||||
return len(self._lst)
|
||||
|
|
@ -61,7 +66,7 @@ class TableModel(PamhyrTableModel):
|
|||
column = index.column()
|
||||
|
||||
if self._headers[column] == "name":
|
||||
return self._lst.get(row).name
|
||||
return self._lst[row].name
|
||||
|
||||
return QVariant()
|
||||
|
||||
|
|
@ -91,29 +96,36 @@ class TableModel(PamhyrTableModel):
|
|||
|
||||
self._undo.push(
|
||||
AddCommand(
|
||||
self._lst, row, self._data.ic_adists
|
||||
self._data._Pollutants, row, self._data.ic_adists
|
||||
)
|
||||
)
|
||||
|
||||
self._setup_lst()
|
||||
self.endInsertRows()
|
||||
self.layoutChanged.emit()
|
||||
|
||||
def delete(self, rows, parent=QModelIndex()):
|
||||
self.beginRemoveRows(parent, rows[0], rows[-1])
|
||||
|
||||
data_rows = {
|
||||
id(pol): i for i, pol in enumerate(self._data._Pollutants._lst)
|
||||
}
|
||||
self._undo.push(
|
||||
DelCommand(
|
||||
self._lst, rows, self._data.ic_adists
|
||||
self._data._Pollutants,
|
||||
[data_rows[id(self._lst[row])] for row in rows
|
||||
if 0 <= row < len(self._lst)],
|
||||
self._data.ic_adists
|
||||
)
|
||||
)
|
||||
|
||||
self._setup_lst()
|
||||
self.endRemoveRows()
|
||||
self.layoutChanged.emit()
|
||||
|
||||
def enabled(self, row, enabled, parent=QModelIndex()):
|
||||
self._undo.push(
|
||||
SetEnabledCommand(
|
||||
self._lst, row, enabled
|
||||
self._data._Pollutants, row, enabled
|
||||
)
|
||||
)
|
||||
self.layoutChanged.emit()
|
||||
|
|
|
|||
Loading…
Reference in New Issue