Skip to content

Commit

Permalink
Merge pull request #219 from homann/measure_cleanup
Browse files Browse the repository at this point in the history
Measure cleanup and fix #5156
  • Loading branch information
homann committed Sep 4, 2012
2 parents ad2ff90 + 0d1b1aa commit a441282
Show file tree
Hide file tree
Showing 20 changed files with 292 additions and 283 deletions.
21 changes: 19 additions & 2 deletions src/app/qgsdecorationscalebar.cpp
Expand Up @@ -23,6 +23,7 @@ email : sbr00pwb@users.sourceforge.net

#include "qgsdecorationscalebardialog.h"

#include "qgis.h"
#include "qgisapp.h"
#include "qgslogger.h"
#include "qgsmapcanvas.h"
Expand Down Expand Up @@ -119,6 +120,7 @@ void QgsDecorationScaleBar::render( QPainter * theQPainter )
//projections) and that just confuses the rest of the code in this
//function, so force to a positive number.
double myMapUnitsPerPixelDouble = qAbs( canvas->mapUnitsPerPixel() );
double myActualSize = mPreferredSize;

// Exit if the canvas width is 0 or layercount is 0 or QGIS will freeze
int myLayerCount = canvas->layerCount();
Expand All @@ -131,9 +133,25 @@ void QgsDecorationScaleBar::render( QPainter * theQPainter )
// Hard coded sizes
int myMajorTickSize = 8;
int myTextOffsetX = 3;
double myActualSize = mPreferredSize;
int myMargin = 20;

QSettings settings;
QGis::UnitType myPreferredUnits = QGis::fromLiteral( settings.value( "/qgis/measure/displayunits", QGis::toLiteral( QGis::Meters ) ).toString() );
QGis::UnitType myMapUnits = canvas->mapUnits();

// Adjust units meter/feet or vice versa
if ( myMapUnits == QGis::Meters && myPreferredUnits == QGis::Feet )
{
// From meter to feet
myMapUnits = QGis::Feet;
myMapUnitsPerPixelDouble /= 0.3084;
}
else if ( myMapUnits == QGis::Feet && myPreferredUnits == QGis::Meters )
{
// From feet to meter
myMapUnits = QGis::Meters;
myMapUnitsPerPixelDouble *= 0.3084;
}
//Calculate size of scale bar for preferred number of map units
double myScaleBarWidth = mPreferredSize / myMapUnitsPerPixelDouble;

Expand Down Expand Up @@ -164,7 +182,6 @@ void QgsDecorationScaleBar::render( QPainter * theQPainter )
}

//Get type of map units and set scale bar unit label text
QGis::UnitType myMapUnits = canvas->mapUnits();
QString myScaleBarUnitLabel;
switch ( myMapUnits )
{
Expand Down
1 change: 1 addition & 0 deletions src/app/qgsdecorationscalebar.h
Expand Up @@ -21,6 +21,7 @@ email : sbr00pwb@users.sourceforge.net
#ifndef QGSCALEBARPLUGIN
#define QGSCALEBARPLUGIN

#include "qgis.h"
#include "qgsdecorationitem.h"

class QPainter;
Expand Down
56 changes: 31 additions & 25 deletions src/app/qgsdisplayangle.cpp
Expand Up @@ -14,58 +14,64 @@
***************************************************************************/

#include "qgsdisplayangle.h"
#include "qgsmapcanvas.h"
#include "qgslogger.h"

#include <QSettings>
#include <cmath>

QgsDisplayAngle::QgsDisplayAngle( QWidget * parent, Qt::WindowFlags f ): QDialog( parent, f )
QgsDisplayAngle::QgsDisplayAngle( QgsMapToolMeasureAngle * tool, Qt::WFlags f )
: QDialog( tool->canvas()->topLevelWidget(), f ), mTool( tool )
{
setupUi( this );
QSettings settings;
int s = settings.value( "/qgis/measure/projectionEnabled", "2" ).toInt();
if ( s == 2 )
mcbProjectionEnabled->setCheckState( Qt::Checked );
else
mcbProjectionEnabled->setCheckState( Qt::Unchecked );

connect( mcbProjectionEnabled, SIGNAL( stateChanged( int ) ),
this, SLOT( changeState() ) );
connect( mcbProjectionEnabled, SIGNAL( stateChanged( int ) ),
this, SIGNAL( changeProjectionEnabledState() ) );
// Update whenever the canvas has refreshed. Maybe more often than needed,
// but at least every time any canvas related settings changes
connect( mTool->canvas(), SIGNAL( mapCanvasRefreshed() ),
this, SLOT( updateSettings() ) );

updateSettings();
}

QgsDisplayAngle::~QgsDisplayAngle()
{

}

bool QgsDisplayAngle::projectionEnabled()

void QgsDisplayAngle::setValueInRadians( double value )
{
mValue = value;
updateUi();
}

void QgsDisplayAngle::updateSettings()
{
return mcbProjectionEnabled->isChecked();
emit changeProjectionEnabledState();
}

void QgsDisplayAngle::setValueInRadians( double value )
void QgsDisplayAngle::updateUi()
{

QSettings settings;
QString unitString = settings.value( "/qgis/measure/angleunits", "degrees" ).toString();
int decimals = settings.value( "/qgis/measure/decimalplaces", "3" ).toInt();

if ( unitString == "degrees" )
{
mAngleLineEdit->setText( tr( "%1 degrees" ).arg( value * 180 / M_PI ) );
mAngleLineEdit->setText( tr( "%1 degrees" ).arg( QLocale::system().toString( mValue * 180 / M_PI ),
'f', decimals ) );
}
else if ( unitString == "radians" )
{
mAngleLineEdit->setText( tr( "%1 radians" ).arg( value ) );
mAngleLineEdit->setText( tr( "%1 radians" ).arg( QLocale::system().toString( mValue ),
'f', decimals ) );

}
else if ( unitString == "gon" )
{
mAngleLineEdit->setText( tr( "%1 gon" ).arg( value / M_PI * 200 ) );
mAngleLineEdit->setText( tr( "%1 gon" ).arg( QLocale::system().toString( mValue / M_PI * 200 ),
'f', decimals ) );
}
}

void QgsDisplayAngle::changeState()
{
QSettings settings;
if ( mcbProjectionEnabled->isChecked() )
settings.setValue( "/qgis/measure/projectionEnabled", 2 );
else
settings.setValue( "/qgis/measure/projectionEnabled", 0 );
}
18 changes: 14 additions & 4 deletions src/app/qgsdisplayangle.h
Expand Up @@ -16,6 +16,7 @@
#ifndef QGSDISPLAYANGLE_H
#define QGSDISPLAYANGLE_H

#include "qgsmaptoolmeasureangle.h"
#include "ui_qgsdisplayanglebase.h"

/**A class that displays results of angle measurements with the proper unit*/
Expand All @@ -24,20 +25,29 @@ class QgsDisplayAngle: public QDialog, private Ui::QgsDisplayAngleBase
Q_OBJECT

public:
QgsDisplayAngle( QWidget * parent = 0, Qt::WindowFlags f = 0 );
QgsDisplayAngle( QgsMapToolMeasureAngle * tool = 0, Qt::WindowFlags f = 0 );
~QgsDisplayAngle();
/**Sets the measured angle value (in radians). The value is going to
be converted to degrees / gon automatically if necessary*/
void setValueInRadians( double value );

bool projectionEnabled();

signals:
void changeProjectionEnabledState();

private slots:
void changeState();

//! When any external settings change
void updateSettings();

private:
//! pointer to tool which owns this dialog
QgsMapToolMeasureAngle * mTool;

//! The value we're showing
double mValue;

//! Updates UI according to user settings.
void updateUi();
};

#endif // QGSDISPLAYANGLE_H
2 changes: 0 additions & 2 deletions src/app/qgsmaptoolfeatureaction.cpp
Expand Up @@ -15,7 +15,6 @@

#include "qgsmaptoolfeatureaction.h"

#include "qgsdistancearea.h"
#include "qgsfeature.h"
#include "qgsfield.h"
#include "qgsgeometry.h"
Expand Down Expand Up @@ -111,7 +110,6 @@ bool QgsMapToolFeatureAction::doAction( QgsVectorLayer *layer, int x, int y )
// load identify radius from settings
QSettings settings;
double identifyValue = settings.value( "/Map/identifyRadius", QGis::DEFAULT_IDENTIFY_RADIUS ).toDouble();
QString ellipsoid = settings.value( "/qgis/measure/ellipsoid", "WGS84" ).toString();

if ( identifyValue <= 0.0 )
identifyValue = QGis::DEFAULT_IDENTIFY_RADIUS;
Expand Down
14 changes: 2 additions & 12 deletions src/app/qgsmaptoolidentify.cpp
Expand Up @@ -204,7 +204,7 @@ bool QgsMapToolIdentify::identifyVectorLayer( QgsVectorLayer *layer, int x, int
// load identify radius from settings
QSettings settings;
double identifyValue = settings.value( "/Map/identifyRadius", QGis::DEFAULT_IDENTIFY_RADIUS ).toDouble();
QString ellipsoid = settings.value( "/qgis/measure/ellipsoid", "WGS84" ).toString();
QString ellipsoid = settings.value( "/qgis/measure/ellipsoid", GEO_NONE ).toString();

if ( identifyValue <= 0.0 )
identifyValue = QGis::DEFAULT_IDENTIFY_RADIUS;
Expand Down Expand Up @@ -392,17 +392,7 @@ void QgsMapToolIdentify::convertMeasurement( QgsDistanceArea &calc, double &meas

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

QGis::UnitType displayUnits;
if ( myDisplayUnitsTxt == "feet" )
{
displayUnits = QGis::Feet;
}
else
{
displayUnits = QGis::Meters;
}
QGis::UnitType displayUnits = QGis::fromLiteral( settings.value( "/qgis/measure/displayunits", QGis::toLiteral( QGis::Meters ) ).toString() );

calc.convertMeasurement( measure, myUnits, displayUnits, isArea );
u = myUnits;
Expand Down
14 changes: 11 additions & 3 deletions src/app/qgsmaptoolmeasureangle.cpp
Expand Up @@ -85,7 +85,7 @@ void QgsMapToolMeasureAngle::canvasReleaseEvent( QMouseEvent * e )
{
if ( mResultDisplay == NULL )
{
mResultDisplay = new QgsDisplayAngle( mCanvas->topLevelWidget() );
mResultDisplay = new QgsDisplayAngle( this );
QObject::connect( mResultDisplay, SIGNAL( rejected() ), this, SLOT( stopMeasuring() ) );
QObject::connect( mResultDisplay, SIGNAL( changeProjectionEnabledState() ),
this, SLOT( changeProjectionEnabledState() ) );
Expand Down Expand Up @@ -180,10 +180,18 @@ void QgsMapToolMeasureAngle::changeProjectionEnabledState()
void QgsMapToolMeasureAngle::configureDistanceArea()
{
QSettings settings;
QString ellipsoidId = settings.value( "/qgis/measure/ellipsoid", "WGS84" ).toString();
QString ellipsoidId = settings.value( "/qgis/measure/ellipsoid", GEO_NONE ).toString();
mDa.setSourceCrs( mCanvas->mapRenderer()->destinationCrs().srsid() );
mDa.setEllipsoid( ellipsoidId );
mDa.setEllipsoidalMode( mResultDisplay->projectionEnabled() ); // FIXME (not when proj is turned off)
// Only use ellipsoidal calculation when project wide transformation is enabled.
if ( mCanvas->mapRenderer()->hasCrsTransformEnabled() )
{
mDa.setEllipsoidalMode( true );
}
else
{
mDa.setEllipsoidalMode( false );
}
}


Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsmaptoolmeasureangle.h
Expand Up @@ -32,7 +32,7 @@ class QgsMapToolMeasureAngle: public QgsMapTool
QgsMapToolMeasureAngle( QgsMapCanvas* canvas );
~QgsMapToolMeasureAngle();

//! Mouse move event for overriding
//! Mouse move event for overridingqgs
void canvasMoveEvent( QMouseEvent * e );

//! Mouse release event for overriding
Expand Down

0 comments on commit a441282

Please sign in to comment.