Skip to content

Commit d750abf

Browse files
stopa85milkalexbruy
authored andcommitted
Fix #3866 for measure angle tool
1 parent cb41f07 commit d750abf

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

src/app/qgsmaptoolmeasureangle.cpp

+19-19
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,15 @@ void QgsMapToolMeasureAngle::canvasMoveEvent( QMouseEvent * e )
4545
mRubberBand->movePoint( point );
4646
if ( mAnglePoints.size() == 2 )
4747
{
48-
if ( !mResultDisplay )
48+
if ( !mResultDisplay->isVisible() )
4949
{
50-
mResultDisplay = new QgsDisplayAngle( mCanvas->topLevelWidget() );
51-
QObject::connect( mResultDisplay, SIGNAL( rejected() ), this, SLOT( stopMeasuring() ) );
52-
QObject::connect( mResultDisplay, SIGNAL( changeProjectionEnabledState() ),
53-
this, SLOT( changeProjectionEnabledState() ) );
5450
mResultDisplay->move( e->pos() - QPoint( 100, 100 ) );
51+
mResultDisplay->show();
5552
}
56-
mResultDisplay->show();
57-
58-
QgsDistanceArea myDa;
59-
configureDistanceArea( myDa );
6053

6154
//angle calculation
62-
double azimuthOne = myDa.bearing( mAnglePoints.at( 1 ), mAnglePoints.at( 0 ) );
63-
double azimuthTwo = myDa.bearing( mAnglePoints.at( 1 ), point );
55+
double azimuthOne = mDa.bearing( mAnglePoints.at( 1 ), mAnglePoints.at( 0 ) );
56+
double azimuthTwo = mDa.bearing( mAnglePoints.at( 1 ), point );
6457
double resultAngle = azimuthTwo - azimuthOne;
6558
QgsDebugMsg( QString::number( qAbs( resultAngle ) ) );
6659
QgsDebugMsg( QString::number( M_PI ) );
@@ -90,6 +83,14 @@ void QgsMapToolMeasureAngle::canvasReleaseEvent( QMouseEvent * e )
9083

9184
if ( mAnglePoints.size() < 1 )
9285
{
86+
if ( mResultDisplay == NULL )
87+
{
88+
mResultDisplay = new QgsDisplayAngle( mCanvas->topLevelWidget() );
89+
QObject::connect( mResultDisplay, SIGNAL( rejected() ), this, SLOT( stopMeasuring() ) );
90+
QObject::connect( mResultDisplay, SIGNAL( changeProjectionEnabledState() ),
91+
this, SLOT( changeProjectionEnabledState() ) );
92+
}
93+
configureDistanceArea();
9394
createRubberBand();
9495
}
9596

@@ -153,12 +154,11 @@ void QgsMapToolMeasureAngle::changeProjectionEnabledState()
153154
if ( !mResultDisplay )
154155
return;
155156

156-
QgsDistanceArea myDa;
157-
configureDistanceArea( myDa );
157+
configureDistanceArea();
158158

159159
//angle calculation
160-
double azimuthOne = myDa.bearing( mAnglePoints.at( 1 ), mAnglePoints.at( 0 ) );
161-
double azimuthTwo = myDa.bearing( mAnglePoints.at( 1 ), mAnglePoints.at( 2 ) );
160+
double azimuthOne = mDa.bearing( mAnglePoints.at( 1 ), mAnglePoints.at( 0 ) );
161+
double azimuthTwo = mDa.bearing( mAnglePoints.at( 1 ), mAnglePoints.at( 2 ) );
162162
double resultAngle = azimuthTwo - azimuthOne;
163163
QgsDebugMsg( QString::number( fabs( resultAngle ) ) );
164164
QgsDebugMsg( QString::number( M_PI ) );
@@ -177,13 +177,13 @@ void QgsMapToolMeasureAngle::changeProjectionEnabledState()
177177

178178
}
179179

180-
void QgsMapToolMeasureAngle::configureDistanceArea( QgsDistanceArea& da )
180+
void QgsMapToolMeasureAngle::configureDistanceArea()
181181
{
182182
QSettings settings;
183183
QString ellipsoidId = settings.value( "/qgis/measure/ellipsoid", "WGS84" ).toString();
184-
da.setSourceCrs( mCanvas->mapRenderer()->destinationCrs().srsid() );
185-
da.setEllipsoid( ellipsoidId );
186-
da.setProjectionsEnabled( mResultDisplay->projectionEnabled() );
184+
mDa.setSourceCrs( mCanvas->mapRenderer()->destinationCrs().srsid() );
185+
mDa.setEllipsoid( ellipsoidId );
186+
mDa.setProjectionsEnabled( mResultDisplay->projectionEnabled() );
187187
}
188188

189189

src/app/qgsmaptoolmeasureangle.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "qgsmaptool.h"
2020
#include "qgsmapcanvassnapper.h"
2121
#include "qgspoint.h"
22+
#include "qgsdistancearea.h"
2223

2324
class QgsDisplayAngle;
2425
class QgsRubberBand;
@@ -55,6 +56,9 @@ class QgsMapToolMeasureAngle: public QgsMapTool
5556
/**Snaps point to background layers*/
5657
QgsPoint snapPoint( const QPoint& p );
5758

59+
/** tool for measuring */
60+
QgsDistanceArea mDa;
61+
5862
private slots:
5963
/**Deletes the rubber band and the dialog*/
6064
void stopMeasuring();
@@ -63,7 +67,7 @@ class QgsMapToolMeasureAngle: public QgsMapTool
6367
void changeProjectionEnabledState();
6468

6569
//! Configures distance area objects with ellipsoid / output crs
66-
void configureDistanceArea( QgsDistanceArea& da );
70+
void configureDistanceArea();
6771

6872
};
6973

0 commit comments

Comments
 (0)