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:
commit
34b95b7870
@ -81,19 +81,19 @@ class LegendItem(GraphicsWidget, GraphicsWidgetAnchor):
|
|||||||
self.layout.addItem(label, row, 1)
|
self.layout.addItem(label, row, 1)
|
||||||
self.updateSize()
|
self.updateSize()
|
||||||
|
|
||||||
def removeItem(self, name):
|
def removeItem(self, item):
|
||||||
"""
|
"""
|
||||||
Removes one item from the legend.
|
Removes one item from the legend.
|
||||||
|
|
||||||
============== ========================================================
|
============== ========================================================
|
||||||
**Arguments:**
|
**Arguments:**
|
||||||
title The title displayed for this item.
|
item The item to remove or its name.
|
||||||
============== ========================================================
|
============== ========================================================
|
||||||
"""
|
"""
|
||||||
# Thanks, Ulrich!
|
# Thanks, Ulrich!
|
||||||
# cycle for a match
|
# cycle for a match
|
||||||
for sample, label in self.items:
|
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.items.remove( (sample, label) ) # remove from itemlist
|
||||||
self.layout.removeItem(sample) # remove from layout
|
self.layout.removeItem(sample) # remove from layout
|
||||||
sample.close() # remove from drawing
|
sample.close() # remove from drawing
|
||||||
@ -131,6 +131,7 @@ class LegendItem(GraphicsWidget, GraphicsWidgetAnchor):
|
|||||||
dpos = ev.pos() - ev.lastPos()
|
dpos = ev.pos() - ev.lastPos()
|
||||||
self.autoAnchor(self.pos() + dpos)
|
self.autoAnchor(self.pos() + dpos)
|
||||||
|
|
||||||
|
|
||||||
class ItemSample(GraphicsWidget):
|
class ItemSample(GraphicsWidget):
|
||||||
""" Class responsible for drawing a single item in a LegendItem (sans label).
|
""" Class responsible for drawing a single item in a LegendItem (sans label).
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user