[QGIS Commit] r13524 - trunk/qgis/src/providers/postgres

svn_qgis at osgeo.org svn_qgis at osgeo.org
Tue May 18 07:27:50 EDT 2010


Author: jef
Date: 2010-05-18 07:27:48 -0400 (Tue, 18 May 2010)
New Revision: 13524

Modified:
   trunk/qgis/src/providers/postgres/qgspostgresprovider.cpp
   trunk/qgis/src/providers/postgres/qgspostgresprovider.h
Log:
postgres provider: lazy feature count

Modified: trunk/qgis/src/providers/postgres/qgspostgresprovider.cpp
===================================================================
--- trunk/qgis/src/providers/postgres/qgspostgresprovider.cpp	2010-05-18 10:26:11 UTC (rev 13523)
+++ trunk/qgis/src/providers/postgres/qgspostgresprovider.cpp	2010-05-18 11:27:48 UTC (rev 13524)
@@ -139,7 +139,7 @@
 
   deduceEndian();
   calculateExtents();
-  getFeatureCount();
+  featuresCounted = -1;
 
   // set the primary key
   getPrimaryKey();
@@ -735,14 +735,6 @@
   return geomType;
 }
 
-/**
- * Return the feature type
- */
-long QgsPostgresProvider::featureCount() const
-{
-  return featuresCounted;
-}
-
 const QgsField &QgsPostgresProvider::field( int index ) const
 {
   QgsFieldMap::const_iterator it = attributeFields.find( index );
@@ -2753,14 +2745,20 @@
   setDataSourceUri( mUri.uri() );
 
   // need to recalculate the number of features...
-  getFeatureCount();
+  featuresCounted = -1;
   calculateExtents();
 
   return true;
 }
 
-long QgsPostgresProvider::getFeatureCount()
+/**
+ * Return the feature count
+ */
+long QgsPostgresProvider::featureCount() const
 {
+  if( featuresCounted >= 0 )
+    return featuresCounted;
+
   // get total number of features
 
   // First get an approximate count; then delegate to
@@ -2783,12 +2781,12 @@
 
   Result result = connectionRO->PQexec( sql );
 
-  QgsDebugMsg( "Approximate Number of features as text: " +
+  QgsDebugMsg( "number of features as text: " +
                QString::fromUtf8( PQgetvalue( result, 0, 0 ) ) );
 
   featuresCounted = QString::fromUtf8( PQgetvalue( result, 0, 0 ) ).toLong();
 
-  QgsDebugMsg( "Approximate Number of features: " + QString::number( featuresCounted ) );
+  QgsDebugMsg( "number of features: " + QString::number( featuresCounted ) );
 
   return featuresCounted;
 }

Modified: trunk/qgis/src/providers/postgres/qgspostgresprovider.h
===================================================================
--- trunk/qgis/src/providers/postgres/qgspostgresprovider.h	2010-05-18 10:26:11 UTC (rev 13523)
+++ trunk/qgis/src/providers/postgres/qgspostgresprovider.h	2010-05-18 11:27:48 UTC (rev 13524)
@@ -446,7 +446,7 @@
     /**
      * Number of features in the layer
      */
-    long featuresCounted;
+    mutable long featuresCounted;
 
     /**
      * Feature queue that GetNextFeature will retrieve from
@@ -576,9 +576,6 @@
 
     int enabledCapabilities;
 
-    //! Get the feature count based on the where clause
-    long getFeatureCount();
-
     //! Calculate the extents of the layer
     void calculateExtents();
 



More information about the QGIS-commit mailing list