Skip to content

Commit

Permalink
vector layer: fix lazy extent calculation (fixes #9608; introduced in 5…
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Feb 20, 2014
1 parent 55cb04c commit a1ada3c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
33 changes: 19 additions & 14 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -136,6 +136,7 @@ QgsVectorLayer::QgsVectorLayer( QString vectorLayerPath,
, mDiagramRenderer( 0 )
, mDiagramLayerSettings( 0 )
, mValidExtent( false )
, mLazyExtent( true )
, mSymbolFeatureCounted( false )
, mCurrentRendererContext( 0 )

Expand Down Expand Up @@ -1179,15 +1180,30 @@ void QgsVectorLayer::setExtent( const QgsRectangle &r )

QgsRectangle QgsVectorLayer::extent()
{
if ( mValidExtent )
return QgsMapLayer::extent();

QgsRectangle rect;
rect.setMinimal();

if ( !hasGeometryType() )
return rect;

if ( !mValidExtent && mLazyExtent && mDataProvider )
{
// get the extent
QgsRectangle mbr = mDataProvider->extent();

// show the extent
QString s = mbr.toString();

QgsDebugMsg( "Extent of layer: " + s );
// store the extent
setExtent( mbr );

mLazyExtent = false;
}

if( mValidExtent )
return QgsMapLayer::extent();

if ( !mDataProvider )
{
QgsDebugMsg( "invoked with null mDataProvider" );
Expand Down Expand Up @@ -1704,17 +1720,6 @@ bool QgsVectorLayer::setDataProvider( QString const & provider )
// TODO: Check if the provider has the capability to send fullExtentCalculated
connect( mDataProvider, SIGNAL( fullExtentCalculated() ), this, SLOT( updateExtents() ) );

#if 0 // allow lazy calculation of extents and give the creator of the vector layer a chance to 'manually' setExtent
// get the extent
QgsRectangle mbr = mDataProvider->extent();

// show the extent
QString s = mbr.toString();
QgsDebugMsg( "Extent of layer: " + s );
// store the extent
setExtent( mbr );
#endif

// get and store the feature type
mWkbType = mDataProvider->geometryType();

Expand Down
1 change: 1 addition & 0 deletions src/core/qgsvectorlayer.h
Expand Up @@ -1756,6 +1756,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
QgsDiagramLayerSettings *mDiagramLayerSettings;

bool mValidExtent;
bool mLazyExtent;

// Features in renderer classes counted
bool mSymbolFeatureCounted;
Expand Down

0 comments on commit a1ada3c

Please sign in to comment.