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

View File

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