Skip to content

Commit

Permalink
Changed angle measurement to behave same as the other
Browse files Browse the repository at this point in the history
  • Loading branch information
homann committed Sep 4, 2012
1 parent 256d229 commit 80dbb3c
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 26 deletions.
94 changes: 73 additions & 21 deletions src/app/qgsdisplayangle.cpp
Expand Up @@ -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()
Expand All @@ -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 ) );
}
}
23 changes: 21 additions & 2 deletions src/app/qgsdisplayangle.h
Expand Up @@ -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*/
Expand All @@ -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
12 changes: 10 additions & 2 deletions src/app/qgsmaptoolmeasureangle.cpp
Expand Up @@ -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() ) );
Expand Down Expand Up @@ -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() );
}
}


Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsmaptoolmeasureangle.h
Expand Up @@ -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
Expand Down

0 comments on commit 80dbb3c

Please sign in to comment.