Skip to content

Commit

Permalink
QgsMapToolRotateLabel respect rotation unit
Browse files Browse the repository at this point in the history
  • Loading branch information
domi4484 committed Sep 1, 2021
1 parent 3453667 commit 0874a6a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
8 changes: 8 additions & 0 deletions python/core/auto_generated/labeling/qgspallabeling.sip.in
Expand Up @@ -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;
Expand Down
14 changes: 12 additions & 2 deletions src/app/labeling/qgsmaptoolrotatelabel.cpp
Expand Up @@ -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();

Expand Down Expand Up @@ -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 ) )
{
Expand Down

0 comments on commit 0874a6a

Please sign in to comment.