Skip to content

Commit

Permalink
Apply patch #3384 by Sergey Yakushev with few modifications. Mark Qgs…
Browse files Browse the repository at this point in the history
…MapRenderer::distanceArea as deprecated

git-svn-id: http://svn.osgeo.org/qgis/trunk@14992 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Jan 4, 2011
1 parent 023e17f commit 862024a
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 68 deletions.
77 changes: 39 additions & 38 deletions src/app/qgsmaptoolmeasureangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,46 +45,38 @@ void QgsMapToolMeasureAngle::canvasMoveEvent( QMouseEvent * e )
mRubberBand->movePoint( point );
if ( mAnglePoints.size() == 2 )
{
//do angle calculation
QgsDistanceArea* distArea = mCanvas->mapRenderer()->distanceArea();
if ( distArea )
if ( !mResultDisplay )
{
//show angle in dialog
if ( !mResultDisplay )
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();

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 resultAngle = azimuthTwo - azimuthOne;
QgsDebugMsg( QString::number( qAbs( resultAngle ) ) );
QgsDebugMsg( QString::number( M_PI ) );
if ( qAbs( resultAngle ) > M_PI )
{
if ( resultAngle < 0 )
{
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 ) );
resultAngle = M_PI + ( resultAngle + M_PI );
}
mResultDisplay->show();

QgsDistanceArea myDa;
myDa.setSourceCrs( mCanvas->mapRenderer()->destinationSrs().srsid() );
myDa.setEllipsoid( distArea->ellipsoid() );
myDa.setProjectionsEnabled( mResultDisplay->projectionEnabled() );

//angle calculation
double azimuthOne = myDa.bearing( mAnglePoints.at( 1 ), mAnglePoints.at( 0 ) );
double azimuthTwo = myDa.bearing( mAnglePoints.at( 1 ), point );
double resultAngle = azimuthTwo - azimuthOne;
QgsDebugMsg( QString::number( qAbs( resultAngle ) ) );
QgsDebugMsg( QString::number( M_PI ) );
if ( qAbs( resultAngle ) > M_PI )
else
{
if ( resultAngle < 0 )
{
resultAngle = M_PI + ( resultAngle + M_PI );
}
else
{
resultAngle = -M_PI + ( resultAngle - M_PI );
}
resultAngle = -M_PI + ( resultAngle - M_PI );
}

mResultDisplay->setValueInRadians( resultAngle );
}

mResultDisplay->setValueInRadians( resultAngle );
}
}

Expand Down Expand Up @@ -160,11 +152,9 @@ void QgsMapToolMeasureAngle::changeProjectionEnabledState()
return;
if ( !mResultDisplay )
return;

QgsDistanceArea myDa;
myDa.setSourceCrs( mCanvas->mapRenderer()->destinationSrs().srsid() );
myDa.setEllipsoid( mCanvas->mapRenderer()->distanceArea()->ellipsoid() );
myDa.setProjectionsEnabled( mResultDisplay->projectionEnabled() );
configureDistanceArea( myDa );

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

}

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



3 changes: 3 additions & 0 deletions src/app/qgsmaptoolmeasureangle.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ class QgsMapToolMeasureAngle: public QgsMapTool
/** recalculate angle if projection state changed*/
void changeProjectionEnabledState();

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

};

#endif // QGSMAPTOOLMEASUREANGLE_H
59 changes: 31 additions & 28 deletions src/app/qgsmeasuredialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ QgsMeasureDialog::QgsMeasureDialog( QgsMeasureTool* tool, Qt::WFlags f )
else
mcbProjectionEnabled->setCheckState( Qt::Unchecked );

connect( mcbProjectionEnabled, SIGNAL( stateChanged(int) ),
this, SLOT( changeProjectionEnabledState() ));
connect( mcbProjectionEnabled, SIGNAL( stateChanged( int ) ),
this, SLOT( changeProjectionEnabledState() ) );

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

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

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

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

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

QGis::UnitType myUnits = mTool->canvas()->mapUnits();
if (( myUnits == QGis::Degrees || myUnits == QGis::Feet ) &&
mTool->canvas()->mapRenderer()->distanceArea()->ellipsoid() != "NONE" &&
if (( myUnits == QGis::Degrees || myUnits == QGis::Feet ) &&
mcbProjectionEnabled->isChecked() )
{
// Measuring on an ellipsoid returns meters, and so does using projections???
myUnits = QGis::Meters;
QgsDebugMsg( "We're measuring on an ellipsoid or using projections, the system is returning meters" );
}

// Get the units for display
QSettings settings;
QString myDisplayUnitsTxt = settings.value( "/qgis/measure/displayunits", "meters" ).toString();

// Only convert between meters and feet
if ( myUnits == QGis::Meters && myDisplayUnitsTxt == "feet" )
{
Expand Down Expand Up @@ -314,9 +309,9 @@ void QgsMeasureDialog::changeProjectionEnabledState()
// store value
QSettings settings;
if ( mcbProjectionEnabled->isChecked() )
settings.setValue( "/qgis/measure/projectionEnabled", 2);
settings.setValue( "/qgis/measure/projectionEnabled", 2 );
else
settings.setValue( "/qgis/measure/projectionEnabled", 0);
settings.setValue( "/qgis/measure/projectionEnabled", 0 );

// clear interface
mTable->clear();
Expand All @@ -327,13 +322,11 @@ void QgsMeasureDialog::changeProjectionEnabledState()
updateUi();

int decimalPlaces = settings.value( "/qgis/measure/decimalplaces", "3" ).toInt();

// create DistanceArea
QgsDistanceArea myDa;
myDa.setSourceCrs( mTool->canvas()->mapRenderer()->destinationSrs().srsid() );
myDa.setEllipsoid( mTool->canvas()->mapRenderer()->distanceArea()->ellipsoid() );
myDa.setProjectionsEnabled( mcbProjectionEnabled->isChecked() );

QgsDistanceArea myDa;
configureDistanceArea( myDa );

if ( mMeasureArea )
{
double area = 0.0;
Expand All @@ -342,14 +335,15 @@ void QgsMeasureDialog::changeProjectionEnabledState()
area = myDa.measurePolygon( mTool->points() );
}
editTotal->setText( formatArea( area, decimalPlaces ) );
}else
}
else
{
QList<QgsPoint>::const_iterator it;
bool b = true; // first point
QgsPoint p1,p2;
for (it=mTool->points().constBegin(); it != mTool->points().constEnd(); ++it)

QgsPoint p1, p2;

for ( it = mTool->points().constBegin(); it != mTool->points().constEnd(); ++it )
{
p2 = *it;
if ( !b )
Expand All @@ -373,3 +367,12 @@ void QgsMeasureDialog::changeProjectionEnabledState()
}
}
}

void QgsMeasureDialog::configureDistanceArea( QgsDistanceArea& da )
{
QSettings settings;
QString ellipsoidId = settings.value( "/qgis/measure/ellipsoid", "WGS84" ).toString();
da.setSourceCrs( mTool->canvas()->mapRenderer()->destinationSrs().srsid() );
da.setEllipsoid( ellipsoidId );
da.setProjectionsEnabled( mcbProjectionEnabled->isChecked() );
}
3 changes: 3 additions & 0 deletions src/app/qgsmeasuredialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ class QgsMeasureDialog : public QDialog, private Ui::QgsMeasureBase
//! Converts the measurement, depending on settings in options and current transformation
void convertMeasurement( double &measure, QGis::UnitType &u, bool isArea );

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

double mTotal;

//! indicates whether we're measuring distances or areas
Expand Down
1 change: 1 addition & 0 deletions src/core/qgsmaprenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class CORE_EXPORT QgsMapRenderer : public QObject
void updateScale();

//! Return the measuring object
//! @note deprecated.
QgsDistanceArea* distanceArea() { return mDistArea; }
QGis::UnitType mapUnits() const;
void setMapUnits( QGis::UnitType u );
Expand Down
2 changes: 1 addition & 1 deletion src/ui/qgsdisplayanglebase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<item row="0" column="0">
<widget class="QCheckBox" name="mcbProjectionEnabled">
<property name="text">
<string>Ellipsoidal (WGS84)</string>
<string>Ellipsoidal</string>
</property>
</widget>
</item>
Expand Down
2 changes: 1 addition & 1 deletion src/ui/qgsmeasurebase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
<item row="0" column="0" colspan="3">
<widget class="QCheckBox" name="mcbProjectionEnabled">
<property name="text">
<string>Ellipsoidal (WGS84)</string>
<string>Ellipsoidal</string>
</property>
</widget>
</item>
Expand Down

0 comments on commit 862024a

Please sign in to comment.