[QGIS Commit] r11680 - trunk/qgis/src/app

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sat Sep 19 09:02:51 EDT 2009


Author: mhugent
Date: 2009-09-19 09:02:49 -0400 (Sat, 19 Sep 2009)
New Revision: 11680

Modified:
   trunk/qgis/src/app/qgsmaptoolrotatepointsymbols.cpp
   trunk/qgis/src/app/qgsmaptoolrotatepointsymbols.h
Log:
Round rotation to 15 degree values if ctrl-key is pressed

Modified: trunk/qgis/src/app/qgsmaptoolrotatepointsymbols.cpp
===================================================================
--- trunk/qgis/src/app/qgsmaptoolrotatepointsymbols.cpp	2009-09-19 12:16:10 UTC (rev 11679)
+++ trunk/qgis/src/app/qgsmaptoolrotatepointsymbols.cpp	2009-09-19 13:02:49 UTC (rev 11680)
@@ -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)
 {
 
 }
@@ -161,7 +162,20 @@
   {
     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 )
@@ -172,10 +186,20 @@
     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;
       }
@@ -248,3 +272,9 @@
   mRotationItem->update();
 }
 
+int QgsMapToolRotatePointSymbols::roundTo15Degrees(double n)
+{
+  int m = (int)(n / 15.0 + 0.5);
+  return (m * 15);
+}
+

Modified: trunk/qgis/src/app/qgsmaptoolrotatepointsymbols.h
===================================================================
--- trunk/qgis/src/app/qgsmaptoolrotatepointsymbols.h	2009-09-19 12:16:10 UTC (rev 11679)
+++ trunk/qgis/src/app/qgsmaptoolrotatepointsymbols.h	2009-09-19 13:02:49 UTC (rev 11680)
@@ -50,6 +50,8 @@
     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
@@ -63,6 +65,8 @@
     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



More information about the QGIS-commit mailing list