Skip to content
Permalink
Browse files

Manage opacity for markers in vector layers

  • Loading branch information
pblottiere committed Mar 1, 2019
1 parent 2ed420e commit 4aa854042baafdd5d15b69a27eec96736f15206a
Showing with 14 additions and 1 deletion.
  1. +14 −1 src/core/layertree/qgslayertreemodellegendnode.cpp
@@ -535,10 +535,23 @@ void QgsSymbolLegendNode::drawSymbol( const QgsLegendSettings &settings, QJsonOb
context.setExpressionContext( expContext );

QPixmap pix = QgsSymbolLayerUtils::symbolPreviewPixmap( mItem.symbol(), minimumIconSize(), 0, &context );
QImage img( pix.toImage().convertToFormat( QImage::Format_ARGB32_Premultiplied ) );

int opacity = 255;
if ( QgsVectorLayer *vectorLayer = dynamic_cast<QgsVectorLayer *>( layerNode()->layer() ) )
opacity = ( 255 * vectorLayer->opacity() );

if ( opacity != 255 )
{
QPainter painter;
painter.begin( &img );
painter.setCompositionMode( QPainter::CompositionMode_DestinationIn );
painter.fillRect( pix.rect(), QColor( 0, 0, 0, opacity ) );
painter.end();
}

QByteArray byteArray;
QBuffer buffer( &byteArray );
QImage img( pix.toImage().convertToFormat( QImage::Format_ARGB32_Premultiplied ) );
img.save( &buffer, "PNG" );
QString base64 = QString::fromLatin1( byteArray.toBase64().data() );
json[ "icon" ] = base64;

0 comments on commit 4aa8540

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