Skip to content

Commit a441282

Browse files
committed
Merge pull request #219 from homann/measure_cleanup
Measure cleanup and fix #5156
2 parents ad2ff90 + 0d1b1aa commit a441282

20 files changed

+292
-283
lines changed

src/app/qgsdecorationscalebar.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ email : sbr00pwb@users.sourceforge.net
2323

2424
#include "qgsdecorationscalebardialog.h"
2525

26+
#include "qgis.h"
2627
#include "qgisapp.h"
2728
#include "qgslogger.h"
2829
#include "qgsmapcanvas.h"
@@ -119,6 +120,7 @@ void QgsDecorationScaleBar::render( QPainter * theQPainter )
119120
//projections) and that just confuses the rest of the code in this
120121
//function, so force to a positive number.
121122
double myMapUnitsPerPixelDouble = qAbs( canvas->mapUnitsPerPixel() );
123+
double myActualSize = mPreferredSize;
122124

123125
// Exit if the canvas width is 0 or layercount is 0 or QGIS will freeze
124126
int myLayerCount = canvas->layerCount();
@@ -131,9 +133,25 @@ void QgsDecorationScaleBar::render( QPainter * theQPainter )
131133
// Hard coded sizes
132134
int myMajorTickSize = 8;
133135
int myTextOffsetX = 3;
134-
double myActualSize = mPreferredSize;
135136
int myMargin = 20;
136137

138+
QSettings settings;
139+
QGis::UnitType myPreferredUnits = QGis::fromLiteral( settings.value( "/qgis/measure/displayunits", QGis::toLiteral( QGis::Meters ) ).toString() );
140+
QGis::UnitType myMapUnits = canvas->mapUnits();
141+
142+
// Adjust units meter/feet or vice versa
143+
if ( myMapUnits == QGis::Meters && myPreferredUnits == QGis::Feet )
144+
{
145+
// From meter to feet
146+
myMapUnits = QGis::Feet;
147+
myMapUnitsPerPixelDouble /= 0.3084;
148+
}
149+
else if ( myMapUnits == QGis::Feet && myPreferredUnits == QGis::Meters )
150+
{
151+
// From feet to meter
152+
myMapUnits = QGis::Meters;
153+
myMapUnitsPerPixelDouble *= 0.3084;
154+
}
137155
//Calculate size of scale bar for preferred number of map units
138156
double myScaleBarWidth = mPreferredSize / myMapUnitsPerPixelDouble;
139157

@@ -164,7 +182,6 @@ void QgsDecorationScaleBar::render( QPainter * theQPainter )
164182
}
165183

166184
//Get type of map units and set scale bar unit label text
167-
QGis::UnitType myMapUnits = canvas->mapUnits();
168185
QString myScaleBarUnitLabel;
169186
switch ( myMapUnits )
170187
{

src/app/qgsdecorationscalebar.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ email : sbr00pwb@users.sourceforge.net
2121
#ifndef QGSCALEBARPLUGIN
2222
#define QGSCALEBARPLUGIN
2323

24+
#include "qgis.h"
2425
#include "qgsdecorationitem.h"
2526

2627
class QPainter;

src/app/qgsdisplayangle.cpp

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,58 +14,64 @@
1414
***************************************************************************/
1515

1616
#include "qgsdisplayangle.h"
17+
#include "qgsmapcanvas.h"
18+
#include "qgslogger.h"
19+
1720
#include <QSettings>
1821
#include <cmath>
1922

20-
QgsDisplayAngle::QgsDisplayAngle( QWidget * parent, Qt::WindowFlags f ): QDialog( parent, f )
23+
QgsDisplayAngle::QgsDisplayAngle( QgsMapToolMeasureAngle * tool, Qt::WFlags f )
24+
: QDialog( tool->canvas()->topLevelWidget(), f ), mTool( tool )
2125
{
2226
setupUi( this );
2327
QSettings settings;
24-
int s = settings.value( "/qgis/measure/projectionEnabled", "2" ).toInt();
25-
if ( s == 2 )
26-
mcbProjectionEnabled->setCheckState( Qt::Checked );
27-
else
28-
mcbProjectionEnabled->setCheckState( Qt::Unchecked );
2928

30-
connect( mcbProjectionEnabled, SIGNAL( stateChanged( int ) ),
31-
this, SLOT( changeState() ) );
32-
connect( mcbProjectionEnabled, SIGNAL( stateChanged( int ) ),
33-
this, SIGNAL( changeProjectionEnabledState() ) );
29+
// Update whenever the canvas has refreshed. Maybe more often than needed,
30+
// but at least every time any canvas related settings changes
31+
connect( mTool->canvas(), SIGNAL( mapCanvasRefreshed() ),
32+
this, SLOT( updateSettings() ) );
33+
34+
updateSettings();
3435
}
3536

3637
QgsDisplayAngle::~QgsDisplayAngle()
3738
{
3839

3940
}
4041

41-
bool QgsDisplayAngle::projectionEnabled()
42+
43+
void QgsDisplayAngle::setValueInRadians( double value )
44+
{
45+
mValue = value;
46+
updateUi();
47+
}
48+
49+
void QgsDisplayAngle::updateSettings()
4250
{
43-
return mcbProjectionEnabled->isChecked();
51+
emit changeProjectionEnabledState();
4452
}
4553

46-
void QgsDisplayAngle::setValueInRadians( double value )
54+
void QgsDisplayAngle::updateUi()
4755
{
56+
4857
QSettings settings;
4958
QString unitString = settings.value( "/qgis/measure/angleunits", "degrees" ).toString();
59+
int decimals = settings.value( "/qgis/measure/decimalplaces", "3" ).toInt();
60+
5061
if ( unitString == "degrees" )
5162
{
52-
mAngleLineEdit->setText( tr( "%1 degrees" ).arg( value * 180 / M_PI ) );
63+
mAngleLineEdit->setText( tr( "%1 degrees" ).arg( QLocale::system().toString( mValue * 180 / M_PI ),
64+
'f', decimals ) );
5365
}
5466
else if ( unitString == "radians" )
5567
{
56-
mAngleLineEdit->setText( tr( "%1 radians" ).arg( value ) );
68+
mAngleLineEdit->setText( tr( "%1 radians" ).arg( QLocale::system().toString( mValue ),
69+
'f', decimals ) );
70+
5771
}
5872
else if ( unitString == "gon" )
5973
{
60-
mAngleLineEdit->setText( tr( "%1 gon" ).arg( value / M_PI * 200 ) );
74+
mAngleLineEdit->setText( tr( "%1 gon" ).arg( QLocale::system().toString( mValue / M_PI * 200 ),
75+
'f', decimals ) );
6176
}
6277
}
63-
64-
void QgsDisplayAngle::changeState()
65-
{
66-
QSettings settings;
67-
if ( mcbProjectionEnabled->isChecked() )
68-
settings.setValue( "/qgis/measure/projectionEnabled", 2 );
69-
else
70-
settings.setValue( "/qgis/measure/projectionEnabled", 0 );
71-
}

src/app/qgsdisplayangle.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#ifndef QGSDISPLAYANGLE_H
1717
#define QGSDISPLAYANGLE_H
1818

19+
#include "qgsmaptoolmeasureangle.h"
1920
#include "ui_qgsdisplayanglebase.h"
2021

2122
/**A class that displays results of angle measurements with the proper unit*/
@@ -24,20 +25,29 @@ class QgsDisplayAngle: public QDialog, private Ui::QgsDisplayAngleBase
2425
Q_OBJECT
2526

2627
public:
27-
QgsDisplayAngle( QWidget * parent = 0, Qt::WindowFlags f = 0 );
28+
QgsDisplayAngle( QgsMapToolMeasureAngle * tool = 0, Qt::WindowFlags f = 0 );
2829
~QgsDisplayAngle();
2930
/**Sets the measured angle value (in radians). The value is going to
3031
be converted to degrees / gon automatically if necessary*/
3132
void setValueInRadians( double value );
3233

33-
bool projectionEnabled();
34-
3534
signals:
3635
void changeProjectionEnabledState();
3736

3837
private slots:
39-
void changeState();
4038

39+
//! When any external settings change
40+
void updateSettings();
41+
42+
private:
43+
//! pointer to tool which owns this dialog
44+
QgsMapToolMeasureAngle * mTool;
45+
46+
//! The value we're showing
47+
double mValue;
48+
49+
//! Updates UI according to user settings.
50+
void updateUi();
4151
};
4252

4353
#endif // QGSDISPLAYANGLE_H

src/app/qgsmaptoolfeatureaction.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
#include "qgsmaptoolfeatureaction.h"
1717

18-
#include "qgsdistancearea.h"
1918
#include "qgsfeature.h"
2019
#include "qgsfield.h"
2120
#include "qgsgeometry.h"
@@ -111,7 +110,6 @@ bool QgsMapToolFeatureAction::doAction( QgsVectorLayer *layer, int x, int y )
111110
// load identify radius from settings
112111
QSettings settings;
113112
double identifyValue = settings.value( "/Map/identifyRadius", QGis::DEFAULT_IDENTIFY_RADIUS ).toDouble();
114-
QString ellipsoid = settings.value( "/qgis/measure/ellipsoid", "WGS84" ).toString();
115113

116114
if ( identifyValue <= 0.0 )
117115
identifyValue = QGis::DEFAULT_IDENTIFY_RADIUS;

src/app/qgsmaptoolidentify.cpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ bool QgsMapToolIdentify::identifyVectorLayer( QgsVectorLayer *layer, int x, int
204204
// load identify radius from settings
205205
QSettings settings;
206206
double identifyValue = settings.value( "/Map/identifyRadius", QGis::DEFAULT_IDENTIFY_RADIUS ).toDouble();
207-
QString ellipsoid = settings.value( "/qgis/measure/ellipsoid", "WGS84" ).toString();
207+
QString ellipsoid = settings.value( "/qgis/measure/ellipsoid", GEO_NONE ).toString();
208208

209209
if ( identifyValue <= 0.0 )
210210
identifyValue = QGis::DEFAULT_IDENTIFY_RADIUS;
@@ -392,17 +392,7 @@ void QgsMapToolIdentify::convertMeasurement( QgsDistanceArea &calc, double &meas
392392

393393
// Get the units for display
394394
QSettings settings;
395-
QString myDisplayUnitsTxt = settings.value( "/qgis/measure/displayunits", "meters" ).toString();
396-
397-
QGis::UnitType displayUnits;
398-
if ( myDisplayUnitsTxt == "feet" )
399-
{
400-
displayUnits = QGis::Feet;
401-
}
402-
else
403-
{
404-
displayUnits = QGis::Meters;
405-
}
395+
QGis::UnitType displayUnits = QGis::fromLiteral( settings.value( "/qgis/measure/displayunits", QGis::toLiteral( QGis::Meters ) ).toString() );
406396

407397
calc.convertMeasurement( measure, myUnits, displayUnits, isArea );
408398
u = myUnits;

src/app/qgsmaptoolmeasureangle.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ void QgsMapToolMeasureAngle::canvasReleaseEvent( QMouseEvent * e )
8585
{
8686
if ( mResultDisplay == NULL )
8787
{
88-
mResultDisplay = new QgsDisplayAngle( mCanvas->topLevelWidget() );
88+
mResultDisplay = new QgsDisplayAngle( this );
8989
QObject::connect( mResultDisplay, SIGNAL( rejected() ), this, SLOT( stopMeasuring() ) );
9090
QObject::connect( mResultDisplay, SIGNAL( changeProjectionEnabledState() ),
9191
this, SLOT( changeProjectionEnabledState() ) );
@@ -180,10 +180,18 @@ void QgsMapToolMeasureAngle::changeProjectionEnabledState()
180180
void QgsMapToolMeasureAngle::configureDistanceArea()
181181
{
182182
QSettings settings;
183-
QString ellipsoidId = settings.value( "/qgis/measure/ellipsoid", "WGS84" ).toString();
183+
QString ellipsoidId = settings.value( "/qgis/measure/ellipsoid", GEO_NONE ).toString();
184184
mDa.setSourceCrs( mCanvas->mapRenderer()->destinationCrs().srsid() );
185185
mDa.setEllipsoid( ellipsoidId );
186-
mDa.setEllipsoidalMode( mResultDisplay->projectionEnabled() ); // FIXME (not when proj is turned off)
186+
// Only use ellipsoidal calculation when project wide transformation is enabled.
187+
if ( mCanvas->mapRenderer()->hasCrsTransformEnabled() )
188+
{
189+
mDa.setEllipsoidalMode( true );
190+
}
191+
else
192+
{
193+
mDa.setEllipsoidalMode( false );
194+
}
187195
}
188196

189197

src/app/qgsmaptoolmeasureangle.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class QgsMapToolMeasureAngle: public QgsMapTool
3232
QgsMapToolMeasureAngle( QgsMapCanvas* canvas );
3333
~QgsMapToolMeasureAngle();
3434

35-
//! Mouse move event for overriding
35+
//! Mouse move event for overridingqgs
3636
void canvasMoveEvent( QMouseEvent * e );
3737

3838
//! Mouse release event for overriding

0 commit comments

Comments
 (0)