forked from M-Labs/artiq
1
0
Fork 0

fix DictSyncModel

This commit is contained in:
Simon Renblad 2024-03-20 17:26:03 +08:00
parent 13a36bf911
commit eebe0fefd8
1 changed files with 10 additions and 6 deletions

View File

@ -121,15 +121,19 @@ class DictSyncModel(QtCore.QAbstractTableModel):
old_row = self.row_to_key.index(k)
new_row = self._find_row(k, v)
if old_row == new_row:
self.backing_store[k] = v
self.dataChanged.emit(self.index(old_row, 0),
self.index(old_row, len(self.headers)-1))
else:
self.beginMoveRows(QtCore.QModelIndex(), old_row, old_row,
QtCore.QModelIndex(), new_row)
self.backing_store[k] = v
self.row_to_key[old_row], self.row_to_key[new_row] = \
self.row_to_key[new_row], self.row_to_key[old_row]
if old_row != new_row:
begin = min(old_row, new_row)
end = max(old_row, new_row)
self.beginMoveRows(QtCore.QModelIndex(), begin + 1, end - 1,
QtCore.QModelIndex(), begin)
self.backing_store[k] = v
self.row_to_key.pop(old_row)
if old_row < new_row:
new_row -= 1
self.row_to_key.insert(new_row, k)
self.endMoveRows()
else:
row = self._find_row(k, v)