Skip to content

Commit 70579b7

Browse files
author
homann
committed
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
1 parent 7371526 commit 70579b7

File tree

6 files changed

+24
-36
lines changed

6 files changed

+24
-36
lines changed

src/app/qgsmeasuredialog.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,13 @@ void QgsMeasureDialog::convertMeasurement(double &measure, QGis::UnitType &u, bo
234234
// The parameter &u is out only...
235235

236236
QGis::UnitType myUnits = mTool->canvas()->mapUnits();
237-
if ( myUnits == QGis::Degrees &&
237+
if ( (myUnits == QGis::Degrees || myUnits == QGis::Feet ) &&
238238
mTool->canvas()->mapRenderer()->distanceArea()->ellipsoid() != "NONE" &&
239239
mTool->canvas()->mapRenderer()->distanceArea()->hasCrsTransformEnabled() )
240240
{
241-
// Measuring on an ellipsoid returns meters
241+
// Measuring on an ellipsoid returns meters, and so does using projections???
242242
myUnits = QGis::Meters;
243-
QgsDebugMsg( "We're measuring on an ellipsoid, returning meters" );
243+
QgsDebugMsg( "We're measuring on an ellipsoid or using projections, the system is returning meters" );
244244
}
245245

246246
// Get the units for display

src/app/qgsmeasuretool.cpp

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void QgsMeasureTool::activate()
6363
mRightMouseClicked = false;
6464

6565
// ensure that we have correct settings
66-
updateProjection();
66+
updateSettings();
6767

6868
// If we suspect that they have data that is projected, yet the
6969
// map CRS is set to a geographic one, warn them.
@@ -93,17 +93,11 @@ void QgsMeasureTool::deactivate()
9393

9494
void QgsMeasureTool::restart()
9595
{
96-
updateProjection();
9796
mPoints.clear();
98-
9997
mRubberBand->reset( mMeasureArea );
10098

101-
// re-read color settings
102-
QSettings settings;
103-
int myRed = settings.value( "/qgis/default_measure_color_red", 180 ).toInt();
104-
int myGreen = settings.value( "/qgis/default_measure_color_green", 180 ).toInt();
105-
int myBlue = settings.value( "/qgis/default_measure_color_blue", 180 ).toInt();
106-
mRubberBand->setColor( QColor( myRed, myGreen, myBlue ) );
99+
// re-read settings
100+
updateSettings();
107101

108102
mRightMouseClicked = false;
109103
mWrongProjectProjection = false;
@@ -114,18 +108,9 @@ void QgsMeasureTool::restart()
114108

115109

116110

117-
void QgsMeasureTool::updateProjection()
111+
void QgsMeasureTool::updateSettings()
118112
{
119-
// set ellipsoid
120113
QSettings settings;
121-
// QString ellipsoid = settings.readEntry("/qgis/measure/ellipsoid", "WGS84");
122-
// mCalc->setEllipsoid(ellipsoid);
123-
124-
// set source CRS and projections enabled flag
125-
// QgsMapRenderer* mapRender = mCanvas->mapRenderer();
126-
// mCalc->setProjectionsEnabled(mapRender->hasCrsTransformEnabled());
127-
// int srsid = mapRender->destinationSrs().srsid();
128-
// mCalc->setSourceCrs(srsid);
129114

130115
int myRed = settings.value( "/qgis/default_measure_color_red", 180 ).toInt();
131116
int myGreen = settings.value( "/qgis/default_measure_color_green", 180 ).toInt();
@@ -184,12 +169,6 @@ void QgsMeasureTool::addPoint( QgsPoint &point )
184169
{
185170
QgsDebugMsg( "point=" + point.toString() );
186171

187-
if ( mWrongProjectProjection )
188-
{
189-
updateProjection();
190-
mWrongProjectProjection = false;
191-
}
192-
193172
// don't add points with the same coordinates
194173
if ( mPoints.size() > 0 && point == mPoints[0] )
195174
return;

src/app/qgsmeasuretool.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,11 @@ class QgsMeasureTool : public QgsMapTool
6666
//! called when map tool is being deactivated
6767
virtual void deactivate();
6868

69-
protected:
70-
69+
public slots:
7170
//! updates the projections we're using
72-
void updateProjection();
71+
void updateSettings();
72+
73+
protected:
7374

7475
QList<QgsPoint> mPoints;
7576

src/app/qgsprojectproperties.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ void QgsProjectProperties::apply()
291291
{
292292
QgsCoordinateReferenceSystem srs( myCRSID, QgsCoordinateReferenceSystem::InternalCrsId );
293293
myRender->setDestinationSrs( srs );
294-
294+
QgsDebugMsg( QString( "Selected CRS " ) + srs.description() );
295295
// write the currently selected projections _proj string_ to project settings
296296
QgsDebugMsg( QString( "SpatialRefSys/ProjectCRSProj4String: %1" ).arg( projectionSelector->selectedProj4String() ) );
297297
QgsProject::instance()->writeEntry( "SpatialRefSys", "/ProjectCRSProj4String", projectionSelector->selectedProj4String() );

src/core/qgsscalecalculator.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@ double QgsScaleCalculator::dpi()
4141

4242
void QgsScaleCalculator::setMapUnits( QGis::UnitType mapUnits )
4343
{
44+
QgsDebugMsg( QString( "Map units set to %1" ).arg( QString::number( mapUnits ) ) );
4445
mMapUnits = mapUnits;
4546
}
4647

4748
QGis::UnitType QgsScaleCalculator::mapUnits() const
4849
{
50+
QgsDebugMsg( QString( "Map units returned as %1" ).arg( QString::number( mMapUnits ) ) );
4951
return mMapUnits;
5052
}
5153

src/plugins/scale_bar/plugin.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ email : sbr00pwb@users.sourceforge.net
4343
#include <QColor>
4444
#include <QMenu>
4545
#include <QFile>
46+
#include <QLocale>
4647

4748
//non qt includes
4849
#include <cmath>
@@ -262,17 +263,22 @@ void QgsScaleBarPlugin::renderScaleBar( QPainter * theQPainter )
262263
if ( myActualSize > 5280.0 ) //5280 feet to the mile
263264
{
264265
myScaleBarUnitLabel = tr( " miles" );
265-
myActualSize = myActualSize / 5280;
266+
// Adjust scale bar width to get even numbers
267+
myActualSize = myActualSize / 5000;
268+
myScaleBarWidth = ( myScaleBarWidth * 5280 ) / 5000;
266269
}
267270
else if ( myActualSize == 5280.0 ) //5280 feet to the mile
268271
{
269272
myScaleBarUnitLabel = tr( " mile" );
270-
myActualSize = myActualSize / 5280;
273+
// Adjust scale bar width to get even numbers
274+
myActualSize = myActualSize / 5000;
275+
myScaleBarWidth = ( myScaleBarWidth * 5280 ) / 5000;
271276
}
272277
else if ( myActualSize < 1 )
273278
{
274279
myScaleBarUnitLabel = tr( " inches" );
275-
myActualSize = myActualSize * 12;
280+
myActualSize = myActualSize * 10;
281+
myScaleBarWidth = ( myScaleBarWidth * 10 ) / 12;
276282
}
277283
else if ( myActualSize == 1.0 )
278284
{
@@ -304,7 +310,7 @@ void QgsScaleBarPlugin::renderScaleBar( QPainter * theQPainter )
304310
double myFontHeight = myFontMetrics.height();
305311

306312
//Set the maximum label
307-
QString myScaleBarMaxLabel = QString::number( myActualSize );
313+
QString myScaleBarMaxLabel = QLocale::system().toString( myActualSize );
308314

309315
//Calculate total width of scale bar and label
310316
double myTotalScaleBarWidth = myScaleBarWidth + myFontWidth;

0 commit comments

Comments
 (0)