Skip to content

Commit

Permalink
fix #3866
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Jun 3, 2011
1 parent 3ac604f commit 50d255f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 24 deletions.
35 changes: 12 additions & 23 deletions src/app/qgsmeasuredialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,25 +97,21 @@ void QgsMeasureDialog::mouseMove( QgsPoint &point )
QSettings settings;
int decimalPlaces = settings.value( "/qgis/measure/decimalplaces", "3" ).toInt();

// Create QgsDistance Area for customization ProjectionEnabled setting
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
if ( mMeasureArea && mTool->points().size() > 1 )
{
QList<QgsPoint> tmpPoints = mTool->points();
tmpPoints.append( point );
double area = myDa.measurePolygon( tmpPoints );
double area = mDa.measurePolygon( tmpPoints );
editTotal->setText( formatArea( area, decimalPlaces ) );
}
else if ( !mMeasureArea && mTool->points().size() > 0 )
{
QgsPoint p1( mTool->points().last() ), p2( point );

double d = myDa.measureLine( p1, p2 );
double d = mDa.measureLine( p1, p2 );
editTotal->setText( formatDistance( mTotal + d, decimalPlaces ) );
QGis::UnitType myDisplayUnits;
// Ignore units
Expand All @@ -130,14 +126,10 @@ void QgsMeasureDialog::addPoint( QgsPoint &point )
QSettings settings;
int decimalPlaces = settings.value( "/qgis/measure/decimalplaces", "3" ).toInt();

// Create QgsDistance Area for customization ProjectionEnabled setting
QgsDistanceArea myDa;
configureDistanceArea( myDa );

int numPoints = mTool->points().size();
if ( mMeasureArea && numPoints > 2 )
{
double area = myDa.measurePolygon( mTool->points() );
double area = mDa.measurePolygon( mTool->points() );
editTotal->setText( formatArea( area, decimalPlaces ) );
}
else if ( !mMeasureArea && numPoints > 1 )
Expand All @@ -146,7 +138,7 @@ void QgsMeasureDialog::addPoint( QgsPoint &point )

QgsPoint p1 = mTool->points()[last], p2 = mTool->points()[last+1];

double d = myDa.measureLine( p1, p2 );
double d = mDa.measureLine( p1, p2 );

mTotal += d;
editTotal->setText( formatDistance( mTotal, decimalPlaces ) );
Expand Down Expand Up @@ -243,7 +235,7 @@ void QgsMeasureDialog::updateUi()
break;
case QGis::UnknownUnit:
mTable->setHeaderLabels( QStringList( tr( "Segments" ) ) );
};
}

if ( mMeasureArea )
{
Expand All @@ -256,6 +248,7 @@ void QgsMeasureDialog::updateUi()
editTotal->setText( formatDistance( 0, decimalPlaces ) );
}

configureDistanceArea();
}

void QgsMeasureDialog::convertMeasurement( double &measure, QGis::UnitType &u, bool isArea )
Expand Down Expand Up @@ -322,16 +315,12 @@ void QgsMeasureDialog::changeProjectionEnabledState()

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

// create DistanceArea
QgsDistanceArea myDa;
configureDistanceArea( myDa );

if ( mMeasureArea )
{
double area = 0.0;
if ( mTool->points().size() > 1 )
{
area = myDa.measurePolygon( mTool->points() );
area = mDa.measurePolygon( mTool->points() );
}
editTotal->setText( formatArea( area, decimalPlaces ) );
}
Expand All @@ -347,7 +336,7 @@ void QgsMeasureDialog::changeProjectionEnabledState()
p2 = *it;
if ( !b )
{
double d = myDa.measureLine( p1, p2 );
double d = mDa.measureLine( p1, p2 );
mTotal += d;
editTotal->setText( formatDistance( mTotal, decimalPlaces ) );
QGis::UnitType myDisplayUnits;
Expand All @@ -367,11 +356,11 @@ void QgsMeasureDialog::changeProjectionEnabledState()
}
}

void QgsMeasureDialog::configureDistanceArea( QgsDistanceArea& da )
void QgsMeasureDialog::configureDistanceArea()
{
QSettings settings;
QString ellipsoidId = settings.value( "/qgis/measure/ellipsoid", "WGS84" ).toString();
da.setSourceCrs( mTool->canvas()->mapRenderer()->destinationCrs().srsid() );
da.setEllipsoid( ellipsoidId );
da.setProjectionsEnabled( mcbProjectionEnabled->isChecked() );
mDa.setSourceCrs( mTool->canvas()->mapRenderer()->destinationCrs().srsid() );
mDa.setEllipsoid( ellipsoidId );
mDa.setProjectionsEnabled( mcbProjectionEnabled->isChecked() );
}
4 changes: 3 additions & 1 deletion src/app/qgsmeasuredialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,15 @@ class QgsMeasureDialog : public QDialog, private Ui::QgsMeasureBase
void convertMeasurement( double &measure, QGis::UnitType &u, bool isArea );

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

double mTotal;

//! indicates whether we're measuring distances or areas
bool mMeasureArea;

QgsDistanceArea mDa;

//! pointer to measure tool which owns this dialog
QgsMeasureTool* mTool;
};
Expand Down

0 comments on commit 50d255f

Please sign in to comment.