Conversation
t20100
left a comment
There was a problem hiding this comment.
The previous behavior was fine and should not change IMO.
The manual add/remove can co-exist with the "automatic" sync with the plot: We just need to make sure in work in all conditions
src/silx/gui/plot/LegendsWidget.py
Outdated
| else: | ||
| plot.sigItemAdded.connect(self._onItemAdded) | ||
| plot.sigItemRemoved.connect(self._onItemRemoved) | ||
| plot.sigItemRemoved.connect(self._onItemRemovedFromPlot) |
There was a problem hiding this comment.
Why removing sigItemAdded connection?
The idea is to have 2 ways to manage the items:
- Automatically from a
PlotWidgetthroughsigItemAdded,sigItemRemoved - Manually with explicit
addItem,removeItem
Both mode should co-exist and work in corner cases e.g.:
- remove an item added automatically and then remove it from the plot
- add an item manually that was already added automatically (in this case it should not be added)
setPlotWidget(None)should not remove item added manually that do not belong to the previous plot
Note: We could remove setPlotWidget and have users do the connections sigItemAdded -> addItem, sigItemRemoved -> removeItem, but quite a few widgets provides an automatic update through a setPlotWidget (or setPlot) method, so it is worth keeping it IMO.
There was a problem hiding this comment.
Okay, Now I understand features, by default it should be like previous way,
additionally, if the user wants to remove an item, then we could remove from legend and from plot widget,
if user wants to addItem to legend, it should also add it into plot.
There was a problem hiding this comment.
Actually, if we implement this feature, we dont have to go for the sorting of items based on the Items.type,
user can manually arange Items using multiple LegendWidgets, and order them as they want,
because, if we try to do manually, then it complicates the code, may be we need to find some clever sorting insertion, deletion, data structure, ?
|
As mentioned, made clear, add,remove Items as public, only delete the items belongs to the previous plot, when it changes from plot to another. added orphan items interaction check, and added manual/automated items interference check |
t20100
left a comment
There was a problem hiding this comment.
LGTM, thanks for the updates!
I put one minor change of the boolean asserts.
Not for this PR, but provided how much the tests are accessing _itemWidgets keys, we may add a getItems method to LegendsWidget as the one of PlotWidget
| assert orphan_item.isVisible() is True | ||
| assert item_widget._label.isEnabled() is True | ||
| qapp_utils.mouseClick(item_widget, qt.Qt.LeftButton) | ||
| qapp.processEvents() | ||
| assert orphan_item.isVisible() is False | ||
| assert item_widget._label.isEnabled() is False | ||
| qapp_utils.mouseClick(item_widget, qt.Qt.LeftButton) | ||
| assert orphan_item.isVisible() is True | ||
| assert item_widget._label.isEnabled() is True |
There was a problem hiding this comment.
No need for is True and is False is not:
| assert orphan_item.isVisible() is True | |
| assert item_widget._label.isEnabled() is True | |
| qapp_utils.mouseClick(item_widget, qt.Qt.LeftButton) | |
| qapp.processEvents() | |
| assert orphan_item.isVisible() is False | |
| assert item_widget._label.isEnabled() is False | |
| qapp_utils.mouseClick(item_widget, qt.Qt.LeftButton) | |
| assert orphan_item.isVisible() is True | |
| assert item_widget._label.isEnabled() is True | |
| assert orphan_item.isVisible() | |
| assert item_widget._label.isEnabled() | |
| qapp_utils.mouseClick(item_widget, qt.Qt.LeftButton) | |
| qapp.processEvents() | |
| assert not orphan_item.isVisible() | |
| assert not item_widget._label.isEnabled() | |
| qapp_utils.mouseClick(item_widget, qt.Qt.LeftButton) | |
| assert orphan_item.isVisible() | |
| assert item_widget._label.isEnabled() |
In the LegendWidgets, we are moving from default add/remove Items (based on the internal Items trigger action from the plotwidget), to application explicit add/remove Items calls