Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed Rotation anchor issue while zooming panning
  • Loading branch information
vinayan authored and mhugent committed Jan 12, 2013
1 parent 68e7b01 commit 0db0e7a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
23 changes: 20 additions & 3 deletions src/app/qgsmaptoolrotatefeature.cpp
@@ -1,3 +1,18 @@
/***************************************************************************
qgsmaptoolrotatefeature.cpp - map tool for rotating features by mouse drag
---------------------
begin : January 2012
copyright : (C) 2012 by Vinayan Parameswaran
email : vinayan123 at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsmaptoolrotatefeature.h"
#include "qgsgeometry.h"
#include "qgslogger.h"
Expand Down Expand Up @@ -33,17 +48,19 @@ void QgsMapToolRotateFeature::canvasMoveEvent( QMouseEvent * e )
mAnchorPoint->setCenter(toMapCoordinates(e->pos()));
mStartPointMapCoords = toMapCoordinates(e->pos());
mStPoint = e->pos();
return;
return;
}
if ( mRubberBand )
{
double XDistance = mStPoint.x() - e->pos().x();
double YDistance = mStPoint.y() - e->pos().y();
mRotation = atan2(YDistance, XDistance) * (180/PI);

mStPoint = toCanvasCoordinates(mStartPointMapCoords);
double offsetX = mStPoint.x() - mRubberBand->x();
double offsetY = mStPoint.y() - mRubberBand->y();
mRubberBand->setTransform(QTransform().translate(offsetX, offsetY).rotate(mRotation).translate(-1 * offsetX, -1 * offsetY));

mRubberBand->setTransform(QTransform().translate(offsetX,offsetY).rotate(mRotation).translate(-1 * offsetX, -1 * offsetY));
mRubberBand->update();
}
}
Expand Down Expand Up @@ -101,7 +118,7 @@ void QgsMapToolRotateFeature::canvasReleaseEvent( QMouseEvent * e )
return;
}

//calculations for affine transformation..
//calculations for affine transformation
double angle = -1 * mRotation * (PI/180);
QgsPoint anchorPoint = mStartPointMapCoords;
double a = cos(angle);
Expand Down
8 changes: 4 additions & 4 deletions src/app/qgsmaptoolrotatefeature.h
@@ -1,9 +1,9 @@
/***************************************************************************
qgsmaptoolmovefeature.h - map tool for translating features by mouse drag
qgsmaptoolrotatefeature.h - map tool for rotating features by mouse drag
---------------------
begin : Juli 2007
copyright : (C) 2007 by Marco Hugentobler
email : marco dot hugentobler at karto dot baug dot ethz dot ch
begin : January 2013
copyright : (C) 2013 by Vinayan Parameswaran
email : vinayan123 at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
Expand Down

0 comments on commit 0db0e7a

Please sign in to comment.