Skip to content
Permalink
Browse files

[layouts] Fix a crash when using multiframe items when no pages exist

  • Loading branch information
nyalldawson committed Jun 20, 2018
1 parent afde31b commit fb3ff6d226b74afb38bd89e7cf8df21dcd98779c
Showing with 32 additions and 1 deletion.
  1. +1 −1 src/core/layout/qgslayoutmultiframe.cpp
  2. +31 −0 tests/src/core/testqgslayoutmultiframe.cpp
@@ -148,7 +148,7 @@ void QgsLayoutMultiFrame::recalculateFrameSizes()
}

//at end of frames but there is still content left. Add other pages if ResizeMode ==
if ( currentItem && mResizeMode != UseExistingFrames )
if ( mLayout->pageCollection()->pageCount() > 0 && currentItem && mResizeMode != UseExistingFrames )
{
while ( ( mResizeMode == RepeatOnEveryPage ) || currentY < totalHeight )
{
@@ -50,6 +50,7 @@ class TestQgsLayoutMultiFrame : public QObject
void registry();
void deleteFrame();
void writeReadXml();
void noPageNoCrash();

private:
QgsLayout *mLayout = nullptr;
@@ -620,5 +621,35 @@ void TestQgsLayoutMultiFrame::writeReadXml()
QCOMPARE( html2->frames(), QList< QgsLayoutFrame * >() << frame2 );
}

void TestQgsLayoutMultiFrame::noPageNoCrash()
{
QgsProject p;

// create layout, no pages
QgsLayout c( &p );
// add an multiframe
QgsLayoutItemHtml *html = new QgsLayoutItemHtml( &c );
c.addMultiFrame( html );
html->setContentMode( QgsLayoutItemHtml::ManualHtml );
html->setHtml( QStringLiteral( "<div style=\"height: 2000px\">hi</div>" ) );
QgsLayoutFrame *frame = new QgsLayoutFrame( &c, html );
frame->attemptSetSceneRect( QRectF( 1, 1, 10, 1 ) );
c.addLayoutItem( frame );
html->addFrame( frame );

html->setResizeMode( QgsLayoutMultiFrame::UseExistingFrames );
html->recalculateFrameSizes();
QCOMPARE( html->frameCount(), 1 );
html->setResizeMode( QgsLayoutMultiFrame::ExtendToNextPage );
html->recalculateFrameSizes();
QCOMPARE( html->frameCount(), 1 );
html->setResizeMode( QgsLayoutMultiFrame::RepeatOnEveryPage );
html->recalculateFrameSizes();
QCOMPARE( html->frameCount(), 1 );
html->setResizeMode( QgsLayoutMultiFrame::RepeatUntilFinished );
html->recalculateFrameSizes();
QCOMPARE( html->frameCount(), 1 );
}

QGSTEST_MAIN( TestQgsLayoutMultiFrame )
#include "testqgslayoutmultiframe.moc"

0 comments on commit fb3ff6d

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