mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-01 00:05:25 -04:00
Changed angle measurement to behave same as the other
This commit is contained in:
parent
c1decf7a18
commit
950bc2fa63
@ -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 ) );
|
||||
}
|
||||
else if ( unitString == "radians" )
|
||||
{
|
||||
mAngleLineEdit->setText( tr( "%1 radians" ).arg( value ) );
|
||||
}
|
||||
else if ( unitString == "gon" )
|
||||
{
|
||||
mAngleLineEdit->setText( tr( "%1 gon" ).arg( value / M_PI * 200 ) );
|
||||
if ( mcbProjectionEnabled->isChecked() )
|
||||
{
|
||||
settings.setValue( "/qgis/measure/projectionEnabled", 2 );
|
||||
}
|
||||
else
|
||||
{
|
||||
settings.setValue( "/qgis/measure/projectionEnabled", 0 );
|
||||
}
|
||||
updateSettings();
|
||||
}
|
||||
}
|
||||
|
||||
void QgsDisplayAngle::changeState()
|
||||
void QgsDisplayAngle::updateSettings()
|
||||
{
|
||||
QSettings settings;
|
||||
if ( mcbProjectionEnabled->isChecked() )
|
||||
settings.setValue( "/qgis/measure/projectionEnabled", 2 );
|
||||
|
||||
int s = settings.value( "/qgis/measure/projectionEnabled", "2" ).toInt();
|
||||
if ( s == 2 )
|
||||
{
|
||||
mEllipsoidal = true;
|
||||
}
|
||||
else
|
||||
settings.setValue( "/qgis/measure/projectionEnabled", 0 );
|
||||
{
|
||||
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();
|
||||
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,7 +25,7 @@ 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*/
|
||||
@ -32,12 +33,30 @@ class QgsDisplayAngle: public QDialog, private Ui::QgsDisplayAngleBase
|
||||
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user