Skip to content

Commit e444f00

Browse files
committed
Fix calculation of layout bounds considers page shadow
1 parent cdb0ace commit e444f00

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/core/layout/qgslayout.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,20 @@ QRectF QgsLayout::layoutBounds( bool ignorePages, double margin ) const
138138
if ( !isPage || !ignorePages )
139139
{
140140
//expand bounds with current item's bounds
141+
QRectF itemBounds;
142+
if ( isPage )
143+
{
144+
// for pages we only consider the item's rect - not the bounding rect
145+
// as the bounding rect contains extra padding
146+
itemBounds = layoutItem->mapToScene( layoutItem->rect() ).boundingRect();
147+
}
148+
else
149+
itemBounds = item->sceneBoundingRect();
150+
141151
if ( bounds.isValid() )
142-
bounds = bounds.united( item->sceneBoundingRect() );
152+
bounds = bounds.united( itemBounds );
143153
else
144-
bounds = item->sceneBoundingRect();
154+
bounds = itemBounds;
145155
}
146156
}
147157

tests/src/core/testqgslayout.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,10 @@ void TestQgsLayout::bounds()
292292
QGSCOMPARENEAR( compositionBoundsNoPage.top(), 49.79, 0.01 );
293293
#endif
294294

295-
QGSCOMPARENEAR( layoutBounds.height(), 211.000000, 0.01 );
296-
QGSCOMPARENEAR( layoutBounds.width(), 298.000000, 0.01 );
297-
QGSCOMPARENEAR( layoutBounds.left(), -0.500000, 0.01 );
298-
QGSCOMPARENEAR( layoutBounds.top(), -0.500000, 0.01 );
295+
QGSCOMPARENEAR( layoutBounds.height(), 210.000000, 0.01 );
296+
QGSCOMPARENEAR( layoutBounds.width(), 297.000000, 0.01 );
297+
QGSCOMPARENEAR( layoutBounds.left(), 0.00000, 0.01 );
298+
QGSCOMPARENEAR( layoutBounds.top(), 0.00000, 0.01 );
299299

300300
QRectF compositionBoundsNoPage = l.layoutBounds( true );
301301
QGSCOMPARENEAR( compositionBoundsNoPage.height(), 175.704581, 0.01 );

0 commit comments

Comments
 (0)