Skip to content

Commit

Permalink
Initialize distance/area calculator only if we will be doing any calc…
Browse files Browse the repository at this point in the history
…ulations

(saves crs lookups when creating search tree nodes)


git-svn-id: http://svn.osgeo.org/qgis/trunk@13177 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Mar 28, 2010
1 parent a066fe3 commit 0d2e05f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
38 changes: 29 additions & 9 deletions src/core/qgssearchtreenode.cpp
Expand Up @@ -18,6 +18,7 @@
/* $Id$ */

#include "qgslogger.h"
#include "qgsdistancearea.h"
#include "qgsfield.h"
#include "qgsgeometry.h"
#include "qgssearchtreenode.h"
Expand All @@ -42,6 +43,8 @@ QgsSearchTreeNode::QgsSearchTreeNode( double number )
mNumber = number;
mLeft = NULL;
mRight = NULL;

init();
}


Expand All @@ -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();
}


Expand All @@ -80,6 +76,8 @@ QgsSearchTreeNode::QgsSearchTreeNode( QString text, bool isColumnRef )
mText = text;
stripText();
}

init();
}


Expand All @@ -100,6 +98,8 @@ QgsSearchTreeNode::QgsSearchTreeNode( const QgsSearchTreeNode& node )
mRight = new QgsSearchTreeNode( *node.mRight );
else
mRight = NULL;

init();
}


Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions src/core/qgssearchtreenode.h
Expand Up @@ -24,10 +24,10 @@
#include <QString>
#include <QVariant>

#include <qgsdistancearea.h>
#include <qgsfield.h>
#include <qgsfeature.h>

class QgsDistanceArea;
class QgsSearchTreeValue;

/** \ingroup core
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 0d2e05f

Please sign in to comment.