Skip to content

Commit

Permalink
Fix #3866 for measure angle tool
Browse files Browse the repository at this point in the history
  • Loading branch information
stopa85milk authored and alexbruy committed Jun 18, 2011
1 parent cb41f07 commit d750abf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
38 changes: 19 additions & 19 deletions src/app/qgsmaptoolmeasureangle.cpp
Expand Up @@ -45,22 +45,15 @@ void QgsMapToolMeasureAngle::canvasMoveEvent( QMouseEvent * e )
mRubberBand->movePoint( point );
if ( mAnglePoints.size() == 2 )
{
if ( !mResultDisplay )
if ( !mResultDisplay->isVisible() )
{
mResultDisplay = new QgsDisplayAngle( mCanvas->topLevelWidget() );
QObject::connect( mResultDisplay, SIGNAL( rejected() ), this, SLOT( stopMeasuring() ) );
QObject::connect( mResultDisplay, SIGNAL( changeProjectionEnabledState() ),
this, SLOT( changeProjectionEnabledState() ) );
mResultDisplay->move( e->pos() - QPoint( 100, 100 ) );
mResultDisplay->show();
}
mResultDisplay->show();

QgsDistanceArea myDa;
configureDistanceArea( myDa );

//angle calculation
double azimuthOne = myDa.bearing( mAnglePoints.at( 1 ), mAnglePoints.at( 0 ) );
double azimuthTwo = myDa.bearing( mAnglePoints.at( 1 ), point );
double azimuthOne = mDa.bearing( mAnglePoints.at( 1 ), mAnglePoints.at( 0 ) );
double azimuthTwo = mDa.bearing( mAnglePoints.at( 1 ), point );
double resultAngle = azimuthTwo - azimuthOne;
QgsDebugMsg( QString::number( qAbs( resultAngle ) ) );
QgsDebugMsg( QString::number( M_PI ) );
Expand Down Expand Up @@ -90,6 +83,14 @@ void QgsMapToolMeasureAngle::canvasReleaseEvent( QMouseEvent * e )

if ( mAnglePoints.size() < 1 )
{
if ( mResultDisplay == NULL )
{
mResultDisplay = new QgsDisplayAngle( mCanvas->topLevelWidget() );
QObject::connect( mResultDisplay, SIGNAL( rejected() ), this, SLOT( stopMeasuring() ) );
QObject::connect( mResultDisplay, SIGNAL( changeProjectionEnabledState() ),
this, SLOT( changeProjectionEnabledState() ) );
}
configureDistanceArea();
createRubberBand();
}

Expand Down Expand Up @@ -153,12 +154,11 @@ void QgsMapToolMeasureAngle::changeProjectionEnabledState()
if ( !mResultDisplay )
return;

QgsDistanceArea myDa;
configureDistanceArea( myDa );
configureDistanceArea();

//angle calculation
double azimuthOne = myDa.bearing( mAnglePoints.at( 1 ), mAnglePoints.at( 0 ) );
double azimuthTwo = myDa.bearing( mAnglePoints.at( 1 ), mAnglePoints.at( 2 ) );
double azimuthOne = mDa.bearing( mAnglePoints.at( 1 ), mAnglePoints.at( 0 ) );
double azimuthTwo = mDa.bearing( mAnglePoints.at( 1 ), mAnglePoints.at( 2 ) );
double resultAngle = azimuthTwo - azimuthOne;
QgsDebugMsg( QString::number( fabs( resultAngle ) ) );
QgsDebugMsg( QString::number( M_PI ) );
Expand All @@ -177,13 +177,13 @@ void QgsMapToolMeasureAngle::changeProjectionEnabledState()

}

void QgsMapToolMeasureAngle::configureDistanceArea( QgsDistanceArea& da )
void QgsMapToolMeasureAngle::configureDistanceArea()
{
QSettings settings;
QString ellipsoidId = settings.value( "/qgis/measure/ellipsoid", "WGS84" ).toString();
da.setSourceCrs( mCanvas->mapRenderer()->destinationCrs().srsid() );
da.setEllipsoid( ellipsoidId );
da.setProjectionsEnabled( mResultDisplay->projectionEnabled() );
mDa.setSourceCrs( mCanvas->mapRenderer()->destinationCrs().srsid() );
mDa.setEllipsoid( ellipsoidId );
mDa.setProjectionsEnabled( mResultDisplay->projectionEnabled() );
}


Expand Down
6 changes: 5 additions & 1 deletion src/app/qgsmaptoolmeasureangle.h
Expand Up @@ -19,6 +19,7 @@
#include "qgsmaptool.h"
#include "qgsmapcanvassnapper.h"
#include "qgspoint.h"
#include "qgsdistancearea.h"

class QgsDisplayAngle;
class QgsRubberBand;
Expand Down Expand Up @@ -55,6 +56,9 @@ class QgsMapToolMeasureAngle: public QgsMapTool
/**Snaps point to background layers*/
QgsPoint snapPoint( const QPoint& p );

/** tool for measuring */
QgsDistanceArea mDa;

private slots:
/**Deletes the rubber band and the dialog*/
void stopMeasuring();
Expand All @@ -63,7 +67,7 @@ class QgsMapToolMeasureAngle: public QgsMapTool
void changeProjectionEnabledState();

//! Configures distance area objects with ellipsoid / output crs
void configureDistanceArea( QgsDistanceArea& da );
void configureDistanceArea();

};

Expand Down

0 comments on commit d750abf

Please sign in to comment.