Skip to content

Commit

Permalink
Ensure correct symbol geometry type is used for more preview icons
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson authored and github-actions[bot] committed Nov 1, 2021
1 parent b2cac9b commit 252b1e9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
Expand Up @@ -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

Expand Down
18 changes: 17 additions & 1 deletion src/core/symbology/qgssymbollayerutils.cpp
Expand Up @@ -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;
Expand All @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion src/core/symbology/qgssymbollayerutils.h
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/gui/symbology/qgslayerpropertieswidget.cpp
Expand Up @@ -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 );
Expand Down

0 comments on commit 252b1e9

Please sign in to comment.