Commit c0fcb7c8 authored by Valentin Valls's avatar Valentin Valls

Add toolbar to create new items

parent 47f1ebb4
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg id="svg6" version="1.1" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<metadata id="metadata2">
<rdf:RDF>
<cc:Work rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
<dc:title/>
</cc:Work>
</rdf:RDF>
</metadata>
<path id="path4" d="m4.0413 27.281c8.6016-0.008824 3.1105-23.891 11.959-23.917 8.8482-0.026233 3.2362 23.908 11.959 23.917" fill="none" stroke="#00a14b" stroke-width="2.1827"/>
<g id="g843" transform="translate(-34.36 -7.0998)">
<path id="path4693-1" d="m50.401 10.659v26.711" fill="none" stroke="#00a14b" stroke-dasharray="2.37510014, 2.37510014" stroke-width="2.3751"/>
<g id="g899" transform="translate(39.007 -3.5796)" stroke="#000">
<g id="g888" transform="translate(-3.2784 2.6943)" fill="none" stroke="#000" stroke-width=".15">
<g id="g865" transform="translate(.8631 13.263)" fill="#000" stroke="#000" stroke-miterlimit="10" stroke-width=".5" style="font-variant-east_asian:normal">
<rect id="rect861" x="24.483" y="7.225" width="1.239" height="8.379" style="font-variant-east_asian:normal"/>
<rect id="rect863" x="20.913" y="10.796" width="8.38" height="1.237" style="font-variant-east_asian:normal"/>
</g>
</g>
</g>
</g>
</svg>
......@@ -206,6 +206,93 @@ class YAxesPropertyItemDelegate(qt.QStyledItemDelegate):
editor.move(pos)
class _AddItemAction(qt.QWidgetAction):
def __init__(self, parent: qt.QObject, tree: qt.QTreeView):
super(_AddItemAction, self).__init__(parent)
self.__tree = tree
selectionModel = self.__tree.selectionModel()
selectionModel.currentChanged.connect(self.__selectionChanged)
widget = qt.QToolButton(parent)
icon = icons.getQIcon("flint:icons/add-item")
widget.setIcon(icon)
widget.setAutoRaise(True)
widget.setToolTip("CReate new items in the plot")
widget.setPopupMode(qt.QToolButton.InstantPopup)
widget.setEnabled(False)
widget.setText("Create items")
self.setDefaultWidget(widget)
menu = qt.QMenu(parent)
menu.aboutToShow.connect(self.__aboutToShow)
widget.setMenu(menu)
def __aboutToShow(self):
menu: qt.QMenu = self.sender()
menu.clear()
item = self.__getSelectedPlotItem()
if isinstance(item, plot_item_model.CurveMixIn):
menu.addSection("Statistics")
action = qt.QAction(self)
action.setText("Max marker")
icon = icons.getQIcon("flint:icons/item-stats")
action.setIcon(icon)
action.triggered.connect(self.__createMax)
menu.addAction(action)
menu.addSection("Functions")
action = qt.QAction(self)
action.setText("Derivative function")
icon = icons.getQIcon("flint:icons/item-stats")
action.setIcon(icon)
action.triggered.connect(self.__createDerivative)
menu.addAction(action)
else:
action = qt.QAction(self)
action.setText("No available items")
action.setEnabled(False)
menu.addAction(action)
def __selectionChanged(self, current: qt.QModelIndex, previous: qt.QModelIndex):
item = self.__getSelectedPlotItem()
self.defaultWidget().setEnabled(item is not None)
def __getSelectedPlotItem(self):
index = self.__tree.currentIndex()
if not index.isValid():
self.setEnabled(False)
return
model = self.__tree.model()
index = model.index(index.row(), 0, index.parent())
model = self.__tree.model()
item = model.itemFromIndex(index)
if isinstance(item, _DataItem):
plotItem = item.plotItem()
return plotItem
return None
def __createMax(self):
parentItem = self.__getSelectedPlotItem()
if parentItem is not None:
plot = parentItem.plot()
newItem = plot_state_model.MaxCurveItem(plot)
newItem.setSource(parentItem)
with plot.transaction():
plot.addItem(newItem)
def __createDerivative(self):
parentItem = self.__getSelectedPlotItem()
if parentItem is not None:
plot = parentItem.plot()
newItem = plot_state_model.DerivativeItem(plot)
newItem.setSource(parentItem)
with plot.transaction():
plot.addItem(newItem)
class _DataItem(_property_tree_helper.ScanRowItem):
def __init__(self):
super(_DataItem, self).__init__()
......@@ -248,6 +335,9 @@ class _DataItem(_property_tree_helper.ScanRowItem):
def setPlotModel(self, plotModel: plot_model.Plot):
self.__plotModel = plotModel
def plotModel(self) -> Optional[plot_model.Plot]:
return self.__plotModel
def axesItem(self) -> qt.QStandardItem:
return self.__yaxes
......@@ -399,6 +489,9 @@ class _DataItem(_property_tree_helper.ScanRowItem):
return None
def plotItem(self) -> Optional[plot_model.Item]:
return self.__plotItem
def setPlotItem(self, plotItem):
self.__plotItem = plotItem
......@@ -477,9 +570,20 @@ class CurvePlotPropertyWidget(qt.QWidget):
self.__scan = None
self.__focusWidget = None
toolBar = self.__createToolBar()
layout = qt.QVBoxLayout(self)
layout.setSpacing(0)
layout.addWidget(toolBar)
layout.addWidget(self.__tree)
def __createToolBar(self):
toolBar = qt.QToolBar(self)
toolBar.setMovable(False)
action = _AddItemAction(self, self.__tree)
toolBar.addAction(action)
return toolBar
def setFlintModel(self, flintModel: flint_model.FlintState = None):
if self.__flintModel is not None:
self.__flintModel.currentScanChanged.disconnect(self.__currentScanChanged)
......
Markdown is supported
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