Merge remote-tracking branch 'henesissrl/infinite_line_speedup' into infiniteline-tests
This commit is contained in:
commit
52863064de
@ -64,6 +64,9 @@ class InfiniteLine(GraphicsObject):
|
|||||||
self.setHoverPen(color=(255,0,0), width=self.pen.width())
|
self.setHoverPen(color=(255,0,0), width=self.pen.width())
|
||||||
self.currentPen = self.pen
|
self.currentPen = self.pen
|
||||||
|
|
||||||
|
self._boundingRect = None
|
||||||
|
self._line = None
|
||||||
|
|
||||||
def setMovable(self, m):
|
def setMovable(self, m):
|
||||||
"""Set whether the line is movable by the user."""
|
"""Set whether the line is movable by the user."""
|
||||||
self.movable = m
|
self.movable = m
|
||||||
@ -135,6 +138,10 @@ class InfiniteLine(GraphicsObject):
|
|||||||
newPos[1] = min(newPos[1], self.maxRange[1])
|
newPos[1] = min(newPos[1], self.maxRange[1])
|
||||||
|
|
||||||
if self.p != newPos:
|
if self.p != newPos:
|
||||||
|
# Invalidate bounding rect and line
|
||||||
|
self._boundingRect = None
|
||||||
|
self._line = None
|
||||||
|
|
||||||
self.p = newPos
|
self.p = newPos
|
||||||
GraphicsObject.setPos(self, Point(self.p))
|
GraphicsObject.setPos(self, Point(self.p))
|
||||||
self.update()
|
self.update()
|
||||||
@ -175,23 +182,36 @@ class InfiniteLine(GraphicsObject):
|
|||||||
#print "ignore", change
|
#print "ignore", change
|
||||||
#return GraphicsObject.itemChange(self, change, val)
|
#return GraphicsObject.itemChange(self, change, val)
|
||||||
|
|
||||||
def boundingRect(self):
|
def viewTransformChanged(self):
|
||||||
#br = UIGraphicsItem.boundingRect(self)
|
self._boundingRect = None
|
||||||
br = self.viewRect()
|
self._line = None
|
||||||
## add a 4-pixel radius around the line for mouse interaction.
|
GraphicsObject.viewTransformChanged(self)
|
||||||
|
|
||||||
px = self.pixelLength(direction=Point(1,0), ortho=True) ## get pixel length orthogonal to the line
|
def viewChanged(self, view, oldView):
|
||||||
if px is None:
|
self._boundingRect = None
|
||||||
px = 0
|
self._line = None
|
||||||
w = (max(4, self.pen.width()/2, self.hoverPen.width()/2)+1) * px
|
GraphicsObject.viewChanged(self, view, oldView)
|
||||||
br.setBottom(-w)
|
|
||||||
br.setTop(w)
|
def boundingRect(self):
|
||||||
return br.normalized()
|
if self._boundingRect is None:
|
||||||
|
#br = UIGraphicsItem.boundingRect(self)
|
||||||
|
br = self.viewRect()
|
||||||
|
## add a 4-pixel radius around the line for mouse interaction.
|
||||||
|
|
||||||
|
px = self.pixelLength(direction=Point(1,0), ortho=True) ## get pixel length orthogonal to the line
|
||||||
|
if px is None:
|
||||||
|
px = 0
|
||||||
|
w = (max(4, self.pen.width()/2, self.hoverPen.width()/2)+1) * px
|
||||||
|
br.setBottom(-w)
|
||||||
|
br.setTop(w)
|
||||||
|
br = br.normalized()
|
||||||
|
self._boundingRect = br
|
||||||
|
self._line = QtCore.QLineF(br.right(), 0, br.left(), 0)
|
||||||
|
return self._boundingRect
|
||||||
|
|
||||||
def paint(self, p, *args):
|
def paint(self, p, *args):
|
||||||
br = self.boundingRect()
|
|
||||||
p.setPen(self.currentPen)
|
p.setPen(self.currentPen)
|
||||||
p.drawLine(Point(br.right(), 0), Point(br.left(), 0))
|
p.drawLine(self._line)
|
||||||
|
|
||||||
def dataBounds(self, axis, frac=1.0, orthoRange=None):
|
def dataBounds(self, axis, frac=1.0, orthoRange=None):
|
||||||
if axis == 0:
|
if axis == 0:
|
||||||
|
Loading…
Reference in New Issue
Block a user