Skip to content

Commit

Permalink
Merge pull request #18 from zdomke/dev_axis_tbl_delete
Browse files Browse the repository at this point in the history
ENH: Replace Delete Axis button with inline button
  • Loading branch information
YektaY authored May 13, 2024
2 parents cbe3b46 + 395d684 commit 18a92c9
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 18 deletions.
7 changes: 0 additions & 7 deletions archive_viewer/archive_viewer.ui
Original file line number Diff line number Diff line change
Expand Up @@ -293,13 +293,6 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="del_axis_row_btn">
<property name="text">
<string>Delete Axis</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
Expand Down
18 changes: 9 additions & 9 deletions archive_viewer/mixins/axis_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from qtpy.QtWidgets import QHeaderView
from pyqtgraph import ViewBox
from table_models import ArchiverAxisModel
from widgets import ComboBoxDelegate, ScientificNotationDelegate
from widgets import ComboBoxDelegate, ScientificNotationDelegate, DeleteRowDelegate


class AxisTableMixin:
Expand All @@ -18,9 +18,8 @@ def axis_table_init(self) -> None:

hdr = self.ui.time_axis_tbl.horizontalHeader()
hdr.setSectionResizeMode(QHeaderView.Stretch)

self.ui.add_axis_row_btn.clicked.connect(self.addAxis)
self.ui.del_axis_row_btn.clicked.connect(self.removeSelectedAxis)
del_col = self.axis_table_model.getColumnIndex("")
hdr.setSectionResizeMode(del_col, QHeaderView.ResizeToContents)

plot_viewbox = self.ui.archiver_plot.plotItem.vb
plot_viewbox.sigXRangeChanged.connect(self.set_axis_datetimes)
Expand All @@ -29,6 +28,8 @@ def axis_table_init(self) -> None:
self.ui.main_start_datetime.dateTimeChanged.connect(lambda qdt: self.set_time_axis_range((qdt, None)))
self.ui.main_end_datetime.dateTimeChanged.connect(lambda qdt: self.set_time_axis_range((None, qdt)))

self.ui.add_axis_row_btn.clicked.connect(self.addAxis)

def axis_delegates_init(self) -> None:
"""Initialize and set the ItemDelegates for the axis table."""
orientation_col = self.axis_table_model.getColumnIndex("Y-Axis Orientation")
Expand All @@ -44,6 +45,10 @@ def axis_delegates_init(self) -> None:
max_range_del = ScientificNotationDelegate(self.ui.time_axis_tbl)
self.ui.time_axis_tbl.setItemDelegateForColumn(max_range_col, max_range_del)

delete_col = self.axis_table_model.getColumnIndex("")
delete_row_del = DeleteRowDelegate(self.ui.time_axis_tbl)
self.ui.time_axis_tbl.setItemDelegateForColumn(delete_col, delete_row_del)

Slot(object)
def set_time_axis_range(self, raw_range: Tuple[QDateTime, QDateTime] = (None, None)) -> None:
"""PyQT Slot to set the plot's X-Axis range. This slot should be
Expand Down Expand Up @@ -104,8 +109,3 @@ def set_axis_datetimes(self, _: ViewBox = None, time_range: Tuple[float, float]
def addAxis(self) -> None:
"""Slot for button to add a new row to the axis table."""
self.axis_table_model.append()

@Slot()
def removeSelectedAxis(self) -> None:
"""Slot for button to remove a row from the axis table."""
self.axis_table_model.removeAtIndex(self.ui.time_axis_tbl.currentIndex())
3 changes: 2 additions & 1 deletion archive_viewer/mixins/traces_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def traces_table_init(self) -> None:
hdr.setSectionResizeMode(QHeaderView.Stretch)
channel_col = self.curves_model.getColumnIndex("Channel")
hdr.setSectionResizeMode(channel_col, QHeaderView.ResizeToContents)
hdr.setSectionResizeMode(self.curves_model.getColumnIndex(""), QHeaderView.ResizeToContents)
del_col = self.curves_model.getColumnIndex("")
hdr.setSectionResizeMode(del_col, QHeaderView.ResizeToContents)

def curve_delegates_init(self) -> None:
"""Set column delegates for the Traces table to display widgets."""
Expand Down
14 changes: 14 additions & 0 deletions archive_viewer/table_models/axis_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class ArchiverAxisModel(BasePlotAxesModel):
"""
def __init__(self, plot: BasePlot, parent=None) -> None:
super().__init__(plot, parent)
self._column_names = self._column_names + ("",)

self.checkable_col = {self.getColumnIndex("Enable Auto Range"),
self.getColumnIndex("Log Mode")}

Expand Down Expand Up @@ -91,6 +93,18 @@ def append(self, name: str = "") -> None:
row = self.rowCount() - 1
self.attach_range_changed(row, new_axis)

def removeAtIndex(self, index: QModelIndex) -> None:
"""Removes the axis at the given table index.
Parameters
----------
index : QModelIndex
An index in the row to be removed.
"""
if self.rowCount() <= 1:
self.append()
super().removeAtIndex(index)

def get_axis(self, index: int) -> BasePlotAxisItem:
"""Return the BasePlotAxisItem for a given row number.
Expand Down
2 changes: 1 addition & 1 deletion archive_viewer/widgets/item_delegates.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def initStyleOption(self, option: QStyleOptionViewItem, index: QModelIndex) -> N
editor = QPushButton(self.parent())
icon = editor.style().standardIcon(QStyle.SP_DialogCancelButton)
editor.setIcon(icon)
editor.setToolTip("Delete Trace")
editor.setToolTip("Delete Row")
editor.clicked.connect(lambda: self.commitData.emit(editor))

self.editor_list.append(editor)
Expand Down

0 comments on commit 18a92c9

Please # to comment.