Skip to content
Permalink
Browse files

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
  • Loading branch information
homann
homann committed Aug 12, 2009
1 parent 7371526 commit 70579b7279dd7fedd23d319bdbae974a73255452
@@ -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
@@ -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;
@@ -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;

@@ -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() );
@@ -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;
}

@@ -43,6 +43,7 @@ email : sbr00pwb@users.sourceforge.net
#include <QColor>
#include <QMenu>
#include <QFile>
#include <QLocale>

//non qt includes
#include <cmath>
@@ -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;

0 comments on commit 70579b7

Please sign in to comment.
You can’t perform that action at this time.