Merge pull request #588 from acq4/plotcurve-composition

Add PlotCurveItem composition mode
This commit is contained in:
Luke Campagnola 2017-10-04 09:14:52 -07:00 committed by GitHub
commit 7c1d2a231b

View File

@ -68,6 +68,7 @@ class PlotCurveItem(GraphicsObject):
'antialias': getConfigOption('antialias'), 'antialias': getConfigOption('antialias'),
'connect': 'all', 'connect': 'all',
'mouseWidth': 8, # width of shape responding to mouse click 'mouseWidth': 8, # width of shape responding to mouse click
'compositionMode': None,
} }
self.setClickable(kargs.get('clickable', False)) self.setClickable(kargs.get('clickable', False))
self.setData(*args, **kargs) self.setData(*args, **kargs)
@ -93,6 +94,24 @@ class PlotCurveItem(GraphicsObject):
self._mouseShape = None self._mouseShape = None
self._boundingRect = None self._boundingRect = None
def setCompositionMode(self, mode):
"""Change the composition mode of the item (see QPainter::CompositionMode
in the Qt documentation). This is useful when overlaying multiple items.
============================================ ============================================================
**Most common arguments:**
QtGui.QPainter.CompositionMode_SourceOver Default; image replaces the background if it
is opaque. Otherwise, it uses the alpha channel to blend
the image with the background.
QtGui.QPainter.CompositionMode_Overlay The image color is mixed with the background color to
reflect the lightness or darkness of the background.
QtGui.QPainter.CompositionMode_Plus Both the alpha and color of the image and background pixels
are added together.
QtGui.QPainter.CompositionMode_Multiply The output is the image color multiplied by the background.
============================================ ============================================================
"""
self.opts['compositionMode'] = mode
self.update()
def getData(self): def getData(self):
return self.xData, self.yData return self.xData, self.yData
@ -274,7 +293,7 @@ class PlotCurveItem(GraphicsObject):
def setData(self, *args, **kargs): def setData(self, *args, **kargs):
""" """
============== ======================================================== =============== ========================================================
**Arguments:** **Arguments:**
x, y (numpy arrays) Data to show x, y (numpy arrays) Data to show
pen Pen to use when drawing. Any single argument accepted by pen Pen to use when drawing. Any single argument accepted by
@ -298,7 +317,9 @@ class PlotCurveItem(GraphicsObject):
to be drawn. "finite" causes segments to be omitted if to be drawn. "finite" causes segments to be omitted if
they are attached to nan or inf values. For any other they are attached to nan or inf values. For any other
connectivity, specify an array of boolean values. connectivity, specify an array of boolean values.
============== ======================================================== compositionMode See :func:`setCompositionMode
<pyqtgraph.PlotCurveItem.setCompositionMode>`.
=============== ========================================================
If non-keyword arguments are used, they will be interpreted as If non-keyword arguments are used, they will be interpreted as
setData(y) for a single argument and setData(x, y) for two setData(y) for a single argument and setData(x, y) for two
@ -311,6 +332,9 @@ class PlotCurveItem(GraphicsObject):
def updateData(self, *args, **kargs): def updateData(self, *args, **kargs):
profiler = debug.Profiler() profiler = debug.Profiler()
if 'compositionMode' in kargs:
self.setCompositionMode(kargs['compositionMode'])
if len(args) == 1: if len(args) == 1:
kargs['y'] = args[0] kargs['y'] = args[0]
elif len(args) == 2: elif len(args) == 2:
@ -430,7 +454,6 @@ class PlotCurveItem(GraphicsObject):
x = None x = None
y = None y = None
path = self.getPath() path = self.getPath()
profiler('generate path') profiler('generate path')
if self._exportOpts is not False: if self._exportOpts is not False:
@ -440,6 +463,9 @@ class PlotCurveItem(GraphicsObject):
p.setRenderHint(p.Antialiasing, aa) p.setRenderHint(p.Antialiasing, aa)
cmode = self.opts['compositionMode']
if cmode is not None:
p.setCompositionMode(cmode)
if self.opts['brush'] is not None and self.opts['fillLevel'] is not None: if self.opts['brush'] is not None and self.opts['fillLevel'] is not None:
if self.fillPath is None: if self.fillPath is None: