Skip to content
Permalink
Browse files
Apply patch #3384 by Sergey Yakushev with few modifications. Mark Qgs…
…MapRenderer::distanceArea as deprecated

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@14992 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Jan 4, 2011
1 parent a9e75c8 commit 48b9b7e80bf15ca1f8d974ff46b8c2901acc1c8a
@@ -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 );
}
}

@@ -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 ) );
@@ -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() );
}



@@ -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
@@ -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();
}
@@ -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();
@@ -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 )
@@ -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" )
{
@@ -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();
@@ -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;
@@ -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 )
@@ -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() );
}
@@ -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
@@ -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 );
@@ -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>
@@ -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>

0 comments on commit 48b9b7e

Please sign in to comment.