forked from IPKM/nmreval
improve performance for show/hide graphs
This commit is contained in:
parent
c5706084bf
commit
ea62a05bd3
@ -84,7 +84,7 @@ class DataTree(QtWidgets.QTreeWidget):
|
|||||||
self.update_indexes()
|
self.update_indexes()
|
||||||
|
|
||||||
@QtCore.pyqtSlot(QtWidgets.QTreeWidgetItem)
|
@QtCore.pyqtSlot(QtWidgets.QTreeWidgetItem)
|
||||||
def data_change(self, item: QtWidgets.QTreeWidgetItem) -> tuple[set, set]:
|
def data_change(self, item: QtWidgets.QTreeWidgetItem, emit: bool = True) -> tuple[set, set]:
|
||||||
idd = item.data(0, QtCore.Qt.UserRole)
|
idd = item.data(0, QtCore.Qt.UserRole)
|
||||||
is_selected = item.checkState(0) == QtCore.Qt.Checked
|
is_selected = item.checkState(0) == QtCore.Qt.Checked
|
||||||
to_be_hidden = set()
|
to_be_hidden = set()
|
||||||
@ -142,9 +142,10 @@ class DataTree(QtWidgets.QTreeWidget):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.keyChanged.emit(idd, item.text(0))
|
if emit:
|
||||||
|
self.keyChanged.emit(idd, item.text(0))
|
||||||
|
|
||||||
if to_be_shown or to_be_hidden:
|
if (to_be_shown or to_be_hidden) and emit:
|
||||||
self.stateChanged.emit(list(to_be_shown), list(to_be_hidden))
|
self.stateChanged.emit(list(to_be_shown), list(to_be_hidden))
|
||||||
|
|
||||||
return to_be_shown, to_be_hidden
|
return to_be_shown, to_be_hidden
|
||||||
@ -316,26 +317,24 @@ class DataTree(QtWidgets.QTreeWidget):
|
|||||||
if idx.column() != 0:
|
if idx.column() != 0:
|
||||||
continue
|
continue
|
||||||
item = self.itemFromIndex(idx)
|
item = self.itemFromIndex(idx)
|
||||||
|
|
||||||
if item.parent() is None:
|
if item.parent() is None:
|
||||||
is_selected = item.checkState(0)
|
|
||||||
self.blockSignals(True)
|
|
||||||
for i in range(item.childCount()):
|
for i in range(item.childCount()):
|
||||||
child = item.child(i)
|
child = item.child(i)
|
||||||
from_parent.append(child)
|
from_parent.append(child)
|
||||||
self.blockSignals(False)
|
sets.append(item)
|
||||||
if is_selected == QtCore.Qt.Checked:
|
|
||||||
item.setCheckState(0, QtCore.Qt.Unchecked)
|
|
||||||
else:
|
|
||||||
item.setCheckState(0, QtCore.Qt.Checked)
|
|
||||||
|
|
||||||
else:
|
|
||||||
sets.append(item)
|
|
||||||
|
|
||||||
|
to_be_hidden = set()
|
||||||
|
to_be_shown = set()
|
||||||
|
self.blockSignals(True)
|
||||||
for it in sets:
|
for it in sets:
|
||||||
if it in from_parent:
|
if it in from_parent:
|
||||||
continue
|
continue
|
||||||
it.setCheckState(0, QtCore.Qt.Unchecked if it.checkState(0) == QtCore.Qt.Checked else QtCore.Qt.Checked)
|
it.setCheckState(0, QtCore.Qt.Unchecked if it.checkState(0) == QtCore.Qt.Checked else QtCore.Qt.Checked)
|
||||||
|
s1, s2 = self.data_change(it, emit=False)
|
||||||
|
to_be_hidden |= s2
|
||||||
|
to_be_shown |= s1
|
||||||
|
self.blockSignals(False)
|
||||||
|
self.stateChanged.emit(list(to_be_shown), list(to_be_hidden))
|
||||||
else:
|
else:
|
||||||
super().keyPressEvent(evt)
|
super().keyPressEvent(evt)
|
||||||
|
|
||||||
|
@ -177,9 +177,9 @@ class QGraphWindow(QtWidgets.QGraphicsView, Ui_GraphWindow):
|
|||||||
if isinstance(name, str):
|
if isinstance(name, str):
|
||||||
name = [name]
|
name = [name]
|
||||||
plots = [plots]
|
plots = [plots]
|
||||||
|
toplevel = len(self.sets)
|
||||||
|
self.listWidget.blockSignals(True)
|
||||||
for (real_plot, imag_plot, err_plot), n in zip(plots, name):
|
for (real_plot, imag_plot, err_plot), n in zip(plots, name):
|
||||||
toplevel = len(self.sets)
|
|
||||||
self.sets.append(n)
|
self.sets.append(n)
|
||||||
|
|
||||||
if real_plot:
|
if real_plot:
|
||||||
@ -199,7 +199,16 @@ class QGraphWindow(QtWidgets.QGraphicsView, Ui_GraphWindow):
|
|||||||
list_item.setCheckState(QtCore.Qt.Checked)
|
list_item.setCheckState(QtCore.Qt.Checked)
|
||||||
self.listWidget.addItem(list_item)
|
self.listWidget.addItem(list_item)
|
||||||
|
|
||||||
self.show_item(name)
|
toplevel += 1
|
||||||
|
self.listWidget.blockSignals(False)
|
||||||
|
|
||||||
|
if len(name) < 200:
|
||||||
|
self.show_item(name)
|
||||||
|
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'
|
||||||
|
'Please display them manually in smaller batches, thank you!')
|
||||||
|
|
||||||
def remove(self, name: str | list):
|
def remove(self, name: str | list):
|
||||||
if isinstance(name, str):
|
if isinstance(name, str):
|
||||||
|
@ -385,12 +385,16 @@ class UpperManagement(QtCore.QObject):
|
|||||||
|
|
||||||
def change_visibility(self, selected: list, deselected: list):
|
def change_visibility(self, selected: list, deselected: list):
|
||||||
"""Change status of list of ids after status change in datawidget"""
|
"""Change status of list of ids after status change in datawidget"""
|
||||||
|
for item_list, func in [(selected, 'show_item'), (deselected, 'hide_item')]:
|
||||||
|
grouping = {}
|
||||||
|
for s in item_list:
|
||||||
|
g = self.data[s].graph
|
||||||
|
if g not in grouping:
|
||||||
|
grouping[g] = []
|
||||||
|
grouping[g].append(s)
|
||||||
|
|
||||||
for s in selected:
|
for k, v in grouping.items():
|
||||||
self.graphs[self.data[s].graph].show_item([s])
|
getattr(self.graphs[k], func)(v)
|
||||||
|
|
||||||
for d in deselected:
|
|
||||||
self.graphs[self.data[d].graph].hide_item([d])
|
|
||||||
|
|
||||||
@QtCore.pyqtSlot(str, str)
|
@QtCore.pyqtSlot(str, str)
|
||||||
def change_keys(self, identifier: str, name: str):
|
def change_keys(self, identifier: str, name: str):
|
||||||
|
@ -134,8 +134,8 @@ class HdfNode:
|
|||||||
else:
|
else:
|
||||||
self.parameter[key] = value
|
self.parameter[key] = value
|
||||||
|
|
||||||
if self.parent is not None:
|
# if self.parent is not None:
|
||||||
self.parent.set_parameter(key, value, keep=True)
|
# self.parent.set_parameter(key, value, keep=True)
|
||||||
|
|
||||||
def set_title_parameter(self, child_node, params):
|
def set_title_parameter(self, child_node, params):
|
||||||
if params:
|
if params:
|
||||||
@ -174,7 +174,7 @@ class HdfReader(HdfNode):
|
|||||||
self.create_node(self.file[base], parent=self)
|
self.create_node(self.file[base], parent=self)
|
||||||
except OSError:
|
except OSError:
|
||||||
self.file = None
|
self.file = None
|
||||||
raise IOError('Invalid file ' + filename)
|
raise IOError(f'Invalid file {filename}')
|
||||||
|
|
||||||
def __call__(self, filename, base='data_pool'):
|
def __call__(self, filename, base='data_pool'):
|
||||||
super().clear()
|
super().clear()
|
||||||
@ -215,6 +215,7 @@ class HdfReader(HdfNode):
|
|||||||
parent[name] = data
|
parent[name] = data
|
||||||
parent.num_signals += 1
|
parent.num_signals += 1
|
||||||
|
|
||||||
|
# searching for attributes is performance bottleneck but necessary
|
||||||
for desc in attr.keys():
|
for desc in attr.keys():
|
||||||
# looking for description_KEY in attributes
|
# looking for description_KEY in attributes
|
||||||
m = re.search(r'description_(?P<var>\S+)', desc)
|
m = re.search(r'description_(?P<var>\S+)', desc)
|
||||||
|
Loading…
Reference in New Issue
Block a user