Skip to content

Commit 4aa8540

Browse files
committedMar 19, 2019
Manage opacity for markers in vector layers
1 parent 2ed420e commit 4aa8540

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed
 

‎src/core/layertree/qgslayertreemodellegendnode.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,10 +535,23 @@ void QgsSymbolLegendNode::drawSymbol( const QgsLegendSettings &settings, QJsonOb
535535
context.setExpressionContext( expContext );
536536

537537
QPixmap pix = QgsSymbolLayerUtils::symbolPreviewPixmap( mItem.symbol(), minimumIconSize(), 0, &context );
538+
QImage img( pix.toImage().convertToFormat( QImage::Format_ARGB32_Premultiplied ) );
539+
540+
int opacity = 255;
541+
if ( QgsVectorLayer *vectorLayer = dynamic_cast<QgsVectorLayer *>( layerNode()->layer() ) )
542+
opacity = ( 255 * vectorLayer->opacity() );
543+
544+
if ( opacity != 255 )
545+
{
546+
QPainter painter;
547+
painter.begin( &img );
548+
painter.setCompositionMode( QPainter::CompositionMode_DestinationIn );
549+
painter.fillRect( pix.rect(), QColor( 0, 0, 0, opacity ) );
550+
painter.end();
551+
}
538552

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

0 commit comments

Comments
 (0)
Please sign in to comment.