Skip to content

Commit b438381

Browse files
committed
Fix issue with label items not emitting SIG_ITEM_MOVED signal when moved interactively
1 parent 276c11f commit b438381

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ In this release, test coverage is 75%.
1010

1111
🛠️ Bug fixes:
1212

13+
* Label items (`LabelItem`, `LegendBoxItem`, `DataInfoLabel`, ...) were not emitting
14+
the `SIG_ITEM_MOVED` signal when moved interactively (with the mouse) if the item
15+
anchor was attached to the canvas
1316
* Colormap: fixed context menu entry update (colormap icon was updated as expected, but
1417
the colormap name was not)
1518
* Rotate/crop dialog: added missing toolbar on plot widget

plotpy/items/label.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from qwt import QwtPlotItem
2525

2626
from plotpy.config import CONF, _
27+
from plotpy.coords import canvas_to_axes
2728
from plotpy.interfaces import IBasePlotItem, ISerializableType, IShapeItemType
2829
from plotpy.items.curve.base import CurveItem
2930
from plotpy.styles.label import LabelParam
@@ -428,18 +429,20 @@ def move_local_shape(self, old_pos: QPointF, new_pos: QPointF) -> None:
428429
old_pos: Old position
429430
new_pos: New position
430431
"""
432+
plot = self.plot()
433+
if plot is None:
434+
return
431435
if self.G in ANCHORS or not self.labelparam.move_anchor:
432436
# Move canvas offset
433437
lx, ly = self.C
434438
lx += new_pos.x() - old_pos.x()
435439
ly += new_pos.y() - old_pos.y()
436440
self.C = lx, ly
437441
self.labelparam.xc, self.labelparam.yc = lx, ly
442+
lx0, ly0 = canvas_to_axes(self, old_pos)
443+
lx1, ly1 = canvas_to_axes(self, new_pos)
438444
else:
439445
# Move anchor
440-
plot = self.plot()
441-
if plot is None:
442-
return
443446
lx0, ly0 = self.G
444447
cx = plot.transform(self.xAxis(), lx0)
445448
cy = plot.transform(self.yAxis(), ly0)
@@ -449,7 +452,7 @@ def move_local_shape(self, old_pos: QPointF, new_pos: QPointF) -> None:
449452
ly1 = plot.invTransform(self.yAxis(), cy)
450453
self.G = lx1, ly1
451454
self.labelparam.xg, self.labelparam.yg = lx1, ly1
452-
plot.SIG_ITEM_MOVED.emit(self, lx0, ly0, lx1, ly1)
455+
plot.SIG_ITEM_MOVED.emit(self, lx0, ly0, lx1, ly1)
453456

454457
def move_with_selection(self, delta_x: float, delta_y: float) -> None:
455458
"""Translate the item together with other selected items

0 commit comments

Comments
 (0)