From f015f0879ee007c80b7f8957a98b715bf369dce8 Mon Sep 17 00:00:00 2001 From: Luke Campagnola Date: Mon, 13 Jul 2020 16:37:29 -0700 Subject: [PATCH] TargetItem fix + performance improvements - avoid extra work when setLabelAngle would have no effect - fix errors from bad parent transform (usually the displaying widget has not been given a size yet) --- pyqtgraph/graphicsItems/TargetItem.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/pyqtgraph/graphicsItems/TargetItem.py b/pyqtgraph/graphicsItems/TargetItem.py index 114c9e6e..782e8a3b 100644 --- a/pyqtgraph/graphicsItems/TargetItem.py +++ b/pyqtgraph/graphicsItems/TargetItem.py @@ -39,8 +39,9 @@ class TargetItem(GraphicsObject): self._updateLabel() def setLabelAngle(self, angle): - self.labelAngle = angle - self._updateLabel() + if self.labelAngle != angle: + self.labelAngle = angle + self._updateLabel() def boundingRect(self): if self._picture is None: @@ -81,8 +82,14 @@ class TargetItem(GraphicsObject): # Note: could do this with self.pixelLength, but this is faster. o = self.mapToScene(QtCore.QPointF(0, 0)) - px = abs(1.0 / (self.mapToScene(QtCore.QPointF(1, 0)) - o).x()) - py = abs(1.0 / (self.mapToScene(QtCore.QPointF(0, 1)) - o).y()) + dx = (self.mapToScene(QtCore.QPointF(1, 0)) - o).x() + dy = (self.mapToScene(QtCore.QPointF(0, 1)) - o).y() + if dx == 0 or dy == 0: + p.end() + self._bounds = QtCore.QRectF() + return + px = abs(1.0 / dx) + py = abs(1.0 / dy) r, w, h = self._radii w = w * px