Skip to content

Commit 48b9b7e

Browse files
author
mhugent
committed
Apply patch #3384 by Sergey Yakushev with few modifications. Mark QgsMapRenderer::distanceArea as deprecated
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@14992 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent a9e75c8 commit 48b9b7e

File tree

7 files changed

+79
-68
lines changed

7 files changed

+79
-68
lines changed

src/app/qgsmaptoolmeasureangle.cpp

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -45,46 +45,38 @@ void QgsMapToolMeasureAngle::canvasMoveEvent( QMouseEvent * e )
4545
mRubberBand->movePoint( point );
4646
if ( mAnglePoints.size() == 2 )
4747
{
48-
//do angle calculation
49-
QgsDistanceArea* distArea = mCanvas->mapRenderer()->distanceArea();
50-
if ( distArea )
48+
if ( !mResultDisplay )
5149
{
52-
//show angle in dialog
53-
if ( !mResultDisplay )
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() ) );
54+
mResultDisplay->move( e->pos() - QPoint( 100, 100 ) );
55+
}
56+
mResultDisplay->show();
57+
58+
QgsDistanceArea myDa;
59+
configureDistanceArea( myDa );
60+
61+
//angle calculation
62+
double azimuthOne = myDa.bearing( mAnglePoints.at( 1 ), mAnglePoints.at( 0 ) );
63+
double azimuthTwo = myDa.bearing( mAnglePoints.at( 1 ), point );
64+
double resultAngle = azimuthTwo - azimuthOne;
65+
QgsDebugMsg( QString::number( qAbs( resultAngle ) ) );
66+
QgsDebugMsg( QString::number( M_PI ) );
67+
if ( qAbs( resultAngle ) > M_PI )
68+
{
69+
if ( resultAngle < 0 )
5470
{
55-
mResultDisplay = new QgsDisplayAngle( mCanvas->topLevelWidget() );
56-
QObject::connect( mResultDisplay, SIGNAL( rejected() ), this, SLOT( stopMeasuring() ) );
57-
QObject::connect( mResultDisplay, SIGNAL( changeProjectionEnabledState() ),
58-
this, SLOT( changeProjectionEnabledState() ) );
59-
mResultDisplay->move( e->pos() - QPoint( 100, 100 ) );
71+
resultAngle = M_PI + ( resultAngle + M_PI );
6072
}
61-
mResultDisplay->show();
62-
63-
QgsDistanceArea myDa;
64-
myDa.setSourceCrs( mCanvas->mapRenderer()->destinationSrs().srsid() );
65-
myDa.setEllipsoid( distArea->ellipsoid() );
66-
myDa.setProjectionsEnabled( mResultDisplay->projectionEnabled() );
67-
68-
//angle calculation
69-
double azimuthOne = myDa.bearing( mAnglePoints.at( 1 ), mAnglePoints.at( 0 ) );
70-
double azimuthTwo = myDa.bearing( mAnglePoints.at( 1 ), point );
71-
double resultAngle = azimuthTwo - azimuthOne;
72-
QgsDebugMsg( QString::number( qAbs( resultAngle ) ) );
73-
QgsDebugMsg( QString::number( M_PI ) );
74-
if ( qAbs( resultAngle ) > M_PI )
73+
else
7574
{
76-
if ( resultAngle < 0 )
77-
{
78-
resultAngle = M_PI + ( resultAngle + M_PI );
79-
}
80-
else
81-
{
82-
resultAngle = -M_PI + ( resultAngle - M_PI );
83-
}
75+
resultAngle = -M_PI + ( resultAngle - M_PI );
8476
}
85-
86-
mResultDisplay->setValueInRadians( resultAngle );
8777
}
78+
79+
mResultDisplay->setValueInRadians( resultAngle );
8880
}
8981
}
9082

@@ -160,11 +152,9 @@ void QgsMapToolMeasureAngle::changeProjectionEnabledState()
160152
return;
161153
if ( !mResultDisplay )
162154
return;
163-
155+
164156
QgsDistanceArea myDa;
165-
myDa.setSourceCrs( mCanvas->mapRenderer()->destinationSrs().srsid() );
166-
myDa.setEllipsoid( mCanvas->mapRenderer()->distanceArea()->ellipsoid() );
167-
myDa.setProjectionsEnabled( mResultDisplay->projectionEnabled() );
157+
configureDistanceArea( myDa );
168158

169159
//angle calculation
170160
double azimuthOne = myDa.bearing( mAnglePoints.at( 1 ), mAnglePoints.at( 0 ) );
@@ -187,3 +177,14 @@ void QgsMapToolMeasureAngle::changeProjectionEnabledState()
187177

188178
}
189179

180+
void QgsMapToolMeasureAngle::configureDistanceArea( QgsDistanceArea& da )
181+
{
182+
QSettings settings;
183+
QString ellipsoidId = settings.value( "/qgis/measure/ellipsoid", "WGS84" ).toString();
184+
da.setSourceCrs( mCanvas->mapRenderer()->destinationSrs().srsid() );
185+
da.setEllipsoid( ellipsoidId );
186+
da.setProjectionsEnabled( mResultDisplay->projectionEnabled() );
187+
}
188+
189+
190+

src/app/qgsmaptoolmeasureangle.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ class QgsMapToolMeasureAngle: public QgsMapTool
6262
/** recalculate angle if projection state changed*/
6363
void changeProjectionEnabledState();
6464

65+
//! Configures distance area objects with ellipsoid / output crs
66+
void configureDistanceArea( QgsDistanceArea& da );
67+
6568
};
6669

6770
#endif // QGSMAPTOOLMEASUREANGLE_H

src/app/qgsmeasuredialog.cpp

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ QgsMeasureDialog::QgsMeasureDialog( QgsMeasureTool* tool, Qt::WFlags f )
5858
else
5959
mcbProjectionEnabled->setCheckState( Qt::Unchecked );
6060

61-
connect( mcbProjectionEnabled, SIGNAL( stateChanged(int) ),
62-
this, SLOT( changeProjectionEnabledState() ));
61+
connect( mcbProjectionEnabled, SIGNAL( stateChanged( int ) ),
62+
this, SLOT( changeProjectionEnabledState() ) );
6363

6464
updateUi();
6565
}
@@ -99,14 +99,12 @@ void QgsMeasureDialog::mouseMove( QgsPoint &point )
9999
int decimalPlaces = settings.value( "/qgis/measure/decimalplaces", "3" ).toInt();
100100

101101
// Create QgsDistance Area for customization ProjectionEnabled setting
102-
QgsDistanceArea myDa;
103-
myDa.setSourceCrs( mTool->canvas()->mapRenderer()->destinationSrs().srsid() );
104-
myDa.setEllipsoid( mTool->canvas()->mapRenderer()->distanceArea()->ellipsoid() );
105-
myDa.setProjectionsEnabled( mcbProjectionEnabled->isChecked() );
102+
QgsDistanceArea myDa;
103+
configureDistanceArea( myDa );
106104

107105
// show current distance/area while moving the point
108106
// by creating a temporary copy of point array
109-
// and adding moving point at the end
107+
// and adding moving point at the end
110108
if ( mMeasureArea && mTool->points().size() > 1 )
111109
{
112110
QList<QgsPoint> tmpPoints = mTool->points();
@@ -134,10 +132,8 @@ void QgsMeasureDialog::addPoint( QgsPoint &point )
134132
int decimalPlaces = settings.value( "/qgis/measure/decimalplaces", "3" ).toInt();
135133

136134
// Create QgsDistance Area for customization ProjectionEnabled setting
137-
QgsDistanceArea myDa;
138-
myDa.setSourceCrs( mTool->canvas()->mapRenderer()->destinationSrs().srsid() );
139-
myDa.setEllipsoid( mTool->canvas()->mapRenderer()->distanceArea()->ellipsoid() );
140-
myDa.setProjectionsEnabled( mcbProjectionEnabled->isChecked() );
135+
QgsDistanceArea myDa;
136+
configureDistanceArea( myDa );
141137

142138
int numPoints = mTool->points().size();
143139
if ( mMeasureArea && numPoints > 2 )
@@ -269,19 +265,18 @@ void QgsMeasureDialog::convertMeasurement( double &measure, QGis::UnitType &u, b
269265
// The parameter &u is out only...
270266

271267
QGis::UnitType myUnits = mTool->canvas()->mapUnits();
272-
if (( myUnits == QGis::Degrees || myUnits == QGis::Feet ) &&
273-
mTool->canvas()->mapRenderer()->distanceArea()->ellipsoid() != "NONE" &&
268+
if (( myUnits == QGis::Degrees || myUnits == QGis::Feet ) &&
274269
mcbProjectionEnabled->isChecked() )
275270
{
276271
// Measuring on an ellipsoid returns meters, and so does using projections???
277272
myUnits = QGis::Meters;
278273
QgsDebugMsg( "We're measuring on an ellipsoid or using projections, the system is returning meters" );
279274
}
280-
275+
281276
// Get the units for display
282277
QSettings settings;
283278
QString myDisplayUnitsTxt = settings.value( "/qgis/measure/displayunits", "meters" ).toString();
284-
279+
285280
// Only convert between meters and feet
286281
if ( myUnits == QGis::Meters && myDisplayUnitsTxt == "feet" )
287282
{
@@ -314,9 +309,9 @@ void QgsMeasureDialog::changeProjectionEnabledState()
314309
// store value
315310
QSettings settings;
316311
if ( mcbProjectionEnabled->isChecked() )
317-
settings.setValue( "/qgis/measure/projectionEnabled", 2);
312+
settings.setValue( "/qgis/measure/projectionEnabled", 2 );
318313
else
319-
settings.setValue( "/qgis/measure/projectionEnabled", 0);
314+
settings.setValue( "/qgis/measure/projectionEnabled", 0 );
320315

321316
// clear interface
322317
mTable->clear();
@@ -327,13 +322,11 @@ void QgsMeasureDialog::changeProjectionEnabledState()
327322
updateUi();
328323

329324
int decimalPlaces = settings.value( "/qgis/measure/decimalplaces", "3" ).toInt();
330-
325+
331326
// create DistanceArea
332-
QgsDistanceArea myDa;
333-
myDa.setSourceCrs( mTool->canvas()->mapRenderer()->destinationSrs().srsid() );
334-
myDa.setEllipsoid( mTool->canvas()->mapRenderer()->distanceArea()->ellipsoid() );
335-
myDa.setProjectionsEnabled( mcbProjectionEnabled->isChecked() );
336-
327+
QgsDistanceArea myDa;
328+
configureDistanceArea( myDa );
329+
337330
if ( mMeasureArea )
338331
{
339332
double area = 0.0;
@@ -342,14 +335,15 @@ void QgsMeasureDialog::changeProjectionEnabledState()
342335
area = myDa.measurePolygon( mTool->points() );
343336
}
344337
editTotal->setText( formatArea( area, decimalPlaces ) );
345-
}else
338+
}
339+
else
346340
{
347341
QList<QgsPoint>::const_iterator it;
348342
bool b = true; // first point
349-
350-
QgsPoint p1,p2;
351-
352-
for (it=mTool->points().constBegin(); it != mTool->points().constEnd(); ++it)
343+
344+
QgsPoint p1, p2;
345+
346+
for ( it = mTool->points().constBegin(); it != mTool->points().constEnd(); ++it )
353347
{
354348
p2 = *it;
355349
if ( !b )
@@ -373,3 +367,12 @@ void QgsMeasureDialog::changeProjectionEnabledState()
373367
}
374368
}
375369
}
370+
371+
void QgsMeasureDialog::configureDistanceArea( QgsDistanceArea& da )
372+
{
373+
QSettings settings;
374+
QString ellipsoidId = settings.value( "/qgis/measure/ellipsoid", "WGS84" ).toString();
375+
da.setSourceCrs( mTool->canvas()->mapRenderer()->destinationSrs().srsid() );
376+
da.setEllipsoid( ellipsoidId );
377+
da.setProjectionsEnabled( mcbProjectionEnabled->isChecked() );
378+
}

src/app/qgsmeasuredialog.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ class QgsMeasureDialog : public QDialog, private Ui::QgsMeasureBase
8080
//! Converts the measurement, depending on settings in options and current transformation
8181
void convertMeasurement( double &measure, QGis::UnitType &u, bool isArea );
8282

83+
//! Configures distance area objects with ellipsoid / output crs
84+
void configureDistanceArea( QgsDistanceArea& da );
85+
8386
double mTotal;
8487

8588
//! indicates whether we're measuring distances or areas

src/core/qgsmaprenderer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ class CORE_EXPORT QgsMapRenderer : public QObject
134134
void updateScale();
135135

136136
//! Return the measuring object
137+
//! @note deprecated.
137138
QgsDistanceArea* distanceArea() { return mDistArea; }
138139
QGis::UnitType mapUnits() const;
139140
void setMapUnits( QGis::UnitType u );

src/ui/qgsdisplayanglebase.ui

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
<item row="0" column="0">
4848
<widget class="QCheckBox" name="mcbProjectionEnabled">
4949
<property name="text">
50-
<string>Ellipsoidal (WGS84)</string>
50+
<string>Ellipsoidal</string>
5151
</property>
5252
</widget>
5353
</item>

src/ui/qgsmeasurebase.ui

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
<item row="0" column="0" colspan="3">
102102
<widget class="QCheckBox" name="mcbProjectionEnabled">
103103
<property name="text">
104-
<string>Ellipsoidal (WGS84)</string>
104+
<string>Ellipsoidal</string>
105105
</property>
106106
</widget>
107107
</item>

0 commit comments

Comments
 (0)