Tables: Skip table undo commands when data is unchanged (avoid data duplicates in db)

dev_dylan
Dylan Jeannin 2026-05-26 12:27:41 +02:00
parent c44597dfbd
commit 09997a0074
31 changed files with 120 additions and 0 deletions

View File

@ -107,6 +107,9 @@ class TableModel(PamhyrTableModel):
if not index.isValid() or role != Qt.EditRole:
return False
if self.is_same_data(index, value):
return False
row = index.row()
column = index.column()

View File

@ -167,6 +167,9 @@ class TableModel(PamhyrTableModel):
if not index.isValid() or role != Qt.EditRole:
return False
if self.is_same_data(index, value):
return False
row = index.row()
column = index.column()

View File

@ -97,6 +97,9 @@ class TableModel(PamhyrTableModel):
if not index.isValid() or role != Qt.EditRole:
return False
if self.is_same_data(index, value):
return False
row = index.row()
column = index.column()

View File

@ -170,6 +170,9 @@ class TableModel(PamhyrTableModel):
if not index.isValid() or role != Qt.EditRole:
return False
if self.is_same_data(index, value):
return False
row = index.row()
column = index.column()

View File

@ -174,6 +174,9 @@ class D90TableModel(PamhyrTableModel):
if not index.isValid() or role != Qt.EditRole:
return False
if self.is_same_data(index, value):
return False
row = index.row()
column = index.column()

View File

@ -186,6 +186,9 @@ class DIFTableModel(PamhyrTableModel):
if not index.isValid() or role != Qt.EditRole:
return False
if self.is_same_data(index, value):
return False
row = index.row()
column = index.column()

View File

@ -134,6 +134,9 @@ class FrictionTableModel(PamhyrTableModel):
if not index.isValid() or role != Qt.EditRole:
return False
if self.is_same_data(index, value):
return False
row = index.row()
column = index.column()

View File

@ -114,6 +114,9 @@ class GeometryProfileTableModel(PamhyrTableModel):
column = index.column()
if role == Qt.EditRole:
if self.is_same_data(index, value):
return False
try:
if column == 0:
self._undo.push(

View File

@ -95,6 +95,9 @@ class GeometryReachTableModel(PamhyrTableModel):
column = index.column()
if role == Qt.EditRole and index.column() != 2:
if self.is_same_data(index, value):
return False
try:
if index.column() == 0:
self._undo.push(

View File

@ -138,6 +138,9 @@ class TableModel(PamhyrTableModel):
if not index.isValid() or role != Qt.EditRole:
return False
if self.is_same_data(index, value):
return False
row = index.row()
column = index.column()
@ -288,6 +291,9 @@ class ParametersTableModel(PamhyrTableModel):
if not index.isValid() or role != Qt.EditRole:
return False
if self.is_same_data(index, value):
return False
if self._hs_index is None:
return QVariant()

View File

@ -169,6 +169,9 @@ class TableModel(PamhyrTableModel):
if not index.isValid() or role != Qt.EditRole:
return False
if self.is_same_data(index, value):
return False
row = index.row()
column = index.column()
na = self._trad['not_associated']

View File

@ -153,6 +153,9 @@ class InitialConditionTableModel(PamhyrTableModel):
if not index.isValid() or role != Qt.EditRole:
return False
if self.is_same_data(index, value):
return False
row = index.row()
column = index.column()

View File

@ -188,6 +188,9 @@ class InitialConditionTableModel(PamhyrTableModel):
if not index.isValid() or role != Qt.EditRole:
return False
if self.is_same_data(index, value):
return False
row = index.row()
column = index.column()

View File

@ -86,6 +86,9 @@ class TableModel(PamhyrTableModel):
if not index.isValid() or role != Qt.EditRole:
return False
if self.is_same_data(index, value):
return False
row = index.row()
column = index.column()

View File

@ -197,6 +197,9 @@ class TableModel(PamhyrTableModel):
if not index.isValid() or role != Qt.EditRole:
return False
if self.is_same_data(index, value):
return False
row = index.row()
column = index.column()

View File

@ -100,6 +100,9 @@ class TableModel(PamhyrTableModel):
if not index.isValid() or role != Qt.EditRole:
return False
if self.is_same_data(index, value):
return False
row = index.row()
column = index.column()

View File

@ -162,6 +162,9 @@ class TableModel(PamhyrTableModel):
if not index.isValid() or role != Qt.EditRole:
return False
if self.is_same_data(index, value):
return False
row = index.row()
column = index.column()

View File

@ -105,6 +105,9 @@ class NodeTableModel(PamhyrTableModel):
return False
if role == Qt.EditRole:
if self.is_same_data(index, value):
return False
try:
self._undo.push(
SetCommand(
@ -155,6 +158,9 @@ class EdgeTableModel(PamhyrTableModel):
if role != Qt.EditRole:
return QVariant()
if self.is_same_data(index, value):
return False
try:
if (self._headers[index.column()] == "node1" or
self._headers[index.column()] == "node2"):

View File

@ -149,6 +149,9 @@ class TableModel(PamhyrTableModel):
if not index.isValid() or role != Qt.EditRole:
return False
if self.is_same_data(index, value):
return False
row = index.row()
column = index.column()
na = self._trad['not_associated']

View File

@ -64,6 +64,9 @@ class TableModel(PamhyrTableModel):
if not index.isValid() or role != Qt.EditRole:
return False
if self.is_same_data(index, value):
return False
row = index.row()
column = index.column()

View File

@ -74,6 +74,9 @@ class TableModel(PamhyrTableModel):
if not index.isValid() or role != Qt.EditRole:
return False
if self.is_same_data(index, value):
return False
row = index.row()
column = index.column()

View File

@ -68,6 +68,9 @@ class TableModel(PamhyrTableModel):
if not index.isValid() or role != Qt.EditRole:
return False
if self.is_same_data(index, value):
return False
row = index.row()
column = index.column()

View File

@ -140,6 +140,9 @@ class TableModel(PamhyrTableModel):
if not index.isValid() or role != Qt.EditRole:
return False
if self.is_same_data(index, value):
return False
row = index.row()
column = index.column()

View File

@ -74,6 +74,9 @@ class ScenariosTableModel(PamhyrTableModel):
return False
if role == Qt.EditRole:
if self.is_same_data(index, value):
return False
try:
self._undo.push(
SetCommand(

View File

@ -65,6 +65,9 @@ class TableModel(PamhyrTableModel):
if not index.isValid() or role != Qt.EditRole:
return False
if self.is_same_data(index, value):
return False
row = index.row()
column = index.column()

View File

@ -121,6 +121,9 @@ class TableModel(PamhyrTableModel):
if not index.isValid() or role != Qt.EditRole:
return False
if self.is_same_data(index, value):
return False
row = index.row()
column = index.column()

View File

@ -116,6 +116,9 @@ class TableModel(PamhyrTableModel):
if not index.isValid() or role != Qt.EditRole:
return False
if self.is_same_data(index, value):
return False
row = index.row()
column = index.column()

View File

@ -55,6 +55,9 @@ class TableModel(PamhyrTableModel):
if not index.isValid() or role != Qt.EditRole:
return False
if self.is_same_data(index, value):
return False
row = index.row()
column = index.column()

View File

@ -79,6 +79,9 @@ class TableModel(PamhyrTableModel):
if not index.isValid() or role != Qt.EditRole:
return False
if self.is_same_data(index, value):
return False
row = index.row()
column = index.column()

View File

@ -84,6 +84,9 @@ class TableModel(PamhyrTableModel):
if not index.isValid() or role != Qt.EditRole:
return False
if self.is_same_data(index, value):
return False
row = index.row()
column = index.column()

View File

@ -142,6 +142,30 @@ class PamhyrTableModel(QAbstractTableModel):
return QVariant()
def is_same_data(self, index, value):
current = self.data(index, Qt.ItemDataRole.DisplayRole)
if isinstance(current, QVariant):
current = current.value()
if str(current) == str(value):
return True
if hasattr(value, "display_name"):
if str(current) == str(value.display_name()):
return True
if hasattr(value, "name"):
if str(current) == str(value.name):
return True
try:
return (
float(str(current).replace(",", ".")) ==
float(str(value).replace(",", "."))
)
except (TypeError, ValueError):
return False
def data(self, index, role):
raise NotImplementedMethodeError(self, self.data)