Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Round rotation to 15 degree values if ctrl-key is pressed
git-svn-id: http://svn.osgeo.org/qgis/trunk@11680 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Sep 19, 2009
1 parent faf0dd2 commit 793a32f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
36 changes: 33 additions & 3 deletions src/app/qgsmaptoolrotatepointsymbols.cpp
Expand Up @@ -25,7 +25,8 @@
#include <QMouseEvent>

QgsMapToolRotatePointSymbols::QgsMapToolRotatePointSymbols( QgsMapCanvas* canvas ): QgsMapToolEdit( canvas ), \
mActiveLayer( 0 ), mFeatureNumber( 0 ), mCurrentMouseAzimut( 0.0 ), mCurrentRotationFeature( 0.0 ), mRotating( false ), mRotationItem( 0 )
mActiveLayer( 0 ), mFeatureNumber( 0 ), mCurrentMouseAzimut( 0.0 ), mCurrentRotationFeature( 0.0 ), \
mRotating( false ), mRotationItem( 0 ), mCtrlPressed(false)
{

}
Expand Down Expand Up @@ -161,7 +162,20 @@ void QgsMapToolRotatePointSymbols::canvasMoveEvent( QMouseEvent * e )
{
mCurrentMouseAzimut -= 360;
}
setPixmapItemRotation( (int)(mCurrentRotationFeature) );

//if shift-modifier is pressed, round to 15 degrees
int displayValue;
if(e->modifiers() & Qt::ControlModifier)
{
displayValue = roundTo15Degrees(mCurrentRotationFeature);
mCtrlPressed = true;
}
else
{
displayValue = (int)(mCurrentRotationFeature);
mCtrlPressed = false;
}
setPixmapItemRotation(displayValue);
}

void QgsMapToolRotatePointSymbols::canvasReleaseEvent( QMouseEvent * e )
Expand All @@ -172,10 +186,20 @@ void QgsMapToolRotatePointSymbols::canvasReleaseEvent( QMouseEvent * e )
bool rotateSuccess = true;

//write mCurrentRotationFeature to all rotation attributes of feature (mFeatureNumber)
int rotation;
if(mCtrlPressed) //round to 15 degrees
{
rotation = roundTo15Degrees(mCurrentRotationFeature);
}
else
{
rotation = (int)mCurrentRotationFeature;
}

QList<int>::const_iterator it = mCurrentRotationAttributes.constBegin();
for ( ; it != mCurrentRotationAttributes.constEnd(); ++it )
{
if ( !mActiveLayer->changeAttributeValue( mFeatureNumber, *it, (int)(mCurrentRotationFeature), true ) )
if ( !mActiveLayer->changeAttributeValue( mFeatureNumber, *it, rotation, true ) )
{
rotateSuccess = false;
}
Expand Down Expand Up @@ -248,3 +272,9 @@ void QgsMapToolRotatePointSymbols::setPixmapItemRotation( double rotation )
mRotationItem->update();
}

int QgsMapToolRotatePointSymbols::roundTo15Degrees(double n)
{
int m = (int)(n / 15.0 + 0.5);
return (m * 15);
}

4 changes: 4 additions & 0 deletions src/app/qgsmaptoolrotatepointsymbols.h
Expand Up @@ -50,6 +50,8 @@ class QgsMapToolRotatePointSymbols: public QgsMapToolEdit
QPoint mSnappedPoint;
/**Item that displays rotation during mouse move*/
QgsPointRotationItem* mRotationItem;
/**True if ctrl was pressed during the last mouse move event*/
bool mCtrlPressed;

/**Finds out the rotation attributes of mActiveLayers
@param vl the point vector layer
Expand All @@ -63,6 +65,8 @@ class QgsMapToolRotatePointSymbols: public QgsMapToolEdit
void createPixmapItem();
/**Sets the rotation of the pixmap item*/
void setPixmapItemRotation( double rotation );
/**Rounds value to 15 degree integer (used if ctrl pressed)*/
static int roundTo15Degrees(double n);
};

#endif // QGSMAPTOOLROTATEPOINTSYMBOLS_H

0 comments on commit 793a32f

Please sign in to comment.