Skip to content

Commit

Permalink
Avoid resizing group children to nan sizes when layout groups are res…
Browse files Browse the repository at this point in the history
…ized
  • Loading branch information
nyalldawson committed Oct 17, 2024
1 parent 1253dcf commit e1147fe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/core/layout/qgslayoutitemgroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ void QgsLayoutItemGroup::attemptResize( const QgsLayoutSize &size, bool includes
command->saveBeforeState();
}

QRectF itemRect = mapRectFromItem( item, item->rect() );
const QRectF originalItemRect = item->rect();
QRectF itemRect = mapRectFromItem( item, originalItemRect );
QgsLayoutUtils::relativeResizeRect( itemRect, oldRect, newRect );

itemRect = itemRect.normalized();
Expand Down
16 changes: 12 additions & 4 deletions src/core/layout/qgslayoututils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,18 @@ QgsRenderContext QgsLayoutUtils::createRenderContextForLayout( QgsLayout *layout
void QgsLayoutUtils::relativeResizeRect( QRectF &rectToResize, const QRectF &boundsBefore, const QRectF &boundsAfter )
{
//linearly scale rectToResize relative to the scaling from boundsBefore to boundsAfter
double left = relativePosition( rectToResize.left(), boundsBefore.left(), boundsBefore.right(), boundsAfter.left(), boundsAfter.right() );
double right = relativePosition( rectToResize.right(), boundsBefore.left(), boundsBefore.right(), boundsAfter.left(), boundsAfter.right() );
double top = relativePosition( rectToResize.top(), boundsBefore.top(), boundsBefore.bottom(), boundsAfter.top(), boundsAfter.bottom() );
double bottom = relativePosition( rectToResize.bottom(), boundsBefore.top(), boundsBefore.bottom(), boundsAfter.top(), boundsAfter.bottom() );
const double left = !qgsDoubleNear( boundsBefore.left(), boundsBefore.right() )
? relativePosition( rectToResize.left(), boundsBefore.left(), boundsBefore.right(), boundsAfter.left(), boundsAfter.right() )
: boundsAfter.left();
const double right = !qgsDoubleNear( boundsBefore.left(), boundsBefore.right() )
? relativePosition( rectToResize.right(), boundsBefore.left(), boundsBefore.right(), boundsAfter.left(), boundsAfter.right() )
: boundsAfter.right();
const double top = !qgsDoubleNear( boundsBefore.top(), boundsBefore.bottom() )
? relativePosition( rectToResize.top(), boundsBefore.top(), boundsBefore.bottom(), boundsAfter.top(), boundsAfter.bottom() )
: boundsAfter.top();
const double bottom = !qgsDoubleNear( boundsBefore.top(), boundsBefore.bottom() )
? relativePosition( rectToResize.bottom(), boundsBefore.top(), boundsBefore.bottom(), boundsAfter.top(), boundsAfter.bottom() )
: boundsAfter.bottom();

rectToResize.setRect( left, top, right - left, bottom - top );
}
Expand Down

0 comments on commit e1147fe

Please sign in to comment.