mirror of https://gitlab.com/pamhyr/pamhyr2
fix add/del/undo/redo in edit BoundaryConditionsAdisTS + quick fix in edit LateralContributionsAdisTS
parent
99cb2883a1
commit
11e1302e05
|
|
@ -143,9 +143,9 @@ class Data(SQLSubModel):
|
||||||
table = execute(
|
table = execute(
|
||||||
"SELECT pamhyr_id, deleted, data0, data1, scenario FROM " +
|
"SELECT pamhyr_id, deleted, data0, data1, scenario FROM " +
|
||||||
"boundary_condition_data_adists " +
|
"boundary_condition_data_adists " +
|
||||||
f"WHERE bca = {bca.id} " +
|
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 scenario = {scenario.id}"
|
f"AND bca = {bca.id}"
|
||||||
)
|
)
|
||||||
|
|
||||||
if table is not None:
|
if table is not None:
|
||||||
|
|
@ -188,8 +188,8 @@ class Data(SQLSubModel):
|
||||||
execute(
|
execute(
|
||||||
"INSERT INTO " +
|
"INSERT INTO " +
|
||||||
"boundary_condition_data_adists(" +
|
"boundary_condition_data_adists(" +
|
||||||
"pamhyr_id, data0, data1, bca, scenario) " +
|
"pamhyr_id, deleted, data0, data1, bca, scenario) " +
|
||||||
f"VALUES ({self.id}, '{data0}', {data1}, {bca.id}, " +
|
f"VALUES ({self.id}, {self._db_format(self.is_deleted())}, '{data0}', {data1}, {bca.id}, " +
|
||||||
f"{self._status.scenario_id})"
|
f"{self._status.scenario_id})"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -437,7 +437,14 @@ class BoundaryConditionAdisTS(SQLSubModel):
|
||||||
d._data_traversal(predicate, modifier, data)
|
d._data_traversal(predicate, modifier, data)
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
return len(self._data)
|
return len(
|
||||||
|
list(
|
||||||
|
filter(
|
||||||
|
lambda el: el is not None and not el.is_deleted(),
|
||||||
|
self._data
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def time_convert(cls, data):
|
def time_convert(cls, data):
|
||||||
|
|
@ -493,7 +500,12 @@ class BoundaryConditionAdisTS(SQLSubModel):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def data(self):
|
def data(self):
|
||||||
return self._data.copy()
|
return list(
|
||||||
|
filter(
|
||||||
|
lambda el: el is not None and not el.is_deleted(),
|
||||||
|
self._data
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _default_0(self):
|
def _default_0(self):
|
||||||
|
|
@ -537,7 +549,7 @@ class BoundaryConditionAdisTS(SQLSubModel):
|
||||||
def delete_i(self, indexes):
|
def delete_i(self, indexes):
|
||||||
self._data = list(
|
self._data = list(
|
||||||
map(
|
map(
|
||||||
lambda e: e[1],
|
lambda e: e[1].set_as_deleted(),
|
||||||
filter(
|
filter(
|
||||||
lambda e: e[0] not in indexes,
|
lambda e: e[0] not in indexes,
|
||||||
enumerate(self.data)
|
enumerate(self.data)
|
||||||
|
|
|
||||||
|
|
@ -410,7 +410,7 @@ class LateralContributionAdisTS(SQLSubModel):
|
||||||
return len(
|
return len(
|
||||||
list(
|
list(
|
||||||
filter(
|
filter(
|
||||||
lambda el: not el.is_deleted(),
|
lambda el: el is not None and not el.is_deleted(),
|
||||||
self._data
|
self._data
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
@ -456,7 +456,12 @@ class LateralContributionAdisTS(SQLSubModel):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def data(self):
|
def data(self):
|
||||||
return self._data.copy()
|
return list(
|
||||||
|
filter(
|
||||||
|
lambda el: el is not None and not el.is_deleted(),
|
||||||
|
self._data
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def begin_rk(self):
|
def begin_rk(self):
|
||||||
|
|
@ -497,7 +502,7 @@ class LateralContributionAdisTS(SQLSubModel):
|
||||||
def delete_i(self, indexes):
|
def delete_i(self, indexes):
|
||||||
self._data = list(
|
self._data = list(
|
||||||
map(
|
map(
|
||||||
lambda e: e[1],
|
lambda e: e[1].set_as_deleted(),
|
||||||
filter(
|
filter(
|
||||||
lambda e: e[0] not in indexes,
|
lambda e: e[0] not in indexes,
|
||||||
enumerate(self.data)
|
enumerate(self.data)
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,22 @@ logger = logging.getLogger()
|
||||||
|
|
||||||
|
|
||||||
class TableModel(PamhyrTableModel):
|
class TableModel(PamhyrTableModel):
|
||||||
|
def get_true_data_row(self, row):
|
||||||
|
if len(self._data.data) > 0:
|
||||||
|
bc = self._data.data[row]
|
||||||
|
else:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
return next(
|
||||||
|
map(
|
||||||
|
lambda e: e[0],
|
||||||
|
filter(
|
||||||
|
lambda e: e[1] == bc,
|
||||||
|
enumerate(self._data._data)
|
||||||
|
)
|
||||||
|
), 0
|
||||||
|
)
|
||||||
|
|
||||||
def data(self, index, role):
|
def data(self, index, role):
|
||||||
if role == Qt.TextAlignmentRole:
|
if role == Qt.TextAlignmentRole:
|
||||||
return Qt.AlignHCenter | Qt.AlignVCenter
|
return Qt.AlignHCenter | Qt.AlignVCenter
|
||||||
|
|
@ -63,6 +79,7 @@ class TableModel(PamhyrTableModel):
|
||||||
value = QVariant()
|
value = QVariant()
|
||||||
|
|
||||||
if 0 <= column < 2:
|
if 0 <= column < 2:
|
||||||
|
row = self.get_true_data_row(row)
|
||||||
v = self._data._data[row][column]
|
v = self._data._data[row][column]
|
||||||
if self._data._types[column] == float:
|
if self._data._types[column] == float:
|
||||||
value = f"{v:.4f}"
|
value = f"{v:.4f}"
|
||||||
|
|
@ -84,6 +101,8 @@ class TableModel(PamhyrTableModel):
|
||||||
column = index.column()
|
column = index.column()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
row = self.get_true_data_row(row)
|
||||||
|
|
||||||
self._undo.push(
|
self._undo.push(
|
||||||
SetDataCommand(
|
SetDataCommand(
|
||||||
self._data, row, column, value
|
self._data, row, column, value
|
||||||
|
|
@ -110,14 +129,20 @@ class TableModel(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])
|
||||||
|
_rows = list(
|
||||||
|
map(
|
||||||
|
lambda r: self.get_true_data_row(r),
|
||||||
|
rows
|
||||||
|
)
|
||||||
|
)
|
||||||
self._undo.push(
|
self._undo.push(
|
||||||
DelCommand(
|
DelCommand(
|
||||||
self._data, rows
|
self._data, _rows
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
self.endRemoveRows()
|
self.endRemoveRows()
|
||||||
|
self.layoutChanged.emit()
|
||||||
|
|
||||||
def sort(self, _reverse, parent=QModelIndex()):
|
def sort(self, _reverse, parent=QModelIndex()):
|
||||||
self.layoutAboutToBeChanged.emit()
|
self.layoutAboutToBeChanged.emit()
|
||||||
|
|
|
||||||
|
|
@ -80,10 +80,11 @@ class DelCommand(QUndoCommand):
|
||||||
|
|
||||||
def undo(self):
|
def undo(self):
|
||||||
for row, el in self._bc:
|
for row, el in self._bc:
|
||||||
self._data.insert(row, el)
|
el.set_as_not_deleted()
|
||||||
|
|
||||||
def redo(self):
|
def redo(self):
|
||||||
self._data.delete_i(self._rows)
|
for row, el in self._bc:
|
||||||
|
el.set_as_deleted()
|
||||||
|
|
||||||
|
|
||||||
class PasteCommand(QUndoCommand):
|
class PasteCommand(QUndoCommand):
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,23 @@ logger = logging.getLogger()
|
||||||
|
|
||||||
|
|
||||||
class TableModel(PamhyrTableModel):
|
class TableModel(PamhyrTableModel):
|
||||||
|
def get_true_data_row(self, row):
|
||||||
|
|
||||||
|
if len(self._data.data) > 0:
|
||||||
|
lc = self._data.data[row]
|
||||||
|
else:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
return next(
|
||||||
|
map(
|
||||||
|
lambda e: e[0],
|
||||||
|
filter(
|
||||||
|
lambda e: e[1] == lc,
|
||||||
|
enumerate(self._data._data)
|
||||||
|
)
|
||||||
|
), 0
|
||||||
|
)
|
||||||
|
|
||||||
def data(self, index, role):
|
def data(self, index, role):
|
||||||
if role == Qt.TextAlignmentRole:
|
if role == Qt.TextAlignmentRole:
|
||||||
return Qt.AlignHCenter | Qt.AlignVCenter
|
return Qt.AlignHCenter | Qt.AlignVCenter
|
||||||
|
|
@ -65,6 +82,7 @@ class TableModel(PamhyrTableModel):
|
||||||
value = QVariant()
|
value = QVariant()
|
||||||
|
|
||||||
if 0 <= column < 2:
|
if 0 <= column < 2:
|
||||||
|
row = self.get_true_data_row(row)
|
||||||
v = self._data._data[row][column]
|
v = self._data._data[row][column]
|
||||||
if self._data._types[column] == float:
|
if self._data._types[column] == float:
|
||||||
value = f"{v:.4f}"
|
value = f"{v:.4f}"
|
||||||
|
|
@ -86,6 +104,8 @@ class TableModel(PamhyrTableModel):
|
||||||
column = index.column()
|
column = index.column()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
row = self.get_true_data_row(row)
|
||||||
|
|
||||||
self._undo.push(
|
self._undo.push(
|
||||||
SetDataCommand(
|
SetDataCommand(
|
||||||
self._data, row, column, value
|
self._data, row, column, value
|
||||||
|
|
@ -113,10 +133,18 @@ class TableModel(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])
|
||||||
|
|
||||||
|
_rows = list(
|
||||||
|
map(
|
||||||
|
lambda r: self.get_true_data_row(r),
|
||||||
|
rows
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
self._undo.push(
|
self._undo.push(
|
||||||
DelCommand(
|
DelCommand(
|
||||||
self._data, rows
|
self._data, _rows
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
self.endRemoveRows()
|
self.endRemoveRows()
|
||||||
|
self.layoutChanged.emit()
|
||||||
|
|
|
||||||
|
|
@ -76,8 +76,8 @@ class DelCommand(QUndoCommand):
|
||||||
|
|
||||||
def undo(self):
|
def undo(self):
|
||||||
for row, el in self._lc:
|
for row, el in self._lc:
|
||||||
self._data._data.insert(row, el)
|
el.set_as_not_deleted()
|
||||||
|
|
||||||
def redo(self):
|
def redo(self):
|
||||||
for row in self._rows:
|
for row, el in self._lc:
|
||||||
del self._data._data[row]
|
el.set_as_deleted()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue