Skip to content
Permalink
Browse files
Ensure correct symbol geometry type is used for more preview icons
  • Loading branch information
nyalldawson committed Nov 2, 2021
1 parent 9ed2768 commit 375cc467bb670875e926212c9a052fc0567ce936
@@ -250,14 +250,15 @@ Returns a pixmap preview for a color ramp.
.. seealso:: :py:func:`symbolPreviewIcon`
%End

static QPicture symbolLayerPreviewPicture( const QgsSymbolLayer *layer, QgsUnitTypes::RenderUnit units, QSize size, const QgsMapUnitScale &scale = QgsMapUnitScale() );
static QPicture symbolLayerPreviewPicture( const QgsSymbolLayer *layer, QgsUnitTypes::RenderUnit units, QSize size, const QgsMapUnitScale &scale = QgsMapUnitScale(), Qgis::SymbolType parentSymbolType = Qgis::SymbolType::Hybrid );
%Docstring
Draws a symbol layer preview to a QPicture

:param layer: symbol layer to draw
:param units: size units
:param size: target size of preview picture
:param scale: map unit scale for preview
:param parentSymbolType: since QGIS 3.22, can be used to specify the parent symbol type so that geometry generator preview icons are correctly calculated

:return: QPicture containing symbol layer preview

@@ -842,7 +842,7 @@ double QgsSymbolLayerUtils::estimateMaxSymbolBleed( QgsSymbol *symbol, const Qgs
return maxBleed;
}

QPicture QgsSymbolLayerUtils::symbolLayerPreviewPicture( const QgsSymbolLayer *layer, QgsUnitTypes::RenderUnit units, QSize size, const QgsMapUnitScale & )
QPicture QgsSymbolLayerUtils::symbolLayerPreviewPicture( const QgsSymbolLayer *layer, QgsUnitTypes::RenderUnit units, QSize size, const QgsMapUnitScale &, Qgis::SymbolType parentSymbolType )
{
QPicture picture;
QPainter painter;
@@ -852,6 +852,22 @@ QPicture QgsSymbolLayerUtils::symbolLayerPreviewPicture( const QgsSymbolLayer *l
renderContext.setForceVectorOutput( true );
renderContext.setFlag( Qgis::RenderContextFlag::RenderSymbolPreview, true );
QgsSymbolRenderContext symbolContext( renderContext, units, 1.0, false, Qgis::SymbolRenderHints(), nullptr );

switch ( parentSymbolType )
{
case Qgis::SymbolType::Marker:
symbolContext.setOriginalGeometryType( QgsWkbTypes::PointGeometry );
break;
case Qgis::SymbolType::Line:
symbolContext.setOriginalGeometryType( QgsWkbTypes::LineGeometry );
break;
case Qgis::SymbolType::Fill:
symbolContext.setOriginalGeometryType( QgsWkbTypes::PolygonGeometry );
break;
case Qgis::SymbolType::Hybrid:
break;
}

std::unique_ptr< QgsSymbolLayer > layerClone( layer->clone() );
layerClone->drawPreviewIcon( symbolContext, size );
painter.end();
@@ -248,11 +248,12 @@ class CORE_EXPORT QgsSymbolLayerUtils
* \param units size units
* \param size target size of preview picture
* \param scale map unit scale for preview
* \param parentSymbolType since QGIS 3.22, can be used to specify the parent symbol type so that geometry generator preview icons are correctly calculated
* \returns QPicture containing symbol layer preview
* \see symbolLayerPreviewIcon()
* \since QGIS 2.9
*/
static QPicture symbolLayerPreviewPicture( const QgsSymbolLayer *layer, QgsUnitTypes::RenderUnit units, QSize size, const QgsMapUnitScale &scale = QgsMapUnitScale() );
static QPicture symbolLayerPreviewPicture( const QgsSymbolLayer *layer, QgsUnitTypes::RenderUnit units, QSize size, const QgsMapUnitScale &scale = QgsMapUnitScale(), Qgis::SymbolType parentSymbolType = Qgis::SymbolType::Hybrid );

/**
* Draws a symbol layer preview to an icon.
@@ -345,7 +345,7 @@ void QgsLayerPropertiesWidget::emitSignalChanged()
mLayer->paintEffect()->setEnabled( false );
paintEffectToggled = true;
}
mEffectWidget->setPreviewPicture( QgsSymbolLayerUtils::symbolLayerPreviewPicture( mLayer, QgsUnitTypes::RenderMillimeters, QSize( 60, 60 ) ) );
mEffectWidget->setPreviewPicture( QgsSymbolLayerUtils::symbolLayerPreviewPicture( mLayer, QgsUnitTypes::RenderMillimeters, QSize( 60, 60 ), QgsMapUnitScale(), mSymbol ? mSymbol->type() : Qgis::SymbolType::Hybrid ) );
if ( paintEffectToggled )
{
mLayer->paintEffect()->setEnabled( true );

0 comments on commit 375cc46

Please sign in to comment.