Skip to content

Commit 5441a1e

Browse files
committedNov 4, 2013
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
1 parent f30f229 commit 5441a1e

File tree

5 files changed

+18
-9
lines changed

5 files changed

+18
-9
lines changed
 

‎src/core/composer/qgscomposermap.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,14 @@ void QgsComposerMap::draw( QPainter *painter, const QgsRectangle& extent, const
191191
{
192192
theRendererContext->setDrawEditingInformation( false );
193193
theRendererContext->setRenderingStopped( false );
194-
}
194+
theRendererContext->setRenderingPrintComposition( true );
195195

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

199-
// make the renderer respect the composition's useAdvancedEffects flag
200-
theRendererContext->setUseAdvancedEffects( mComposition->useAdvancedEffects() );
199+
// make the renderer respect the composition's useAdvancedEffects flag
200+
theRendererContext->setUseAdvancedEffects( mComposition->useAdvancedEffects() );
201+
}
201202

202203
//force composer map scale for scale dependent visibility
203204
double bk_scale = theMapRenderer.scale();

‎src/core/qgsrendercontext.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ QgsRenderContext::QgsRenderContext()
2828
mScaleFactor( 1.0 ),
2929
mRasterScaleFactor( 1.0 ),
3030
mRendererScale( 1.0 ),
31-
mLabelingEngine( NULL )
31+
mLabelingEngine( NULL ),
32+
mRenderingPrintComposition( false )
3233
{
3334

3435
}

‎src/core/qgsrendercontext.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ class CORE_EXPORT QgsRenderContext
9595
//! Added in QGIS v2.0
9696
void setSelectionColor( const QColor& color ) { mSelectionColor = color; }
9797

98+
/**True if the rendering request comes from a print composition, false it comes from a normal window request */
99+
void setRenderingPrintComposition( bool renderingPrintComposition ) { mRenderingPrintComposition = renderingPrintComposition; }
100+
bool renderingPrintComposition( ) const { return mRenderingPrintComposition; }
101+
98102
private:
99103

100104
/**Painter for rendering operations*/
@@ -133,6 +137,9 @@ class CORE_EXPORT QgsRenderContext
133137

134138
/** Color used for features that are marked as selected */
135139
QColor mSelectionColor;
140+
141+
/**True if the rendering request comes from a print composition, false it comes from a normal window request */
142+
bool mRenderingPrintComposition;
136143
};
137144

138145
#endif

‎src/core/qgsvectorlayer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -694,15 +694,15 @@ bool QgsVectorLayer::draw( QgsRenderContext& rendererContext )
694694
.setSubsetOfAttributes( attributes );
695695

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

702702
featureRequest.setFlags( featureRequest.flags() | QgsFeatureRequest::SimplifyGeometries );
703703
featureRequest.setCoordinateTransform( rendererContext.coordinateTransform() );
704704
featureRequest.setMapToPixel( &rendererContext.mapToPixel() );
705-
featureRequest.setMapToPixelTol( mSimplifyDrawingTol * 72.0f/dpi );
705+
featureRequest.setMapToPixelTol( mSimplifyDrawingTol * 96.0f/dpi );
706706
}
707707

708708
QgsFeatureIterator fit = getFeatures( featureRequest );

‎src/core/qgsvectorlayer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1373,7 +1373,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
13731373
bool simplifyDrawing() const { return mSimplifyDrawing; }
13741374

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

13781378
public slots:
13791379
/**

0 commit comments

Comments
 (0)
Please sign in to comment.