From 70579b7279dd7fedd23d319bdbae974a73255452 Mon Sep 17 00:00:00 2001 From: homann Date: Wed, 12 Aug 2009 15:08:22 +0000 Subject: [PATCH] Clean up measure tool and fix the measurement when layer is in feet. Fix for #1219 git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@11359 c8812cc2-4d05-0410-92ff-de0c093fc19c --- src/app/qgsmeasuredialog.cpp | 6 +++--- src/app/qgsmeasuretool.cpp | 29 ++++------------------------- src/app/qgsmeasuretool.h | 7 ++++--- src/app/qgsprojectproperties.cpp | 2 +- src/core/qgsscalecalculator.cpp | 2 ++ src/plugins/scale_bar/plugin.cpp | 14 ++++++++++---- 6 files changed, 24 insertions(+), 36 deletions(-) diff --git a/src/app/qgsmeasuredialog.cpp b/src/app/qgsmeasuredialog.cpp index 74307d8ee875..1abe672438ae 100644 --- a/src/app/qgsmeasuredialog.cpp +++ b/src/app/qgsmeasuredialog.cpp @@ -234,13 +234,13 @@ void QgsMeasureDialog::convertMeasurement(double &measure, QGis::UnitType &u, bo // 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 diff --git a/src/app/qgsmeasuretool.cpp b/src/app/qgsmeasuretool.cpp index 735a7706fb03..8214f5ea9045 100644 --- a/src/app/qgsmeasuretool.cpp +++ b/src/app/qgsmeasuretool.cpp @@ -63,7 +63,7 @@ void QgsMeasureTool::activate() 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::deactivate() 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,18 +108,9 @@ void QgsMeasureTool::restart() -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(); @@ -184,12 +169,6 @@ void QgsMeasureTool::addPoint( QgsPoint &point ) { 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; diff --git a/src/app/qgsmeasuretool.h b/src/app/qgsmeasuretool.h index 33b2fcd44a13..c2ddc55fc09d 100644 --- a/src/app/qgsmeasuretool.h +++ b/src/app/qgsmeasuretool.h @@ -66,10 +66,11 @@ class QgsMeasureTool : public QgsMapTool //! called when map tool is being deactivated virtual void deactivate(); - protected: - + public slots: //! updates the projections we're using - void updateProjection(); + void updateSettings(); + + protected: QList mPoints; diff --git a/src/app/qgsprojectproperties.cpp b/src/app/qgsprojectproperties.cpp index 27167a3cf8ae..82c20fb62968 100644 --- a/src/app/qgsprojectproperties.cpp +++ b/src/app/qgsprojectproperties.cpp @@ -291,7 +291,7 @@ void QgsProjectProperties::apply() { 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() ); diff --git a/src/core/qgsscalecalculator.cpp b/src/core/qgsscalecalculator.cpp index 71ba952ffa52..9f3ee0cc9e55 100644 --- a/src/core/qgsscalecalculator.cpp +++ b/src/core/qgsscalecalculator.cpp @@ -41,11 +41,13 @@ double QgsScaleCalculator::dpi() 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; } diff --git a/src/plugins/scale_bar/plugin.cpp b/src/plugins/scale_bar/plugin.cpp index 71e5c398aca9..24af528577b7 100644 --- a/src/plugins/scale_bar/plugin.cpp +++ b/src/plugins/scale_bar/plugin.cpp @@ -43,6 +43,7 @@ email : sbr00pwb@users.sourceforge.net #include #include #include +#include //non qt includes #include @@ -262,17 +263,22 @@ void QgsScaleBarPlugin::renderScaleBar( QPainter * theQPainter ) 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 @@ void QgsScaleBarPlugin::renderScaleBar( QPainter * theQPainter ) 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;