Skip to content
Permalink
Browse files

Changed angle measurement to behave same as the other

  • Loading branch information
homann committed Aug 29, 2012
1 parent c1decf7 commit 950bc2fa63478a4719556d97fb0374a7fac30949
Showing with 105 additions and 26 deletions.
  1. +73 −21 src/app/qgsdisplayangle.cpp
  2. +21 −2 src/app/qgsdisplayangle.h
  3. +10 −2 src/app/qgsmaptoolmeasureangle.cpp
  4. +1 −1 src/app/qgsmaptoolmeasureangle.h
@@ -14,23 +14,27 @@
***************************************************************************/

#include "qgsdisplayangle.h"
#include "qgsmapcanvas.h"
#include "qgslogger.h"

#include <QSettings>
#include <cmath>

QgsDisplayAngle::QgsDisplayAngle( QWidget * parent, Qt::WindowFlags f ): QDialog( parent, f )
QgsDisplayAngle::QgsDisplayAngle( QgsMapToolMeasureAngle * tool, Qt::WFlags f )
: QDialog( tool->canvas()->topLevelWidget(), f ), mTool( tool )
{
setupUi( this );
QSettings settings;
int s = settings.value( "/qgis/measure/projectionEnabled", "2" ).toInt();
if ( s == 2 )
mcbProjectionEnabled->setCheckState( Qt::Checked );
else
mcbProjectionEnabled->setCheckState( Qt::Unchecked );

// Update when the ellipsoidal button has changed state.
connect( mcbProjectionEnabled, SIGNAL( stateChanged( int ) ),
this, SLOT( changeState() ) );
connect( mcbProjectionEnabled, SIGNAL( stateChanged( int ) ),
this, SIGNAL( changeProjectionEnabledState() ) );
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() ),
this, SLOT( updateSettings() ) );

updateSettings();
}

QgsDisplayAngle::~QgsDisplayAngle()
@@ -44,28 +48,76 @@ bool QgsDisplayAngle::projectionEnabled()
}

void QgsDisplayAngle::setValueInRadians( double value )
{
mValue = value;
updateUi();
}

void QgsDisplayAngle::ellipsoidalButton()
{
QSettings settings;
QString unitString = settings.value( "/qgis/measure/angleunits", "degrees" ).toString();
if ( unitString == "degrees" )

// We set check state to Unchecked and button to Disabled when disabling CRS,
// which generates a call here. Ignore that event!
if ( mcbProjectionEnabled->isEnabled() )
{
mAngleLineEdit->setText( tr( "%1 degrees" ).arg( value * 180 / M_PI ) );
if ( mcbProjectionEnabled->isChecked() )
{
settings.setValue( "/qgis/measure/projectionEnabled", 2 );
}
else
{
settings.setValue( "/qgis/measure/projectionEnabled", 0 );
}
updateSettings();
}
else if ( unitString == "radians" )
}

void QgsDisplayAngle::updateSettings()
{
QSettings settings;

int s = settings.value( "/qgis/measure/projectionEnabled", "2" ).toInt();
if ( s == 2 )
{
mAngleLineEdit->setText( tr( "%1 radians" ).arg( value ) );
mEllipsoidal = true;
}
else if ( unitString == "gon" )
else
{
mAngleLineEdit->setText( tr( "%1 gon" ).arg( value / M_PI * 200 ) );
mEllipsoidal = false;
}
QgsDebugMsg( "****************" );
QgsDebugMsg( QString( "Ellipsoidal: %1" ).arg( mEllipsoidal ? "true" : "false" ) );

updateUi();
emit changeProjectionEnabledState();

}

void QgsDisplayAngle::changeState()
void QgsDisplayAngle::updateUi()
{
mcbProjectionEnabled->setEnabled( mTool->canvas()->hasCrsTransformEnabled() );
mcbProjectionEnabled->setCheckState( mTool->canvas()->hasCrsTransformEnabled()
&& mEllipsoidal ? Qt::Checked : Qt::Unchecked );

QSettings settings;
if ( mcbProjectionEnabled->isChecked() )
settings.setValue( "/qgis/measure/projectionEnabled", 2 );
else
settings.setValue( "/qgis/measure/projectionEnabled", 0 );
QString unitString = settings.value( "/qgis/measure/angleunits", "degrees" ).toString();
int decimals = settings.value( "/qgis/measure/decimalplaces", "3" ).toInt();

if ( unitString == "degrees" )
{
mAngleLineEdit->setText( tr( "%1 degrees" ).arg( QLocale::system().toString( mValue * 180 / M_PI ),
'f', decimals ) );
}
else if ( unitString == "radians" )
{
mAngleLineEdit->setText( tr( "%1 radians" ).arg( QLocale::system().toString( mValue ),
'f', decimals ) );

}
else if ( unitString == "gon" )
{
mAngleLineEdit->setText( tr( "%1 gon" ).arg( QLocale::system().toString( mValue / M_PI * 200 ),
'f', decimals ) );
}
}
@@ -16,6 +16,7 @@
#ifndef QGSDISPLAYANGLE_H
#define QGSDISPLAYANGLE_H

#include "qgsmaptoolmeasureangle.h"
#include "ui_qgsdisplayanglebase.h"

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

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

bool projectionEnabled();


signals:
void changeProjectionEnabledState();

private slots:
void changeState();

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

//! Updates UI according to user settings.
void updateUi();
};

#endif // QGSDISPLAYANGLE_H
@@ -85,7 +85,7 @@ void QgsMapToolMeasureAngle::canvasReleaseEvent( QMouseEvent * e )
{
if ( mResultDisplay == NULL )
{
mResultDisplay = new QgsDisplayAngle( mCanvas->topLevelWidget() );
mResultDisplay = new QgsDisplayAngle( this );
QObject::connect( mResultDisplay, SIGNAL( rejected() ), this, SLOT( stopMeasuring() ) );
QObject::connect( mResultDisplay, SIGNAL( changeProjectionEnabledState() ),
this, SLOT( changeProjectionEnabledState() ) );
@@ -183,7 +183,15 @@ void QgsMapToolMeasureAngle::configureDistanceArea()
QString ellipsoidId = settings.value( "/qgis/measure/ellipsoid", "WGS84" ).toString();
mDa.setSourceCrs( mCanvas->mapRenderer()->destinationCrs().srsid() );
mDa.setEllipsoid( ellipsoidId );
mDa.setEllipsoidalMode( mResultDisplay->projectionEnabled() ); // FIXME (not when proj is turned off)
int s = settings.value( "/qgis/measure/projectionEnabled", "2" ).toInt();
if ( s == 2 )
{
mDa.setEllipsoidalMode( mResultDisplay->projectionEnabled() );
}
else
{
mDa.setEllipsoidalMode( mResultDisplay->projectionEnabled() );
}
}


@@ -32,7 +32,7 @@ class QgsMapToolMeasureAngle: public QgsMapTool
QgsMapToolMeasureAngle( QgsMapCanvas* canvas );
~QgsMapToolMeasureAngle();

//! Mouse move event for overriding
//! Mouse move event for overridingqgs
void canvasMoveEvent( QMouseEvent * e );

//! Mouse release event for overriding

0 comments on commit 950bc2f

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