Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add optional shape argument to symbolPreviewPixmap/symbolPreviewImage
  • Loading branch information
nyalldawson committed Apr 21, 2020
1 parent ae8e5cf commit fe435a3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
11 changes: 9 additions & 2 deletions python/core/auto_generated/symbology/qgssymbollayerutils.sip.in
Expand Up @@ -200,19 +200,21 @@ Returns the size scaled in pixels according to the uom attribute.

static QPainter::CompositionMode decodeBlendMode( const QString &s );

static QIcon symbolPreviewIcon( const QgsSymbol *symbol, QSize size, int padding = 0 );
static QIcon symbolPreviewIcon( const QgsSymbol *symbol, QSize size, int padding = 0, QgsLegendPatchShape *shape = 0 );
%Docstring
Returns an icon preview for a color ramp.

:param symbol: symbol
:param size: target pixmap size
:param padding: space between icon edge and symbol
:param shape: optional legend patch shape to use for rendering the preview icon

.. seealso:: :py:func:`symbolPreviewPixmap`
%End

static QPixmap symbolPreviewPixmap( const QgsSymbol *symbol, QSize size, int padding = 0, QgsRenderContext *customContext = 0, bool selected = false,
const QgsExpressionContext *expressionContext = 0 );
const QgsExpressionContext *expressionContext = 0,
const QgsLegendPatchShape *shape = 0 );
%Docstring
Returns a pixmap preview for a color ramp.

Expand All @@ -222,6 +224,7 @@ Returns a pixmap preview for a color ramp.
:param customContext: render context to use when rendering symbol
:param selected: set to ``True`` to render the symbol in a selected state
:param expressionContext: optional custom expression context
:param shape: optional legend patch shape to use for rendering the preview icon

.. note::

Expand All @@ -235,6 +238,10 @@ Returns a pixmap preview for a color ramp.

Parameter expressionContext added in QGIS 3.10

.. note::

Parameter shape added in QGIS 3.14

.. seealso:: :py:func:`symbolPreviewIcon`
%End

Expand Down
10 changes: 5 additions & 5 deletions src/core/symbology/qgssymbollayerutils.cpp
Expand Up @@ -761,12 +761,12 @@ QPainter::CompositionMode QgsSymbolLayerUtils::decodeBlendMode( const QString &s
return QPainter::CompositionMode_SourceOver; // "Normal"
}

QIcon QgsSymbolLayerUtils::symbolPreviewIcon( const QgsSymbol *symbol, QSize size, int padding )
QIcon QgsSymbolLayerUtils::symbolPreviewIcon( const QgsSymbol *symbol, QSize size, int padding, QgsLegendPatchShape *shape )
{
return QIcon( symbolPreviewPixmap( symbol, size, padding ) );
return QIcon( symbolPreviewPixmap( symbol, size, padding, nullptr, false, nullptr, shape ) );
}

QPixmap QgsSymbolLayerUtils::symbolPreviewPixmap( const QgsSymbol *symbol, QSize size, int padding, QgsRenderContext *customContext, bool selected, const QgsExpressionContext *expressionContext )
QPixmap QgsSymbolLayerUtils::symbolPreviewPixmap( const QgsSymbol *symbol, QSize size, int padding, QgsRenderContext *customContext, bool selected, const QgsExpressionContext *expressionContext, const QgsLegendPatchShape *shape )
{
Q_ASSERT( symbol );
QPixmap pixmap( size );
Expand Down Expand Up @@ -806,12 +806,12 @@ QPixmap QgsSymbolLayerUtils::symbolPreviewPixmap( const QgsSymbol *symbol, QSize
prop.setActive( false );
}
}
symbol_noDD->drawPreviewIcon( &painter, size, customContext, selected, expressionContext );
symbol_noDD->drawPreviewIcon( &painter, size, customContext, selected, expressionContext, shape );
}
else
{
std::unique_ptr<QgsSymbol> symbolClone( symbol->clone( ) );
symbolClone->drawPreviewIcon( &painter, size, customContext, selected, expressionContext );
symbolClone->drawPreviewIcon( &painter, size, customContext, selected, expressionContext, shape );
}

painter.end();
Expand Down
8 changes: 6 additions & 2 deletions src/core/symbology/qgssymbollayerutils.h
Expand Up @@ -212,9 +212,10 @@ class CORE_EXPORT QgsSymbolLayerUtils
* \param symbol symbol
* \param size target pixmap size
* \param padding space between icon edge and symbol
* \param shape optional legend patch shape to use for rendering the preview icon
* \see symbolPreviewPixmap()
*/
static QIcon symbolPreviewIcon( const QgsSymbol *symbol, QSize size, int padding = 0 );
static QIcon symbolPreviewIcon( const QgsSymbol *symbol, QSize size, int padding = 0, QgsLegendPatchShape *shape = nullptr );

/**
* Returns a pixmap preview for a color ramp.
Expand All @@ -224,13 +225,16 @@ class CORE_EXPORT QgsSymbolLayerUtils
* \param customContext render context to use when rendering symbol
* \param selected set to TRUE to render the symbol in a selected state
* \param expressionContext optional custom expression context
* \param shape optional legend patch shape to use for rendering the preview icon
* \note Parameter customContext added in QGIS 2.6
* \note Parameter selected added in QGIS 3.10
* \note Parameter expressionContext added in QGIS 3.10
* \note Parameter shape added in QGIS 3.14
* \see symbolPreviewIcon()
*/
static QPixmap symbolPreviewPixmap( const QgsSymbol *symbol, QSize size, int padding = 0, QgsRenderContext *customContext = nullptr, bool selected = false,
const QgsExpressionContext *expressionContext = nullptr );
const QgsExpressionContext *expressionContext = nullptr,
const QgsLegendPatchShape *shape = nullptr );

/**
* Draws a symbol layer preview to a QPicture
Expand Down

0 comments on commit fe435a3

Please sign in to comment.