Skip to content

Commit

Permalink
Fix issue with label items not emitting SIG_ITEM_MOVED signal when mo…
Browse files Browse the repository at this point in the history
…ved interactively
  • Loading branch information
PierreRaybaut committed Apr 28, 2024
1 parent 276c11f commit b438381
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions plotpy/items/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -428,18 +429,20 @@ 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
lx += new_pos.x() - old_pos.x()
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)
Expand All @@ -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
Expand Down

0 comments on commit b438381

Please sign in to comment.