Skip to content
Permalink
Browse files
QgsMapToolRotateLabel respect rotation unit
  • Loading branch information
domi4484 committed Sep 1, 2021
1 parent 3453667 commit 0874a6a4e3f019c764d9597a17898fb48d31ffa1
@@ -397,11 +397,19 @@ Sets the polygon placement ``flags``, which dictate how polygon labels can be pl
QgsUnitTypes::AngleUnit rotationUnit() const;
%Docstring
Unit for rotation of labels.

.. seealso:: :py:func:`setRotationUnit`

.. versionadded:: 3.22
%End

void setRotationUnit( QgsUnitTypes::AngleUnit angleUnit );
%Docstring
Set unit for rotation of labels.

.. seealso:: :py:func:`rotationUnit`

.. versionadded:: 3.22
%End

double maxCurvedCharAngleIn;
@@ -161,6 +161,12 @@ void QgsMapToolRotateLabel::canvasPressEvent( QgsMapMouseEvent *e )
{
mCurrentRotation = 0;
}

// Convert to degree
mCurrentRotation = mCurrentRotation
* QgsUnitTypes::fromUnitToUnitFactor( mCurrentLabel.settings.rotationUnit(),
QgsUnitTypes::AngleDegrees );

mStartRotation = mCurrentRotation;
createRubberBands();

@@ -209,12 +215,16 @@ void QgsMapToolRotateLabel::canvasPressEvent( QgsMapMouseEvent *e )
return;
}

const double rotation = mCtrlPressed ? roundTo15Degrees( mCurrentRotation ) : mCurrentRotation;
if ( qgsDoubleNear( rotation, mStartRotation ) ) //mouse button pressed / released, but no rotation
const double rotationDegree = mCtrlPressed ? roundTo15Degrees( mCurrentRotation ) : mCurrentRotation;
if ( qgsDoubleNear( rotationDegree, mStartRotation ) ) //mouse button pressed / released, but no rotation
{
return;
}

// Convert back to settings unit
const double rotation = rotationDegree * QgsUnitTypes::fromUnitToUnitFactor( QgsUnitTypes::AngleDegrees,
mCurrentLabel.settings.rotationUnit() );

vlayer->beginEditCommand( tr( "Rotated label" ) + QStringLiteral( " '%1'" ).arg( currentLabelText( 24 ) ) );
if ( !vlayer->changeAttributeValue( mCurrentLabel.pos.featureId, rotationCol, rotation ) )
{

0 comments on commit 0874a6a

Please sign in to comment.