Skip to content

Commit

Permalink
Fix calculation of layout bounds considers page shadow
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 25, 2017
1 parent cdb0ace commit e444f00
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
14 changes: 12 additions & 2 deletions src/core/layout/qgslayout.cpp
Expand Up @@ -138,10 +138,20 @@ QRectF QgsLayout::layoutBounds( bool ignorePages, double margin ) const
if ( !isPage || !ignorePages )
{
//expand bounds with current item's bounds
QRectF itemBounds;
if ( isPage )
{
// for pages we only consider the item's rect - not the bounding rect
// as the bounding rect contains extra padding
itemBounds = layoutItem->mapToScene( layoutItem->rect() ).boundingRect();
}
else
itemBounds = item->sceneBoundingRect();

if ( bounds.isValid() )
bounds = bounds.united( item->sceneBoundingRect() );
bounds = bounds.united( itemBounds );
else
bounds = item->sceneBoundingRect();
bounds = itemBounds;
}
}

Expand Down
8 changes: 4 additions & 4 deletions tests/src/core/testqgslayout.cpp
Expand Up @@ -292,10 +292,10 @@ void TestQgsLayout::bounds()
QGSCOMPARENEAR( compositionBoundsNoPage.top(), 49.79, 0.01 );
#endif

QGSCOMPARENEAR( layoutBounds.height(), 211.000000, 0.01 );
QGSCOMPARENEAR( layoutBounds.width(), 298.000000, 0.01 );
QGSCOMPARENEAR( layoutBounds.left(), -0.500000, 0.01 );
QGSCOMPARENEAR( layoutBounds.top(), -0.500000, 0.01 );
QGSCOMPARENEAR( layoutBounds.height(), 210.000000, 0.01 );
QGSCOMPARENEAR( layoutBounds.width(), 297.000000, 0.01 );
QGSCOMPARENEAR( layoutBounds.left(), 0.00000, 0.01 );
QGSCOMPARENEAR( layoutBounds.top(), 0.00000, 0.01 );

QRectF compositionBoundsNoPage = l.layoutBounds( true );
QGSCOMPARENEAR( compositionBoundsNoPage.height(), 175.704581, 0.01 );
Expand Down

0 comments on commit e444f00

Please sign in to comment.