Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Feature #8725: Disable simplification in composer
Disable the simplification of geometries when the render request comes
from a print composition to avoid rendering quality issues
  • Loading branch information
ahuarte47 committed Dec 17, 2013
1 parent e98a938 commit 0324de4
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
11 changes: 6 additions & 5 deletions src/core/composer/qgscomposermap.cpp
Expand Up @@ -199,13 +199,14 @@ void QgsComposerMap::draw( QPainter *painter, const QgsRectangle& extent, const
{
theRendererContext->setDrawEditingInformation( false );
theRendererContext->setRenderingStopped( false );
}
theRendererContext->setRenderingPrintComposition( true );

// force vector output (no caching of marker images etc.)
theRendererContext->setForceVectorOutput( true );
// force vector output (no caching of marker images etc.)
theRendererContext->setForceVectorOutput( true );

// make the renderer respect the composition's useAdvancedEffects flag
theRendererContext->setUseAdvancedEffects( mComposition->useAdvancedEffects() );
// make the renderer respect the composition's useAdvancedEffects flag
theRendererContext->setUseAdvancedEffects( mComposition->useAdvancedEffects() );
}

//force composer map scale for scale dependent visibility
double bk_scale = theMapRenderer.scale();
Expand Down
3 changes: 2 additions & 1 deletion src/core/qgsrendercontext.cpp
Expand Up @@ -28,7 +28,8 @@ QgsRenderContext::QgsRenderContext()
mScaleFactor( 1.0 ),
mRasterScaleFactor( 1.0 ),
mRendererScale( 1.0 ),
mLabelingEngine( NULL )
mLabelingEngine( NULL ),
mRenderingPrintComposition( false )
{

}
Expand Down
7 changes: 7 additions & 0 deletions src/core/qgsrendercontext.h
Expand Up @@ -95,6 +95,10 @@ class CORE_EXPORT QgsRenderContext
//! Added in QGIS v2.0
void setSelectionColor( const QColor& color ) { mSelectionColor = color; }

/**True if the rendering request comes from a print composition, false it comes from a normal window request */
void setRenderingPrintComposition( bool renderingPrintComposition ) { mRenderingPrintComposition = renderingPrintComposition; }
bool renderingPrintComposition( ) const { return mRenderingPrintComposition; }

private:

/**Painter for rendering operations*/
Expand Down Expand Up @@ -133,6 +137,9 @@ class CORE_EXPORT QgsRenderContext

/** Color used for features that are marked as selected */
QColor mSelectionColor;

/**True if the rendering request comes from a print composition, false it comes from a normal window request */
bool mRenderingPrintComposition;
};

#endif
4 changes: 2 additions & 2 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -694,15 +694,15 @@ bool QgsVectorLayer::draw( QgsRenderContext& rendererContext )
.setSubsetOfAttributes( attributes );

// Enable the simplification of the geometries before fetch the features using the current map2pixel context.
if ( simplifyDrawingCanbeApplied() && !(featureRequest.flags() & QgsFeatureRequest::NoGeometry) )
if ( simplifyDrawingCanbeApplied() && !(featureRequest.flags() & QgsFeatureRequest::NoGeometry) && !rendererContext.renderingPrintComposition() )
{
QPainter* p = rendererContext.painter();
float dpi = ( p->device()->logicalDpiX() + p->device()->logicalDpiY() ) / 2;

featureRequest.setFlags( featureRequest.flags() | QgsFeatureRequest::SimplifyGeometries );
featureRequest.setCoordinateTransform( rendererContext.coordinateTransform() );
featureRequest.setMapToPixel( &rendererContext.mapToPixel() );
featureRequest.setMapToPixelTol( mSimplifyDrawingTol * 72.0f/dpi );
featureRequest.setMapToPixelTol( mSimplifyDrawingTol * 96.0f/dpi );
}

QgsFeatureIterator fit = getFeatures( featureRequest );
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsvectorlayer.h
Expand Up @@ -1375,7 +1375,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
bool simplifyDrawing() const { return mSimplifyDrawing; }

/** Returns whether the VectorLayer can apply geometry simplification in FeatureRequests */
bool simplifyDrawingCanbeApplied() const { return mSimplifyDrawing && !mEditBuffer; }
bool simplifyDrawingCanbeApplied() const { return mSimplifyDrawing && !mEditBuffer && ( !mCurrentRendererContext || !mCurrentRendererContext->renderingPrintComposition() ); }

public slots:
/**
Expand Down

0 comments on commit 0324de4

Please sign in to comment.