Skip to content
Permalink
Browse files
Using QgsProject settings instead, not fully tested
  • Loading branch information
homann committed Nov 25, 2012
1 parent 47aed17 commit 194d94c5ed7b3b6d73d9494930e3de0c2139997e
@@ -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();
@@ -18,6 +18,7 @@
#include "qgsfield.h"
#include "qgslogger.h"
#include "qgsmapcanvas.h"
#include "qgsproject.h"
#include "qgsvectorlayer.h"
#include "qgsvectordataprovider.h"
#include "qgsuniquevaluerenderer.h"
@@ -220,11 +221,10 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat
{

QgsDistanceArea myDa;
QSettings settings;

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

for ( QgsFieldMap::const_iterator it = theFieldMap.begin(); it != theFieldMap.end(); ++it )
{
@@ -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"
@@ -538,11 +539,10 @@ void QgsAttributeTableDialog::doSearch( QString searchString )
{

QgsDistanceArea myDa;
QSettings settings;

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

// parse search string and build parsed tree
QgsExpression search( searchString );
@@ -18,6 +18,7 @@
#include "qgsdistancearea.h"
#include "qgsexpression.h"
#include "qgsmapcanvas.h"
#include "qgsproject.h"
#include "qgsvectordataprovider.h"
#include "qgsvectorlayer.h"

@@ -85,11 +86,10 @@ void QgsFieldCalculator::accept()

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

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


QString calcString = builder->expressionText();
@@ -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>
@@ -894,6 +895,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() )
{
@@ -59,6 +59,9 @@ const char * QgsProjectProperties::GEO_NONE_DESC = QT_TRANSLATE_NOOP( "QgsOption
QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *parent, Qt::WFlags fl )
: QDialog( parent, fl )
, mMapCanvas( mapCanvas )
, mEllipsoidList()
, mEllipsoidIndex( 0 )

{
setupUi( this );
connect( buttonBox, SIGNAL( accepted() ), this, SLOT( accept() ) );
@@ -114,7 +117,6 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa

QgsDebugMsg( "Setting upp ellipsoid" );

mEllipsoidIndex = 0;
populateEllipsoidList();

// Reading ellipsoid from setttings
@@ -138,6 +140,7 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa

updateEllipsoidUI( myIndex );


int dp = QgsProject::instance()->readNumEntry( "PositionPrecision", "/DecimalPlaces" );
spinBoxDP->setValue( dp );

@@ -553,12 +556,12 @@ void QgsProjectProperties::apply()
minor = QLocale::system().toDouble( leSemiMinor->text() );
}
QgsProject::instance()->writeEntry( "Measure", "/Ellipsoid", QString( "PARAMETER:%1:%2" )
.arg( major, 0, 'g', 17 )
.arg( minor, 0, 'g', 17 ) );
.arg( major, 0, 'g', 17 )
.arg( minor, 0, 'g', 17 ) );
}
else
{
QgsProject::instance()->writeEntry( "Measure", "/Ellipsoid", mEllipsoidList[ mEllipsoidIndex ].acronym );
QgsProject::instance()->writeEntry( "Measure", "/Ellipsoid", mEllipsoidList[ mEllipsoidIndex ].acronym );
}

//set the color for selections
@@ -1395,6 +1398,11 @@ void QgsProjectProperties::populateEllipsoidList()

void QgsProjectProperties::updateEllipsoidUI( int newIndex )
{
// Just return if the list isn't populated yet
if ( mEllipsoidList.isEmpty() )
{
return;
}
// Called whenever settings change, adjusts the UI accordingly
// Pre-select current ellipsoid

@@ -55,3 +55,9 @@ void QgsExpressionBuilderDialog::closeEvent( QCloseEvent *event )
QSettings settings;
settings.setValue( "/Windows/ExpressionBuilderDialog/geometry", saveGeometry() );
}

void QgsExpressionBuilderDialog::setGeomCalculator( const QgsDistanceArea & da )
{
// Store in child widget only.
builder->setGeomCalculator( da );
}
@@ -17,6 +17,7 @@
#define QGSEXPRESSIONBUILDERDIALOG_H

#include <QDialog>
#include "qgsdistancearea.h"
#include "ui_qgsexpressionbuilderdialogbase.h"

/** A generic dialog for building expression strings
@@ -34,6 +35,11 @@ class GUI_EXPORT QgsExpressionBuilderDialog : public QDialog, private Ui::QgsExp

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
@@ -242,8 +242,7 @@ bool QgsExpressionBuilderWidget::isExpressionValid()

void QgsExpressionBuilderWidget::setGeomCalculator( const QgsDistanceArea & da )
{
Q_UNUSED( da );
// TODO! FIXME!!!
mDa = da;
}

QString QgsExpressionBuilderWidget::expressionText()
@@ -278,16 +277,8 @@ void QgsExpressionBuilderWidget::on_txtExpressionString_textChanged()

if ( mLayer )
{
// Only set ellipsoid if we have layer...
QgsDistanceArea myDa;
QSettings settings;

myDa.setEllipsoid( settings.value( "/qgis/measure/ellipsoid", GEO_NONE ).toString() );
myDa.setSourceCrs( mLayer->crs().srsid() );
// myDa.setEllipsoidalMode(QgisApp::instance()->mapCanvas()->mapRenderer()->hasCrsTransformEnabled() );
myDa.setEllipsoidalMode( false );

exp.setGeomCalculator( myDa );
// Only set calculator if we have layer, else use default.
exp.setGeomCalculator( mDa );

if ( !mFeature.isValid() )
{
@@ -425,12 +416,12 @@ QString QgsExpressionBuilderWidget::loadFunctionHelp( QgsExpressionItem* express
return "";

QString helpContents;
// Return the function help that is set for the function if there is one.
// Return the function help that is set for the function if there is one.
if ( !expressionItem->getHelpText().isEmpty() )
{
QString myStyle = QgsApplication::reportStyleSheet();
helpContents = "<head><style>" + myStyle + "</style></head><body>" + expressionItem->getHelpText() + "</body>";
return helpContents;
QString myStyle = QgsApplication::reportStyleSheet();
helpContents = "<head><style>" + myStyle + "</style></head><body>" + expressionItem->getHelpText() + "</body>";
return helpContents;
}
// set up the path to the help file
QString helpFilesPath = QgsApplication::pkgDataPath() + "/resources/function_help/";
@@ -123,7 +123,8 @@ class GUI_EXPORT QgsExpressionBuilderWidget : public QWidget, private Ui::QgsExp

void loadFieldNames( QgsFieldMap fields );

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

@@ -181,6 +182,7 @@ class GUI_EXPORT QgsExpressionBuilderWidget : public QWidget, private Ui::QgsExp
QgsFeature mFeature;
QgsExpressionHighlighter* highlighter;
bool mExpressionValid;
QgsDistanceArea mDa;
};

#endif // QGSEXPRESSIONBUILDER_H

0 comments on commit 194d94c

Please sign in to comment.