Initialize distance/area calculator only if we will be doing any calculations

(saves crs lookups when creating search tree nodes)


git-svn-id: http://svn.osgeo.org/qgis/trunk@13177 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
wonder 2010-03-28 09:44:13 +00:00
parent a066fe33eb
commit 0d2e05fada
2 changed files with 34 additions and 11 deletions

View File

@ -18,6 +18,7 @@
/* $Id$ */
#include "qgslogger.h"
#include "qgsdistancearea.h"
#include "qgsfield.h"
#include "qgsgeometry.h"
#include "qgssearchtreenode.h"
@ -42,6 +43,8 @@ QgsSearchTreeNode::QgsSearchTreeNode( double number )
mNumber = number;
mLeft = NULL;
mRight = NULL;
init();
}
@ -53,14 +56,7 @@ QgsSearchTreeNode::QgsSearchTreeNode( Operator op, QgsSearchTreeNode* left,
mLeft = left;
mRight = right;
if ( mOp == opLENGTH || mOp == opAREA )
{
//initialize QgsDistanceArea
mCalc.setProjectionsEnabled( false );
QSettings settings;
QString ellipsoid = settings.value( "/qgis/measure/ellipsoid", "WGS84" ).toString();
mCalc.setEllipsoid( ellipsoid );
}
init();
}
@ -80,6 +76,8 @@ QgsSearchTreeNode::QgsSearchTreeNode( QString text, bool isColumnRef )
mText = text;
stripText();
}
init();
}
@ -100,6 +98,8 @@ QgsSearchTreeNode::QgsSearchTreeNode( const QgsSearchTreeNode& node )
mRight = new QgsSearchTreeNode( *node.mRight );
else
mRight = NULL;
init();
}
@ -112,6 +112,26 @@ QgsSearchTreeNode::~QgsSearchTreeNode()
if ( mRight )
delete mRight;
delete mCalc;
}
void QgsSearchTreeNode::init()
{
if ( mType == tOperator && ( mOp == opLENGTH || mOp == opAREA ) )
{
//initialize QgsDistanceArea
mCalc = new QgsDistanceArea;
mCalc->setProjectionsEnabled( false );
QSettings settings;
QString ellipsoid = settings.value( "/qgis/measure/ellipsoid", "WGS84" ).toString();
mCalc->setEllipsoid( ellipsoid );
}
else
{
mCalc = NULL;
}
}
void QgsSearchTreeNode::stripText()
@ -432,7 +452,7 @@ QgsSearchTreeValue QgsSearchTreeNode::valueAgainst( const QgsFieldMap& fields, c
{
return QgsSearchTreeValue( 0 );
}
return QgsSearchTreeValue( mCalc.measure( geom ) );
return QgsSearchTreeValue( mCalc->measure( geom ) );
}
//string operations with one argument

View File

@ -24,10 +24,10 @@
#include <QString>
#include <QVariant>
#include <qgsdistancearea.h>
#include <qgsfield.h>
#include <qgsfeature.h>
class QgsDistanceArea;
class QgsSearchTreeValue;
/** \ingroup core
@ -147,6 +147,9 @@ class CORE_EXPORT QgsSearchTreeNode
//! strips mText when node is of string type
void stripText();
//! initialize node's internals
void init();
private:
//! node type
@ -164,7 +167,7 @@ class CORE_EXPORT QgsSearchTreeNode
QgsSearchTreeNode* mRight;
/**For length() and area() functions*/
QgsDistanceArea mCalc;
QgsDistanceArea* mCalc;
};
// TODO: put it into separate file