From ff92cc30c81a7c58775eddda30e35583bed5cda3 Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Sun, 28 Jan 2018 09:16:37 +0100 Subject: [PATCH] Fix previous commit (UI deleting optimisation) --- src/bitmessageqt/__init__.py | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index 1ced3809..b3d19017 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -2990,14 +2990,15 @@ class MyForm(settingsmixin.SMainWindow): shifted = QtGui.QApplication.queryKeyboardModifiers() & QtCore.Qt.ShiftModifier tableWidget.setUpdatesEnabled(False); inventoryHashesToTrash = [] - for row in tableWidget.selectedIndexes(): - currentRow = row.row() - inventoryHashToTrash = str(tableWidget.item( - currentRow, 3).data(QtCore.Qt.UserRole).toPyObject()) - if inventoryHashToTrash in inventoryHashesToTrash: - continue - inventoryHashesToTrash.append(inventoryHashToTrash) - tableWidget.removeRow(currentRow) + # ranges in reversed order + for r in sorted(tableWidget.selectedRanges(), key=lambda r: r.topRow())[::-1]: + for i in range(r.bottomRow()-r.topRow()+1): + inventoryHashToTrash = str(tableWidget.item( + r.topRow()+i, 3).data(QtCore.Qt.UserRole).toPyObject()) + if inventoryHashToTrash in inventoryHashesToTrash: + continue + inventoryHashesToTrash.append(inventoryHashToTrash) + tableWidget.model().removeRows(r.topRow(), r.bottomRow()-r.topRow()+1) idCount = len(inventoryHashesToTrash) if folder == "trash" or shifted: sqlExecuteChunked('''DELETE FROM inbox WHERE msgid IN ({0})''', @@ -3019,14 +3020,15 @@ class MyForm(settingsmixin.SMainWindow): currentRow = 0 tableWidget.setUpdatesEnabled(False) inventoryHashesToTrash = [] - for row in tableWidget.selectedIndexes(): - currentRow = row.row() - inventoryHashToTrash = str(tableWidget.item( - currentRow, 3).data(QtCore.Qt.UserRole).toPyObject()) - if inventoryHashToTrash in inventoryHashesToTrash: - continue - inventoryHashesToTrash.append(inventoryHashToTrash) - tableWidget.removeRow(currentRow) + # ranges in reversed order + for r in sorted(tableWidget.selectedRanges(), key=lambda r: r.topRow())[::-1]: + for i in range(r.bottomRow()-r.topRow()+1): + inventoryHashToTrash = str(tableWidget.item( + r.topRow()+i, 3).data(QtCore.Qt.UserRole).toPyObject()) + if inventoryHashToTrash in inventoryHashesToTrash: + continue + inventoryHashesToTrash.append(inventoryHashToTrash) + tableWidget.model().removeRows(r.topRow(), r.bottomRow()-r.topRow()+1) if currentRow == 0: tableWidget.selectRow(currentRow) else: