24
24
from qwt import QwtPlotItem
25
25
26
26
from plotpy .config import CONF , _
27
+ from plotpy .coords import canvas_to_axes
27
28
from plotpy .interfaces import IBasePlotItem , ISerializableType , IShapeItemType
28
29
from plotpy .items .curve .base import CurveItem
29
30
from plotpy .styles .label import LabelParam
@@ -428,18 +429,20 @@ def move_local_shape(self, old_pos: QPointF, new_pos: QPointF) -> None:
428
429
old_pos: Old position
429
430
new_pos: New position
430
431
"""
432
+ plot = self .plot ()
433
+ if plot is None :
434
+ return
431
435
if self .G in ANCHORS or not self .labelparam .move_anchor :
432
436
# Move canvas offset
433
437
lx , ly = self .C
434
438
lx += new_pos .x () - old_pos .x ()
435
439
ly += new_pos .y () - old_pos .y ()
436
440
self .C = lx , ly
437
441
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 )
438
444
else :
439
445
# Move anchor
440
- plot = self .plot ()
441
- if plot is None :
442
- return
443
446
lx0 , ly0 = self .G
444
447
cx = plot .transform (self .xAxis (), lx0 )
445
448
cy = plot .transform (self .yAxis (), ly0 )
@@ -449,7 +452,7 @@ def move_local_shape(self, old_pos: QPointF, new_pos: QPointF) -> None:
449
452
ly1 = plot .invTransform (self .yAxis (), cy )
450
453
self .G = lx1 , ly1
451
454
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 )
453
456
454
457
def move_with_selection (self , delta_x : float , delta_y : float ) -> None :
455
458
"""Translate the item together with other selected items
0 commit comments