Skip to content
Permalink
Browse files

Add a render context flag so we know when a render operation is

occurring for drawing a symbol preview

Because these have no map association, certain settings like
sizes in "meters in map units" will have no meaning, and may need
special handling

Refs #28690
  • Loading branch information
nyalldawson committed Jun 16, 2020
1 parent 2264fef commit b7eac0772165233268c3ee37cf7aa3ecb32716ff
@@ -43,6 +43,7 @@ to be rendered etc.
RenderPartialOutput,
RenderPreviewJob,
RenderBlocking,
RenderSymbolPreview,
};
typedef QFlags<QgsRenderContext::Flag> Flags;

@@ -1388,6 +1388,7 @@ QgsRenderContext *QgsLayerTreeModel::createTemporaryRenderContext() const
context->setScaleFactor( dpi / 25.4 );
context->setRendererScale( scale );
context->setMapToPixel( QgsMapToPixel( mupp ) );
context->setFlag( QgsRenderContext::RenderSymbolPreview );
return validData ? context.release() : nullptr;
}

@@ -405,6 +405,7 @@ QgsRenderContext *QgsLayerTreeModelLegendNode::createTemporaryRenderContext() co
context->setRendererScale( scale );
context->setMapToPixel( QgsMapToPixel( mupp ) );
context->setFlag( QgsRenderContext::Antialiasing, true );
context->setFlag( QgsRenderContext::RenderSymbolPreview, true );
return context.release();
}

@@ -79,6 +79,7 @@ class CORE_EXPORT QgsRenderContext : public QgsTemporalRangeObject
RenderPartialOutput = 0x100, //!< Whether to make extra effort to update map image with partially rendered layers (better for interactive map canvas). Added in QGIS 3.0
RenderPreviewJob = 0x200, //!< Render is a 'canvas preview' render, and shortcuts should be taken to ensure fast rendering
RenderBlocking = 0x400, //!< Render and load remote sources in the same thread to ensure rendering remote sources (svg and images). WARNING: this flag must NEVER be used from GUI based applications (like the main QGIS application) or crashes will result. Only for use in external scripts or QGIS server.
RenderSymbolPreview = 0x800, //!< The render is for a symbol preview only and map based properties may not be available, so care should be taken to handle map unit based sizes in an appropriate way.
};
Q_DECLARE_FLAGS( Flags, Flag )

@@ -511,6 +511,7 @@ void QgsSymbol::drawPreviewIcon( QPainter *painter, QSize size, QgsRenderContext
{
tempContext.reset( new QgsRenderContext( QgsRenderContext::fromQPainter( painter ) ) );
context = tempContext.get();
context->setFlag( QgsRenderContext::RenderSymbolPreview, true );
}

const bool prevForceVector = context->forceVectorOutput();
@@ -631,6 +632,7 @@ QImage QgsSymbol::bigSymbolPreviewImage( QgsExpressionContext *expressionContext
}

QgsRenderContext context = QgsRenderContext::fromQPainter( &p );
context.setFlag( QgsRenderContext::RenderSymbolPreview );
if ( expressionContext )
context.setExpressionContext( *expressionContext );

@@ -838,6 +838,7 @@ QPicture QgsSymbolLayerUtils::symbolLayerPreviewPicture( const QgsSymbolLayer *l
painter.setRenderHint( QPainter::Antialiasing );
QgsRenderContext renderContext = QgsRenderContext::fromQPainter( &painter );
renderContext.setForceVectorOutput( true );
renderContext.setFlag( QgsRenderContext::RenderSymbolPreview, true );
QgsSymbolRenderContext symbolContext( renderContext, units, 1.0, false, nullptr, nullptr );
std::unique_ptr< QgsSymbolLayer > layerClone( layer->clone() );
layerClone->drawPreviewIcon( symbolContext, size );
@@ -853,6 +854,7 @@ QIcon QgsSymbolLayerUtils::symbolLayerPreviewIcon( const QgsSymbolLayer *layer,
painter.begin( &pixmap );
painter.setRenderHint( QPainter::Antialiasing );
QgsRenderContext renderContext = QgsRenderContext::fromQPainter( &painter );
renderContext.setFlag( QgsRenderContext::RenderSymbolPreview );
// build a minimal expression context
QgsExpressionContext expContext;
expContext.appendScopes( QgsExpressionContextUtils::globalProjectLayerScopes( nullptr ) );

0 comments on commit b7eac07

Please sign in to comment.
You can’t perform that action at this time.