correction of a bug regarding the exact placement of the label

This commit is contained in:
lesauxvi 2016-02-17 07:03:13 +01:00
parent 5888603ebf
commit 010cda004b

View File

@ -193,12 +193,8 @@ class InfiniteLine(GraphicsObject):
self.p = newPos self.p = newPos
self._invalidateCache() self._invalidateCache()
if self.textItem is not None and self.getViewBox() is not None and isinstance(self.getViewBox(), ViewBox): if self.textItem is not None and isinstance(self.getViewBox(), ViewBox):
self.updateText() self.updateText()
if self.draggableLabel:
GraphicsObject.setPos(self, Point(self.p))
else: # precise location needed
GraphicsObject.setPos(self, self._exactPos)
else: # no label displayed or called just before being dragged for the first time else: # no label displayed or called just before being dragged for the first time
GraphicsObject.setPos(self, Point(self.p)) GraphicsObject.setPos(self, Point(self.p))
self.update() self.update()
@ -225,7 +221,6 @@ class InfiniteLine(GraphicsObject):
fmt = fmt + self.suffix fmt = fmt + self.suffix
self.textItem.setText(fmt.format(self.value()), color=self.textColor) self.textItem.setText(fmt.format(self.value()), color=self.textColor)
posY = ymin+pos*(ymax-ymin) posY = ymin+pos*(ymax-ymin)
#self.p = [self.value(), posY]
self._exactPos = Point(self.value(), posY) self._exactPos = Point(self.value(), posY)
elif self.angle == 0: # horizontal line elif self.angle == 0: # horizontal line
diffMin = self.value()-ymin diffMin = self.value()-ymin
@ -239,8 +234,11 @@ class InfiniteLine(GraphicsObject):
fmt = fmt + self.suffix fmt = fmt + self.suffix
self.textItem.setText(fmt.format(self.value()), color=self.textColor) self.textItem.setText(fmt.format(self.value()), color=self.textColor)
posX = xmin+pos*(xmax-xmin) posX = xmin+pos*(xmax-xmin)
#self.p = [posX, self.value()]
self._exactPos = Point(posX, self.value()) self._exactPos = Point(posX, self.value())
if self.draggableLabel:
GraphicsObject.setPos(self, Point(self.p))
else: # precise location needed
GraphicsObject.setPos(self, self._exactPos)
def getXPos(self): def getXPos(self):
return self.p[0] return self.p[0]
@ -356,8 +354,7 @@ class InfiniteLine(GraphicsObject):
(eg, the view range has changed or the view was resized) (eg, the view range has changed or the view was resized)
""" """
self._invalidateCache() self._invalidateCache()
if isinstance(self.getViewBox(), ViewBox) and self.textItem is not None:
if self.getViewBox() is not None and isinstance(self.getViewBox(), ViewBox) and self.textItem is not None:
self.updateText() self.updateText()
def showLabel(self, state): def showLabel(self, state):