Commit 8eef7392 authored by Valentin Valls's avatar Valentin Valls
Browse files

Rework item creation UI as an item param editor

parent 3960e2fd
Pipeline #75286 passed with stages
in 120 minutes and 16 seconds
...@@ -270,13 +270,13 @@ class _AddItemAction(qt.QWidgetAction): ...@@ -270,13 +270,13 @@ class _AddItemAction(qt.QWidgetAction):
menu: qt.QMenu = self.sender() menu: qt.QMenu = self.sender()
menu.clear() menu.clear()
availableItemFactory = { availableItemParamEditor = {
MaxCurveItem: None, MaxCurveItem: None,
MinCurveItem: None, MinCurveItem: None,
DerivativeItem: None, DerivativeItem: None,
NegativeItem: None, NegativeItem: None,
GaussianFitItem: None, GaussianFitItem: None,
NormalizedCurveItem: self.__createNormalized, NormalizedCurveItem: self.__editNormalizedParams,
NormalizedZeroOneItem: None, NormalizedZeroOneItem: None,
} }
...@@ -284,14 +284,14 @@ class _AddItemAction(qt.QWidgetAction): ...@@ -284,14 +284,14 @@ class _AddItemAction(qt.QWidgetAction):
if isinstance(item, plot_item_model.CurveMixIn): if isinstance(item, plot_item_model.CurveMixIn):
menu.addSection("Statistics") menu.addSection("Statistics")
for className, chassFactory in availableItemFactory.items(): for className, editor in availableItemParamEditor.items():
try: try:
name = className.NAME name = className.NAME
except Exception: except Exception:
name = className.__name__ name = className.__name__
chassFactory = functools.partial(
if chassFactory is None: self.__createChildItem, className, editor
chassFactory = functools.partial(self.__createChildItem, className) )
action = qt.QAction(self) action = qt.QAction(self)
action.setText(name) action.setText(name)
icon = icons.getQIcon("flint:icons/item-stats") icon = icons.getQIcon("flint:icons/item-stats")
...@@ -307,23 +307,39 @@ class _AddItemAction(qt.QWidgetAction): ...@@ -307,23 +307,39 @@ class _AddItemAction(qt.QWidgetAction):
def __selectionChanged(self, current: plot_model.Item): def __selectionChanged(self, current: plot_model.Item):
self.defaultWidget().setEnabled(current is not None) self.defaultWidget().setEnabled(current is not None)
def __createChildItem(self, itemClass): def __createChildItem(self, itemClass, itemEditor):
parentItem = self.parent().selectedPlotItem() parentItem = self.parent().selectedPlotItem()
if parentItem is not None: if parentItem is None:
plotModel = parentItem.plot() return
newItem = itemClass(plotModel) plotModel = parentItem.plot()
newItem.setSource(parentItem) newItem = itemClass(plotModel)
with plotModel.transaction(): if itemEditor is not None:
plotModel.addItem(newItem) result = itemEditor(newItem)
# FIXME: It would be better to make it part of the model if not result:
plotModel.tagUserEditTime() newItem.deleteLater()
return
def __createNormalized(self): # Sanity check as we did a user selection in between it is not atomic
parentItem = self.parent().selectedPlotItem() parentItem = self.parent().selectedPlotItem()
if parentItem is None: if parentItem is None:
newItem.deleteLater()
return return
# Avoid strong reference plotModel = parentItem.plot()
parentItem = None if plotModel is None:
newItem.deleteLater()
return
newItem.setSource(parentItem)
with plotModel.transaction():
plotModel.addItem(newItem)
# FIXME: It would be better to make it part of the model
plotModel.tagUserEditTime()
def __editNormalizedParams(self, item: NormalizedCurveItem):
"""Edit NormalizedCurveItem parameters.
Returns true if the edition succeeded, else false.
"""
parentWidget = self.parent() parentWidget = self.parent()
scan = parentWidget.scan() scan = parentWidget.scan()
dialog = SelectChannelDialog(parentWidget) dialog = SelectChannelDialog(parentWidget)
...@@ -333,22 +349,11 @@ class _AddItemAction(qt.QWidgetAction): ...@@ -333,22 +349,11 @@ class _AddItemAction(qt.QWidgetAction):
return return
monitorName = dialog.selectedChannelName() monitorName = dialog.selectedChannelName()
if monitorName is None: if monitorName is None:
return return False
# As we did a user selection make sure the item is still there plotModel = item.plot()
parentItem = self.parent().selectedPlotItem()
if parentItem is None:
return
plotModel = parentItem.plot()
if plotModel is None:
return
newItem = NormalizedCurveItem(plotModel)
channel = plot_model.ChannelRef(plotModel, monitorName) channel = plot_model.ChannelRef(plotModel, monitorName)
newItem.setMonitorChannel(channel) item.setMonitorChannel(channel)
newItem.setSource(parentItem) return True
with plotModel.transaction():
plotModel.addItem(newItem)
# FIXME: It would be better to make it part of the model
plotModel.tagUserEditTime()
class _DataItem(_property_tree_helper.ScanRowItem): class _DataItem(_property_tree_helper.ScanRowItem):
......
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