[QGIS Commit] r14992 - in trunk/qgis/src: app core ui

svn_qgis at osgeo.org svn_qgis at osgeo.org
Tue Jan 4 09:32:20 EST 2011


Author: mhugent
Date: 2011-01-04 06:32:19 -0800 (Tue, 04 Jan 2011)
New Revision: 14992

Modified:
   trunk/qgis/src/app/qgsmaptoolmeasureangle.cpp
   trunk/qgis/src/app/qgsmaptoolmeasureangle.h
   trunk/qgis/src/app/qgsmeasuredialog.cpp
   trunk/qgis/src/app/qgsmeasuredialog.h
   trunk/qgis/src/core/qgsmaprenderer.h
   trunk/qgis/src/ui/qgsdisplayanglebase.ui
   trunk/qgis/src/ui/qgsmeasurebase.ui
Log:
Apply patch #3384 by Sergey Yakushev with few modifications. Mark QgsMapRenderer::distanceArea as deprecated

Modified: trunk/qgis/src/app/qgsmaptoolmeasureangle.cpp
===================================================================
--- trunk/qgis/src/app/qgsmaptoolmeasureangle.cpp	2011-01-03 14:03:05 UTC (rev 14991)
+++ trunk/qgis/src/app/qgsmaptoolmeasureangle.cpp	2011-01-04 14:32:19 UTC (rev 14992)
@@ -45,46 +45,38 @@
   mRubberBand->movePoint( point );
   if ( mAnglePoints.size() == 2 )
   {
-    //do angle calculation
-    QgsDistanceArea* distArea = mCanvas->mapRenderer()->distanceArea();
-    if ( distArea )
+    if ( !mResultDisplay )
     {
-      //show angle in dialog
-      if ( !mResultDisplay )
+      mResultDisplay = new QgsDisplayAngle( mCanvas->topLevelWidget() );
+      QObject::connect( mResultDisplay, SIGNAL( rejected() ), this, SLOT( stopMeasuring() ) );
+      QObject::connect( mResultDisplay, SIGNAL( changeProjectionEnabledState() ),
+                        this, SLOT( changeProjectionEnabledState() ) );
+      mResultDisplay->move( e->pos() - QPoint( 100, 100 ) );
+    }
+    mResultDisplay->show();
+
+    QgsDistanceArea myDa;
+    configureDistanceArea( myDa );
+
+    //angle calculation
+    double azimuthOne = myDa.bearing( mAnglePoints.at( 1 ), mAnglePoints.at( 0 ) );
+    double azimuthTwo = myDa.bearing( mAnglePoints.at( 1 ), point );
+    double resultAngle = azimuthTwo - azimuthOne;
+    QgsDebugMsg( QString::number( qAbs( resultAngle ) ) );
+    QgsDebugMsg( QString::number( M_PI ) );
+    if ( qAbs( resultAngle ) > M_PI )
+    {
+      if ( resultAngle < 0 )
       {
-        mResultDisplay = new QgsDisplayAngle( mCanvas->topLevelWidget() );
-        QObject::connect( mResultDisplay, SIGNAL( rejected() ), this, SLOT( stopMeasuring() ) );
-        QObject::connect( mResultDisplay, SIGNAL( changeProjectionEnabledState() ), 
-            this, SLOT( changeProjectionEnabledState() ) );
-        mResultDisplay->move( e->pos() - QPoint( 100, 100 ) );
+        resultAngle = M_PI + ( resultAngle + M_PI );
       }
-      mResultDisplay->show();   
-      
-      QgsDistanceArea myDa;
-      myDa.setSourceCrs( mCanvas->mapRenderer()->destinationSrs().srsid() );
-      myDa.setEllipsoid( distArea->ellipsoid() );
-      myDa.setProjectionsEnabled( mResultDisplay->projectionEnabled() );
-
-      //angle calculation
-      double azimuthOne = myDa.bearing( mAnglePoints.at( 1 ), mAnglePoints.at( 0 ) );
-      double azimuthTwo = myDa.bearing( mAnglePoints.at( 1 ), point );
-      double resultAngle = azimuthTwo - azimuthOne;
-      QgsDebugMsg( QString::number( qAbs( resultAngle ) ) );
-      QgsDebugMsg( QString::number( M_PI ) );
-      if ( qAbs( resultAngle ) > M_PI )
+      else
       {
-        if ( resultAngle < 0 )
-        {
-          resultAngle = M_PI + ( resultAngle + M_PI );
-        }
-        else
-        {
-          resultAngle = -M_PI + ( resultAngle - M_PI );
-        }
+        resultAngle = -M_PI + ( resultAngle - M_PI );
       }
+    }
 
-      mResultDisplay->setValueInRadians( resultAngle );
-    }
+    mResultDisplay->setValueInRadians( resultAngle );
   }
 }
 
@@ -160,11 +152,9 @@
     return;
   if ( !mResultDisplay )
     return;
-  
+
   QgsDistanceArea myDa;
-  myDa.setSourceCrs( mCanvas->mapRenderer()->destinationSrs().srsid() );
-  myDa.setEllipsoid( mCanvas->mapRenderer()->distanceArea()->ellipsoid() );
-  myDa.setProjectionsEnabled( mResultDisplay->projectionEnabled() );
+  configureDistanceArea( myDa );
 
   //angle calculation
   double azimuthOne = myDa.bearing( mAnglePoints.at( 1 ), mAnglePoints.at( 0 ) );
@@ -187,3 +177,14 @@
 
 }
 
+void QgsMapToolMeasureAngle::configureDistanceArea( QgsDistanceArea& da )
+{
+  QSettings settings;
+  QString ellipsoidId = settings.value( "/qgis/measure/ellipsoid", "WGS84" ).toString();
+  da.setSourceCrs( mCanvas->mapRenderer()->destinationSrs().srsid() );
+  da.setEllipsoid( ellipsoidId );
+  da.setProjectionsEnabled( mResultDisplay->projectionEnabled() );
+}
+
+
+

Modified: trunk/qgis/src/app/qgsmaptoolmeasureangle.h
===================================================================
--- trunk/qgis/src/app/qgsmaptoolmeasureangle.h	2011-01-03 14:03:05 UTC (rev 14991)
+++ trunk/qgis/src/app/qgsmaptoolmeasureangle.h	2011-01-04 14:32:19 UTC (rev 14992)
@@ -62,6 +62,9 @@
     /** recalculate angle if projection state changed*/
     void changeProjectionEnabledState();
 
+    //! Configures distance area objects with ellipsoid / output crs
+    void configureDistanceArea( QgsDistanceArea& da );
+
 };
 
 #endif // QGSMAPTOOLMEASUREANGLE_H

Modified: trunk/qgis/src/app/qgsmeasuredialog.cpp
===================================================================
--- trunk/qgis/src/app/qgsmeasuredialog.cpp	2011-01-03 14:03:05 UTC (rev 14991)
+++ trunk/qgis/src/app/qgsmeasuredialog.cpp	2011-01-04 14:32:19 UTC (rev 14992)
@@ -58,8 +58,8 @@
   else
     mcbProjectionEnabled->setCheckState( Qt::Unchecked );
 
-  connect( mcbProjectionEnabled, SIGNAL( stateChanged(int) ), 
-      this, SLOT( changeProjectionEnabledState() ));
+  connect( mcbProjectionEnabled, SIGNAL( stateChanged( int ) ),
+           this, SLOT( changeProjectionEnabledState() ) );
 
   updateUi();
 }
@@ -99,14 +99,12 @@
   int decimalPlaces = settings.value( "/qgis/measure/decimalplaces", "3" ).toInt();
 
   // Create QgsDistance Area for customization ProjectionEnabled setting
-  QgsDistanceArea myDa;  
-  myDa.setSourceCrs( mTool->canvas()->mapRenderer()->destinationSrs().srsid() );
-  myDa.setEllipsoid( mTool->canvas()->mapRenderer()->distanceArea()->ellipsoid() );
-  myDa.setProjectionsEnabled( mcbProjectionEnabled->isChecked() );
+  QgsDistanceArea myDa;
+  configureDistanceArea( myDa );
 
   // show current distance/area while moving the point
   // by creating a temporary copy of point array
-  // and adding moving point at the end  
+  // and adding moving point at the end
   if ( mMeasureArea && mTool->points().size() > 1 )
   {
     QList<QgsPoint> tmpPoints = mTool->points();
@@ -134,10 +132,8 @@
   int decimalPlaces = settings.value( "/qgis/measure/decimalplaces", "3" ).toInt();
 
   // Create QgsDistance Area for customization ProjectionEnabled setting
-  QgsDistanceArea myDa;  
-  myDa.setSourceCrs( mTool->canvas()->mapRenderer()->destinationSrs().srsid() );
-  myDa.setEllipsoid( mTool->canvas()->mapRenderer()->distanceArea()->ellipsoid() );
-  myDa.setProjectionsEnabled( mcbProjectionEnabled->isChecked() );
+  QgsDistanceArea myDa;
+  configureDistanceArea( myDa );
 
   int numPoints = mTool->points().size();
   if ( mMeasureArea && numPoints > 2 )
@@ -269,19 +265,18 @@
   // The parameter &u is out only...
 
   QGis::UnitType myUnits = mTool->canvas()->mapUnits();
-  if (( myUnits == QGis::Degrees || myUnits == QGis::Feet ) &&
-      mTool->canvas()->mapRenderer()->distanceArea()->ellipsoid() != "NONE" &&
+  if (( myUnits == QGis::Degrees || myUnits == QGis::Feet )  &&
       mcbProjectionEnabled->isChecked() )
   {
     // Measuring on an ellipsoid returns meters, and so does using projections???
     myUnits = QGis::Meters;
     QgsDebugMsg( "We're measuring on an ellipsoid or using projections, the system is returning meters" );
   }
-   
+
   // Get the units for display
   QSettings settings;
   QString myDisplayUnitsTxt = settings.value( "/qgis/measure/displayunits", "meters" ).toString();
-  
+
   // Only convert between meters and feet
   if ( myUnits == QGis::Meters && myDisplayUnitsTxt == "feet" )
   {
@@ -314,9 +309,9 @@
   // store value
   QSettings settings;
   if ( mcbProjectionEnabled->isChecked() )
-    settings.setValue( "/qgis/measure/projectionEnabled", 2);
+    settings.setValue( "/qgis/measure/projectionEnabled", 2 );
   else
-    settings.setValue( "/qgis/measure/projectionEnabled", 0);
+    settings.setValue( "/qgis/measure/projectionEnabled", 0 );
 
   // clear interface
   mTable->clear();
@@ -327,13 +322,11 @@
   updateUi();
 
   int decimalPlaces = settings.value( "/qgis/measure/decimalplaces", "3" ).toInt();
- 
+
   // create DistanceArea
-  QgsDistanceArea myDa;  
-  myDa.setSourceCrs( mTool->canvas()->mapRenderer()->destinationSrs().srsid() );
-  myDa.setEllipsoid( mTool->canvas()->mapRenderer()->distanceArea()->ellipsoid() );
-  myDa.setProjectionsEnabled( mcbProjectionEnabled->isChecked() );
-  
+  QgsDistanceArea myDa;
+  configureDistanceArea( myDa );
+
   if ( mMeasureArea )
   {
     double area = 0.0;
@@ -342,14 +335,15 @@
       area = myDa.measurePolygon( mTool->points() );
     }
     editTotal->setText( formatArea( area, decimalPlaces ) );
-  }else
+  }
+  else
   {
     QList<QgsPoint>::const_iterator it;
     bool b = true; // first point
-  
-    QgsPoint p1,p2;
-     
-    for (it=mTool->points().constBegin(); it != mTool->points().constEnd(); ++it)
+
+    QgsPoint p1, p2;
+
+    for ( it = mTool->points().constBegin(); it != mTool->points().constEnd(); ++it )
     {
       p2 = *it;
       if ( !b )
@@ -373,3 +367,12 @@
     }
   }
 }
+
+void QgsMeasureDialog::configureDistanceArea( QgsDistanceArea& da )
+{
+  QSettings settings;
+  QString ellipsoidId = settings.value( "/qgis/measure/ellipsoid", "WGS84" ).toString();
+  da.setSourceCrs( mTool->canvas()->mapRenderer()->destinationSrs().srsid() );
+  da.setEllipsoid( ellipsoidId );
+  da.setProjectionsEnabled( mcbProjectionEnabled->isChecked() );
+}

Modified: trunk/qgis/src/app/qgsmeasuredialog.h
===================================================================
--- trunk/qgis/src/app/qgsmeasuredialog.h	2011-01-03 14:03:05 UTC (rev 14991)
+++ trunk/qgis/src/app/qgsmeasuredialog.h	2011-01-04 14:32:19 UTC (rev 14992)
@@ -80,6 +80,9 @@
     //! Converts the measurement, depending on settings in options and current transformation
     void convertMeasurement( double &measure, QGis::UnitType &u, bool isArea );
 
+    //! Configures distance area objects with ellipsoid / output crs
+    void configureDistanceArea( QgsDistanceArea& da );
+
     double mTotal;
 
     //! indicates whether we're measuring distances or areas

Modified: trunk/qgis/src/core/qgsmaprenderer.h
===================================================================
--- trunk/qgis/src/core/qgsmaprenderer.h	2011-01-03 14:03:05 UTC (rev 14991)
+++ trunk/qgis/src/core/qgsmaprenderer.h	2011-01-04 14:32:19 UTC (rev 14992)
@@ -134,6 +134,7 @@
     void updateScale();
 
     //! Return the measuring object
+    //! @note deprecated.
     QgsDistanceArea* distanceArea() { return mDistArea; }
     QGis::UnitType mapUnits() const;
     void setMapUnits( QGis::UnitType u );

Modified: trunk/qgis/src/ui/qgsdisplayanglebase.ui
===================================================================
--- trunk/qgis/src/ui/qgsdisplayanglebase.ui	2011-01-03 14:03:05 UTC (rev 14991)
+++ trunk/qgis/src/ui/qgsdisplayanglebase.ui	2011-01-04 14:32:19 UTC (rev 14992)
@@ -47,7 +47,7 @@
    <item row="0" column="0">
     <widget class="QCheckBox" name="mcbProjectionEnabled">
      <property name="text">
-      <string>Ellipsoidal (WGS84)</string>
+      <string>Ellipsoidal</string>
      </property>
     </widget>
    </item>

Modified: trunk/qgis/src/ui/qgsmeasurebase.ui
===================================================================
--- trunk/qgis/src/ui/qgsmeasurebase.ui	2011-01-03 14:03:05 UTC (rev 14991)
+++ trunk/qgis/src/ui/qgsmeasurebase.ui	2011-01-04 14:32:19 UTC (rev 14992)
@@ -101,7 +101,7 @@
    <item row="0" column="0" colspan="3">
     <widget class="QCheckBox" name="mcbProjectionEnabled">
      <property name="text">
-      <string>Ellipsoidal (WGS84)</string>
+      <string>Ellipsoidal</string>
      </property>
     </widget>
    </item>



More information about the QGIS-commit mailing list