Skip to content

Commit d83af5b

Browse files
author
wonder
committed
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/qgis@13177 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 50298dd commit d83af5b

File tree

2 files changed

+34
-11
lines changed

2 files changed

+34
-11
lines changed

src/core/qgssearchtreenode.cpp

+29-9
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
/* $Id$ */
1919

2020
#include "qgslogger.h"
21+
#include "qgsdistancearea.h"
2122
#include "qgsfield.h"
2223
#include "qgsgeometry.h"
2324
#include "qgssearchtreenode.h"
@@ -42,6 +43,8 @@ QgsSearchTreeNode::QgsSearchTreeNode( double number )
4243
mNumber = number;
4344
mLeft = NULL;
4445
mRight = NULL;
46+
47+
init();
4548
}
4649

4750

@@ -53,14 +56,7 @@ QgsSearchTreeNode::QgsSearchTreeNode( Operator op, QgsSearchTreeNode* left,
5356
mLeft = left;
5457
mRight = right;
5558

56-
if ( mOp == opLENGTH || mOp == opAREA )
57-
{
58-
//initialize QgsDistanceArea
59-
mCalc.setProjectionsEnabled( false );
60-
QSettings settings;
61-
QString ellipsoid = settings.value( "/qgis/measure/ellipsoid", "WGS84" ).toString();
62-
mCalc.setEllipsoid( ellipsoid );
63-
}
59+
init();
6460
}
6561

6662

@@ -80,6 +76,8 @@ QgsSearchTreeNode::QgsSearchTreeNode( QString text, bool isColumnRef )
8076
mText = text;
8177
stripText();
8278
}
79+
80+
init();
8381
}
8482

8583

@@ -100,6 +98,8 @@ QgsSearchTreeNode::QgsSearchTreeNode( const QgsSearchTreeNode& node )
10098
mRight = new QgsSearchTreeNode( *node.mRight );
10199
else
102100
mRight = NULL;
101+
102+
init();
103103
}
104104

105105

@@ -112,6 +112,26 @@ QgsSearchTreeNode::~QgsSearchTreeNode()
112112

113113
if ( mRight )
114114
delete mRight;
115+
116+
delete mCalc;
117+
}
118+
119+
120+
void QgsSearchTreeNode::init()
121+
{
122+
if ( mType == tOperator && ( mOp == opLENGTH || mOp == opAREA ) )
123+
{
124+
//initialize QgsDistanceArea
125+
mCalc = new QgsDistanceArea;
126+
mCalc->setProjectionsEnabled( false );
127+
QSettings settings;
128+
QString ellipsoid = settings.value( "/qgis/measure/ellipsoid", "WGS84" ).toString();
129+
mCalc->setEllipsoid( ellipsoid );
130+
}
131+
else
132+
{
133+
mCalc = NULL;
134+
}
115135
}
116136

117137
void QgsSearchTreeNode::stripText()
@@ -432,7 +452,7 @@ QgsSearchTreeValue QgsSearchTreeNode::valueAgainst( const QgsFieldMap& fields, c
432452
{
433453
return QgsSearchTreeValue( 0 );
434454
}
435-
return QgsSearchTreeValue( mCalc.measure( geom ) );
455+
return QgsSearchTreeValue( mCalc->measure( geom ) );
436456
}
437457

438458
//string operations with one argument

src/core/qgssearchtreenode.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
#include <QString>
2525
#include <QVariant>
2626

27-
#include <qgsdistancearea.h>
2827
#include <qgsfield.h>
2928
#include <qgsfeature.h>
3029

30+
class QgsDistanceArea;
3131
class QgsSearchTreeValue;
3232

3333
/** \ingroup core
@@ -147,6 +147,9 @@ class CORE_EXPORT QgsSearchTreeNode
147147
//! strips mText when node is of string type
148148
void stripText();
149149

150+
//! initialize node's internals
151+
void init();
152+
150153
private:
151154

152155
//! node type
@@ -164,7 +167,7 @@ class CORE_EXPORT QgsSearchTreeNode
164167
QgsSearchTreeNode* mRight;
165168

166169
/**For length() and area() functions*/
167-
QgsDistanceArea mCalc;
170+
QgsDistanceArea* mCalc;
168171
};
169172

170173
// TODO: put it into separate file

0 commit comments

Comments
 (0)