Skip to content

Commit 0324de4

Browse files
committed
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 e98a938 commit 0324de4

5 files changed

+18
-9
lines changed

src/core/composer/qgscomposermap.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,14 @@ void QgsComposerMap::draw( QPainter *painter, const QgsRectangle& extent, const
199199
{
200200
theRendererContext->setDrawEditingInformation( false );
201201
theRendererContext->setRenderingStopped( false );
202-
}
202+
theRendererContext->setRenderingPrintComposition( true );
203203

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

207-
// make the renderer respect the composition's useAdvancedEffects flag
208-
theRendererContext->setUseAdvancedEffects( mComposition->useAdvancedEffects() );
207+
// make the renderer respect the composition's useAdvancedEffects flag
208+
theRendererContext->setUseAdvancedEffects( mComposition->useAdvancedEffects() );
209+
}
209210

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

src/core/qgsrendercontext.cpp

+2-1
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

+7
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

+2-2
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1375,7 +1375,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
13751375
bool simplifyDrawing() const { return mSimplifyDrawing; }
13761376

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

13801380
public slots:
13811381
/**

0 commit comments

Comments
 (0)