From 0d2e05fadab57d798ce65e9a182b5f35d21911a6 Mon Sep 17 00:00:00 2001 From: wonder Date: Sun, 28 Mar 2010 09:44:13 +0000 Subject: [PATCH] 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 --- src/core/qgssearchtreenode.cpp | 38 ++++++++++++++++++++++++++-------- src/core/qgssearchtreenode.h | 7 +++++-- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/src/core/qgssearchtreenode.cpp b/src/core/qgssearchtreenode.cpp index a1872c9a8fa..a121bab1538 100644 --- a/src/core/qgssearchtreenode.cpp +++ b/src/core/qgssearchtreenode.cpp @@ -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 diff --git a/src/core/qgssearchtreenode.h b/src/core/qgssearchtreenode.h index af69426ab76..934abfb7f04 100644 --- a/src/core/qgssearchtreenode.h +++ b/src/core/qgssearchtreenode.h @@ -24,10 +24,10 @@ #include #include -#include #include #include +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