@@ -134,7 +134,7 @@ QgsPostgresProvider::QgsPostgresProvider( QString const & uri )
134134 }
135135
136136 deduceEndian ();
137- calculateExtents ();
137+ layerExtent. setMinimal ();
138138 featuresCounted = -1 ;
139139
140140 // set the primary key
@@ -717,12 +717,6 @@ void QgsPostgresProvider::setExtent( QgsRectangle& newExtent )
717717 layerExtent.setYMinimum ( newExtent.yMinimum () );
718718}
719719
720- // TODO - make this function return the real extent_
721- QgsRectangle QgsPostgresProvider::extent ()
722- {
723- return layerExtent; // extent_->MinX, extent_->MinY, extent_->MaxX, extent_->MaxY);
724- }
725-
726720/* *
727721 * Return the feature type
728722 */
@@ -2740,9 +2734,8 @@ bool QgsPostgresProvider::setSubsetString( QString theSQL )
27402734 // uri? Perhaps this needs some rationalisation.....
27412735 setDataSourceUri ( mUri .uri () );
27422736
2743- // need to recalculate the number of features...
27442737 featuresCounted = -1 ;
2745- calculateExtents ();
2738+ layerExtent. setMinimal ();
27462739
27472740 return true ;
27482741}
@@ -2752,16 +2745,13 @@ bool QgsPostgresProvider::setSubsetString( QString theSQL )
27522745 */
27532746long QgsPostgresProvider::featureCount () const
27542747{
2755- if ( featuresCounted >= 0 )
2748+ if ( featuresCounted >= 0 )
27562749 return featuresCounted;
27572750
27582751 // get total number of features
2759-
2760- // First get an approximate count; then delegate to
2761- // a thread the task of getting the full count.
27622752 QString sql;
27632753
2764- if ( !isQuery && mUseEstimatedMetadata && sqlWhereClause. isEmpty () )
2754+ if ( !isQuery && mUseEstimatedMetadata )
27652755 {
27662756 sql = QString ( " select reltuples::int from pg_catalog.pg_class where oid=regclass(%1)::oid" ).arg ( quotedValue ( mQuery ) );
27672757 }
@@ -2787,130 +2777,79 @@ long QgsPostgresProvider::featureCount() const
27872777 return featuresCounted;
27882778}
27892779
2790- void QgsPostgresProvider::calculateExtents ()
2780+ QgsRectangle QgsPostgresProvider::extent ()
27912781{
2792- QString sql;
2793- Result result;
2794- QString ext;
2795-
2796- // get the extents
2797- if ( !isQuery && ( mUseEstimatedMetadata || sqlWhereClause.isEmpty () ) )
2782+ if ( layerExtent.isEmpty () )
27982783 {
2799- // do stats exists?
2800- sql = QString ( " SELECT COUNT(*) FROM pg_stats WHERE schemaname=%1 AND tablename=%2 AND attname=%3" )
2801- .arg ( quotedValue ( mSchemaName ) )
2802- .arg ( quotedValue ( mTableName ) )
2803- .arg ( quotedValue ( geometryColumn ) );
2804- result = connectionRO->PQexec ( sql );
2805- if ( PQresultStatus ( result ) == PGRES_TUPLES_OK && PQntuples ( result ) == 1 )
2784+ QString sql;
2785+ Result result;
2786+ QString ext;
2787+
2788+ // get the extents
2789+ if ( !isQuery && ( mUseEstimatedMetadata || sqlWhereClause.isEmpty () ) )
28062790 {
2807- if ( QString::fromUtf8 ( PQgetvalue ( result, 0 , 0 ) ).toInt () > 0 )
2791+ // do stats exists?
2792+ sql = QString ( " SELECT COUNT(*) FROM pg_stats WHERE schemaname=%1 AND tablename=%2 AND attname=%3" )
2793+ .arg ( quotedValue ( mSchemaName ) )
2794+ .arg ( quotedValue ( mTableName ) )
2795+ .arg ( quotedValue ( geometryColumn ) );
2796+ result = connectionRO->PQexec ( sql );
2797+ if ( PQresultStatus ( result ) == PGRES_TUPLES_OK && PQntuples ( result ) == 1 )
28082798 {
2809- sql = QString ( " select estimated_extent(%1,%2,%3)" )
2810- .arg ( quotedValue ( mSchemaName ) )
2811- .arg ( quotedValue ( mTableName ) )
2812- .arg ( quotedValue ( geometryColumn ) );
2813- result = connectionRO->PQexec ( sql );
2814- if ( PQresultStatus ( result ) == PGRES_TUPLES_OK && PQntuples ( result ) == 1 )
2815- ext = PQgetvalue ( result, 0 , 0 );
2799+ if ( QString::fromUtf8 ( PQgetvalue ( result, 0 , 0 ) ).toInt () > 0 )
2800+ {
2801+ sql = QString ( " select estimated_extent(%1,%2,%3)" )
2802+ .arg ( quotedValue ( mSchemaName ) )
2803+ .arg ( quotedValue ( mTableName ) )
2804+ .arg ( quotedValue ( geometryColumn ) );
2805+ result = connectionRO->PQexec ( sql );
2806+ if ( PQresultStatus ( result ) == PGRES_TUPLES_OK && PQntuples ( result ) == 1 )
2807+ ext = PQgetvalue ( result, 0 , 0 );
2808+ }
28162809 }
2817- }
2818- else
2819- {
2820- QgsDebugMsg ( QString ( " no column statistics for %1.%2.%3" ).arg ( mSchemaName ).arg ( mTableName ).arg ( geometryColumn ) );
2821- }
2822- }
2823-
2824- if ( ext.isEmpty () )
2825- {
2826- sql = QString ( " select extent(%1) from %2" )
2827- .arg ( quotedIdentifier ( geometryColumn ) )
2828- .arg ( mQuery );
2829-
2830- if ( !sqlWhereClause.isEmpty () )
2831- sql += QString ( " where %1" ).arg ( sqlWhereClause );
2832-
2833- result = connectionRO->PQexec ( sql );
2834- if ( PQresultStatus ( result ) != PGRES_TUPLES_OK )
2835- connectionRO->PQexecNR ( " ROLLBACK" );
2836- else if ( PQntuples ( result ) == 1 )
2837- ext = PQgetvalue ( result, 0 , 0 );
2838- }
2839-
2840- QgsDebugMsg ( " Got extents using: " + sql );
2841-
2842- QRegExp rx ( " \\ ((.+) (.+),(.+) (.+)\\ )" );
2843- if ( ext.contains ( rx ) )
2844- {
2845- QStringList ex = rx.capturedTexts ();
2846-
2847- layerExtent.setXMinimum ( ex[1 ].toDouble () );
2848- layerExtent.setYMinimum ( ex[2 ].toDouble () );
2849- layerExtent.setXMaximum ( ex[3 ].toDouble () );
2850- layerExtent.setYMaximum ( ex[4 ].toDouble () );
2851- }
2852- else
2853- {
2854- QgsDebugMsg ( " extents query failed" );
2855- }
2856-
2857- QgsDebugMsg ( " Set extents to: " + layerExtent.toString () );
2858- }
2859-
2860- /* *
2861- * Event sink for events from threads
2862- */
2863- void QgsPostgresProvider::customEvent ( QEvent * e )
2864- {
2865- QgsDebugMsg ( " received a custom event " + QString::number ( e->type () ) );
2866-
2867- switch (( int ) e->type () )
2868- {
2869- case QGis::ProviderExtentCalcEvent:
2870-
2871- QgsDebugMsg ( " extent has been calculated" );
2872-
2873- // Collect the new extent from the event and set this layer's
2874- // extent with it.
2875-
2810+ else
28762811 {
2877- QgsRectangle* r = (( QgsProviderExtentCalcEvent* ) e )->layerExtent ();
2878- setExtent ( *r );
2812+ QgsDebugMsg ( QString ( " no column statistics for %1.%2.%3" ).arg ( mSchemaName ).arg ( mTableName ).arg ( geometryColumn ) );
28792813 }
2814+ }
28802815
2881- QgsDebugMsg ( " new extent has been saved" );
2882-
2883- QgsDebugMsg ( " Set extent to: " + layerExtent.toString () );
2884-
2885- QgsDebugMsg ( " emitting fullExtentCalculated()" );
2886-
2887- emit fullExtentCalculated ();
2888-
2889- // TODO: Only uncomment this when the overview map canvas has been subclassed
2890- // from the QgsMapCanvas
2891-
2892- // QgsDebugMsg("emitting repaintRequested()");
2893- // emit repaintRequested();
2894-
2895- break ;
2816+ if ( ext.isEmpty () )
2817+ {
2818+ sql = QString ( " select extent(%1) from %2" )
2819+ .arg ( quotedIdentifier ( geometryColumn ) )
2820+ .arg ( mQuery );
28962821
2897- case QGis::ProviderCountCalcEvent:
2822+ if ( !sqlWhereClause.isEmpty () )
2823+ sql += QString ( " where %1" ).arg ( sqlWhereClause );
28982824
2899- QgsDebugMsg ( " count has been calculated" );
2825+ result = connectionRO->PQexec ( sql );
2826+ if ( PQresultStatus ( result ) != PGRES_TUPLES_OK )
2827+ connectionRO->PQexecNR ( " ROLLBACK" );
2828+ else if ( PQntuples ( result ) == 1 )
2829+ ext = PQgetvalue ( result, 0 , 0 );
2830+ }
29002831
2901- featuresCounted = (( QgsProviderCountCalcEvent* ) e )-> featuresCounted ( );
2832+ QgsDebugMsg ( " Got extents using: " + sql );
29022833
2903- QgsDebugMsg ( " count is " + QString::number ( featuresCounted ) );
2834+ QRegExp rx ( " \\ ((.+) (.+),(.+) (.+)\\ )" );
2835+ if ( ext.contains ( rx ) )
2836+ {
2837+ QStringList ex = rx.capturedTexts ();
29042838
2905- break ;
2839+ layerExtent.setXMinimum ( ex[1 ].toDouble () );
2840+ layerExtent.setYMinimum ( ex[2 ].toDouble () );
2841+ layerExtent.setXMaximum ( ex[3 ].toDouble () );
2842+ layerExtent.setYMaximum ( ex[4 ].toDouble () );
2843+ }
2844+ else
2845+ {
2846+ QgsDebugMsg ( " extents query failed" );
2847+ }
29062848
2907- default :
2908- // do nothing
2909- break ;
2849+ QgsDebugMsg ( " Set extents to: " + layerExtent.toString () );
29102850 }
29112851
2912- QgsDebugMsg ( " Finished processing custom event " + QString::number ( e->type () ) );
2913-
2852+ return layerExtent;
29142853}
29152854
29162855
0 commit comments