Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add flag to turn off rendering crosshairs in the background of preview
images generated for markers by QgsSymbol::bigSymbolPreviewImage()
  • Loading branch information
nyalldawson committed Oct 21, 2020
1 parent 9aa805c commit 4f4b286
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
13 changes: 12 additions & 1 deletion python/core/auto_generated/symbology/qgssymbol.sip.in
Expand Up @@ -322,12 +322,20 @@ matches the settings from that context.
.. seealso:: :py:func:`drawPreviewIcon`
%End

QImage bigSymbolPreviewImage( QgsExpressionContext *expressionContext = 0 );
enum PreviewFlag
{
FlagIncludeCrosshairsForMarkerSymbols,
};
typedef QFlags<QgsSymbol::PreviewFlag> PreviewFlags;


QImage bigSymbolPreviewImage( QgsExpressionContext *expressionContext = 0, QgsSymbol::PreviewFlags flags = QgsSymbol::FlagIncludeCrosshairsForMarkerSymbols );
%Docstring
Returns a large (roughly 100x100 pixel) preview image for the symbol.

:param expressionContext: optional expression context, for evaluation of
data defined symbol properties
:param flags: optional flags to control how preview image is generated

.. seealso:: :py:func:`asImage`

Expand Down Expand Up @@ -1238,6 +1246,9 @@ style and colors instead of the symbol's normal style.

};

QFlags<QgsSymbol::PreviewFlag> operator|(QgsSymbol::PreviewFlag f1, QFlags<QgsSymbol::PreviewFlag> f2);



/************************************************************************
* This file has been generated automatically from *
Expand Down
4 changes: 2 additions & 2 deletions src/core/symbology/qgssymbol.cpp
Expand Up @@ -634,7 +634,7 @@ QImage QgsSymbol::asImage( QSize size, QgsRenderContext *customContext )
}


QImage QgsSymbol::bigSymbolPreviewImage( QgsExpressionContext *expressionContext )
QImage QgsSymbol::bigSymbolPreviewImage( QgsExpressionContext *expressionContext, QgsSymbol::PreviewFlags flags )
{
QImage preview( QSize( 100, 100 ), QImage::Format_ARGB32_Premultiplied );
preview.fill( 0 );
Expand All @@ -643,7 +643,7 @@ QImage QgsSymbol::bigSymbolPreviewImage( QgsExpressionContext *expressionContext
p.setRenderHint( QPainter::Antialiasing );
p.translate( 0.5, 0.5 ); // shift by half a pixel to avoid blurring due antialiasing

if ( mType == QgsSymbol::Marker )
if ( mType == QgsSymbol::Marker && flags & PreviewFlag::FlagIncludeCrosshairsForMarkerSymbols )
{
p.setPen( QPen( Qt::gray ) );
p.drawLine( 0, 50, 100, 50 );
Expand Down
17 changes: 16 additions & 1 deletion src/core/symbology/qgssymbol.h
Expand Up @@ -369,15 +369,28 @@ class CORE_EXPORT QgsSymbol
*/
QImage asImage( QSize size, QgsRenderContext *customContext = nullptr );

/**
* Flags for controlling how symbol preview images are generated.
*
* \since QGIS 3.16
*/
enum PreviewFlag
{
FlagIncludeCrosshairsForMarkerSymbols = 1 << 0, //!< Include a crosshairs reference image in the background of marker symbol previews
};
Q_DECLARE_FLAGS( PreviewFlags, PreviewFlag )

/**
* Returns a large (roughly 100x100 pixel) preview image for the symbol.
*
* \param expressionContext optional expression context, for evaluation of
* data defined symbol properties
* \param flags optional flags to control how preview image is generated
*
* \see asImage()
* \see drawPreviewIcon()
*/
QImage bigSymbolPreviewImage( QgsExpressionContext *expressionContext = nullptr );
QImage bigSymbolPreviewImage( QgsExpressionContext *expressionContext = nullptr, QgsSymbol::PreviewFlags flags = QgsSymbol::FlagIncludeCrosshairsForMarkerSymbols );

/**
* Returns a string dump of the symbol's properties.
Expand Down Expand Up @@ -1263,5 +1276,7 @@ class CORE_EXPORT QgsFillSymbol : public QgsSymbol
QVector<QPolygonF> *translateRings( const QVector<QPolygonF> *rings, double dx, double dy ) const;
};

Q_DECLARE_OPERATORS_FOR_FLAGS( QgsSymbol::PreviewFlags )

#endif

0 comments on commit 4f4b286

Please sign in to comment.