[QGIS Commit] r13177 - trunk/qgis/src/core

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sun Mar 28 05:44:14 EDT 2010


Author: wonder
Date: 2010-03-28 05:44:13 -0400 (Sun, 28 Mar 2010)
New Revision: 13177

Modified:
   trunk/qgis/src/core/qgssearchtreenode.cpp
   trunk/qgis/src/core/qgssearchtreenode.h
Log:
Initialize distance/area calculator only if we will be doing any calculations
(saves crs lookups when creating search tree nodes)


Modified: trunk/qgis/src/core/qgssearchtreenode.cpp
===================================================================
--- trunk/qgis/src/core/qgssearchtreenode.cpp	2010-03-28 08:34:54 UTC (rev 13176)
+++ trunk/qgis/src/core/qgssearchtreenode.cpp	2010-03-28 09:44:13 UTC (rev 13177)
@@ -18,6 +18,7 @@
 /* $Id$ */
 
 #include "qgslogger.h"
+#include "qgsdistancearea.h"
 #include "qgsfield.h"
 #include "qgsgeometry.h"
 #include "qgssearchtreenode.h"
@@ -42,6 +43,8 @@
   mNumber = number;
   mLeft   = NULL;
   mRight  = NULL;
+
+  init();
 }
 
 
@@ -53,14 +56,7 @@
   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 @@
     mText = text;
     stripText();
   }
+
+  init();
 }
 
 
@@ -100,6 +98,8 @@
     mRight = new QgsSearchTreeNode( *node.mRight );
   else
     mRight = NULL;
+
+  init();
 }
 
 
@@ -112,8 +112,28 @@
 
   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()
 {
   // strip single quotes on start,end
@@ -432,7 +452,7 @@
         {
           return QgsSearchTreeValue( 0 );
         }
-        return QgsSearchTreeValue( mCalc.measure( geom ) );
+        return QgsSearchTreeValue( mCalc->measure( geom ) );
       }
 
       //string operations with one argument

Modified: trunk/qgis/src/core/qgssearchtreenode.h
===================================================================
--- trunk/qgis/src/core/qgssearchtreenode.h	2010-03-28 08:34:54 UTC (rev 13176)
+++ trunk/qgis/src/core/qgssearchtreenode.h	2010-03-28 09:44:13 UTC (rev 13177)
@@ -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 @@
     //! strips mText when node is of string type
     void stripText();
 
+    //! initialize node's internals
+    void init();
+
   private:
 
     //! node type
@@ -164,7 +167,7 @@
     QgsSearchTreeNode* mRight;
 
     /**For length() and area() functions*/
-    QgsDistanceArea mCalc;
+    QgsDistanceArea* mCalc;
 };
 
 // TODO: put it into separate file



More information about the QGIS-commit mailing list