Showing with 27 additions and 15 deletions.
  1. +19 −14 src/core/qgsvectorlayer.cpp
  2. +1 −0 src/core/qgsvectorlayer.h
  3. +7 −1 src/core/raster/qgsrasterdataprovider.h
33 changes: 19 additions & 14 deletions src/core/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
8 changes: 7 additions & 1 deletion src/core/raster/qgsrasterdataprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,13 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider, public QgsRast
/* It makes no sense to set input on provider */
bool setInput( QgsRasterInterface* input ) { Q_UNUSED( input ); return false; }

/** \brief Renders the layer as an image */
/** \brief Renders the layer as an image
\note When render caching (/qgis/enable_render_caching) is on the wms
provider doesn't wait for the reply of the getmap request or all
tiles replies and can return incomplete images.
Temporarily disable render caching if you require the complete
wms image in the first call.
*/
virtual QImage* draw( const QgsRectangle & viewExtent, int pixelWidth, int pixelHeight ) = 0;

/** Get the extent of the data source.
Expand Down