diff --git a/src/app/qgsmaptoolrotatelabel.cpp b/src/app/qgsmaptoolrotatelabel.cpp index ff6a9ff15b76..2976ae00ce03 100644 --- a/src/app/qgsmaptoolrotatelabel.cpp +++ b/src/app/qgsmaptoolrotatelabel.cpp @@ -75,7 +75,7 @@ void QgsMapToolRotateLabel::canvasPressEvent( QgsMapMouseEvent *e ) if ( true ) { - mCurrentMouseAzimuth = azimuthToCCW( mRotationPoint.azimuth( toMapCoordinates( e->pos() ) ) ); + mCurrentMouseAzimuth = convertAzimuth( mRotationPoint.azimuth( toMapCoordinates( e->pos() ) ) ); bool hasRotationValue; int rotationCol; @@ -91,7 +91,7 @@ void QgsMapToolRotateLabel::canvasPressEvent( QgsMapMouseEvent *e ) mRotationPreviewBox = createRotationPreviewBox(); mRotationItem = new QgsPointRotationItem( mCanvas ); - mRotationItem->setOrientation( QgsPointRotationItem::Counterclockwise ); + mRotationItem->setOrientation( QgsPointRotationItem::Clockwise ); mRotationItem->setSymbol( QgsApplication::getThemePixmap( QStringLiteral( "mActionRotatePointSymbols.svg" ) ).toImage() ); mRotationItem->setPointLocation( mRotationPoint ); mRotationItem->setSymbolRotation( mCurrentRotation ); @@ -104,15 +104,17 @@ void QgsMapToolRotateLabel::canvasMoveEvent( QgsMapMouseEvent *e ) if ( mLabelRubberBand ) { QgsPointXY currentPoint = toMapCoordinates( e->pos() ); - double azimuth = azimuthToCCW( mRotationPoint.azimuth( currentPoint ) ); + double azimuth = convertAzimuth( mRotationPoint.azimuth( currentPoint ) ); double azimuthDiff = azimuth - mCurrentMouseAzimuth; azimuthDiff = azimuthDiff > 180 ? azimuthDiff - 360 : azimuthDiff; mCurrentRotation += azimuthDiff; - mCurrentRotation = mCurrentRotation - static_cast( static_cast( mCurrentRotation / 360 ) ) * 360; //mCurrentRotation % 360; - mCurrentRotation = mCurrentRotation < 0 ? 360 - mCurrentRotation : mCurrentRotation; + if ( mCurrentRotation >= 360 || mCurrentRotation <= -360 ) + mCurrentRotation = std::fmod( mCurrentRotation, 360.0 ); + if ( mCurrentRotation < 0 ) + mCurrentRotation += 360.0; - mCurrentMouseAzimuth = azimuth - static_cast( static_cast( azimuth / 360 ) ) * 360; + mCurrentMouseAzimuth = std::fmod( azimuth, 360.0 ); //if shift-modifier is pressed, round to 15 degrees int displayValue; @@ -181,9 +183,10 @@ int QgsMapToolRotateLabel::roundTo15Degrees( double n ) return ( m * 15 ); } -double QgsMapToolRotateLabel::azimuthToCCW( double a ) +double QgsMapToolRotateLabel::convertAzimuth( double a ) { - return ( a > 0 ? 360 - a : -a ); + a -= 90; // convert from 0 = north to 0 = east + return ( a <= -180.0 ? 360 + a : a ); } QgsRubberBand *QgsMapToolRotateLabel::createRotationPreviewBox() @@ -218,15 +221,15 @@ void QgsMapToolRotateLabel::setRotationPreviewBox( double rotation ) for ( int i = 0; i < boxPoints.size(); ++i ) { - mRotationPreviewBox->addPoint( rotatePointCounterClockwise( boxPoints.at( i ), mRotationPoint, rotation ) ); + mRotationPreviewBox->addPoint( rotatePointClockwise( boxPoints.at( i ), mRotationPoint, rotation ) ); } - mRotationPreviewBox->addPoint( rotatePointCounterClockwise( boxPoints.at( 0 ), mRotationPoint, rotation ) ); + mRotationPreviewBox->addPoint( rotatePointClockwise( boxPoints.at( 0 ), mRotationPoint, rotation ) ); mRotationPreviewBox->show(); } -QgsPointXY QgsMapToolRotateLabel::rotatePointCounterClockwise( const QgsPointXY &input, const QgsPointXY ¢erPoint, double degrees ) +QgsPointXY QgsMapToolRotateLabel::rotatePointClockwise( const QgsPointXY &input, const QgsPointXY ¢erPoint, double degrees ) const { - double rad = degrees / 180 * M_PI; + double rad = -degrees / 180 * M_PI; double v1x = input.x() - centerPoint.x(); double v1y = input.y() - centerPoint.y(); diff --git a/src/app/qgsmaptoolrotatelabel.h b/src/app/qgsmaptoolrotatelabel.h index 91b299a10c88..510ab5eb8429 100644 --- a/src/app/qgsmaptoolrotatelabel.h +++ b/src/app/qgsmaptoolrotatelabel.h @@ -37,14 +37,14 @@ class APP_EXPORT QgsMapToolRotateLabel: public QgsMapToolLabel protected: static int roundTo15Degrees( double n ); - //! Converts azimuth value to counterclockwise 0 - 360 - static double azimuthToCCW( double a ); + //! Converts azimuth value so that 0 is corresponds to East + static double convertAzimuth( double a ); QgsRubberBand *createRotationPreviewBox(); void setRotationPreviewBox( double rotation ); - //! Rotates input point counterclockwise around centerPoint - QgsPointXY rotatePointCounterClockwise( const QgsPointXY &input, const QgsPointXY ¢erPoint, double degrees ); + //! Rotates input point clockwise around centerPoint + QgsPointXY rotatePointClockwise( const QgsPointXY &input, const QgsPointXY ¢erPoint, double degrees ) const; double mStartRotation; //rotation value prior to start rotating double mCurrentRotation;