diff --git a/pydm/tests/widgets/test_curve_editor.py b/pydm/tests/widgets/test_curve_editor.py index 12d01a68e..f19dfbf83 100644 --- a/pydm/tests/widgets/test_curve_editor.py +++ b/pydm/tests/widgets/test_curve_editor.py @@ -8,7 +8,10 @@ RedrawModeColumnDelegate, PlotStyleColumnDelegate, ) +from ...widgets import PyDMArchiverTimePlot +from ...widgets.axis_table_model import BasePlotAxesModel from ...widgets.baseplot_table_model import BasePlotCurvesModel +from ...widgets.archiver_time_plot_editor import PyDMArchiverTimePlotCurvesModel from ...widgets.scatterplot_curve_editor import ScatterPlotCurveEditorDialog from ...widgets.timeplot_curve_editor import TimePlotCurveEditorDialog from ...widgets.waveformplot import WaveformCurveItem @@ -120,6 +123,33 @@ def test_axis_editor(qtbot): assert type(axis_view.itemDelegateForColumn(axis_orientation_index)) is AxisColumnDelegate +def test_axis_table_model(qtmodeltester): + """Check the validity of the BasePlotAxesModel with pytest-qt""" + base_plot = BasePlot() + axis_model = BasePlotAxesModel(plot=base_plot) + axis_model.append("FooBar") + + qtmodeltester.check(axis_model, force_py=True) + + +def test_curves_table_model(qtmodeltester): + """Check the validity of the BasePlotCurvesModel with pytest-qt""" + base_plot = BasePlot() + curves_model = BasePlotCurvesModel(plot=base_plot) + curves_model.append() + + qtmodeltester.check(curves_model, force_py=True) + + +def test_archive_table_model(qtmodeltester): + """Check the validity of the PyDMArchiverTimePlotCurvesModel with pytest-qt""" + archiver_plot = PyDMArchiverTimePlot() + archive_model = PyDMArchiverTimePlotCurvesModel(plot=archiver_plot) + archive_model.append() + + qtmodeltester.check(archive_model, force_py=True) + + def test_plot_style_column_delegate(qtbot): """Verify the functionality of the show/hide column feature""" diff --git a/pydm/widgets/archiver_time_plot_editor.py b/pydm/widgets/archiver_time_plot_editor.py index 2a9d100c7..d7972a6a1 100644 --- a/pydm/widgets/archiver_time_plot_editor.py +++ b/pydm/widgets/archiver_time_plot_editor.py @@ -1,5 +1,5 @@ from typing import Any, Optional -from qtpy.QtCore import Qt, QModelIndex, QObject, QVariant +from qtpy.QtCore import Qt, QModelIndex, QObject from qtpy.QtGui import QColor from .archiver_time_plot import ArchivePlotCurveItem, FormulaCurveItem from .baseplot import BasePlot, BasePlotCurveItem @@ -16,7 +16,11 @@ def __init__(self, plot: BasePlot, parent: Optional[QObject] = None): self.checkable_cols = {self.getColumnIndex("Live Data"), self.getColumnIndex("Archive Data")} - def flags(self, index): + def flags(self, index: QModelIndex) -> Qt.ItemFlags: + """Return flags that determine how users can interact with the items in the table""" + if not index.isValid(): + return Qt.NoItemFlags + flags = super().flags(index) if index.column() in self.checkable_cols: flags = Qt.ItemIsEnabled | Qt.ItemIsUserCheckable | Qt.ItemIsSelectable @@ -24,7 +28,7 @@ def flags(self, index): def data(self, index, role=Qt.DisplayRole): if not index.isValid(): - return QVariant() + return None if role == Qt.CheckStateRole and index.column() in self.checkable_cols: value = super().data(index, Qt.DisplayRole) return Qt.Checked if value else Qt.Unchecked @@ -37,12 +41,12 @@ def get_data(self, column_name: str, curve: BasePlotCurveItem) -> Any: if column_name == "Channel": if isinstance(curve, FormulaCurveItem): if curve.formula is None: - return QVariant() + return "" return str(curve.formula) # We are either a Formula or a PV (for now at leasts) else: if curve.address is None: - return QVariant() + return "" return str(curve.address) elif column_name == "Live Data": @@ -53,7 +57,7 @@ def get_data(self, column_name: str, curve: BasePlotCurveItem) -> Any: def setData(self, index, value, role=Qt.DisplayRole): if not index.isValid(): - return QVariant() + return None elif role == Qt.CheckStateRole and index.column() in self.checkable_cols: return super().setData(index, value, Qt.EditRole) elif index.column() not in self.checkable_cols: diff --git a/pydm/widgets/axis_table_model.py b/pydm/widgets/axis_table_model.py index 9358d553c..e2ccbb871 100644 --- a/pydm/widgets/axis_table_model.py +++ b/pydm/widgets/axis_table_model.py @@ -29,7 +29,10 @@ def plot(self): def plot(self, new_plot): self._plot = new_plot - def flags(self, index): + def flags(self, index: QModelIndex) -> Qt.ItemFlags: + """Return flags that determine how users can interact with the items in the table""" + if not index.isValid(): + return Qt.NoItemFlags return Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsEditable def rowCount(self, parent=None): @@ -42,17 +45,17 @@ def columnCount(self, parent=None): def data(self, index, role=Qt.DisplayRole): if not index.isValid(): - return QVariant() + return None if index.row() >= self.rowCount(): - return QVariant() + return None if index.column() >= self.columnCount(): - return QVariant() + return None column_name = self._column_names[index.column()] axis = self.plot._axes[index.row()] if role == Qt.DisplayRole or role == Qt.EditRole: return self.get_data(column_name, axis) else: - return QVariant() + return None def get_data(self, column_name, axis): if column_name == "Y-Axis Name": diff --git a/pydm/widgets/baseplot_table_model.py b/pydm/widgets/baseplot_table_model.py index 9a0a4ab57..5f4b329d9 100644 --- a/pydm/widgets/baseplot_table_model.py +++ b/pydm/widgets/baseplot_table_model.py @@ -1,4 +1,4 @@ -from qtpy.QtCore import QAbstractTableModel, Qt, QVariant +from qtpy.QtCore import QAbstractTableModel, Qt, QVariant, QModelIndex from qtpy.QtGui import QBrush from .baseplot import BasePlotCurveItem @@ -42,7 +42,10 @@ def plot(self, new_plot): def clear(self): self.plot.clearCurves() - def flags(self, index): + def flags(self, index: QModelIndex) -> Qt.ItemFlags: + """Return flags that determine how users can interact with the items in the table""" + if not index.isValid(): + return None column_name = self._column_names[index.column()] if column_name == "Color" or column_name == "Limit Color": return Qt.ItemIsSelectable | Qt.ItemIsEnabled @@ -58,11 +61,11 @@ def columnCount(self, parent=None): def data(self, index, role=Qt.DisplayRole): if not index.isValid(): - return QVariant() + return None if index.row() >= self.rowCount(): - return QVariant() + return None if index.column() >= self.columnCount(): - return QVariant() + return None column_name = self._column_names[index.column()] curve = self.plot._curves[index.row()] if role == Qt.DisplayRole or role == Qt.EditRole: @@ -72,12 +75,12 @@ def data(self, index, role=Qt.DisplayRole): elif role == Qt.BackgroundRole and column_name == "Limit Color": return QBrush(curve.threshold_color) else: - return QVariant() + return None def get_data(self, column_name, curve): if column_name == "Label": if curve.name() is None: - return QVariant() + return "" return str(curve.name()) elif column_name == "Y-Axis Name": return curve.y_axis_name