Skip to content

Commit

Permalink
Just get the index of the column from the tabel model directly
Browse files Browse the repository at this point in the history
  • Loading branch information
jbellister-slac committed Jan 20, 2022
1 parent 3c67b6f commit 450169c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
22 changes: 11 additions & 11 deletions pydm/tests/widgets/test_curve_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ def test_waveform_curve_editor(qtbot):
# 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
color_index = table_model._column_names.index('Color')
line_style_index = table_model._column_names.index('Line Style')
symbol_index = table_model._column_names.index('Symbol')
redraw_mode_index = table_model._column_names.index('Redraw Mode')
color_index = table_model.getColumnIndex('Color')
line_style_index = table_model.getColumnIndex('Line Style')
symbol_index = table_model.getColumnIndex('Symbol')
redraw_mode_index = table_model.getColumnIndex('Redraw Mode')

assert type(table_view.itemDelegateForColumn(color_index)) is ColorColumnDelegate
assert type(table_view.itemDelegateForColumn(line_style_index)) is LineColumnDelegate
Expand All @@ -57,9 +57,9 @@ def test_timeplot_curve_editor(qtbot):
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._column_names.index('Color')
line_style_index = table_model._column_names.index('Line Style')
symbol_index = table_model._column_names.index('Symbol')
color_index = table_model.getColumnIndex('Color')
line_style_index = table_model.getColumnIndex('Line Style')
symbol_index = table_model.getColumnIndex('Symbol')

assert type(table_view.itemDelegateForColumn(color_index)) is ColorColumnDelegate
assert type(table_view.itemDelegateForColumn(line_style_index)) is LineColumnDelegate
Expand All @@ -85,10 +85,10 @@ def test_scatterplot_editor(qtbot):
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._column_names.index('Color')
line_style_index = table_model._column_names.index('Line Style')
symbol_index = table_model._column_names.index('Symbol')
redraw_mode_index = table_model._column_names.index('Redraw Mode')
color_index = table_model.getColumnIndex('Color')
line_style_index = table_model.getColumnIndex('Line Style')
symbol_index = table_model.getColumnIndex('Symbol')
redraw_mode_index = table_model.getColumnIndex('Redraw Mode')

assert type(table_view.itemDelegateForColumn(color_index)) is ColorColumnDelegate
assert type(table_view.itemDelegateForColumn(line_style_index)) is LineColumnDelegate
Expand Down
4 changes: 4 additions & 0 deletions pydm/widgets/baseplot_table_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ def append(self, name=None, color=None):
def removeAtIndex(self, index):
pass

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)

def needsColorDialog(self, index):
column_name = self._column_names[index.column()]
if column_name == "Color":
Expand Down
2 changes: 1 addition & 1 deletion pydm/widgets/scatterplot_curve_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ def __init__(self, plot, parent=None):

self.setup_delegate_columns(index=3)
redraw_mode_delegate = RedrawModeColumnDelegate(self)
self.table_view.setItemDelegateForColumn(9, redraw_mode_delegate)
self.table_view.setItemDelegateForColumn(self.table_model.getColumnIndex("Redraw Mode"), redraw_mode_delegate)
2 changes: 1 addition & 1 deletion pydm/widgets/waveformplot_curve_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ def __init__(self, plot, parent=None):

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

0 comments on commit 450169c

Please sign in to comment.