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