[QGIS Commit] r11359 - in trunk/qgis/src: app core plugins/scale_bar

svn_qgis at osgeo.org svn_qgis at osgeo.org
Wed Aug 12 11:08:22 EDT 2009


Author: homann
Date: 2009-08-12 11:08:22 -0400 (Wed, 12 Aug 2009)
New Revision: 11359

Modified:
   trunk/qgis/src/app/qgsmeasuredialog.cpp
   trunk/qgis/src/app/qgsmeasuretool.cpp
   trunk/qgis/src/app/qgsmeasuretool.h
   trunk/qgis/src/app/qgsprojectproperties.cpp
   trunk/qgis/src/core/qgsscalecalculator.cpp
   trunk/qgis/src/plugins/scale_bar/plugin.cpp
Log:
Clean up measure tool and fix the measurement when layer is in feet. Fix for #1219

Modified: trunk/qgis/src/app/qgsmeasuredialog.cpp
===================================================================
--- trunk/qgis/src/app/qgsmeasuredialog.cpp	2009-08-12 14:15:16 UTC (rev 11358)
+++ trunk/qgis/src/app/qgsmeasuredialog.cpp	2009-08-12 15:08:22 UTC (rev 11359)
@@ -234,13 +234,13 @@
   // The parameter &u is out only...
   
   QGis::UnitType myUnits = mTool->canvas()->mapUnits();
-  if ( myUnits == QGis::Degrees &&
+  if ( (myUnits == QGis::Degrees || myUnits == QGis::Feet ) &&
        mTool->canvas()->mapRenderer()->distanceArea()->ellipsoid() != "NONE" &&
        mTool->canvas()->mapRenderer()->distanceArea()->hasCrsTransformEnabled() )
   {
-    // Measuring on an ellipsoid returns meters
+    // Measuring on an ellipsoid returns meters, and so does using projections???
     myUnits = QGis::Meters;
-    QgsDebugMsg( "We're measuring on an ellipsoid, returning meters" );
+    QgsDebugMsg( "We're measuring on an ellipsoid or using projections, the system is returning meters" );
   }
 
   // Get the units for display

Modified: trunk/qgis/src/app/qgsmeasuretool.cpp
===================================================================
--- trunk/qgis/src/app/qgsmeasuretool.cpp	2009-08-12 14:15:16 UTC (rev 11358)
+++ trunk/qgis/src/app/qgsmeasuretool.cpp	2009-08-12 15:08:22 UTC (rev 11359)
@@ -63,7 +63,7 @@
   mRightMouseClicked = false;
 
   // ensure that we have correct settings
-  updateProjection();
+  updateSettings();
 
   // If we suspect that they have data that is projected, yet the
   // map CRS is set to a geographic one, warn them.
@@ -93,17 +93,11 @@
 
 void QgsMeasureTool::restart()
 {
-  updateProjection();
   mPoints.clear();
-
   mRubberBand->reset( mMeasureArea );
 
-  // re-read color settings
-  QSettings settings;
-  int myRed = settings.value( "/qgis/default_measure_color_red", 180 ).toInt();
-  int myGreen = settings.value( "/qgis/default_measure_color_green", 180 ).toInt();
-  int myBlue = settings.value( "/qgis/default_measure_color_blue", 180 ).toInt();
-  mRubberBand->setColor( QColor( myRed, myGreen, myBlue ) );
+  // re-read settings
+  updateSettings();
 
   mRightMouseClicked = false;
   mWrongProjectProjection = false;
@@ -114,19 +108,10 @@
 
 
 
-void QgsMeasureTool::updateProjection()
+void QgsMeasureTool::updateSettings()
 {
-  // set ellipsoid
   QSettings settings;
-  // QString ellipsoid = settings.readEntry("/qgis/measure/ellipsoid", "WGS84");
-  // mCalc->setEllipsoid(ellipsoid);
 
-  // set source CRS and projections enabled flag
-  // QgsMapRenderer* mapRender = mCanvas->mapRenderer();
-  // mCalc->setProjectionsEnabled(mapRender->hasCrsTransformEnabled());
-  // int srsid = mapRender->destinationSrs().srsid();
-  // mCalc->setSourceCrs(srsid);
-
   int myRed = settings.value( "/qgis/default_measure_color_red", 180 ).toInt();
   int myGreen = settings.value( "/qgis/default_measure_color_green", 180 ).toInt();
   int myBlue = settings.value( "/qgis/default_measure_color_blue", 180 ).toInt();
@@ -184,12 +169,6 @@
 {
   QgsDebugMsg( "point=" + point.toString() );
 
-  if ( mWrongProjectProjection )
-  {
-    updateProjection();
-    mWrongProjectProjection = false;
-  }
-
   // don't add points with the same coordinates
   if ( mPoints.size() > 0 && point == mPoints[0] )
     return;

Modified: trunk/qgis/src/app/qgsmeasuretool.h
===================================================================
--- trunk/qgis/src/app/qgsmeasuretool.h	2009-08-12 14:15:16 UTC (rev 11358)
+++ trunk/qgis/src/app/qgsmeasuretool.h	2009-08-12 15:08:22 UTC (rev 11359)
@@ -66,11 +66,12 @@
     //! called when map tool is being deactivated
     virtual void deactivate();
 
+  public slots:
+    //! updates the projections we're using
+    void updateSettings();
+
   protected:
 
-    //! updates the projections we're using
-    void updateProjection();
-
     QList<QgsPoint> mPoints;
 
     QgsMeasureDialog* mDialog;

Modified: trunk/qgis/src/app/qgsprojectproperties.cpp
===================================================================
--- trunk/qgis/src/app/qgsprojectproperties.cpp	2009-08-12 14:15:16 UTC (rev 11358)
+++ trunk/qgis/src/app/qgsprojectproperties.cpp	2009-08-12 15:08:22 UTC (rev 11359)
@@ -291,7 +291,7 @@
   {
     QgsCoordinateReferenceSystem srs( myCRSID, QgsCoordinateReferenceSystem::InternalCrsId );
     myRender->setDestinationSrs( srs );
-
+    QgsDebugMsg( QString( "Selected CRS " ) + srs.description() );
     // write the currently selected projections _proj string_ to project settings
     QgsDebugMsg( QString( "SpatialRefSys/ProjectCRSProj4String: %1" ).arg( projectionSelector->selectedProj4String() ) );
     QgsProject::instance()->writeEntry( "SpatialRefSys", "/ProjectCRSProj4String", projectionSelector->selectedProj4String() );

Modified: trunk/qgis/src/core/qgsscalecalculator.cpp
===================================================================
--- trunk/qgis/src/core/qgsscalecalculator.cpp	2009-08-12 14:15:16 UTC (rev 11358)
+++ trunk/qgis/src/core/qgsscalecalculator.cpp	2009-08-12 15:08:22 UTC (rev 11359)
@@ -41,11 +41,13 @@
 
 void QgsScaleCalculator::setMapUnits( QGis::UnitType mapUnits )
 {
+  QgsDebugMsg( QString( "Map units set to %1" ).arg( QString::number( mapUnits ) ) );
   mMapUnits = mapUnits;
 }
 
 QGis::UnitType QgsScaleCalculator::mapUnits() const
 {
+  QgsDebugMsg( QString( "Map units returned as %1" ).arg( QString::number( mMapUnits ) ) );
   return mMapUnits;
 }
 

Modified: trunk/qgis/src/plugins/scale_bar/plugin.cpp
===================================================================
--- trunk/qgis/src/plugins/scale_bar/plugin.cpp	2009-08-12 14:15:16 UTC (rev 11358)
+++ trunk/qgis/src/plugins/scale_bar/plugin.cpp	2009-08-12 15:08:22 UTC (rev 11359)
@@ -43,6 +43,7 @@
 #include <QColor>
 #include <QMenu>
 #include <QFile>
+#include <QLocale>
 
 //non qt includes
 #include <cmath>
@@ -262,17 +263,22 @@
         if ( myActualSize > 5280.0 ) //5280 feet to the mile
         {
           myScaleBarUnitLabel = tr( " miles" );
-          myActualSize = myActualSize / 5280;
+	  // Adjust scale bar width to get even numbers
+          myActualSize = myActualSize / 5000;
+	  myScaleBarWidth = ( myScaleBarWidth * 5280 ) / 5000;
         }
         else if ( myActualSize == 5280.0 ) //5280 feet to the mile
         {
           myScaleBarUnitLabel = tr( " mile" );
-          myActualSize = myActualSize / 5280;
+	  // Adjust scale bar width to get even numbers
+          myActualSize = myActualSize / 5000;
+	  myScaleBarWidth = ( myScaleBarWidth * 5280 ) / 5000;
         }
         else if ( myActualSize < 1 )
         {
           myScaleBarUnitLabel = tr( " inches" );
-          myActualSize = myActualSize * 12;
+          myActualSize = myActualSize * 10;
+	  myScaleBarWidth = ( myScaleBarWidth * 10 ) / 12;
         }
         else if ( myActualSize == 1.0 )
         {
@@ -304,7 +310,7 @@
     double myFontHeight = myFontMetrics.height();
 
     //Set the maximum label
-    QString myScaleBarMaxLabel = QString::number( myActualSize );
+    QString myScaleBarMaxLabel = QLocale::system().toString( myActualSize );
 
     //Calculate total width of scale bar and label
     double myTotalScaleBarWidth = myScaleBarWidth + myFontWidth;



More information about the QGIS-commit mailing list