From ffecc9c87331132e714680b8a2a75e1dcfc8eddd Mon Sep 17 00:00:00 2001 From: Dominik Demuth Date: Sat, 8 Apr 2023 17:16:05 +0200 Subject: [PATCH] remove duplicates of keys in deletion; may help with #36 --- src/gui_qt/data/datawidget/datawidget.py | 11 +++++++++-- src/gui_qt/main/management.py | 4 +++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/gui_qt/data/datawidget/datawidget.py b/src/gui_qt/data/datawidget/datawidget.py index c40089a..cf4b741 100644 --- a/src/gui_qt/data/datawidget/datawidget.py +++ b/src/gui_qt/data/datawidget/datawidget.py @@ -287,13 +287,20 @@ class DataTree(QtWidgets.QTreeWidget): for idx in self.selectedIndexes(): if idx.column() == 1: continue + item = self.itemFromIndex(idx) if item.parent() is None: for c_i in range(item.childCount()): - rm_sets.append(item.child(c_i).data(0, QtCore.Qt.UserRole)) + # add sets inside graph to removal + child_data = item.child(c_i).data(0, QtCore.Qt.UserRole) + if child_data not in rm_sets: + rm_sets.append(child_data) rm_graphs.append(item.data(0, QtCore.Qt.UserRole)) + else: - rm_sets.append(item.data(0, QtCore.Qt.UserRole)) + item_data = item.data(0, QtCore.Qt.UserRole) + if item_data not in rm_sets: + rm_sets.append(item_data) # self.deleteItem.emit(rm_sets+rm_graphs) self.management.delete_sets(rm_sets+rm_graphs) diff --git a/src/gui_qt/main/management.py b/src/gui_qt/main/management.py index 3f2ccc0..6d71fb2 100644 --- a/src/gui_qt/main/management.py +++ b/src/gui_qt/main/management.py @@ -291,8 +291,10 @@ class UpperManagement(QtCore.QObject): if k in self.data: cmd = DeleteCommand(self.data, k, self.newData, self.deleteData) self.undostack.push(cmd) - else: + elif k in self.graphs: rm_graphs.append(k) + else: + logger.warning(f'delete_sets: {k} is not in data or graph found') for k in rm_graphs: cmd = DeleteGraphCommand(self.graphs, k, self.restoreGraph, self.deleteGraph)