From 337b81a89b48c32afa07fe6ff08ce5f5964d456b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustavo=20I=C3=B1iguez=20Goia?= Date: Sat, 4 Jan 2025 00:44:34 +0100 Subject: [PATCH] ui: fixed acting on selected rows When selecting rows with CTRL we were not copying/deleting rules correctly. Closes #1245 --- .../customwidgets/generictableview.py | 21 +++++++++++-------- ui/opensnitch/dialogs/stats.py | 9 ++++---- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/ui/opensnitch/customwidgets/generictableview.py b/ui/opensnitch/customwidgets/generictableview.py index b5e5770e..fb6482b5 100644 --- a/ui/opensnitch/customwidgets/generictableview.py +++ b/ui/opensnitch/customwidgets/generictableview.py @@ -337,16 +337,19 @@ class GenericTableView(QTableView): self.selectionModel().clearCurrentIndex() def copySelection(self): - selection = self.selectedIndexes() - if selection: - rows = sorted(index.row() for index in selection) - rowcount = rows[-1] - rows[0] + 1 - table = self.model().copySelectedRows( - selection[0].row() + self.vScrollBar.value() - 1, - rowcount) - return table + model = self.selectionModel() + curModel = self.model() + selection = model.selectedRows() + if not selection: + return None - return None + rows = [] + for idx in selection: + row = [] + for col in range(0, curModel.columnCount()): + row.append(curModel.index(idx.row(), col).data()) + rows.append(row) + return rows def getCurrentIndex(self): return self.selectionModel().currentIndex().internalId() diff --git a/ui/opensnitch/dialogs/stats.py b/ui/opensnitch/dialogs/stats.py index 939482ee..85712383 100644 --- a/ui/opensnitch/dialogs/stats.py +++ b/ui/opensnitch/dialogs/stats.py @@ -1066,6 +1066,8 @@ class StatsDialog(QtWidgets.QDialog, uic.loadUiType(DIALOG_UI_PATH)[0]): cur_idx = self.tabWidget.currentIndex() if self.tabWidget.currentIndex() == self.TAB_RULES and self.fwTable.isVisible(): cur_idx = self.TAB_FIREWALL + elif self.tabWidget.currentIndex() == self.TAB_RULES and not self.fwTable.isVisible(): + cur_idx = self.TAB_RULES selection = self.TABLES[cur_idx]['view'].copySelection() if selection: stream = io.StringIO() @@ -1564,10 +1566,9 @@ class StatsDialog(QtWidgets.QDialog, uic.loadUiType(DIALOG_UI_PATH)[0]): self._notifications_sent[nid] = noti elif cur_idx == self.TAB_RULES and self.rulesTable.isVisible(): - selection = self.TABLES[cur_idx]['view'].copySelection() - for row in selection: - name = row[self.COL_R_NAME] - node = row[self.COL_R_NODE] + for idx in selection: + name = model.index(idx.row(), self.COL_R_NAME).data() + node = model.index(idx.row(), self.COL_R_NODE).data() self._del_rule(name, node) elif cur_idx == self.TAB_RULES and self.alertsTable.isVisible():