Display graph/set number in tree; fixes T243
This commit is contained in:
parent
6eff9b5d91
commit
2c09573d2a
@ -21,7 +21,6 @@ class DataTree(QtWidgets.QTreeWidget):
|
|||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super().__init__(parent=parent)
|
super().__init__(parent=parent)
|
||||||
|
|
||||||
self.setColumnCount(1)
|
|
||||||
self.invisibleRootItem().setFlags(self.invisibleRootItem().flags() ^ QtCore.Qt.ItemIsDropEnabled)
|
self.invisibleRootItem().setFlags(self.invisibleRootItem().flags() ^ QtCore.Qt.ItemIsDropEnabled)
|
||||||
|
|
||||||
self.itemChanged.connect(self.data_change)
|
self.itemChanged.connect(self.data_change)
|
||||||
@ -44,7 +43,7 @@ class DataTree(QtWidgets.QTreeWidget):
|
|||||||
header.setSectionResizeMode(0, QtWidgets.QHeaderView.Stretch)
|
header.setSectionResizeMode(0, QtWidgets.QHeaderView.Stretch)
|
||||||
header.setVisible(False)
|
header.setVisible(False)
|
||||||
header.moveSection(1, 0)
|
header.moveSection(1, 0)
|
||||||
self.setColumnWidth(1, 16)
|
# self.setColumnWidth(1, 16)
|
||||||
self.setItemDelegateForColumn(1, HeaderDelegate())
|
self.setItemDelegateForColumn(1, HeaderDelegate())
|
||||||
|
|
||||||
def add_graph(self, idd: str, name: str):
|
def add_graph(self, idd: str, name: str):
|
||||||
@ -59,6 +58,8 @@ class DataTree(QtWidgets.QTreeWidget):
|
|||||||
self._checked_graphs.add(idd)
|
self._checked_graphs.add(idd)
|
||||||
item.setExpanded(True)
|
item.setExpanded(True)
|
||||||
|
|
||||||
|
self.update_indexes()
|
||||||
|
|
||||||
def add_item(self, items: Union[tuple, List[tuple]], gid: str):
|
def add_item(self, items: Union[tuple, List[tuple]], gid: str):
|
||||||
if isinstance(items, tuple):
|
if isinstance(items, tuple):
|
||||||
items = [items]
|
items = [items]
|
||||||
@ -78,6 +79,8 @@ class DataTree(QtWidgets.QTreeWidget):
|
|||||||
self.resizeColumnToContents(0)
|
self.resizeColumnToContents(0)
|
||||||
break
|
break
|
||||||
|
|
||||||
|
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) -> Tuple[set, set]:
|
||||||
idd = item.data(0, QtCore.Qt.UserRole)
|
idd = item.data(0, QtCore.Qt.UserRole)
|
||||||
@ -189,6 +192,8 @@ class DataTree(QtWidgets.QTreeWidget):
|
|||||||
to_parent.data(0, QtCore.Qt.UserRole), take_from,
|
to_parent.data(0, QtCore.Qt.UserRole), take_from,
|
||||||
pos=-1 if append else row)
|
pos=-1 if append else row)
|
||||||
|
|
||||||
|
self.update_indexes()
|
||||||
|
|
||||||
def move_sets(self, sid: str, gid_in: str, gid_out: str):
|
def move_sets(self, sid: str, gid_in: str, gid_out: str):
|
||||||
self.blockSignals(True)
|
self.blockSignals(True)
|
||||||
to_parent = None
|
to_parent = None
|
||||||
@ -218,8 +223,29 @@ class DataTree(QtWidgets.QTreeWidget):
|
|||||||
from_parent.removeChild(it)
|
from_parent.removeChild(it)
|
||||||
to_parent.addChild(it)
|
to_parent.addChild(it)
|
||||||
|
|
||||||
|
self.update_indexes()
|
||||||
|
|
||||||
self.blockSignals(False)
|
self.blockSignals(False)
|
||||||
|
|
||||||
|
def update_indexes(self):
|
||||||
|
graph_cnt = -1
|
||||||
|
set_cnt = 0
|
||||||
|
iterator = QtWidgets.QTreeWidgetItemIterator(self)
|
||||||
|
while iterator.value():
|
||||||
|
item = iterator.value()
|
||||||
|
if item is not None:
|
||||||
|
if item.parent() is None:
|
||||||
|
graph_cnt += 1
|
||||||
|
set_cnt = 0
|
||||||
|
item.setText(1, f'G[{graph_cnt}]')
|
||||||
|
else:
|
||||||
|
item.setText(1, f'G[{graph_cnt}].S[{set_cnt}]')
|
||||||
|
set_cnt += 1
|
||||||
|
|
||||||
|
iterator += 1
|
||||||
|
|
||||||
|
self.resizeColumnToContents(1)
|
||||||
|
|
||||||
def set_name(self, sid, name):
|
def set_name(self, sid, name):
|
||||||
iterator = QtWidgets.QTreeWidgetItemIterator(self)
|
iterator = QtWidgets.QTreeWidgetItemIterator(self)
|
||||||
while iterator.value():
|
while iterator.value():
|
||||||
@ -306,6 +332,8 @@ class DataTree(QtWidgets.QTreeWidget):
|
|||||||
|
|
||||||
iterator += 1
|
iterator += 1
|
||||||
|
|
||||||
|
self.update_indexes()
|
||||||
|
|
||||||
def contextMenuEvent(self, evt):
|
def contextMenuEvent(self, evt):
|
||||||
menu = QtWidgets.QMenu()
|
menu = QtWidgets.QMenu()
|
||||||
_ = menu.addAction('Hello')
|
_ = menu.addAction('Hello')
|
||||||
|
@ -231,5 +231,11 @@ class HeaderDelegate(QtWidgets.QStyledItemDelegate):
|
|||||||
|
|
||||||
style = QtWidgets.QApplication.style()
|
style = QtWidgets.QApplication.style()
|
||||||
style.drawControl(QtWidgets.QStyle.CE_HeaderSection, header_option, painter)
|
style.drawControl(QtWidgets.QStyle.CE_HeaderSection, header_option, painter)
|
||||||
|
|
||||||
|
text_rect = style.subElementRect(QtWidgets.QStyle.SE_ItemViewItemText, option, None)
|
||||||
|
text_rect.adjust(2, 0, 0, 0)
|
||||||
|
|
||||||
if option.state & QtWidgets.QStyle.State_Selected:
|
if option.state & QtWidgets.QStyle.State_Selected:
|
||||||
painter.fillRect(option.rect, option.palette.highlight())
|
painter.fillRect(option.rect, option.palette.highlight())
|
||||||
|
|
||||||
|
painter.drawText(text_rect, option.displayAlignment, index.data(QtCore.Qt.DisplayRole))
|
||||||
|
@ -86,7 +86,7 @@ class Points:
|
|||||||
y_err = np.atleast_1d(y_err)
|
y_err = np.atleast_1d(y_err)
|
||||||
if y_err.shape != y.shape:
|
if y_err.shape != y.shape:
|
||||||
raise ValueError(f'y_err ({y_err.shape}) and y ({y.shape}) have different shapes')
|
raise ValueError(f'y_err ({y_err.shape}) and y ({y.shape}) have different shapes')
|
||||||
print(x, x.shape, x.ndim)
|
|
||||||
return x, y, y_err, mask
|
return x, y, y_err, mask
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
Loading…
Reference in New Issue
Block a user