Merge pull request #1297 from campagnola/acq4-merge2
ArrowItem performance
This commit is contained in:
commit
49dd944d10
@ -23,10 +23,11 @@ class ArrowItem(QtGui.QGraphicsPathItem):
|
|||||||
opts['headLen'] = opts['size']
|
opts['headLen'] = opts['size']
|
||||||
if 'width' in opts:
|
if 'width' in opts:
|
||||||
opts['headWidth'] = opts['width']
|
opts['headWidth'] = opts['width']
|
||||||
|
pos = opts.pop('pos', (0, 0))
|
||||||
|
|
||||||
defaultOpts = {
|
defaultOpts = {
|
||||||
'pxMode': True,
|
'pxMode': True,
|
||||||
'angle': -150, ## If the angle is 0, the arrow points left
|
'angle': -150, ## If the angle is 0, the arrow points left
|
||||||
'pos': (0,0),
|
|
||||||
'headLen': 20,
|
'headLen': 20,
|
||||||
'headWidth': None,
|
'headWidth': None,
|
||||||
'tipAngle': 25,
|
'tipAngle': 25,
|
||||||
@ -40,7 +41,8 @@ class ArrowItem(QtGui.QGraphicsPathItem):
|
|||||||
|
|
||||||
self.setStyle(**defaultOpts)
|
self.setStyle(**defaultOpts)
|
||||||
|
|
||||||
self.moveBy(*self.opts['pos'])
|
# for backward compatibility
|
||||||
|
self.setPos(*pos)
|
||||||
|
|
||||||
def setStyle(self, **opts):
|
def setStyle(self, **opts):
|
||||||
"""
|
"""
|
||||||
@ -67,11 +69,25 @@ class ArrowItem(QtGui.QGraphicsPathItem):
|
|||||||
tailWidth Width of the tail. default=3
|
tailWidth Width of the tail. default=3
|
||||||
pen The pen used to draw the outline of the arrow.
|
pen The pen used to draw the outline of the arrow.
|
||||||
brush The brush used to fill the arrow.
|
brush The brush used to fill the arrow.
|
||||||
|
pxMode If True, then the arrow is drawn as a fixed size
|
||||||
|
regardless of the scale of its parents (including
|
||||||
|
the ViewBox zoom level).
|
||||||
====================== =================================================
|
====================== =================================================
|
||||||
"""
|
"""
|
||||||
self.opts.update(opts)
|
arrowOpts = ['headLen', 'tipAngle', 'baseAngle', 'tailLen', 'tailWidth', 'headWidth']
|
||||||
|
allowedOpts = ['angle', 'pen', 'brush', 'pxMode'] + arrowOpts
|
||||||
|
needUpdate = False
|
||||||
|
for k,v in opts.items():
|
||||||
|
if k not in allowedOpts:
|
||||||
|
raise KeyError('Invalid arrow style option "%s"' % k)
|
||||||
|
if self.opts.get(k) != v:
|
||||||
|
needUpdate = True
|
||||||
|
self.opts[k] = v
|
||||||
|
|
||||||
opt = dict([(k,self.opts[k]) for k in ['headLen', 'headWidth', 'tipAngle', 'baseAngle', 'tailLen', 'tailWidth']])
|
if not needUpdate:
|
||||||
|
return
|
||||||
|
|
||||||
|
opt = dict([(k,self.opts[k]) for k in arrowOpts if k in self.opts])
|
||||||
tr = QtGui.QTransform()
|
tr = QtGui.QTransform()
|
||||||
tr.rotate(self.opts['angle'])
|
tr.rotate(self.opts['angle'])
|
||||||
self.path = tr.map(fn.makeArrowPath(**opt))
|
self.path = tr.map(fn.makeArrowPath(**opt))
|
||||||
@ -86,7 +102,6 @@ class ArrowItem(QtGui.QGraphicsPathItem):
|
|||||||
else:
|
else:
|
||||||
self.setFlags(self.flags() & ~self.ItemIgnoresTransformations)
|
self.setFlags(self.flags() & ~self.ItemIgnoresTransformations)
|
||||||
|
|
||||||
|
|
||||||
def paint(self, p, *args):
|
def paint(self, p, *args):
|
||||||
p.setRenderHint(QtGui.QPainter.Antialiasing)
|
p.setRenderHint(QtGui.QPainter.Antialiasing)
|
||||||
QtGui.QGraphicsPathItem.paint(self, p, *args)
|
QtGui.QGraphicsPathItem.paint(self, p, *args)
|
||||||
|
Loading…
Reference in New Issue
Block a user