Skip to content

Commit

Permalink
fix #3866
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n authored and timlinux committed Jul 18, 2011
1 parent b847634 commit fc986f0
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 @@ -98,25 +98,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 @@ -131,14 +127,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 @@ -147,7 +139,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 @@ -244,7 +236,7 @@ void QgsMeasureDialog::updateUi()
break;
case QGis::UnknownUnit:
mTable->setHeaderLabels( QStringList( tr( "Segments" ) ) );
};
}

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

configureDistanceArea();
}

void QgsMeasureDialog::convertMeasurement( double &measure, QGis::UnitType &u, bool isArea )
Expand Down Expand Up @@ -323,16 +316,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 @@ -348,7 +337,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 @@ -368,11 +357,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 fc986f0

Please sign in to comment.