Skip to content

Commit

Permalink
Clean up measure tool and fix the measurement when layer is in feet. …
Browse files Browse the repository at this point in the history
…Fix for #1219

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@11359 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
homann committed Aug 12, 2009
1 parent 7371526 commit 70579b7
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 36 deletions.
6 changes: 3 additions & 3 deletions src/app/qgsmeasuredialog.cpp
Expand Up @@ -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
Expand Down
29 changes: 4 additions & 25 deletions src/app/qgsmeasuretool.cpp
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions src/app/qgsmeasuretool.h
Expand Up @@ -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<QgsPoint> mPoints;

Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsprojectproperties.cpp
Expand Up @@ -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() );
Expand Down
2 changes: 2 additions & 0 deletions src/core/qgsscalecalculator.cpp
Expand Up @@ -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;
}

Expand Down
14 changes: 10 additions & 4 deletions src/plugins/scale_bar/plugin.cpp
Expand Up @@ -43,6 +43,7 @@ email : sbr00pwb@users.sourceforge.net
#include <QColor>
#include <QMenu>
#include <QFile>
#include <QLocale>

//non qt includes
#include <cmath>
Expand Down Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 70579b7

Please sign in to comment.