WeatherParam: SetData targets the object, and no longer the line index in the tab, which reduces the risk of error with multiple QUndoCommand, and rewrite of the logic for the other UndoCommand

This commit is contained in:
Dylan Jeannin committed 2026-07-28 13:50:21 +02:00
1 parent 7b2c276643
commit 516efb64e8
4 files changed
+91 -76

No files matched your search

@@ -636,14 +636,38 @@ class WeatherParameters(SQLSubModel):
def add(self, index: int):
value = Data(self._default_0, self._default_1, status=self._status)
self._data.insert(index, value)
self.modified()
self.insert(index, value)
return value
def insert(self, index: int, value):
visible_data = self.data
if index < len(visible_data):
index = self._data.index(visible_data[index])
else:
index = len(self._data)
self._data.insert(index, value)
self.modified()
def set_data_value(self, value, column, data):
value[column] = self._types[column](data)
self.modified()
def set_deleted(self, values, deleted):
for value in values:
if deleted:
value.set_as_deleted()
else:
value.set_as_not_deleted()
self.modified()
def reorder(self, values):
values = iter(values)
self._data = [
value if value.is_deleted() else next(values)
for value in self._data
]
self.modified()
def delete_i(self, indexes):
self._data = list(
map(
@@ -692,10 +716,7 @@ class WeatherParameters(SQLSubModel):
return lst
def _set_i_c_v(self, index, column, value):
v = self._data[index]
v[column] = self._types[column](value)
self._data[index] = v
self.modified()
self.set_data_value(self.get_i(index), column, value)
def set_i_0(self, index: int, value):
self._set_i_c_v(index, 0, value)
@@ -726,15 +747,13 @@ class WeatherParameters(SQLSubModel):
return new
def move_up(self, index):
if index < len(self):
next = index - 1
d = self._data
d[index], d[next] = d[next], d[index]
self.modified()
if 0 < index < len(self):
data = self.data
data[index - 1], data[index] = data[index], data[index - 1]
self.reorder(data)
def move_down(self, index):
if index >= 0:
prev = index + 1
d = self._data
d[index], d[prev] = d[prev], d[index]
self.modified()
if 0 <= index < len(self) - 1:
data = self.data
data[index], data[index + 1] = data[index + 1], data[index]
self.reorder(data)