Skip to content

Commit 24e6862

Browse files
committedAug 29, 2012
Removed Ellipsoid button and added "NONE" as a selectable ellipsoid.
All three measure dialog now work on the same global setting, using ellipsodial calculation only if CRS transformation is turned on in Project Settings, and if the chosen ellipsoid is != "NONE". An old bug made "NONE" not selectable!
1 parent 950bc2f commit 24e6862

11 files changed

+66
-154
lines changed
 

‎src/app/qgsdisplayangle.cpp

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ QgsDisplayAngle::QgsDisplayAngle( QgsMapToolMeasureAngle * tool, Qt::WFlags f )
2626
setupUi( this );
2727
QSettings settings;
2828

29-
// Update when the ellipsoidal button has changed state.
30-
connect( mcbProjectionEnabled, SIGNAL( stateChanged( int ) ),
31-
this, SLOT( ellipsoidalButton() ) );
3229
// Update whenever the canvas has refreshed. Maybe more often than needed,
3330
// but at least every time any canvas related settings changes
3431
connect( mTool->canvas(), SIGNAL( mapCanvasRefreshed() ),
@@ -42,63 +39,20 @@ QgsDisplayAngle::~QgsDisplayAngle()
4239

4340
}
4441

45-
bool QgsDisplayAngle::projectionEnabled()
46-
{
47-
return mcbProjectionEnabled->isChecked();
48-
}
4942

5043
void QgsDisplayAngle::setValueInRadians( double value )
5144
{
5245
mValue = value;
5346
updateUi();
5447
}
5548

56-
void QgsDisplayAngle::ellipsoidalButton()
57-
{
58-
QSettings settings;
59-
60-
// We set check state to Unchecked and button to Disabled when disabling CRS,
61-
// which generates a call here. Ignore that event!
62-
if ( mcbProjectionEnabled->isEnabled() )
63-
{
64-
if ( mcbProjectionEnabled->isChecked() )
65-
{
66-
settings.setValue( "/qgis/measure/projectionEnabled", 2 );
67-
}
68-
else
69-
{
70-
settings.setValue( "/qgis/measure/projectionEnabled", 0 );
71-
}
72-
updateSettings();
73-
}
74-
}
75-
7649
void QgsDisplayAngle::updateSettings()
7750
{
78-
QSettings settings;
79-
80-
int s = settings.value( "/qgis/measure/projectionEnabled", "2" ).toInt();
81-
if ( s == 2 )
82-
{
83-
mEllipsoidal = true;
84-
}
85-
else
86-
{
87-
mEllipsoidal = false;
88-
}
89-
QgsDebugMsg( "****************" );
90-
QgsDebugMsg( QString( "Ellipsoidal: %1" ).arg( mEllipsoidal ? "true" : "false" ) );
91-
92-
updateUi();
9351
emit changeProjectionEnabledState();
94-
9552
}
9653

9754
void QgsDisplayAngle::updateUi()
9855
{
99-
mcbProjectionEnabled->setEnabled( mTool->canvas()->hasCrsTransformEnabled() );
100-
mcbProjectionEnabled->setCheckState( mTool->canvas()->hasCrsTransformEnabled()
101-
&& mEllipsoidal ? Qt::Checked : Qt::Unchecked );
10256

10357
QSettings settings;
10458
QString unitString = settings.value( "/qgis/measure/angleunits", "degrees" ).toString();

‎src/app/qgsdisplayangle.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,18 @@ class QgsDisplayAngle: public QDialog, private Ui::QgsDisplayAngleBase
3131
be converted to degrees / gon automatically if necessary*/
3232
void setValueInRadians( double value );
3333

34-
bool projectionEnabled();
35-
36-
3734
signals:
3835
void changeProjectionEnabledState();
3936

4037
private slots:
4138

42-
//! When the ellipsoidal button is pressed/toggled.
43-
void ellipsoidalButton();
44-
4539
//! When any external settings change
4640
void updateSettings();
4741

4842
private:
4943
//! pointer to tool which owns this dialog
5044
QgsMapToolMeasureAngle * mTool;
5145

52-
//! Holds what the user last set ellipsoid button to.
53-
bool mEllipsoidal;
54-
5546
//! The value we're showing
5647
double mValue;
5748

‎src/app/qgsmaptoolmeasureangle.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,17 +180,17 @@ 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-
int s = settings.value( "/qgis/measure/projectionEnabled", "2" ).toInt();
187-
if ( s == 2 )
186+
// Only use ellipsoidal calculation when project wide transformation is enabled.
187+
if ( mCanvas->mapRenderer()->hasCrsTransformEnabled() )
188188
{
189-
mDa.setEllipsoidalMode( mResultDisplay->projectionEnabled() );
189+
mDa.setEllipsoidalMode( true );
190190
}
191191
else
192192
{
193-
mDa.setEllipsoidalMode( mResultDisplay->projectionEnabled() );
193+
mDa.setEllipsoidalMode( false );
194194
}
195195
}
196196

‎src/app/qgsmeasuredialog.cpp

Lines changed: 15 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ QgsMeasureDialog::QgsMeasureDialog( QgsMeasureTool* tool, Qt::WFlags f )
4848
item->setTextAlignment( 0, Qt::AlignRight );
4949
mTable->addTopLevelItem( item );
5050

51-
// Update when the ellipsoidal button has changed state.
52-
connect( mcbProjectionEnabled, SIGNAL( stateChanged( int ) ),
53-
this, SLOT( ellipsoidalButton() ) );
5451
// Update whenever the canvas has refreshed. Maybe more often than needed,
5552
// but at least every time any canvas related settings changes
5653
connect( mTool->canvas(), SIGNAL( mapCanvasRefreshed() ),
@@ -59,51 +56,32 @@ QgsMeasureDialog::QgsMeasureDialog( QgsMeasureTool* tool, Qt::WFlags f )
5956
updateSettings();
6057
}
6158

62-
void QgsMeasureDialog::ellipsoidalButton()
63-
{
64-
QSettings settings;
65-
66-
// We set check state to Unchecked and button to Disabled when disabling CRS,
67-
// which generates an call here. Ignore that event!
68-
if ( mcbProjectionEnabled->isEnabled() )
69-
{
70-
if ( mcbProjectionEnabled->isChecked() )
71-
{
72-
settings.setValue( "/qgis/measure/projectionEnabled", 2 );
73-
}
74-
else
75-
{
76-
settings.setValue( "/qgis/measure/projectionEnabled", 0 );
77-
}
78-
updateSettings();
79-
}
80-
}
81-
8259
void QgsMeasureDialog::updateSettings()
8360
{
8461
QSettings settings;
8562

86-
int s = settings.value( "/qgis/measure/projectionEnabled", "2" ).toInt();
87-
if ( s == 2 )
63+
mDecimalPlaces = settings.value( "/qgis/measure/decimalplaces", "3" ).toInt();
64+
mCanvasUnits = mTool->canvas()->mapUnits();
65+
mDisplayUnits = QGis::fromLiteral( settings.value( "/qgis/measure/displayunits", QGis::toLiteral( QGis::Meters ) ).toString() );
66+
// Configure QgsDistanceArea
67+
mDa.setSourceCrs( mTool->canvas()->mapRenderer()->destinationCrs().srsid() );
68+
mDa.setEllipsoid( settings.value( "/qgis/measure/ellipsoid", GEO_NONE ).toString() );
69+
// Only use ellipsoidal calculation when project wide transformation is enabled.
70+
if ( mTool->canvas()->mapRenderer()->hasCrsTransformEnabled() )
8871
{
89-
mEllipsoidal = true;
72+
mDa.setEllipsoidalMode( true );
9073
}
9174
else
9275
{
93-
mEllipsoidal = false;
76+
mDa.setEllipsoidalMode( false );
9477
}
9578

96-
mDecimalPlaces = settings.value( "/qgis/measure/decimalplaces", "3" ).toInt();
97-
mCanvasUnits = mTool->canvas()->mapUnits();
98-
mDisplayUnits = QGis::fromLiteral( settings.value( "/qgis/measure/displayunits", QGis::toLiteral( QGis::Meters ) ).toString() );
99-
10079
QgsDebugMsg( "****************" );
101-
QgsDebugMsg( QString( "Ellipsoidal: %1" ).arg( mEllipsoidal ? "true" : "false" ) );
102-
QgsDebugMsg( QString( "Decimalpla.: %1" ).arg( mDecimalPlaces ) );
103-
QgsDebugMsg( QString( "Display u. : %1" ).arg( QGis::toLiteral( mDisplayUnits ) ) );
104-
QgsDebugMsg( QString( "Canvas u. : %1" ).arg( QGis::toLiteral( mCanvasUnits ) ) );
105-
106-
configureDistanceArea();
80+
QgsDebugMsg( QString( "Ellipsoid ID : %1" ).arg( mDa.ellipsoid() ) );
81+
QgsDebugMsg( QString( "Ellipsoidal : %1" ).arg( mDa.ellipsoidalEnabled() ? "true" : "false" ) );
82+
QgsDebugMsg( QString( "Decimalplaces: %1" ).arg( mDecimalPlaces ) );
83+
QgsDebugMsg( QString( "Display units: %1" ).arg( QGis::toLiteral( mDisplayUnits ) ) );
84+
QgsDebugMsg( QString( "Canvas units : %1" ).arg( QGis::toLiteral( mCanvasUnits ) ) );
10785

10886
// clear interface
10987
mTable->clear();
@@ -243,11 +221,6 @@ QString QgsMeasureDialog::formatArea( double area )
243221

244222
void QgsMeasureDialog::updateUi()
245223
{
246-
// If project wide transformation is off, disbale checkbox and unmark it.
247-
// When on, enable checbox and mark with saved value.
248-
mcbProjectionEnabled->setEnabled( mTool->canvas()->hasCrsTransformEnabled() );
249-
mcbProjectionEnabled->setCheckState( mTool->canvas()->hasCrsTransformEnabled() && mEllipsoidal ? Qt::Checked : Qt::Unchecked );
250-
251224
// Set tooltip to indicate how we calculate measurments
252225
QString toolTip = tr( "The calculations are based on:" );
253226
if ( ! mTool->canvas()->hasCrsTransformEnabled() )
@@ -337,12 +310,3 @@ void QgsMeasureDialog::convertMeasurement( double &measure, QGis::UnitType &u, b
337310
u = myUnits;
338311
}
339312

340-
void QgsMeasureDialog::configureDistanceArea()
341-
{
342-
QSettings settings;
343-
QString ellipsoidId = settings.value( "/qgis/measure/ellipsoid", "WGS84" ).toString();
344-
mDa.setSourceCrs( mTool->canvas()->mapRenderer()->destinationCrs().srsid() );
345-
mDa.setEllipsoid( ellipsoidId );
346-
// Only use ellipsoidal calculation when project wide transformation is enabled.
347-
mDa.setEllipsoidalMode( mEllipsoidal && mTool->canvas()->hasCrsTransformEnabled() );
348-
}

‎src/app/qgsmeasuredialog.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@ class QgsMeasureDialog : public QDialog, private Ui::QgsMeasureBase
6363
//! Show the help for the dialog
6464
void on_buttonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); }
6565

66-
//! When the ellipsoidal button is pressed/toggled.
67-
void ellipsoidalButton();
68-
6966
//! When any external settings change
7067
void updateSettings();
7168

@@ -83,16 +80,10 @@ class QgsMeasureDialog : public QDialog, private Ui::QgsMeasureBase
8380
//! Converts the measurement, depending on settings in options and current transformation
8481
void convertMeasurement( double &measure, QGis::UnitType &u, bool isArea );
8582

86-
//! Configures distance area objects with ellipsoid / output crs
87-
void configureDistanceArea();
88-
8983
double mTotal;
9084

9185
//! indicates whether we're measuring distances or areas
9286
bool mMeasureArea;
93-
94-
//! indicates whether user wants ellipsoidal or flat
95-
bool mEllipsoidal;
9687

9788
//! Number of decimal places we want.
9889
int mDecimalPlaces;

‎src/app/qgsoptions.cpp

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include "qgsoptions.h"
2020
#include "qgis.h"
2121
#include "qgisapp.h"
22+
#include "qgsmapcanvas.h"
23+
#include "qgsmaprenderer.h"
2224
#include "qgsgenericprojectionselector.h"
2325
#include "qgscoordinatereferencesystem.h"
2426
#include "qgstolerance.h"
@@ -47,15 +49,14 @@
4749
#include <limits>
4850
#include <sqlite3.h>
4951
#include "qgslogger.h"
50-
#define ELLIPS_FLAT "NONE"
51-
#define ELLIPS_FLAT_DESC "None / Planimetric"
5252

5353
#define CPL_SUPRESS_CPLUSPLUS
5454
#include <gdal.h>
5555
#include <geos_c.h>
5656
#include <cpl_conv.h> // for setting gdal options
5757

5858
#include "qgsconfig.h"
59+
const char * QgsOptions::GEO_NONE_DESC = QT_TRANSLATE_NOOP( "QgsOptions", "None / Planimetric" );
5960

6061
/**
6162
* \class QgsOptions - Set user options and preferences
@@ -278,9 +279,23 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
278279
leProjectGlobalCrs->setText( mDefaultCrs.authid() + " - " + mDefaultCrs.description() );
279280

280281
// populate combo box with ellipsoids
282+
QgsDebugMsg( "Setting upp ellipsoid" );
283+
281284
getEllipsoidList();
285+
// Pre-select current ellipsoid
282286
QString myEllipsoidId = settings.value( "/qgis/measure/ellipsoid", "WGS84" ).toString();
283-
cmbEllipsoid->setItemText( cmbEllipsoid->currentIndex(), getEllipsoidName( myEllipsoidId ) );
287+
cmbEllipsoid->setCurrentIndex( cmbEllipsoid->findText( getEllipsoidName( myEllipsoidId ), Qt::MatchExactly ) );
288+
// Check if CRS transformation is on, or else turn combobox off
289+
if ( QgisApp::instance()->mapCanvas()->mapRenderer()->hasCrsTransformEnabled() )
290+
{
291+
cmbEllipsoid->setEnabled( true );
292+
cmbEllipsoid->setToolTip( "" );
293+
}
294+
else
295+
{
296+
cmbEllipsoid->setEnabled( false );
297+
cmbEllipsoid->setToolTip( "Can only use ellipsoidal calculations when CRS transformation is enabled" );
298+
}
284299

285300
// Set the units for measuring
286301
QString myUnitsTxt = settings.value( "/qgis/measure/displayunits", "meters" ).toString();
@@ -933,7 +948,6 @@ void QgsOptions::saveOptions()
933948
{
934949
settings.setValue( "/qgis/measure/displayunits", "meters" );
935950
}
936-
settings.setValue( "/qgis/measure/ellipsoid", getEllipsoidAcronym( cmbEllipsoid->currentText() ) );
937951

938952
QString angleUnitString = "degrees";
939953
if ( mRadiansRadioButton->isChecked() )
@@ -1161,7 +1175,7 @@ void QgsOptions::getEllipsoidList()
11611175
int myResult;
11621176

11631177

1164-
cmbEllipsoid->addItem( ELLIPS_FLAT_DESC );
1178+
cmbEllipsoid->addItem( tr( GEO_NONE_DESC ) );
11651179
//check the db is available
11661180
myResult = sqlite3_open_v2( QgsApplication::srsDbFilePath().toUtf8().data(), &myDatabase, SQLITE_OPEN_READONLY, NULL );
11671181
if ( myResult )
@@ -1194,7 +1208,8 @@ QString QgsOptions::getEllipsoidAcronym( QString theEllipsoidName )
11941208
const char *myTail;
11951209
sqlite3_stmt *myPreparedStatement;
11961210
int myResult;
1197-
QString myName( ELLIPS_FLAT );
1211+
QString myName = GEO_NONE;
1212+
11981213
//check the db is available
11991214
myResult = sqlite3_open_v2( QgsApplication::srsDbFilePath().toUtf8().data(), &myDatabase, SQLITE_OPEN_READONLY, NULL );
12001215
if ( myResult )
@@ -1226,7 +1241,9 @@ QString QgsOptions::getEllipsoidName( QString theEllipsoidAcronym )
12261241
const char *myTail;
12271242
sqlite3_stmt *myPreparedStatement;
12281243
int myResult;
1229-
QString myName( ELLIPS_FLAT_DESC );
1244+
QString myName;
1245+
1246+
myName = tr( GEO_NONE_DESC );
12301247
//check the db is available
12311248
myResult = sqlite3_open_v2( QgsApplication::srsDbFilePath().toUtf8().data(), &myDatabase, SQLITE_OPEN_READONLY, NULL );
12321249
if ( myResult )

‎src/app/qgsoptions.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ class QgsOptions : public QDialog, private Ui::QgsOptionsBase
194194
QgsCoordinateReferenceSystem mDefaultCrs;
195195
QgsCoordinateReferenceSystem mLayerDefaultCrs;
196196
bool mLoadedGdalDriverList;
197+
198+
static const char * GEO_NONE_DESC;
197199
};
198200

199201
#endif // #ifndef QGSOPTIONS_H

‎src/core/qgis.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,14 @@ class CORE_EXPORT QGis
9797
DegreesDecimalMinutes = 2, // was 5
9898
};
9999

100-
// Provides the canonical name of the type value
100+
//! Provides the canonical name of the type value
101+
// Added in version 2.0
101102
static QString toLiteral( QGis::UnitType unit );
102-
// Converts from the canonical name to the type value
103+
//! Converts from the canonical name to the type value
104+
// Added in version 2.0
103105
static UnitType fromLiteral( QString literal, QGis::UnitType defaultType = UnknownUnit );
104-
// Provides translated version of the type value
106+
//! Provides translated version of the type value
107+
// Added in version 2.0
105108
static QString tr( QGis::UnitType unit );
106109

107110
//! User defined event types
@@ -197,6 +200,10 @@ const int LAT_PREFIX_LEN = 7;
197200
* or user (~/.qgis.qgis.db) defined projection. */
198201
const int USER_CRS_START_ID = 100000;
199202

203+
//! Constant that holds the string representation for "No ellips/No CRS"
204+
// Added in version 2.0
205+
const QString GEO_NONE = "NONE";
206+
200207
//
201208
// Constants for point symbols
202209
//

0 commit comments

Comments
 (0)