improve performance building data tree

This commit is contained in:
Dominik Demuth 2023-09-19 17:22:59 +02:00
parent 9463ed1e6c
commit 0046d04683
3 changed files with 8 additions and 7 deletions

View File

@ -61,7 +61,7 @@ class DataTree(QtWidgets.QTreeWidget):
self.update_indexes() 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): if isinstance(items, tuple):
items = [items] items = [items]
@ -80,8 +80,8 @@ class DataTree(QtWidgets.QTreeWidget):
self.resizeColumnToContents(0) self.resizeColumnToContents(0)
break break
if update:
self.update_indexes() self.update_indexes()
@QtCore.pyqtSlot(QtWidgets.QTreeWidgetItem) @QtCore.pyqtSlot(QtWidgets.QTreeWidgetItem)
def data_change(self, item: QtWidgets.QTreeWidgetItem, emit: bool = True) -> tuple[set, set]: 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.add_graph(idd, name)
self.tree.blockSignals(False) 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.blockSignals(True)
self.tree.add_item((idd, name, value), gid) self.tree.add_item((idd, name, value), gid, update=update)
self.tree.blockSignals(False) self.tree.blockSignals(False)
def add_item_list(self, loi: list, gid: str): def add_item_list(self, loi: list, gid: str):

View File

@ -207,7 +207,7 @@ class QGraphWindow(QtWidgets.QGraphicsView, Ui_GraphWindow):
else: else:
QtWidgets.QMessageBox.warning(self, 'Display disabled', 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' '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!') 'Please display them manually in smaller batches, thank you!')
def remove(self, name: str | list): def remove(self, name: str | list):

View File

@ -353,8 +353,9 @@ class NMRMainWindow(QtWidgets.QMainWindow, Ui_BaseWindow):
for idd in sets: for idd in sets:
new_item = self.management[idd] new_item = self.management[idd]
self.datawidget.blockSignals(True) 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.blockSignals(False)
self.datawidget.tree.update_indexes()
# if graph == self.fit_dialog.connected_figure: # if graph == self.fit_dialog.connected_figure:
# self.fit_dialog.load(self.management.graphs.active(graph)) # self.fit_dialog.load(self.management.graphs.active(graph))