From 0046d0468389a11e00360b97e0ef0f2cc67877e1 Mon Sep 17 00:00:00 2001 From: Dominik Demuth Date: Tue, 19 Sep 2023 17:22:59 +0200 Subject: [PATCH] improve performance building data tree --- src/gui_qt/data/datawidget/datawidget.py | 10 +++++----- src/gui_qt/graphs/graphwindow.py | 2 +- src/gui_qt/main/mainwindow.py | 3 ++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/gui_qt/data/datawidget/datawidget.py b/src/gui_qt/data/datawidget/datawidget.py index 28dc1c1..25ad729 100644 --- a/src/gui_qt/data/datawidget/datawidget.py +++ b/src/gui_qt/data/datawidget/datawidget.py @@ -61,7 +61,7 @@ class DataTree(QtWidgets.QTreeWidget): self.update_indexes() - def add_item(self, items: (tuple | list[tuple]), gid: str): + def add_item(self, items: (tuple | list[tuple]), gid: str, update: bool = True): if isinstance(items, tuple): items = [items] @@ -80,8 +80,8 @@ class DataTree(QtWidgets.QTreeWidget): self.resizeColumnToContents(0) break - - self.update_indexes() + if update: + self.update_indexes() @QtCore.pyqtSlot(QtWidgets.QTreeWidgetItem) def data_change(self, item: QtWidgets.QTreeWidgetItem, emit: bool = True) -> tuple[set, set]: @@ -566,9 +566,9 @@ class DataWidget(QtWidgets.QWidget, Ui_DataWidget): self.tree.add_graph(idd, name) self.tree.blockSignals(False) - def add_item(self, idd: str, name: str, value: str, gid: str): + def add_item(self, idd: str, name: str, value: str, gid: str, update: bool= True): self.tree.blockSignals(True) - self.tree.add_item((idd, name, value), gid) + self.tree.add_item((idd, name, value), gid, update=update) self.tree.blockSignals(False) def add_item_list(self, loi: list, gid: str): diff --git a/src/gui_qt/graphs/graphwindow.py b/src/gui_qt/graphs/graphwindow.py index 6d7eb16..3cfc6f0 100644 --- a/src/gui_qt/graphs/graphwindow.py +++ b/src/gui_qt/graphs/graphwindow.py @@ -207,7 +207,7 @@ class QGraphWindow(QtWidgets.QGraphicsView, Ui_GraphWindow): else: QtWidgets.QMessageBox.warning(self, 'Display disabled', 'If more than 200 sets are added at once, they are not displayed to avoid major performance issues.\n' - 'Building the data tree may still take some time, the checkmark on the left is invalid.\n' + 'The checkmark in the data tree is invalid.\n' 'Please display them manually in smaller batches, thank you!') def remove(self, name: str | list): diff --git a/src/gui_qt/main/mainwindow.py b/src/gui_qt/main/mainwindow.py index 6f1c47b..e20ae11 100644 --- a/src/gui_qt/main/mainwindow.py +++ b/src/gui_qt/main/mainwindow.py @@ -353,8 +353,9 @@ class NMRMainWindow(QtWidgets.QMainWindow, Ui_BaseWindow): for idd in sets: new_item = self.management[idd] self.datawidget.blockSignals(True) - self.datawidget.add_item(new_item.id, new_item.name, new_item.value, graph) + self.datawidget.add_item(new_item.id, new_item.name, new_item.value, graph, update=False) self.datawidget.blockSignals(False) + self.datawidget.tree.update_indexes() # if graph == self.fit_dialog.connected_figure: # self.fit_dialog.load(self.management.graphs.active(graph))