Commit 1a34c16d authored by Valentin Valls's avatar Valentin Valls
Browse files

Fix copyItemConfig type checking

parent db09153a
Pipeline #47157 passed with stages
in 134 minutes and 21 seconds
......@@ -732,11 +732,9 @@ def copyItemsFromRoiNames(
def copyItemConfig(sourceItem: plot_model.Item, destinationItem: plot_model.Item):
"""Copy the configuration and the item tree from a source item to a
destination item"""
if not isinstance(destinationItem, type(sourceItem)):
raise TypeError(
"Both items must have the same type. Found %s" % type(destinationItem)
)
if isinstance(sourceItem, plot_item_model.CurveItem):
if isinstance(sourceItem, plot_item_model.CurveItem) and isinstance(
destinationItem, plot_item_model.CurveItem
):
destinationItem.setVisible(sourceItem.isVisible())
destinationItem.setYAxis(sourceItem.yAxis())
......@@ -752,10 +750,16 @@ def copyItemConfig(sourceItem: plot_model.Item, destinationItem: plot_model.Item
newItem.setSource(destinationSource)
destinationPlot.addItem(newItem)
sourceToDest[item] = newItem
elif isinstance(sourceItem, plot_item_model.RoiItem):
elif isinstance(sourceItem, plot_item_model.RoiItem) and isinstance(
destinationItem, plot_item_model.RoiItem
):
destinationItem.setVisible(sourceItem.isVisible())
else:
raise TypeError("Only available for curve item. Found %s" % type(sourceItem))
raise TypeError(
"No copy available from item type %s to %s"
% (type(sourceItem), type(destinationItem))
)
def updateXAxis(
......
......@@ -843,6 +843,16 @@ def test_update_xaxis_with_index():
assert items[0].yChannel().name() == "y1"
def test_copy_config__with_xaxis_item():
"""Check that we can copy config between 2 different kinds of CurveItem"""
plot = plot_item_model.CurvePlot()
i1 = add_item(plot, "x1", "y1")
i1.setYAxis("right")
i2 = add_item(plot, None, "y2", xIndex=True)
model_helper.copyItemConfig(i1, i2)
assert i2.yAxis() == "right"
def test_update_xaxis_index_with_channel():
plot = plot_item_model.CurvePlot()
add_item(plot, None, "y1", xIndex=True)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment