Skip to content

Commit

Permalink
Merge pull request #45397 from kadas-albireo/master
Browse files Browse the repository at this point in the history
Fix layout legend not showing WMS legend graphics unless image already cached
  • Loading branch information
manisandro committed Oct 5, 2021
2 parents ccd4b71 + b10965d commit dd95ea5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/core/layertree/qgslayertreemodellegendnode.cpp
Expand Up @@ -1250,6 +1250,8 @@ QSizeF QgsWmsLegendNode::drawSymbol( const QgsLegendSettings &settings, ItemCont

if ( ctx && ctx->painter )
{
const QImage image = getLegendGraphic();

switch ( settings.symbolAlignment() )
{
case Qt::AlignLeft:
Expand All @@ -1258,17 +1260,17 @@ QSizeF QgsWmsLegendNode::drawSymbol( const QgsLegendSettings &settings, ItemCont
ctx->top,
settings.wmsLegendSize().width(),
settings.wmsLegendSize().height() ),
mImage,
QRectF( QPointF( 0, 0 ), mImage.size() ) );
image,
QRectF( QPointF( 0, 0 ), image.size() ) );
break;

case Qt::AlignRight:
ctx->painter->drawImage( QRectF( ctx->columnRight - settings.wmsLegendSize().width(),
ctx->top,
settings.wmsLegendSize().width(),
settings.wmsLegendSize().height() ),
mImage,
QRectF( QPointF( 0, 0 ), mImage.size() ) );
image,
QRectF( QPointF( 0, 0 ), image.size() ) );
break;
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/core/layout/qgslayoutitemlegend.cpp
Expand Up @@ -971,7 +971,7 @@ bool QgsLayoutItemLegend::legendFilterOutAtlas() const

void QgsLayoutItemLegend::onAtlasFeature()
{
if ( !mLayout->reportContext().feature().isValid() )
if ( !mLayout || !mLayout->reportContext().feature().isValid() )
return;
mInAtlas = mFilterOutAtlas;
updateFilterByMap();
Expand Down Expand Up @@ -1067,6 +1067,7 @@ QgsLegendModel::QgsLegendModel( QgsLayerTree *rootNode, QObject *parent, QgsLayo
{
setFlag( QgsLayerTreeModel::AllowLegendChangeState, false );
setFlag( QgsLayerTreeModel::AllowNodeReorder, true );
connect( this, &QgsLegendModel::dataChanged, this, &QgsLegendModel::refreshLegend );
}

QgsLegendModel::QgsLegendModel( QgsLayerTree *rootNode, QgsLayoutItemLegend *layout )
Expand All @@ -1075,6 +1076,7 @@ QgsLegendModel::QgsLegendModel( QgsLayerTree *rootNode, QgsLayoutItemLegend *la
{
setFlag( QgsLayerTreeModel::AllowLegendChangeState, false );
setFlag( QgsLayerTreeModel::AllowNodeReorder, true );
connect( this, &QgsLegendModel::dataChanged, this, &QgsLegendModel::refreshLegend );
}

QVariant QgsLegendModel::data( const QModelIndex &index, int role ) const
Expand Down

0 comments on commit dd95ea5

Please sign in to comment.