Skip to content
Permalink
Browse files

Merge pull request #343 from homann/qgsexpression_DA

Settings for measurements ellipsoid moved, fix for #3296 and #4252.
  • Loading branch information
homann committed Dec 1, 2012
2 parents e7995cf + 69308d3 commit 53790add9b0671bcdb88dd8a2deb6804fab01ae3
@@ -61,6 +61,10 @@ class QgsExpression
//! (used by internal functions)
QgsDistanceArea* geomCalculator();

//! Sets the geometry calculator used in evaluation of expressions,
// instead of the default.
void setGeomCalculator( QgsDistanceArea& calc );

/** This function currently replaces each expression between [% and %]
in the string with the result of its evaluation on the feature
passed as argument.
@@ -17,6 +17,11 @@ class QgsExpressionBuilderDialog : QDialog

QString expressionText();

/** Sets geometry calculator used in distance/area calculations.
* @note added in version 2.0
*/
void setGeomCalculator( const QgsDistanceArea & da );

protected:
/**
* Handle closing of the window
@@ -84,6 +84,11 @@ class QgsExpressionBuilderWidget : QWidget

void loadFieldNames( QMap<int, QgsField> fields );

/** Sets geometry calculator used in distance/area calculations.
* @note added in version 2.0
*/
void setGeomCalculator( const QgsDistanceArea & da );

/** Gets the expression string that has been set in the expression area.
* @returns The expression as a string. */
QString expressionText();
@@ -23,6 +23,9 @@ back to QgsVectorLayer.
#include "qgsattributeactiondialog.h"
#include "qgsattributeaction.h"
#include "qgsexpressionbuilderdialog.h"
#include "qgisapp.h"
#include "qgsproject.h"
#include "qgsmapcanvas.h"

#include <QFileDialog>
#include <QHeaderView>
@@ -173,6 +176,13 @@ void QgsAttributeActionDialog::insertExpression()
// display the expression builder
QgsExpressionBuilderDialog dlg( mActions->layer(), selText, this );
dlg.setWindowTitle( tr( "Insert expression" ) );

QgsDistanceArea myDa;
myDa.setSourceCrs( mActions->layer()->crs().srsid() );
myDa.setEllipsoidalMode( QgisApp::instance()->mapCanvas()->mapRenderer()->hasCrsTransformEnabled() );
myDa.setEllipsoid( QgsProject::instance()->readEntry( "Measure", "/Ellipsoid", GEO_NONE ) );
dlg.setGeomCalculator( myDa );

if ( dlg.exec() == QDialog::Accepted )
{
QString expression = dlg.expressionBuilder()->expressionText();
@@ -17,7 +17,8 @@
#include "qgsattributedialog.h"
#include "qgsfield.h"
#include "qgslogger.h"

#include "qgsmapcanvas.h"
#include "qgsproject.h"
#include "qgsvectorlayer.h"
#include "qgsvectordataprovider.h"
#include "qgsuniquevaluerenderer.h"
@@ -218,6 +219,13 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat
}
else
{

QgsDistanceArea myDa;

myDa.setSourceCrs( vl->crs().srsid() );
myDa.setEllipsoidalMode( QgisApp::instance()->mapCanvas()->mapRenderer()->hasCrsTransformEnabled() );
myDa.setEllipsoid( QgsProject::instance()->readEntry( "Measure", "/Ellipsoid", GEO_NONE ) );

for ( QgsFieldMap::const_iterator it = theFieldMap.begin(); it != theFieldMap.end(); ++it )
{
QList<QWidget *> myWidgets = mDialog->findChildren<QWidget*>( it->name() );
@@ -258,6 +266,8 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat
}
}

exp.setGeomCalculator( myDa );

QVariant value = exp.evaluate( mFeature, vl->pendingFields() );

if ( !exp.hasEvalError() )
@@ -32,6 +32,7 @@
#include "qgssearchquerybuilder.h"
#include "qgslogger.h"
#include "qgsmapcanvas.h"
#include "qgsproject.h"
#include "qgsfieldcalculator.h"
#include "qgsfeatureaction.h"
#include "qgsattributeaction.h"
@@ -536,6 +537,13 @@ void QgsAttributeTableDialog::updateSelectionFromLayer()

void QgsAttributeTableDialog::doSearch( QString searchString )
{

QgsDistanceArea myDa;

myDa.setSourceCrs( mLayer->crs().srsid() );
myDa.setEllipsoidalMode( QgisApp::instance()->mapCanvas()->mapRenderer()->hasCrsTransformEnabled() );
myDa.setEllipsoid( QgsProject::instance()->readEntry( "Measure", "/Ellipsoid", GEO_NONE ) );

// parse search string and build parsed tree
QgsExpression search( searchString );
if ( search.hasParserError() )
@@ -556,6 +564,7 @@ void QgsAttributeTableDialog::doSearch( QString searchString )
QApplication::setOverrideCursor( Qt::WaitCursor );
mSelectedFeatures.clear();

search.setGeomCalculator( myDa );
if ( cbxSearchSelectedOnly->isChecked() )
{
QgsFeatureList selectedFeatures = mLayer->selectedFeatures();
@@ -13,12 +13,17 @@
* *
***************************************************************************/

#include "qgisapp.h"
#include "qgsfieldcalculator.h"
#include "qgsdistancearea.h"
#include "qgsexpression.h"
#include "qgsmapcanvas.h"
#include "qgsproject.h"
#include "qgsvectordataprovider.h"
#include "qgsvectorlayer.h"

#include <QMessageBox>
#include <QSettings>

QgsFieldCalculator::QgsFieldCalculator( QgsVectorLayer* vl )
: QDialog()
@@ -78,6 +83,15 @@ QgsFieldCalculator::~QgsFieldCalculator()

void QgsFieldCalculator::accept()
{

// Set up QgsDistanceArea each time we (re-)calculate
QgsDistanceArea myDa;

myDa.setSourceCrs( mVectorLayer->crs().srsid() );
myDa.setEllipsoidalMode( QgisApp::instance()->mapCanvas()->mapRenderer()->hasCrsTransformEnabled() );
myDa.setEllipsoid( QgsProject::instance()->readEntry( "Measure", "/Ellipsoid", GEO_NONE ) );


QString calcString = builder->expressionText();
QgsExpression exp( calcString );

@@ -163,6 +177,7 @@ void QgsFieldCalculator::accept()
}

exp.setCurrentRowNumber( rownum );
exp.setGeomCalculator( myDa );

QVariant value = exp.evaluate( &feature );
if ( exp.hasEvalError() )
@@ -25,7 +25,8 @@
#include "qgslabelengineconfigdialog.h"
#include "qgsexpressionbuilderdialog.h"
#include "qgsexpression.h"
#include "qgsmapcanvas.h"
#include "qgisapp.h"
#include "qgsproject.h"
#include "qgscharacterselectdialog.h"

#include <QColorDialog>
@@ -901,6 +902,13 @@ void QgsLabelingGui::showExpressionDialog()
{
QgsExpressionBuilderDialog dlg( mLayer, cboFieldName->currentText() , this );
dlg.setWindowTitle( tr( "Expression based label" ) );

QgsDistanceArea myDa;
myDa.setSourceCrs( mLayer->crs().srsid() );
myDa.setEllipsoidalMode( QgisApp::instance()->mapCanvas()->mapRenderer()->hasCrsTransformEnabled() );
myDa.setEllipsoid( QgsProject::instance()->readEntry( "Measure", "/Ellipsoid", GEO_NONE ) );
dlg.setGeomCalculator( myDa );

if ( dlg.exec() == QDialog::Accepted )
{
QString expression = dlg.expressionText();
@@ -214,7 +214,8 @@ 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", GEO_NONE ).toString();

QString ellipsoid = QgsProject::instance()->readEntry( "Measure", "/Ellipsoid", GEO_NONE );

if ( identifyValue <= 0.0 )
identifyValue = QGis::DEFAULT_IDENTIFY_RADIUS;
@@ -19,6 +19,7 @@
#include "qgslogger.h"
#include "qgsmapcanvas.h"
#include "qgsmaptopixel.h"
#include "qgsproject.h"
#include "qgsrubberband.h"
#include <QMouseEvent>
#include <QSettings>
@@ -182,7 +183,7 @@ void QgsMapToolMeasureAngle::updateSettings()
void QgsMapToolMeasureAngle::configureDistanceArea()
{
QSettings settings;
QString ellipsoidId = settings.value( "/qgis/measure/ellipsoid", GEO_NONE ).toString();
QString ellipsoidId = QgsProject::instance()->readEntry( "Measure", "/Ellipsoid", GEO_NONE );
mDa.setSourceCrs( mCanvas->mapRenderer()->destinationCrs().srsid() );
mDa.setEllipsoid( ellipsoidId );
// Only use ellipsoidal calculation when project wide transformation is enabled.
@@ -22,6 +22,7 @@
#include "qgsdistancearea.h"
#include "qgsmapcanvas.h"
#include "qgsmaprenderer.h"
#include "qgsproject.h"
#include "qgscoordinatereferencesystem.h"

#include <QCloseEvent>
@@ -60,7 +61,7 @@ void QgsMeasureDialog::updateSettings()
mDisplayUnits = QGis::fromLiteral( settings.value( "/qgis/measure/displayunits", QGis::toLiteral( QGis::Meters ) ).toString() );
// Configure QgsDistanceArea
mDa.setSourceCrs( mTool->canvas()->mapRenderer()->destinationCrs().srsid() );
mDa.setEllipsoid( settings.value( "/qgis/measure/ellipsoid", GEO_NONE ).toString() );
mDa.setEllipsoid( QgsProject::instance()->readEntry( "Measure", "/Ellipsoid", GEO_NONE ) );
// Only use ellipsoidal calculation when project wide transformation is enabled.
if ( mTool->canvas()->mapRenderer()->hasCrsTransformEnabled() )
{

0 comments on commit 53790ad

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