From eebe0fefd8d61c6d7fbfb93ddd02d30c04490c52 Mon Sep 17 00:00:00 2001 From: Simon Renblad Date: Wed, 20 Mar 2024 17:26:03 +0800 Subject: [PATCH] fix DictSyncModel --- artiq/gui/models.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/artiq/gui/models.py b/artiq/gui/models.py index 4d6f19c22..1db1b1021 100644 --- a/artiq/gui/models.py +++ b/artiq/gui/models.py @@ -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)