Skip to content

Commit

Permalink
Updating all indices to use the new method
Browse files Browse the repository at this point in the history
  • Loading branch information
jbellister-slac committed Jan 24, 2022
1 parent 450169c commit 64e3148
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 23 deletions.
7 changes: 0 additions & 7 deletions pydm/tests/widgets/test_curve_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ def test_waveform_curve_editor(qtbot):
table_model = curve_editor.table_model
table_view = curve_editor.table_view

assert table_model.columnCount() == 10

# Verify that the drop downs for columns with non built-in types are all put in the correct place
# Note: We do need to check these on each individual type of curve editor (see below tests) and not just
# in the base plot editor since each plot type can have varying numbers of columns
Expand Down Expand Up @@ -54,8 +52,6 @@ def test_timeplot_curve_editor(qtbot):
table_model = curve_editor.table_model
table_view = curve_editor.table_view

assert table_model.columnCount() == 8

# Verify that the drop downs for columns with non built-in types are all put in the correct place
color_index = table_model.getColumnIndex('Color')
line_style_index = table_model.getColumnIndex('Line Style')
Expand All @@ -82,8 +78,6 @@ def test_scatterplot_editor(qtbot):
table_model = curve_editor.table_model
table_view = curve_editor.table_view

assert table_model.columnCount() == 11

# Verify that the drop downs for columns with non built-in types are all put in the correct place
color_index = table_model.getColumnIndex('Color')
line_style_index = table_model.getColumnIndex('Line Style')
Expand All @@ -109,6 +103,5 @@ def test_axis_editor(qtbot):
axis_view = curve_editor.axis_view

# Verify the column count is correct, and the axis column delegate is placed correctly
assert axis_model.columnCount() == 5
axis_orientation_index = axis_model._column_names.index('Y-Axis Orientation')
assert type(axis_view.itemDelegateForColumn(axis_orientation_index)) is AxisColumnDelegate
4 changes: 4 additions & 0 deletions pydm/widgets/axis_table_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,7 @@ def removeAtIndex(self, index):
self.beginRemoveRows(QModelIndex(), index.row(), index.row())
self._plot.removeAxisAtIndex(index.row())
self.endRemoveRows()

def getColumnIndex(self, column_name):
""" Returns the column index of the name. Raises a ValueError if it's not a valid column name """
return self._column_names.index(column_name)
14 changes: 8 additions & 6 deletions pydm/widgets/baseplot_curve_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def __init__(self, plot, parent=None):
self.axis_model = self.AXIS_MODEL_CLASS(self.plot)
self.axis_view.setModel(self.axis_model)
self.axis_model.plot = plot
self.setup_delegate_columns()
# self.table_view.resizeColumnsToContents()
self.add_button.clicked.connect(self.addCurve)
self.remove_button.clicked.connect(self.removeSelectedCurve)
Expand Down Expand Up @@ -103,15 +104,15 @@ def setup_ui(self):
self.button_box.rejected.connect(self.reject)
self.setWindowTitle("Waveform Curve Editor")

def setup_delegate_columns(self, index=2):
def setup_delegate_columns(self):
symbol_delegate = SymbolColumnDelegate(self)
self.table_view.setItemDelegateForColumn(index+4, symbol_delegate)
self.table_view.setItemDelegateForColumn(self.table_model.getColumnIndex('Symbol'), symbol_delegate)
line_delegate = LineColumnDelegate(self)
self.table_view.setItemDelegateForColumn(index+2, line_delegate)
self.table_view.setItemDelegateForColumn(self.table_model.getColumnIndex('Line Style'), line_delegate)
color_delegate = ColorColumnDelegate(self)
self.table_view.setItemDelegateForColumn(index, color_delegate)
self.table_view.setItemDelegateForColumn(self.table_model.getColumnIndex('Color'), color_delegate)
axis_delegate = AxisColumnDelegate(self)
self.axis_view.setItemDelegateForColumn(1, axis_delegate)
self.axis_view.setItemDelegateForColumn(self.axis_model.getColumnIndex('Y-Axis Orientation'), axis_delegate)

@Slot()
def addCurve(self):
Expand Down Expand Up @@ -162,7 +163,7 @@ def saveChanges(self):
self.accept()

@Slot(int)
def fillAxisData(self, tab_index, axis_name_col_index=4):
def fillAxisData(self, tab_index):
""" When the user clicks on the axis tab, prefill it with rows based on the curves they have created """

# Toggle visibility of the buttons every time the tab changes
Expand All @@ -178,6 +179,7 @@ def fillAxisData(self, tab_index, axis_name_col_index=4):
if 'left' in self.plot.plotItem.axes:
self.plot.plotItem.hideAxis('left')

axis_name_col_index = self.table_model.getColumnIndex('Y-Axis Name')
curve_axis_names = [str(self.table_model.index(i, axis_name_col_index).data())
for i in range(self.table_model.rowCount())]

Expand Down
1 change: 0 additions & 1 deletion pydm/widgets/scatterplot_curve_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,5 @@ class ScatterPlotCurveEditorDialog(BasePlotCurveEditorDialog):
def __init__(self, plot, parent=None):
super(ScatterPlotCurveEditorDialog, self).__init__(plot, parent)

self.setup_delegate_columns(index=3)
redraw_mode_delegate = RedrawModeColumnDelegate(self)
self.table_view.setItemDelegateForColumn(self.table_model.getColumnIndex("Redraw Mode"), redraw_mode_delegate)
8 changes: 0 additions & 8 deletions pydm/widgets/timeplot_curve_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,3 @@ class TimePlotCurveEditorDialog(BasePlotCurveEditorDialog):
This thing is mostly just a wrapper for a table view, with a couple
buttons to add and remove curves, and a button to save the changes."""
TABLE_MODEL_CLASS = PyDMTimePlotCurvesModel

def __init__(self, plot, parent=None):
super(TimePlotCurveEditorDialog, self).__init__(plot, parent)
self.setup_delegate_columns(index=2)

@Slot(int)
def fillAxisData(self, tab_index, axis_name_col_index=3):
super(TimePlotCurveEditorDialog, self).fillAxisData(tab_index, axis_name_col_index=axis_name_col_index)
1 change: 0 additions & 1 deletion pydm/widgets/waveformplot_curve_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,5 @@ class WaveformPlotCurveEditorDialog(BasePlotCurveEditorDialog):
def __init__(self, plot, parent=None):
super(WaveformPlotCurveEditorDialog, self).__init__(plot, parent)

self.setup_delegate_columns(index=3)
redraw_mode_delegate = RedrawModeColumnDelegate(self)
self.table_view.setItemDelegateForColumn(self.table_model.getColumnIndex("Redraw Mode"), redraw_mode_delegate)

0 comments on commit 64e3148

Please sign in to comment.