Skip to content

Commit

Permalink
Removed Ellipsoid button and added "NONE" as a selectable ellipsoid.
Browse files Browse the repository at this point in the history
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 dbb2118
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 154 deletions.
46 changes: 0 additions & 46 deletions src/app/qgsdisplayangle.cpp
Expand Up @@ -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() ),
Expand All @@ -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();
Expand Down
9 changes: 0 additions & 9 deletions src/app/qgsdisplayangle.h
Expand Up @@ -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;

Expand Down
10 changes: 5 additions & 5 deletions src/app/qgsmaptoolmeasureangle.cpp
Expand Up @@ -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 );
}
}

Expand Down
66 changes: 15 additions & 51 deletions src/app/qgsmeasuredialog.cpp
Expand Up @@ -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() ),
Expand All @@ -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();
Expand Down Expand Up @@ -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() )
Expand Down Expand Up @@ -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() );
}
9 changes: 0 additions & 9 deletions src/app/qgsmeasuredialog.h
Expand Up @@ -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();

Expand All @@ -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;
Expand Down
31 changes: 24 additions & 7 deletions src/app/qgsoptions.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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() )
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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 )
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgsoptions.h
Expand Up @@ -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
13 changes: 10 additions & 3 deletions src/core/qgis.h
Expand Up @@ -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
Expand Down Expand Up @@ -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
//
Expand Down

0 comments on commit dbb2118

Please sign in to comment.