Merge pull request #584 from acq4/legenditem-update

LegendItem: make it possible to remove items directly, rather than by name
This commit is contained in:
Luke Campagnola 2017-10-04 09:25:33 -07:00 committed by GitHub
commit 34b95b7870

View File

@ -81,19 +81,19 @@ class LegendItem(GraphicsWidget, GraphicsWidgetAnchor):
self.layout.addItem(label, row, 1)
self.updateSize()
def removeItem(self, name):
def removeItem(self, item):
"""
Removes one item from the legend.
============== ========================================================
**Arguments:**
title The title displayed for this item.
item The item to remove or its name.
============== ========================================================
"""
# Thanks, Ulrich!
# cycle for a match
for sample, label in self.items:
if label.text == name: # hit
if sample.item is item or label.text == item:
self.items.remove( (sample, label) ) # remove from itemlist
self.layout.removeItem(sample) # remove from layout
sample.close() # remove from drawing
@ -131,6 +131,7 @@ class LegendItem(GraphicsWidget, GraphicsWidgetAnchor):
dpos = ev.pos() - ev.lastPos()
self.autoAnchor(self.pos() + dpos)
class ItemSample(GraphicsWidget):
""" Class responsible for drawing a single item in a LegendItem (sans label).