Skip to content

Commit 3c6a232

Browse files
author
homann
committed
A stab at improving the measurement system. Added a new selector in Options for converting the result, and grayed out the layer units when OTFP is on. Should fix #1219, I hope.
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@11340 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 52996e7 commit 3c6a232

8 files changed

+125
-12
lines changed

src/app/qgisapp.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -5435,7 +5435,9 @@ void QgisApp::projectProperties()
54355435
QApplication::restoreOverrideCursor();
54365436

54375437
//pass any refresg signals off to canvases
5438-
//connect (pp,SIGNAL(refresh()), mMapCanvas, SLOT(refresh()));
5438+
// Line below was commented out by wonder three years ago (r4949).
5439+
// It is needed to refresh scale bar after changing display units.
5440+
connect (pp,SIGNAL(refresh()), mMapCanvas, SLOT(refresh()));
54395441

54405442
QgsMapRenderer* myRender = mMapCanvas->mapRenderer();
54415443
bool wasProjected = myRender->hasCrsTransformEnabled();

src/app/qgsmeasuredialog.cpp

+66-10
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "qgsmeasuredialog.h"
1919
#include "qgsmeasuretool.h"
2020

21+
#include "qgslogger.h"
2122
#include "qgscontexthelp.h"
2223
#include "qgsdistancearea.h"
2324
#include "qgsmapcanvas.h"
@@ -89,16 +90,22 @@ void QgsMeasureDialog::mouseMove( QgsPoint &point )
8990
QList<QgsPoint> tmpPoints = mTool->points();
9091
tmpPoints.append( point );
9192
double area = mTool->canvas()->mapRenderer()->distanceArea()->measurePolygon( tmpPoints );
93+
QGis::UnitType myDisplayUnits;
94+
// Ignore units
95+
convertMeasurement( area, myDisplayUnits, true );
9296
editTotal->setText( formatArea( area ) );
9397
}
9498
else if ( !mMeasureArea && mTool->points().size() > 0 )
9599
{
96100
QgsPoint p1( mTool->points().last() ), p2( point );
97101

98102
double d = mTool->canvas()->mapRenderer()->distanceArea()->measureLine( p1, p2 );
103+
editTotal->setText( formatDistance( mTotal + d ) );
104+
QGis::UnitType myDisplayUnits;
105+
// Ignore units
106+
convertMeasurement( d, myDisplayUnits, false );
99107
QTreeWidgetItem *item = mTable->topLevelItem( mTable->topLevelItemCount() - 1 );
100108
item->setText( 0, QLocale::system().toString( d, 'f', 2 ) );
101-
editTotal->setText( formatDistance( mTotal + d ) );
102109
}
103110
}
104111

@@ -108,6 +115,9 @@ void QgsMeasureDialog::addPoint( QgsPoint &point )
108115
if ( mMeasureArea && numPoints > 2 )
109116
{
110117
double area = mTool->canvas()->mapRenderer()->distanceArea()->measurePolygon( mTool->points() );
118+
QGis::UnitType myDisplayUnits;
119+
// Ignore units
120+
convertMeasurement( area, myDisplayUnits, true );
111121
editTotal->setText( formatArea( area ) );
112122
}
113123
else if ( !mMeasureArea && numPoints > 1 )
@@ -121,6 +131,10 @@ void QgsMeasureDialog::addPoint( QgsPoint &point )
121131
mTotal += d;
122132
editTotal->setText( formatDistance( mTotal ) );
123133

134+
QGis::UnitType myDisplayUnits;
135+
// Ignore units
136+
convertMeasurement( d, myDisplayUnits, false );
137+
124138
QTreeWidgetItem *item = mTable->topLevelItem( mTable->topLevelItemCount() - 1 );
125139
item->setText( 0, QLocale::system().toString( d, 'f', 2 ) );
126140

@@ -173,24 +187,26 @@ void QgsMeasureDialog::on_btnHelp_clicked()
173187

174188
QString QgsMeasureDialog::formatDistance( double distance )
175189
{
176-
QString txt;
177-
QString unitLabel;
178-
179-
QGis::UnitType myMapUnits = mTool->canvas()->mapUnits();
180-
return QgsDistanceArea::textUnit( distance, 2, myMapUnits, false );
190+
QGis::UnitType myDisplayUnits;
191+
convertMeasurement( distance, myDisplayUnits, false );
192+
return QgsDistanceArea::textUnit( distance, 2, myDisplayUnits, false );
181193
}
182194

183195
QString QgsMeasureDialog::formatArea( double area )
184196
{
185-
QGis::UnitType myMapUnits = mTool->canvas()->mapUnits();
186-
return QgsDistanceArea::textUnit( area, 2, myMapUnits, true );
197+
QGis::UnitType myDisplayUnits;
198+
convertMeasurement( area, myDisplayUnits, true );
199+
return QgsDistanceArea::textUnit( area, 2, myDisplayUnits, true );
187200
}
188201

189202
void QgsMeasureDialog::updateUi()
190203
{
204+
double dummy = 1.0;
205+
QGis::UnitType myDisplayUnits;
206+
// The dummy distance is ignored
207+
convertMeasurement( dummy, myDisplayUnits, false );
191208

192-
QGis::UnitType myMapUnits = mTool->canvas()->mapUnits();
193-
switch ( myMapUnits )
209+
switch ( myDisplayUnits )
194210
{
195211
case QGis::Meters:
196212
mTable->setHeaderLabels( QStringList( tr( "Segments (in meters)" ) ) );
@@ -218,3 +234,43 @@ void QgsMeasureDialog::updateUi()
218234

219235
}
220236

237+
void QgsMeasureDialog::convertMeasurement(double &measure, QGis::UnitType &u, bool isArea)
238+
{
239+
// Helper for converting between meters and feet
240+
// The parameter &u is out only...
241+
242+
QGis::UnitType myUnits = mTool->canvas()->mapUnits();
243+
if ( myUnits == QGis::Degrees &&
244+
mTool->canvas()->mapRenderer()->distanceArea()->ellipsoid() != "NONE" &&
245+
mTool->canvas()->mapRenderer()->distanceArea()->hasCrsTransformEnabled() )
246+
{
247+
// Measuring on an ellipsoid returns meters
248+
myUnits = QGis::Meters;
249+
}
250+
251+
// Get the units for display
252+
QSettings settings;
253+
QString myDisplayUnitsTxt = settings.value( "/qgis/measure/displayunits", "meters").toString();
254+
255+
// Only convert between meters and feet
256+
if ( myUnits == QGis::Meters && myDisplayUnitsTxt == "feet" )
257+
{
258+
measure /= 0.3048;
259+
if ( isArea )
260+
{
261+
measure /= 0.3048;
262+
}
263+
myUnits = QGis::Feet;
264+
}
265+
if ( myUnits == QGis::Feet && myDisplayUnitsTxt == "meters" )
266+
{
267+
measure *= 0.3048 * 0.3048;
268+
if ( isArea )
269+
{
270+
measure *= 0.3048;
271+
}
272+
myUnits = QGis::Meters;
273+
}
274+
275+
u = myUnits;
276+
}

src/app/qgsmeasuredialog.h

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "ui_qgsmeasurebase.h"
2121

2222
#include "qgspoint.h"
23+
#include "qgsdistancearea.h"
2324

2425
class QCloseEvent;
2526
class QgsMeasureTool;
@@ -72,6 +73,9 @@ class QgsMeasureDialog : public QDialog, private Ui::QgsMeasureBase
7273
//! shows/hides table, shows correct units
7374
void updateUi();
7475

76+
//! Converts the measurement, depending on settings in options and current transformation
77+
void convertMeasurement(double &measure, QGis::UnitType &u, bool isArea);
78+
7579
double mTotal;
7680

7781
//! Help context id

src/app/qgsoptions.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,17 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
113113
getEllipsoidList();
114114
QString myEllipsoidId = settings.value( "/qgis/measure/ellipsoid", "WGS84" ).toString();
115115
cmbEllipsoid->setItemText( cmbEllipsoid->currentIndex(), getEllipsoidName( myEllipsoidId ) );
116+
117+
// Set the units for measuring
118+
QString myUnitsTxt = settings.value( "/qgis/measure/displayunits", "meters").toString();
119+
if ( myUnitsTxt == "feet" )
120+
{
121+
radFeet->setChecked( true );
122+
} else {
123+
radMeters->setChecked( true );
124+
}
125+
126+
116127
// add the themes to the combo box on the option dialog
117128
QDir myThemeDir( QgsApplication::pkgDataPath() + "/themes/" );
118129
myThemeDir.setFilter( QDir::Dirs );
@@ -402,6 +413,15 @@ void QgsOptions::saveOptions()
402413

403414
settings.setValue( "/qgis/measure/ellipsoid", getEllipsoidAcronym( cmbEllipsoid->currentText() ) );
404415

416+
if ( radFeet->isChecked() )
417+
{
418+
settings.setValue( "/qgis/measure/displayunits", "feet" );
419+
}
420+
else
421+
{
422+
settings.setValue( "/qgis/measure/displayunits", "meters" );
423+
}
424+
settings.setValue( "/qgis/measure/ellipsoid", getEllipsoidAcronym( cmbEllipsoid->currentText() ) );
405425
//set the colour for selections
406426
QColor myColor = pbnSelectionColour->color();
407427
settings.setValue( "/qgis/default_selection_color_red", myColor.red() );

src/app/qgsprojectproperties.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
5858
//see if the user wants on the fly projection enabled
5959
bool myProjectionEnabled = myRender->hasCrsTransformEnabled();
6060
cbxProjectionEnabled->setChecked( myProjectionEnabled );
61+
btnGrpMapUnits->setEnabled( !myProjectionEnabled );
6162

6263
long myCRSID = myRender->destinationSrs().srsid();
6364
QgsDebugMsg( "Read project CRSID: " + QString::number( myCRSID ) );
@@ -430,3 +431,9 @@ void QgsProjectProperties::on_mSnappingOptionsPushButton_clicked()
430431
d.layerSettings( mSnappingLayerSettings );
431432
}
432433
}
434+
435+
void QgsProjectProperties::on_cbxProjectionEnabled_stateChanged(int state)
436+
{
437+
btnGrpMapUnits->setEnabled( state == Qt::Unchecked );
438+
}
439+

src/app/qgsprojectproperties.h

+3
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ class QgsProjectProperties : public QDialog, private Ui::QgsProjectPropertiesBas
9393
*/
9494
void on_mSnappingOptionsPushButton_clicked();
9595

96+
void on_cbxProjectionEnabled_stateChanged(int state);
97+
98+
9699
signals:
97100
//! Signal used to inform listeners that the mouse display precision may have changed
98101
void displayPrecisionChanged();

src/ui/qgsoptionsbase.ui

+21
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,27 @@
476476
</property>
477477
</widget>
478478
</item>
479+
<item row="2" column="0">
480+
<widget class="QLabel" name="textLabel1_8">
481+
<property name="text">
482+
<string>Display units (if applicable)</string>
483+
</property>
484+
</widget>
485+
</item>
486+
<item row="2" column="1">
487+
<widget class="QRadioButton" name="radMeters">
488+
<property name="text">
489+
<string>Meters</string>
490+
</property>
491+
</widget>
492+
</item>
493+
<item row="2" column="2">
494+
<widget class="QRadioButton" name="radFeet">
495+
<property name="text">
496+
<string>Feet</string>
497+
</property>
498+
</widget>
499+
</item>
479500
</layout>
480501
</widget>
481502
</item>

src/ui/qgsprojectpropertiesbase.ui

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@
139139
<item row="1" column="0">
140140
<widget class="QGroupBox" name="btnGrpMapUnits">
141141
<property name="title">
142-
<string>Map units</string>
142+
<string>Layer units (only used when CRS transformation is disabled)</string>
143143
</property>
144144
<layout class="QHBoxLayout">
145145
<property name="margin">

0 commit comments

Comments
 (0)