From b4383817fdd05106401a8338a5075c3e2df64958 Mon Sep 17 00:00:00 2001
From: Pierre Raybaut
Date: Sun, 28 Apr 2024 09:53:21 +0200
Subject: [PATCH] Fix issue with label items not emitting SIG_ITEM_MOVED signal
when moved interactively
---
CHANGELOG.md | 3 +++
plotpy/items/label.py | 11 +++++++----
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 08146cb..367bf5b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,9 @@ In this release, test coverage is 75%.
🛠️ Bug fixes:
+* Label items (`LabelItem`, `LegendBoxItem`, `DataInfoLabel`, ...) were not emitting
+ the `SIG_ITEM_MOVED` signal when moved interactively (with the mouse) if the item
+ anchor was attached to the canvas
* Colormap: fixed context menu entry update (colormap icon was updated as expected, but
the colormap name was not)
* Rotate/crop dialog: added missing toolbar on plot widget
diff --git a/plotpy/items/label.py b/plotpy/items/label.py
index 2db16db..5d18c03 100644
--- a/plotpy/items/label.py
+++ b/plotpy/items/label.py
@@ -24,6 +24,7 @@
from qwt import QwtPlotItem
from plotpy.config import CONF, _
+from plotpy.coords import canvas_to_axes
from plotpy.interfaces import IBasePlotItem, ISerializableType, IShapeItemType
from plotpy.items.curve.base import CurveItem
from plotpy.styles.label import LabelParam
@@ -428,6 +429,9 @@ def move_local_shape(self, old_pos: QPointF, new_pos: QPointF) -> None:
old_pos: Old position
new_pos: New position
"""
+ plot = self.plot()
+ if plot is None:
+ return
if self.G in ANCHORS or not self.labelparam.move_anchor:
# Move canvas offset
lx, ly = self.C
@@ -435,11 +439,10 @@ def move_local_shape(self, old_pos: QPointF, new_pos: QPointF) -> None:
ly += new_pos.y() - old_pos.y()
self.C = lx, ly
self.labelparam.xc, self.labelparam.yc = lx, ly
+ lx0, ly0 = canvas_to_axes(self, old_pos)
+ lx1, ly1 = canvas_to_axes(self, new_pos)
else:
# Move anchor
- plot = self.plot()
- if plot is None:
- return
lx0, ly0 = self.G
cx = plot.transform(self.xAxis(), lx0)
cy = plot.transform(self.yAxis(), ly0)
@@ -449,7 +452,7 @@ def move_local_shape(self, old_pos: QPointF, new_pos: QPointF) -> None:
ly1 = plot.invTransform(self.yAxis(), cy)
self.G = lx1, ly1
self.labelparam.xg, self.labelparam.yg = lx1, ly1
- plot.SIG_ITEM_MOVED.emit(self, lx0, ly0, lx1, ly1)
+ plot.SIG_ITEM_MOVED.emit(self, lx0, ly0, lx1, ly1)
def move_with_selection(self, delta_x: float, delta_y: float) -> None:
"""Translate the item together with other selected items