Skip to content
Permalink
Browse files

Fix rotate label tool results in inverted rotation

Fix #17068
  • Loading branch information
nyalldawson committed Sep 4, 2017
1 parent fadfb35 commit 0f407e1e5d924fede147e62f2c6db3112a7be31a
Showing with 19 additions and 16 deletions.
  1. +15 −12 src/app/qgsmaptoolrotatelabel.cpp
  2. +4 −4 src/app/qgsmaptoolrotatelabel.h
@@ -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<float>( static_cast<int>( 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<float>( static_cast<int>( 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 &centerPoint, double degrees )
QgsPointXY QgsMapToolRotateLabel::rotatePointClockwise( const QgsPointXY &input, const QgsPointXY &centerPoint, 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();

@@ -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 &centerPoint, double degrees );
//! Rotates input point clockwise around centerPoint
QgsPointXY rotatePointClockwise( const QgsPointXY &input, const QgsPointXY &centerPoint, double degrees ) const;

double mStartRotation; //rotation value prior to start rotating
double mCurrentRotation;

0 comments on commit 0f407e1

Please sign in to comment.
You can’t perform that action at this time.