[QGIS Commit] r13677 - branches/threading-branch/src/core
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Mon Jun 7 08:53:19 EDT 2010
Author: wonder
Date: 2010-06-07 08:53:18 -0400 (Mon, 07 Jun 2010)
New Revision: 13677
Modified:
branches/threading-branch/src/core/qgsmaprenderer.cpp
branches/threading-branch/src/core/qgsmaprenderer.h
Log:
More housekeeping in QgsMapRenderer
Modified: branches/threading-branch/src/core/qgsmaprenderer.cpp
===================================================================
--- branches/threading-branch/src/core/qgsmaprenderer.cpp 2010-06-07 11:18:24 UTC (rev 13676)
+++ branches/threading-branch/src/core/qgsmaprenderer.cpp 2010-06-07 12:53:18 UTC (rev 13677)
@@ -213,6 +213,8 @@
QgsDebugMsg( "========== Rendering ==========" );
+ QgsDebugMsg( "caching enabled? " + QString::number(mCachingEnabled) );
+
if ( mExtent.isEmpty() )
{
QgsDebugMsg( "empty extent... not rendering" );
@@ -295,20 +297,9 @@
QgsOverlayObjectPositionManager* overlayManager = overlayManagerFromSettings();
- // render all layers in the stack, starting at the base
- QListIterator<QString> li( mLayerSet );
- li.toBack();
- while ( li.hasPrevious() )
- {
- if ( mRenderContext.renderingStopped() )
- {
- break;
- }
+ // do the rendering of all layers
+ renderLayers( overlayManager );
- QString layerId = li.previous();
- renderLayer( layerId, mySameAsLastFlag, overlayManager );
- }
-
QgsDebugMsg( "Done rendering map layers" );
// render labels for vector layers (not using PAL)
@@ -344,106 +335,99 @@
}
-
-
-void QgsMapRenderer::renderLayer( QString layerId, bool mySameAsLastFlag, QgsOverlayObjectPositionManager* overlayManager )
+void QgsMapRenderer::renderLayers( QgsOverlayObjectPositionManager* overlayManager )
{
+ // render all layers in the stack, starting at the base
+ QListIterator<QString> li( mLayerSet );
+ li.toBack();
+ while ( li.hasPrevious() )
+ {
+ if ( mRenderContext.renderingStopped() )
+ {
+ break;
+ }
- // Store the painter in case we need to swap it out for the
- // cache painter
- QPainter * mypContextPainter = mRenderContext.painter();
+ QString layerId = li.previous();
- QgsDebugMsg( "Rendering at layer item " + layerId );
+ QgsDebugMsg( "Rendering at layer item " + layerId );
- //emit drawingProgress(myRenderCounter++, mLayerSet.size());
- QgsMapLayer *ml = QgsMapLayerRegistry::instance()->mapLayer( layerId );
+ //emit drawingProgress(myRenderCounter++, mLayerSet.size());
+ QgsMapLayer *ml = QgsMapLayerRegistry::instance()->mapLayer( layerId );
- if ( !ml )
- {
- QgsDebugMsg( "Layer not found in registry!" );
- return;
- }
+ if ( !ml )
+ {
+ QgsDebugMsg( "Layer not found in registry!" );
+ return;
+ }
- QgsDebugMsg( "Rendering layer " + ml->name() );
- QgsDebugMsg( " Layer minscale " + QString( "%1" ).arg( ml->minimumScale() ) );
- QgsDebugMsg( " Layer maxscale " + QString( "%1" ).arg( ml->maximumScale() ) );
- QgsDebugMsg( " Scale dep. visibility enabled? " + QString( "%1" ).arg( ml->hasScaleBasedVisibility() ) );
- QgsDebugMsg( " Input extent: " + ml->extent().toString() );
+ //QgsDebugMsg( " Layer minscale " + QString( "%1" ).arg( ml->minimumScale() ) );
+ //QgsDebugMsg( " Layer maxscale " + QString( "%1" ).arg( ml->maximumScale() ) );
+ //QgsDebugMsg( " Scale dep. visibility enabled? " + QString( "%1" ).arg( ml->hasScaleBasedVisibility() ) );
+ //QgsDebugMsg( " Input extent: " + ml->extent().toString() );
- if ( ml->hasScaleBasedVisibility() && ( ml->minimumScale() > mScale || ml->maximumScale() < mScale ) && ! mOverview )
- {
- QgsDebugMsg( "Layer not rendered because it is not within the defined "
- "visibility scale range" );
- return;
- }
+ if ( ml->hasScaleBasedVisibility() && ( ml->minimumScale() > mScale || ml->maximumScale() < mScale ) && ! mOverview )
+ {
+ QgsDebugMsg( "Layer not rendered because it is not within the defined "
+ "visibility scale range" );
+ return;
+ }
- connect( ml, SIGNAL( drawingProgress( int, int ) ), this, SLOT( onDrawingProgress( int, int ) ) );
+ QgsCoordinateTransform* ct = NULL;
+ if ( hasCrsTransformEnabled() )
+ {
+ ct = new QgsCoordinateTransform( ml->srs(), *mDestCRS );
+ }
+ mRenderContext.setCoordinateTransform( ct );
- //
- // Now do the call to the layer that actually does
- // the rendering work!
- //
+ //create overlay objects for features within the view extent
+ if ( ml->type() == QgsMapLayer::VectorLayer && overlayManager )
+ {
+ QgsVectorLayer* vl = qobject_cast<QgsVectorLayer *>( ml );
+ if ( vl )
+ {
+ overlayManager->addOverlaysForLayer( vl, mRenderContext );
+ }
+ }
- bool split = false;
- QgsRectangle r1, r2;
- QgsCoordinateTransform* ct;
+ // Force render of layers that are being edited
+ // or if there's a labeling engine that needs the layer to register features
+ if ( ml->type() == QgsMapLayer::VectorLayer )
+ {
+ QgsVectorLayer* vl = qobject_cast<QgsVectorLayer *>( ml );
+ if ( vl->isEditable() ||
+ ( mRenderContext.labelingEngine() && mRenderContext.labelingEngine()->willUseLayer( vl ) ) )
+ {
+ ml->setCacheImage( 0 );
+ }
+ }
- if ( hasCrsTransformEnabled() )
- {
- r1 = mExtent;
- split = splitLayersExtent( ml, r1, r2 );
- ct = new QgsCoordinateTransform( ml->srs(), *mDestCRS );
- mRenderContext.setExtent( r1 );
- }
- else
- {
- ct = NULL;
- }
+ //
+ // Now do the call to the layer that actually does
+ // the rendering work!
+ //
+ connect( ml, SIGNAL( drawingProgress( int, int ) ), this, SLOT( onDrawingProgress( int, int ) ) );
- mRenderContext.setCoordinateTransform( ct );
+ renderLayer( ml );
- //decide if we have to scale the raster
- //this is necessary in case QGraphicsScene is used
- bool scaleRaster = false;
- double rasterScaleFactor = mRenderContext.rasterScaleFactor();
- QgsMapToPixel rasterMapToPixel;
- QgsMapToPixel bk_mapToPixel;
-
- if ( ml->type() == QgsMapLayer::RasterLayer && fabs( rasterScaleFactor - 1.0 ) > 0.000001 )
- {
- scaleRaster = true;
+ disconnect( ml, SIGNAL( drawingProgress( int, int ) ), this, SLOT( onDrawingProgress( int, int ) ) );
}
+}
- //create overlay objects for features within the view extent
- if ( ml->type() == QgsMapLayer::VectorLayer && overlayManager )
- {
- QgsVectorLayer* vl = qobject_cast<QgsVectorLayer *>( ml );
- if ( vl )
- {
- overlayManager->addOverlaysForLayer( vl, mRenderContext );
- }
- }
- // Force render of layers that are being edited
- // or if there's a labeling engine that needs the layer to register features
- if ( ml->type() == QgsMapLayer::VectorLayer )
- {
- QgsVectorLayer* vl = qobject_cast<QgsVectorLayer *>( ml );
- if ( vl->isEditable() ||
- ( mRenderContext.labelingEngine() && mRenderContext.labelingEngine()->willUseLayer( vl ) ) )
- {
- ml->setCacheImage( 0 );
- }
- }
+void QgsMapRenderer::renderLayer( QgsMapLayer* ml )
+{
+ // Store the painter in case we need to swap it out for the
+ // cache painter
+ QPainter * mypContextPainter = mRenderContext.painter();
if ( mCachingEnabled )
{
- if ( !mySameAsLastFlag || ml->cacheImage() == 0 )
+ if ( ml->cacheImage() == 0 )
{
- QgsDebugMsg( "\n\n\nCaching enabled but layer redraw forced by extent change or empty cache\n\n\n" );
- QImage * mypImage = new QImage( mRenderContext.painter()->device()->width(),
- mRenderContext.painter()->device()->height(), QImage::Format_ARGB32 );
+ QgsDebugMsg( "\n\n\nCaching enabled --- redraw forced by extent change or empty cache\n\n\n" );
+ QPaintDevice* device = mRenderContext.painter()->device();
+ QImage * mypImage = new QImage( device->width(), device->height(), QImage::Format_ARGB32_Premultiplied );
mypImage->fill( 0 );
ml->setCacheImage( mypImage ); //no need to delete the old one, maplayer does it for you
QPainter * mypPainter = new QPainter( ml->cacheImage() );
@@ -453,17 +437,28 @@
}
mRenderContext.setPainter( mypPainter );
}
- else if ( mySameAsLastFlag )
+ else
{
//draw from cached image
QgsDebugMsg( "\n\n\nCaching enabled --- drawing layer from cached image\n\n\n" );
mypContextPainter->drawImage( 0, 0, *( ml->cacheImage() ) );
- disconnect( ml, SIGNAL( drawingProgress( int, int ) ), this, SLOT( onDrawingProgress( int, int ) ) );
//short circuit as there is nothing else to do...
return;
}
}
+ //decide if we have to scale the raster
+ //this is necessary in case QGraphicsScene is used
+ bool scaleRaster = false;
+ double rasterScaleFactor = mRenderContext.rasterScaleFactor();
+ QgsMapToPixel rasterMapToPixel;
+ QgsMapToPixel bk_mapToPixel;
+
+ if ( ml->type() == QgsMapLayer::RasterLayer && fabs( rasterScaleFactor - 1.0 ) > 0.000001 )
+ {
+ scaleRaster = true;
+ }
+
if ( scaleRaster )
{
bk_mapToPixel = mRenderContext.mapToPixel();
@@ -475,15 +470,21 @@
mRenderContext.painter()->scale( 1.0 / rasterScaleFactor, 1.0 / rasterScaleFactor );
}
+ // split the rendering into two parts if necessary
+ bool split = false;
+ QgsRectangle r1, r2;
+ if ( hasCrsTransformEnabled() )
+ {
+ r1 = mExtent;
+ split = splitLayersExtent( ml, r1, r2 );
+ mRenderContext.setExtent( r1 );
+ }
+ // draw the layer
if ( !ml->draw( mRenderContext ) )
{
emit drawError( ml );
}
- else
- {
- QgsDebugMsg( "Layer rendered without issues" );
- }
if ( split )
{
@@ -510,7 +511,6 @@
//draw from cached image that we created further up
mypContextPainter->drawImage( 0, 0, *( ml->cacheImage() ) );
}
- disconnect( ml, SIGNAL( drawingProgress( int, int ) ), this, SLOT( onDrawingProgress( int, int ) ) );
}
Modified: branches/threading-branch/src/core/qgsmaprenderer.h
===================================================================
--- branches/threading-branch/src/core/qgsmaprenderer.h 2010-06-07 11:18:24 UTC (rev 13676)
+++ branches/threading-branch/src/core/qgsmaprenderer.h 2010-06-07 12:53:18 UTC (rev 13677)
@@ -233,8 +233,11 @@
*/
bool splitLayersExtent( QgsMapLayer* layer, QgsRectangle& extent, QgsRectangle& r2 );
+ //! render the whole layer set
+ void renderLayers( QgsOverlayObjectPositionManager* overlayManager );
+
//! render one layer
- void renderLayer( QString layerId, bool mySameAsLastFlag, QgsOverlayObjectPositionManager* overlayManager );
+ void renderLayer( QgsMapLayer* ml );
//! render labels for vector layers (not using PAL)
void renderLabels();
More information about the QGIS-commit
mailing list