diff --git a/src/core/layout/qgslayoutitemgroup.cpp b/src/core/layout/qgslayoutitemgroup.cpp index 48041cd30f7a..b9896a4a4054 100644 --- a/src/core/layout/qgslayoutitemgroup.cpp +++ b/src/core/layout/qgslayoutitemgroup.cpp @@ -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(); diff --git a/src/core/layout/qgslayoututils.cpp b/src/core/layout/qgslayoututils.cpp index 73810b8f825a..6cf09cae422b 100644 --- a/src/core/layout/qgslayoututils.cpp +++ b/src/core/layout/qgslayoututils.cpp @@ -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 ); }