Skip to content
Permalink
Browse files

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!
  • Loading branch information
homann committed Sep 4, 2012
1 parent 80dbb3c commit dbb21187b4d2898488df63068ad766f9da1ceece
@@ -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,63 +39,20 @@ QgsDisplayAngle::~QgsDisplayAngle()

}

bool QgsDisplayAngle::projectionEnabled()
{
return mcbProjectionEnabled->isChecked();
}

void QgsDisplayAngle::setValueInRadians( double value )
{
mValue = 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();
@@ -31,27 +31,18 @@ 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();

private:
//! 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;

@@ -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 );
}
}

@@ -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() );
}
@@ -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;
@@ -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,15 +49,14 @@
#include <limits>
#include <sqlite3.h>
#include "qgslogger.h"
#define ELLIPS_FLAT "NONE"
#define ELLIPS_FLAT_DESC "None / Planimetric"

#define CPL_SUPRESS_CPLUSPLUS
#include <gdal.h>
#include <geos_c.h>
#include <cpl_conv.h> // 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();
@@ -935,7 +950,6 @@ void QgsOptions::saveOptions()
{
settings.setValue( "/qgis/measure/displayunits", "meters" );
}
settings.setValue( "/qgis/measure/ellipsoid", getEllipsoidAcronym( cmbEllipsoid->currentText() ) );

QString angleUnitString = "degrees";
if ( mRadiansRadioButton->isChecked() )
@@ -1163,7 +1177,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 )
@@ -1196,7 +1210,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 )
@@ -1228,7 +1243,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 )
@@ -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
@@ -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
//

0 comments on commit dbb2118

Please sign in to comment.
You can’t perform that action at this time.