diff --git a/src/app/qgsdisplayangle.cpp b/src/app/qgsdisplayangle.cpp index 2341546986e..ddc2ec65ab1 100644 --- a/src/app/qgsdisplayangle.cpp +++ b/src/app/qgsdisplayangle.cpp @@ -26,9 +26,6 @@ QgsDisplayAngle::QgsDisplayAngle( QgsMapToolMeasureAngle * tool, Qt::WFlags f ) setupUi( this ); QSettings settings; - // Update when the ellipsoidal button has changed state. - connect( mcbProjectionEnabled, SIGNAL( stateChanged( int ) ), - this, SLOT( ellipsoidalButton() ) ); // Update whenever the canvas has refreshed. Maybe more often than needed, // but at least every time any canvas related settings changes connect( mTool->canvas(), SIGNAL( mapCanvasRefreshed() ), @@ -42,10 +39,6 @@ QgsDisplayAngle::~QgsDisplayAngle() } -bool QgsDisplayAngle::projectionEnabled() -{ - return mcbProjectionEnabled->isChecked(); -} void QgsDisplayAngle::setValueInRadians( double value ) { @@ -53,52 +46,13 @@ void QgsDisplayAngle::setValueInRadians( double value ) updateUi(); } -void QgsDisplayAngle::ellipsoidalButton() -{ - QSettings settings; - - // We set check state to Unchecked and button to Disabled when disabling CRS, - // which generates a call here. Ignore that event! - if ( mcbProjectionEnabled->isEnabled() ) - { - if ( mcbProjectionEnabled->isChecked() ) - { - settings.setValue( "/qgis/measure/projectionEnabled", 2 ); - } - else - { - settings.setValue( "/qgis/measure/projectionEnabled", 0 ); - } - updateSettings(); - } -} - void QgsDisplayAngle::updateSettings() { - QSettings settings; - - int s = settings.value( "/qgis/measure/projectionEnabled", "2" ).toInt(); - if ( s == 2 ) - { - mEllipsoidal = true; - } - else - { - mEllipsoidal = false; - } - QgsDebugMsg( "****************" ); - QgsDebugMsg( QString( "Ellipsoidal: %1" ).arg( mEllipsoidal ? "true" : "false" ) ); - - updateUi(); emit changeProjectionEnabledState(); - } void QgsDisplayAngle::updateUi() { - mcbProjectionEnabled->setEnabled( mTool->canvas()->hasCrsTransformEnabled() ); - mcbProjectionEnabled->setCheckState( mTool->canvas()->hasCrsTransformEnabled() - && mEllipsoidal ? Qt::Checked : Qt::Unchecked ); QSettings settings; QString unitString = settings.value( "/qgis/measure/angleunits", "degrees" ).toString(); diff --git a/src/app/qgsdisplayangle.h b/src/app/qgsdisplayangle.h index c67f42c9d5d..ed358549e64 100644 --- a/src/app/qgsdisplayangle.h +++ b/src/app/qgsdisplayangle.h @@ -31,17 +31,11 @@ class QgsDisplayAngle: public QDialog, private Ui::QgsDisplayAngleBase be converted to degrees / gon automatically if necessary*/ void setValueInRadians( double value ); - bool projectionEnabled(); - - signals: void changeProjectionEnabledState(); private slots: - //! When the ellipsoidal button is pressed/toggled. - void ellipsoidalButton(); - //! When any external settings change void updateSettings(); @@ -49,9 +43,6 @@ class QgsDisplayAngle: public QDialog, private Ui::QgsDisplayAngleBase //! pointer to tool which owns this dialog QgsMapToolMeasureAngle * mTool; - //! Holds what the user last set ellipsoid button to. - bool mEllipsoidal; - //! The value we're showing double mValue; diff --git a/src/app/qgsmaptoolmeasureangle.cpp b/src/app/qgsmaptoolmeasureangle.cpp index f8b7508b15d..719cf7f60c4 100644 --- a/src/app/qgsmaptoolmeasureangle.cpp +++ b/src/app/qgsmaptoolmeasureangle.cpp @@ -180,17 +180,17 @@ void QgsMapToolMeasureAngle::changeProjectionEnabledState() void QgsMapToolMeasureAngle::configureDistanceArea() { QSettings settings; - QString ellipsoidId = settings.value( "/qgis/measure/ellipsoid", "WGS84" ).toString(); + QString ellipsoidId = settings.value( "/qgis/measure/ellipsoid", GEO_NONE ).toString(); mDa.setSourceCrs( mCanvas->mapRenderer()->destinationCrs().srsid() ); mDa.setEllipsoid( ellipsoidId ); - int s = settings.value( "/qgis/measure/projectionEnabled", "2" ).toInt(); - if ( s == 2 ) + // Only use ellipsoidal calculation when project wide transformation is enabled. + if ( mCanvas->mapRenderer()->hasCrsTransformEnabled() ) { - mDa.setEllipsoidalMode( mResultDisplay->projectionEnabled() ); + mDa.setEllipsoidalMode( true ); } else { - mDa.setEllipsoidalMode( mResultDisplay->projectionEnabled() ); + mDa.setEllipsoidalMode( false ); } } diff --git a/src/app/qgsmeasuredialog.cpp b/src/app/qgsmeasuredialog.cpp index 1acf200a307..f30c56a3307 100644 --- a/src/app/qgsmeasuredialog.cpp +++ b/src/app/qgsmeasuredialog.cpp @@ -48,9 +48,6 @@ QgsMeasureDialog::QgsMeasureDialog( QgsMeasureTool* tool, Qt::WFlags f ) item->setTextAlignment( 0, Qt::AlignRight ); mTable->addTopLevelItem( item ); - // Update when the ellipsoidal button has changed state. - connect( mcbProjectionEnabled, SIGNAL( stateChanged( int ) ), - this, SLOT( ellipsoidalButton() ) ); // Update whenever the canvas has refreshed. Maybe more often than needed, // but at least every time any canvas related settings changes connect( mTool->canvas(), SIGNAL( mapCanvasRefreshed() ), @@ -59,51 +56,32 @@ QgsMeasureDialog::QgsMeasureDialog( QgsMeasureTool* tool, Qt::WFlags f ) updateSettings(); } -void QgsMeasureDialog::ellipsoidalButton() -{ - QSettings settings; - - // We set check state to Unchecked and button to Disabled when disabling CRS, - // which generates an call here. Ignore that event! - if ( mcbProjectionEnabled->isEnabled() ) - { - if ( mcbProjectionEnabled->isChecked() ) - { - settings.setValue( "/qgis/measure/projectionEnabled", 2 ); - } - else - { - settings.setValue( "/qgis/measure/projectionEnabled", 0 ); - } - updateSettings(); - } -} - void QgsMeasureDialog::updateSettings() { QSettings settings; - int s = settings.value( "/qgis/measure/projectionEnabled", "2" ).toInt(); - if ( s == 2 ) + mDecimalPlaces = settings.value( "/qgis/measure/decimalplaces", "3" ).toInt(); + mCanvasUnits = mTool->canvas()->mapUnits(); + mDisplayUnits = QGis::fromLiteral( settings.value( "/qgis/measure/displayunits", QGis::toLiteral( QGis::Meters ) ).toString() ); + // Configure QgsDistanceArea + mDa.setSourceCrs( mTool->canvas()->mapRenderer()->destinationCrs().srsid() ); + mDa.setEllipsoid( settings.value( "/qgis/measure/ellipsoid", GEO_NONE ).toString() ); + // Only use ellipsoidal calculation when project wide transformation is enabled. + if ( mTool->canvas()->mapRenderer()->hasCrsTransformEnabled() ) { - mEllipsoidal = true; + mDa.setEllipsoidalMode( true ); } else { - mEllipsoidal = false; + mDa.setEllipsoidalMode( false ); } - mDecimalPlaces = settings.value( "/qgis/measure/decimalplaces", "3" ).toInt(); - mCanvasUnits = mTool->canvas()->mapUnits(); - mDisplayUnits = QGis::fromLiteral( settings.value( "/qgis/measure/displayunits", QGis::toLiteral( QGis::Meters ) ).toString() ); - QgsDebugMsg( "****************" ); - QgsDebugMsg( QString( "Ellipsoidal: %1" ).arg( mEllipsoidal ? "true" : "false" ) ); - QgsDebugMsg( QString( "Decimalpla.: %1" ).arg( mDecimalPlaces ) ); - QgsDebugMsg( QString( "Display u. : %1" ).arg( QGis::toLiteral( mDisplayUnits ) ) ); - QgsDebugMsg( QString( "Canvas u. : %1" ).arg( QGis::toLiteral( mCanvasUnits ) ) ); - - configureDistanceArea(); + QgsDebugMsg( QString( "Ellipsoid ID : %1" ).arg( mDa.ellipsoid() ) ); + QgsDebugMsg( QString( "Ellipsoidal : %1" ).arg( mDa.ellipsoidalEnabled() ? "true" : "false" ) ); + QgsDebugMsg( QString( "Decimalplaces: %1" ).arg( mDecimalPlaces ) ); + QgsDebugMsg( QString( "Display units: %1" ).arg( QGis::toLiteral( mDisplayUnits ) ) ); + QgsDebugMsg( QString( "Canvas units : %1" ).arg( QGis::toLiteral( mCanvasUnits ) ) ); // clear interface mTable->clear(); @@ -243,11 +221,6 @@ QString QgsMeasureDialog::formatArea( double area ) void QgsMeasureDialog::updateUi() { - // If project wide transformation is off, disbale checkbox and unmark it. - // When on, enable checbox and mark with saved value. - mcbProjectionEnabled->setEnabled( mTool->canvas()->hasCrsTransformEnabled() ); - mcbProjectionEnabled->setCheckState( mTool->canvas()->hasCrsTransformEnabled() && mEllipsoidal ? Qt::Checked : Qt::Unchecked ); - // Set tooltip to indicate how we calculate measurments QString toolTip = tr( "The calculations are based on:" ); if ( ! mTool->canvas()->hasCrsTransformEnabled() ) @@ -337,12 +310,3 @@ void QgsMeasureDialog::convertMeasurement( double &measure, QGis::UnitType &u, b u = myUnits; } -void QgsMeasureDialog::configureDistanceArea() -{ - QSettings settings; - QString ellipsoidId = settings.value( "/qgis/measure/ellipsoid", "WGS84" ).toString(); - mDa.setSourceCrs( mTool->canvas()->mapRenderer()->destinationCrs().srsid() ); - mDa.setEllipsoid( ellipsoidId ); - // Only use ellipsoidal calculation when project wide transformation is enabled. - mDa.setEllipsoidalMode( mEllipsoidal && mTool->canvas()->hasCrsTransformEnabled() ); -} diff --git a/src/app/qgsmeasuredialog.h b/src/app/qgsmeasuredialog.h index 72ab6d3c1e1..ba2603844bb 100644 --- a/src/app/qgsmeasuredialog.h +++ b/src/app/qgsmeasuredialog.h @@ -63,9 +63,6 @@ class QgsMeasureDialog : public QDialog, private Ui::QgsMeasureBase //! Show the help for the dialog void on_buttonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); } - //! When the ellipsoidal button is pressed/toggled. - void ellipsoidalButton(); - //! When any external settings change void updateSettings(); @@ -83,16 +80,10 @@ class QgsMeasureDialog : public QDialog, private Ui::QgsMeasureBase //! Converts the measurement, depending on settings in options and current transformation void convertMeasurement( double &measure, QGis::UnitType &u, bool isArea ); - //! Configures distance area objects with ellipsoid / output crs - void configureDistanceArea(); - double mTotal; //! indicates whether we're measuring distances or areas bool mMeasureArea; - - //! indicates whether user wants ellipsoidal or flat - bool mEllipsoidal; //! Number of decimal places we want. int mDecimalPlaces; diff --git a/src/app/qgsoptions.cpp b/src/app/qgsoptions.cpp index 6d48c4945c5..0414c93711a 100644 --- a/src/app/qgsoptions.cpp +++ b/src/app/qgsoptions.cpp @@ -19,6 +19,8 @@ #include "qgsoptions.h" #include "qgis.h" #include "qgisapp.h" +#include "qgsmapcanvas.h" +#include "qgsmaprenderer.h" #include "qgsgenericprojectionselector.h" #include "qgscoordinatereferencesystem.h" #include "qgstolerance.h" @@ -47,8 +49,6 @@ #include #include #include "qgslogger.h" -#define ELLIPS_FLAT "NONE" -#define ELLIPS_FLAT_DESC "None / Planimetric" #define CPL_SUPRESS_CPLUSPLUS #include @@ -56,6 +56,7 @@ #include // for setting gdal options #include "qgsconfig.h" +const char * QgsOptions::GEO_NONE_DESC = QT_TRANSLATE_NOOP( "QgsOptions", "None / Planimetric" ); /** * \class QgsOptions - Set user options and preferences @@ -278,9 +279,23 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) : leProjectGlobalCrs->setText( mDefaultCrs.authid() + " - " + mDefaultCrs.description() ); // populate combo box with ellipsoids + QgsDebugMsg( "Setting upp ellipsoid" ); + getEllipsoidList(); + // Pre-select current ellipsoid QString myEllipsoidId = settings.value( "/qgis/measure/ellipsoid", "WGS84" ).toString(); - cmbEllipsoid->setItemText( cmbEllipsoid->currentIndex(), getEllipsoidName( myEllipsoidId ) ); + cmbEllipsoid->setCurrentIndex( cmbEllipsoid->findText( getEllipsoidName( myEllipsoidId ), Qt::MatchExactly ) ); + // Check if CRS transformation is on, or else turn combobox off + if ( QgisApp::instance()->mapCanvas()->mapRenderer()->hasCrsTransformEnabled() ) + { + cmbEllipsoid->setEnabled( true ); + cmbEllipsoid->setToolTip( "" ); + } + else + { + cmbEllipsoid->setEnabled( false ); + cmbEllipsoid->setToolTip( "Can only use ellipsoidal calculations when CRS transformation is enabled" ); + } // Set the units for measuring QString myUnitsTxt = settings.value( "/qgis/measure/displayunits", "meters" ).toString(); @@ -933,7 +948,6 @@ void QgsOptions::saveOptions() { settings.setValue( "/qgis/measure/displayunits", "meters" ); } - settings.setValue( "/qgis/measure/ellipsoid", getEllipsoidAcronym( cmbEllipsoid->currentText() ) ); QString angleUnitString = "degrees"; if ( mRadiansRadioButton->isChecked() ) @@ -1161,7 +1175,7 @@ void QgsOptions::getEllipsoidList() int myResult; - cmbEllipsoid->addItem( ELLIPS_FLAT_DESC ); + cmbEllipsoid->addItem( tr( GEO_NONE_DESC ) ); //check the db is available myResult = sqlite3_open_v2( QgsApplication::srsDbFilePath().toUtf8().data(), &myDatabase, SQLITE_OPEN_READONLY, NULL ); if ( myResult ) @@ -1194,7 +1208,8 @@ QString QgsOptions::getEllipsoidAcronym( QString theEllipsoidName ) const char *myTail; sqlite3_stmt *myPreparedStatement; int myResult; - QString myName( ELLIPS_FLAT ); + QString myName = GEO_NONE; + //check the db is available myResult = sqlite3_open_v2( QgsApplication::srsDbFilePath().toUtf8().data(), &myDatabase, SQLITE_OPEN_READONLY, NULL ); if ( myResult ) @@ -1226,7 +1241,9 @@ QString QgsOptions::getEllipsoidName( QString theEllipsoidAcronym ) const char *myTail; sqlite3_stmt *myPreparedStatement; int myResult; - QString myName( ELLIPS_FLAT_DESC ); + QString myName; + + myName = tr( GEO_NONE_DESC ); //check the db is available myResult = sqlite3_open_v2( QgsApplication::srsDbFilePath().toUtf8().data(), &myDatabase, SQLITE_OPEN_READONLY, NULL ); if ( myResult ) diff --git a/src/app/qgsoptions.h b/src/app/qgsoptions.h index 5f5942aaf64..9a1efb62df6 100644 --- a/src/app/qgsoptions.h +++ b/src/app/qgsoptions.h @@ -194,6 +194,8 @@ class QgsOptions : public QDialog, private Ui::QgsOptionsBase QgsCoordinateReferenceSystem mDefaultCrs; QgsCoordinateReferenceSystem mLayerDefaultCrs; bool mLoadedGdalDriverList; + + static const char * GEO_NONE_DESC; }; #endif // #ifndef QGSOPTIONS_H diff --git a/src/core/qgis.h b/src/core/qgis.h index 65d80ce13e9..3d9a388190d 100644 --- a/src/core/qgis.h +++ b/src/core/qgis.h @@ -97,11 +97,14 @@ class CORE_EXPORT QGis DegreesDecimalMinutes = 2, // was 5 }; - // Provides the canonical name of the type value + //! Provides the canonical name of the type value + // Added in version 2.0 static QString toLiteral( QGis::UnitType unit ); - // Converts from the canonical name to the type value + //! Converts from the canonical name to the type value + // Added in version 2.0 static UnitType fromLiteral( QString literal, QGis::UnitType defaultType = UnknownUnit ); - // Provides translated version of the type value + //! Provides translated version of the type value + // Added in version 2.0 static QString tr( QGis::UnitType unit ); //! User defined event types @@ -197,6 +200,10 @@ const int LAT_PREFIX_LEN = 7; * or user (~/.qgis.qgis.db) defined projection. */ const int USER_CRS_START_ID = 100000; +//! Constant that holds the string representation for "No ellips/No CRS" +// Added in version 2.0 +const QString GEO_NONE = "NONE"; + // // Constants for point symbols // diff --git a/src/core/qgsdistancearea.cpp b/src/core/qgsdistancearea.cpp index 9a076431001..7efadc32615 100644 --- a/src/core/qgsdistancearea.cpp +++ b/src/core/qgsdistancearea.cpp @@ -91,9 +91,9 @@ bool QgsDistanceArea::setEllipsoid( const QString& ellipsoid ) int myResult; // Shortcut if ellipsoid is none. - if ( ellipsoid == "NONE" ) + if ( ellipsoid == GEO_NONE ) { - mEllipsoid = "NONE"; + mEllipsoid = GEO_NONE; return true; } @@ -337,14 +337,14 @@ double QgsDistanceArea::measureLine( const QList& points ) try { - if ( mEllipsoidalMode && ( mEllipsoid != "NONE" ) ) + if ( mEllipsoidalMode && ( mEllipsoid != GEO_NONE ) ) p1 = mCoordTransform->transform( points[0] ); else p1 = points[0]; for ( QList::const_iterator i = points.begin(); i != points.end(); ++i ) { - if ( mEllipsoidalMode && ( mEllipsoid != "NONE" ) ) + if ( mEllipsoidalMode && ( mEllipsoid != GEO_NONE ) ) { p2 = mCoordTransform->transform( *i ); total += computeDistanceBearing( p1, p2 ); @@ -378,7 +378,7 @@ double QgsDistanceArea::measureLine( const QgsPoint& p1, const QgsPoint& p2 ) QgsPoint pp1 = p1, pp2 = p2; QgsDebugMsg( QString( "Measuring from %1 to %2" ).arg( p1.toString( 4 ) ).arg( p2.toString( 4 ) ) ); - if ( mEllipsoidalMode && ( mEllipsoid != "NONE" ) ) + if ( mEllipsoidalMode && ( mEllipsoid != GEO_NONE ) ) { QgsDebugMsg( QString( "Ellipsoidal calculations is enabled, using ellipsoid %1" ).arg( mEllipsoid ) ); QgsDebugMsg( QString( "From proj4 : %1" ).arg( mCoordTransform->sourceCrs().toProj4() ) ); @@ -447,7 +447,7 @@ unsigned char* QgsDistanceArea::measurePolygon( unsigned char* feature, double* pnt = QgsPoint( x, y ); - if ( mEllipsoidalMode && ( mEllipsoid != "NONE" ) ) + if ( mEllipsoidalMode && ( mEllipsoid != GEO_NONE ) ) { pnt = mCoordTransform->transform( pnt ); } @@ -499,7 +499,7 @@ double QgsDistanceArea::measurePolygon( const QList& points ) try { - if ( mEllipsoidalMode && ( mEllipsoid != "NONE" ) ) + if ( mEllipsoidalMode && ( mEllipsoid != GEO_NONE ) ) { QList pts; for ( QList::const_iterator i = points.begin(); i != points.end(); ++i ) @@ -527,7 +527,7 @@ double QgsDistanceArea::bearing( const QgsPoint& p1, const QgsPoint& p2 ) QgsPoint pp1 = p1, pp2 = p2; double bearing; - if ( mEllipsoidalMode && ( mEllipsoid != "NONE" ) ) + if ( mEllipsoidalMode && ( mEllipsoid != GEO_NONE ) ) { pp1 = mCoordTransform->transform( p1 ); pp2 = mCoordTransform->transform( p2 ); @@ -689,7 +689,7 @@ double QgsDistanceArea::computePolygonArea( const QList& points ) double area; QgsDebugMsgLevel( "Ellipsoid: " + mEllipsoid, 3 ); - if (( ! mEllipsoidalMode ) || ( mEllipsoid == "NONE" ) ) + if (( ! mEllipsoidalMode ) || ( mEllipsoid == GEO_NONE ) ) { return computePolygonFlatArea( points ); } @@ -885,7 +885,7 @@ void QgsDistanceArea::convertMeasurement( double &measure, QGis::UnitType &measu // The parameters measure and measureUnits are in/out if (( measureUnits == QGis::Degrees || measureUnits == QGis::Feet ) && - mEllipsoid != "NONE" && + mEllipsoid != GEO_NONE && mEllipsoidalMode ) { // Measuring on an ellipsoid returned meters. Force! diff --git a/src/ui/qgsdisplayanglebase.ui b/src/ui/qgsdisplayanglebase.ui index b3c3fceab06..5da9fc81659 100644 --- a/src/ui/qgsdisplayanglebase.ui +++ b/src/ui/qgsdisplayanglebase.ui @@ -44,13 +44,6 @@ - - - - Ellipsoidal - - - diff --git a/src/ui/qgsmeasurebase.ui b/src/ui/qgsmeasurebase.ui index 7efac656809..60403793369 100644 --- a/src/ui/qgsmeasurebase.ui +++ b/src/ui/qgsmeasurebase.ui @@ -98,13 +98,6 @@ - - - - Ellipsoidal - - -