Skip to content
Permalink
Browse files

A stab at improving the measurement system. Added a new selector in O…

…ptions for converting the result, and grayed out the layer units when OTFP is on. Should fix #1219, I hope.

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@11340 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
homann
homann committed Aug 10, 2009
1 parent 52996e7 commit 3c6a232ec711e8be1e048350fc8e66371265f191
@@ -5435,7 +5435,9 @@ void QgisApp::projectProperties()
QApplication::restoreOverrideCursor();

//pass any refresg signals off to canvases
//connect (pp,SIGNAL(refresh()), mMapCanvas, SLOT(refresh()));
// Line below was commented out by wonder three years ago (r4949).
// It is needed to refresh scale bar after changing display units.
connect (pp,SIGNAL(refresh()), mMapCanvas, SLOT(refresh()));

QgsMapRenderer* myRender = mMapCanvas->mapRenderer();
bool wasProjected = myRender->hasCrsTransformEnabled();
@@ -18,6 +18,7 @@
#include "qgsmeasuredialog.h"
#include "qgsmeasuretool.h"

#include "qgslogger.h"
#include "qgscontexthelp.h"
#include "qgsdistancearea.h"
#include "qgsmapcanvas.h"
@@ -89,16 +90,22 @@ void QgsMeasureDialog::mouseMove( QgsPoint &point )
QList<QgsPoint> tmpPoints = mTool->points();
tmpPoints.append( point );
double area = mTool->canvas()->mapRenderer()->distanceArea()->measurePolygon( tmpPoints );
QGis::UnitType myDisplayUnits;
// Ignore units
convertMeasurement( area, myDisplayUnits, true );
editTotal->setText( formatArea( area ) );
}
else if ( !mMeasureArea && mTool->points().size() > 0 )
{
QgsPoint p1( mTool->points().last() ), p2( point );

double d = mTool->canvas()->mapRenderer()->distanceArea()->measureLine( p1, p2 );
editTotal->setText( formatDistance( mTotal + d ) );
QGis::UnitType myDisplayUnits;
// Ignore units
convertMeasurement( d, myDisplayUnits, false );
QTreeWidgetItem *item = mTable->topLevelItem( mTable->topLevelItemCount() - 1 );
item->setText( 0, QLocale::system().toString( d, 'f', 2 ) );
editTotal->setText( formatDistance( mTotal + d ) );
}
}

@@ -108,6 +115,9 @@ void QgsMeasureDialog::addPoint( QgsPoint &point )
if ( mMeasureArea && numPoints > 2 )
{
double area = mTool->canvas()->mapRenderer()->distanceArea()->measurePolygon( mTool->points() );
QGis::UnitType myDisplayUnits;
// Ignore units
convertMeasurement( area, myDisplayUnits, true );
editTotal->setText( formatArea( area ) );
}
else if ( !mMeasureArea && numPoints > 1 )
@@ -121,6 +131,10 @@ void QgsMeasureDialog::addPoint( QgsPoint &point )
mTotal += d;
editTotal->setText( formatDistance( mTotal ) );

QGis::UnitType myDisplayUnits;
// Ignore units
convertMeasurement( d, myDisplayUnits, false );

QTreeWidgetItem *item = mTable->topLevelItem( mTable->topLevelItemCount() - 1 );
item->setText( 0, QLocale::system().toString( d, 'f', 2 ) );

@@ -173,24 +187,26 @@ void QgsMeasureDialog::on_btnHelp_clicked()

QString QgsMeasureDialog::formatDistance( double distance )
{
QString txt;
QString unitLabel;

QGis::UnitType myMapUnits = mTool->canvas()->mapUnits();
return QgsDistanceArea::textUnit( distance, 2, myMapUnits, false );
QGis::UnitType myDisplayUnits;
convertMeasurement( distance, myDisplayUnits, false );
return QgsDistanceArea::textUnit( distance, 2, myDisplayUnits, false );
}

QString QgsMeasureDialog::formatArea( double area )
{
QGis::UnitType myMapUnits = mTool->canvas()->mapUnits();
return QgsDistanceArea::textUnit( area, 2, myMapUnits, true );
QGis::UnitType myDisplayUnits;
convertMeasurement( area, myDisplayUnits, true );
return QgsDistanceArea::textUnit( area, 2, myDisplayUnits, true );
}

void QgsMeasureDialog::updateUi()
{
double dummy = 1.0;
QGis::UnitType myDisplayUnits;
// The dummy distance is ignored
convertMeasurement( dummy, myDisplayUnits, false );

QGis::UnitType myMapUnits = mTool->canvas()->mapUnits();
switch ( myMapUnits )
switch ( myDisplayUnits )
{
case QGis::Meters:
mTable->setHeaderLabels( QStringList( tr( "Segments (in meters)" ) ) );
@@ -218,3 +234,43 @@ void QgsMeasureDialog::updateUi()

}

void QgsMeasureDialog::convertMeasurement(double &measure, QGis::UnitType &u, bool isArea)
{
// Helper for converting between meters and feet
// The parameter &u is out only...

QGis::UnitType myUnits = mTool->canvas()->mapUnits();
if ( myUnits == QGis::Degrees &&
mTool->canvas()->mapRenderer()->distanceArea()->ellipsoid() != "NONE" &&
mTool->canvas()->mapRenderer()->distanceArea()->hasCrsTransformEnabled() )
{
// Measuring on an ellipsoid returns meters
myUnits = QGis::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" )
{
measure /= 0.3048;
if ( isArea )
{
measure /= 0.3048;
}
myUnits = QGis::Feet;
}
if ( myUnits == QGis::Feet && myDisplayUnitsTxt == "meters" )
{
measure *= 0.3048 * 0.3048;
if ( isArea )
{
measure *= 0.3048;
}
myUnits = QGis::Meters;
}

u = myUnits;
}
@@ -20,6 +20,7 @@
#include "ui_qgsmeasurebase.h"

#include "qgspoint.h"
#include "qgsdistancearea.h"

class QCloseEvent;
class QgsMeasureTool;
@@ -72,6 +73,9 @@ class QgsMeasureDialog : public QDialog, private Ui::QgsMeasureBase
//! shows/hides table, shows correct units
void updateUi();

//! Converts the measurement, depending on settings in options and current transformation
void convertMeasurement(double &measure, QGis::UnitType &u, bool isArea);

double mTotal;

//! Help context id
@@ -113,6 +113,17 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
getEllipsoidList();
QString myEllipsoidId = settings.value( "/qgis/measure/ellipsoid", "WGS84" ).toString();
cmbEllipsoid->setItemText( cmbEllipsoid->currentIndex(), getEllipsoidName( myEllipsoidId ) );

// Set the units for measuring
QString myUnitsTxt = settings.value( "/qgis/measure/displayunits", "meters").toString();
if ( myUnitsTxt == "feet" )
{
radFeet->setChecked( true );
} else {
radMeters->setChecked( true );
}


// add the themes to the combo box on the option dialog
QDir myThemeDir( QgsApplication::pkgDataPath() + "/themes/" );
myThemeDir.setFilter( QDir::Dirs );
@@ -402,6 +413,15 @@ void QgsOptions::saveOptions()

settings.setValue( "/qgis/measure/ellipsoid", getEllipsoidAcronym( cmbEllipsoid->currentText() ) );

if ( radFeet->isChecked() )
{
settings.setValue( "/qgis/measure/displayunits", "feet" );
}
else
{
settings.setValue( "/qgis/measure/displayunits", "meters" );
}
settings.setValue( "/qgis/measure/ellipsoid", getEllipsoidAcronym( cmbEllipsoid->currentText() ) );
//set the colour for selections
QColor myColor = pbnSelectionColour->color();
settings.setValue( "/qgis/default_selection_color_red", myColor.red() );
@@ -58,6 +58,7 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
//see if the user wants on the fly projection enabled
bool myProjectionEnabled = myRender->hasCrsTransformEnabled();
cbxProjectionEnabled->setChecked( myProjectionEnabled );
btnGrpMapUnits->setEnabled( !myProjectionEnabled );

long myCRSID = myRender->destinationSrs().srsid();
QgsDebugMsg( "Read project CRSID: " + QString::number( myCRSID ) );
@@ -430,3 +431,9 @@ void QgsProjectProperties::on_mSnappingOptionsPushButton_clicked()
d.layerSettings( mSnappingLayerSettings );
}
}

void QgsProjectProperties::on_cbxProjectionEnabled_stateChanged(int state)
{
btnGrpMapUnits->setEnabled( state == Qt::Unchecked );
}

@@ -93,6 +93,9 @@ class QgsProjectProperties : public QDialog, private Ui::QgsProjectPropertiesBas
*/
void on_mSnappingOptionsPushButton_clicked();

void on_cbxProjectionEnabled_stateChanged(int state);


signals:
//! Signal used to inform listeners that the mouse display precision may have changed
void displayPrecisionChanged();
@@ -476,6 +476,27 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="textLabel1_8">
<property name="text">
<string>Display units (if applicable)</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QRadioButton" name="radMeters">
<property name="text">
<string>Meters</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QRadioButton" name="radFeet">
<property name="text">
<string>Feet</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
@@ -139,7 +139,7 @@
<item row="1" column="0">
<widget class="QGroupBox" name="btnGrpMapUnits">
<property name="title">
<string>Map units</string>
<string>Layer units (only used when CRS transformation is disabled)</string>
</property>
<layout class="QHBoxLayout">
<property name="margin">

0 comments on commit 3c6a232

Please sign in to comment.
You can’t perform that action at this time.