Skip to content

Commit

Permalink
toggle columns in the Numeric window
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhrisca committed Mar 19, 2024
1 parent 55e8d3d commit 127cba1
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 7 deletions.
12 changes: 12 additions & 0 deletions src/asammdf/gui/widgets/mdi_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -3099,6 +3099,18 @@ def _load_numeric_window(self, window_info):
font_size = window_info["configuration"].get("font_size", numeric.font().pointSize())
numeric.set_font_size(font_size)

columns_visibility = window_info["configuration"].get("columns_visibility", {})
if columns_visibility:
numeric.channels.columnHeader.toggle_column(
columns_visibility["raw"], numeric.channels.columnHeader.RawColumn
)
numeric.channels.columnHeader.toggle_column(
columns_visibility["scaled"], numeric.channels.columnHeader.ScaledColumn
)
numeric.channels.columnHeader.toggle_column(
columns_visibility["unit"], numeric.channels.columnHeader.UnitColumn
)

return w, pattern_info

def _load_gps_window(self, window_info):
Expand Down
66 changes: 59 additions & 7 deletions src/asammdf/gui/widgets/numeric.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import bisect
from functools import partial
import json
import os
from pathlib import Path
Expand Down Expand Up @@ -856,6 +857,10 @@ def headerData(self, section, orientation, role=None):

class HeaderView(QtWidgets.QTableView):
sorting_changed = QtCore.Signal(int)
NameColumn = 0
RawColumn = 1
ScaledColumn = 2
UnitColumn = 3

def __init__(self, parent):
super().__init__(parent)
Expand Down Expand Up @@ -897,6 +902,22 @@ def __init__(self, parent):

self.resize(self.sizeHint())

self.columns_width = {
self.RawColumn: self.columnWidth(self.RawColumn),
self.ScaledColumn: self.columnWidth(self.ScaledColumn),
self.UnitColumn: self.columnWidth(self.UnitColumn),
}

def all_columns_width(self):
return [self.columnWidth(self.NameColumn), *self.columns_width.values()]

def columns_visibility(self):
return {
"raw": not self.isColumnHidden(self.RawColumn),
"scaled": not self.isColumnHidden(self.ScaledColumn),
"unit": not self.isColumnHidden(self.UnitColumn),
}

def showEvent(self, a0: QtGui.QShowEvent) -> None:
super().showEvent(a0)
self.initial_size = self.size()
Expand All @@ -915,10 +936,29 @@ def show_menu(self, position):
count = len(self.backend)

menu = QtWidgets.QMenu()
menu.addAction(self.tr(f"{count} rows in the numeric window"))
menu.addAction(f"{count} rows in the numeric window")
menu.addSeparator()

menu.addAction("Automatic set columns width")
menu.addSeparator()

menu.addAction(self.tr("Automatic set columns width"))
action = QtGui.QAction("Raw Column", menu)
action.setCheckable(True)
action.setChecked(not self.isColumnHidden(self.RawColumn))
action.toggled.connect(partial(self.toggle_column, column=self.RawColumn))
menu.addAction(action)

action = QtGui.QAction("Scaled Column", menu)
action.setCheckable(True)
action.setChecked(not self.isColumnHidden(self.ScaledColumn))
action.toggled.connect(partial(self.toggle_column, column=self.ScaledColumn))
menu.addAction(action)

action = QtGui.QAction("Unit Column", menu)
action.setCheckable(True)
action.setChecked(not self.isColumnHidden(self.UnitColumn))
action.toggled.connect(partial(self.toggle_column, column=self.UnitColumn))
menu.addAction(action)

action = menu.exec_(self.viewport().mapToGlobal(position))

Expand Down Expand Up @@ -1003,6 +1043,20 @@ def sizeHint(self):

return QtCore.QSize(width, height)

def toggle_column(self, checked, column):
if not checked:
self.columns_width[column] = self.columnWidth(column)

self.setColumnHidden(column, not checked)
self.numeric_viewer.dataView.setColumnHidden(column, not checked)

if checked:
self.setColumnWidth(column, self.columns_width[column])
self.numeric_viewer.dataView.setColumnWidth(column, self.columns_width[column])

self.updateGeometry()
self.numeric_viewer.dataView.updateGeometry()

def minimumSizeHint(self):
return QtCore.QSize(50, self.sizeHint().height())

Expand Down Expand Up @@ -1333,11 +1387,9 @@ def to_config(self):
"channels": channels,
"pattern": pattern,
"float_precision": self.float_precision.currentIndex() - 1,
"header_sections_width": [
self.channels.columnHeader.horizontalHeader().sectionSize(i)
for i in range(self.channels.columnHeader.horizontalHeader().count())
],
"header_sections_width": self.channels.columnHeader.all_columns_width(),
"font_size": self.font().pointSize(),
"columns_visibility": self.channels.columnHeader.columns_visibility(),
}

return config
Expand Down Expand Up @@ -1626,7 +1678,7 @@ def keyPressEvent(self, event):
)

if file_name:
signals = [signal for signal in self.channels.dataView.backend.signals if signal.enable]
signals = [offline_signal.signal for offline_signal in self.channels.dataView.backend.signals]
if signals:
with mdf_module.MDF() as mdf:
groups = {}
Expand Down

0 comments on commit 127cba1

Please sign in to comment.