Skip to content
Permalink
Browse files

[layouts] Fix legend does not respect anchor point when resizing

based on map content

Fixes #19987
  • Loading branch information
nyalldawson committed Oct 15, 2018
1 parent 46b6ffa commit 530397c1683cc787ef90bc27e2d958779ed0d754
Showing with 10 additions and 8 deletions.
  1. +10 −8 src/core/layout/qgslayoutitemlegend.cpp
@@ -106,21 +106,23 @@ void QgsLayoutItemLegend::paint( QPainter *painter, const QStyleOptionGraphicsIt
if ( mForceResize )
{
mForceResize = false;

//set new rect, respecting position mode and data defined size/position
QRectF targetRect = QRectF( pos().x(), pos().y(), size.width(), size.height() );
attemptSetSceneRect( targetRect );
QgsLayoutSize newSize = mLayout->convertFromLayoutUnits( size, sizeWithUnits().units() );
attemptResize( newSize );
}
else if ( size.height() > rect().height() || size.width() > rect().width() )
{
//need to resize box
QRectF targetRect = QRectF( pos().x(), pos().y(), rect().width(), rect().height() );
if ( size.height() > targetRect.height() )
targetRect.setHeight( size.height() );
if ( size.width() > rect().width() )
targetRect.setWidth( size.width() );
QSizeF targetSize = rect().size();
if ( size.height() > targetSize.height() )
targetSize.setHeight( size.height() );
if ( size.width() > targetSize.width() )
targetSize.setWidth( size.width() );

QgsLayoutSize newSize = mLayout->convertFromLayoutUnits( targetSize, sizeWithUnits().units() );
//set new rect, respecting position mode and data defined size/position
attemptSetSceneRect( targetRect );
attemptResize( newSize );
}
}
QgsLayoutItem::paint( painter, itemStyle, pWidget );

0 comments on commit 530397c

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