Skip to content

Commit

Permalink
Hopefully fix intermittently failing composer html test
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Dec 1, 2014
1 parent 78141c4 commit 48edab4
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/core/composer/qgscomposerhtml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,8 @@ double QgsComposerHtml::findNearbyPageBreak( double yPos )
//of maxSearchDistance
int changes = 0;
QRgb currentColor;
bool currentPixelTransparent = false;
bool previousPixelTransparent = false;
QRgb pixelColor;
QList< QPair<int, int> > candidates;
int minRow = qMax( idealPos - maxSearchDistance, 0 );
Expand All @@ -391,12 +393,14 @@ double QgsComposerHtml::findNearbyPageBreak( double yPos )
//since this is likely a line break, or gap between table cells, etc
//but very unlikely to be midway through a text line or picture
pixelColor = mRenderedPage->pixel( col, candidateRow );
if ( pixelColor != currentColor )
currentPixelTransparent = qAlpha( pixelColor ) == 0;
if ( pixelColor != currentColor && !( currentPixelTransparent && previousPixelTransparent ) )
{
//color has changed
currentColor = pixelColor;
changes++;
}
previousPixelTransparent = currentPixelTransparent;
}
candidates.append( qMakePair( candidateRow, changes ) );
}
Expand Down
4 changes: 2 additions & 2 deletions tests/src/core/testqgscomposerhtml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ void TestQgsComposerHtml::tableMultiFrame()
void TestQgsComposerHtml::htmlMultiFrameSmartBreak()
{
QgsComposerHtml* htmlItem = new QgsComposerHtml( mComposition, false );
QgsComposerFrame* htmlFrame = new QgsComposerFrame( mComposition, htmlItem, 10, 10, 100, 50 );
QgsComposerFrame* htmlFrame = new QgsComposerFrame( mComposition, htmlItem, 10, 10, 100, 52 );
htmlItem->addFrame( htmlFrame );
htmlItem->setResizeMode( QgsComposerMultiFrame::RepeatUntilFinished );
htmlItem->setUseSmartBreaks( true );
Expand All @@ -209,7 +209,7 @@ void TestQgsComposerHtml::htmlMultiFrameSmartBreak()
htmlItem->setUrl( QUrl( QString( "file:///%1" ).arg( QString( TEST_DATA_DIR ) + QDir::separator() + "test_html.html" ) ) );
htmlItem->frame( 0 )->setFrameEnabled( true );
QgsCompositionChecker checker1( "composerhtml_smartbreaks1", mComposition );
bool result = checker1.testComposition( mReport );
bool result = checker1.testComposition( mReport, 0, 200 );

//page2
QgsCompositionChecker checker2( "composerhtml_smartbreaks2", mComposition );
Expand Down
4 changes: 2 additions & 2 deletions tests/src/python/test_qgscomposerhtml.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def testHtmlSmartBreaks(self):
"""Test rendering to multiframes with smart breaks."""
composerHtml = QgsComposerHtml(self.mComposition, False)
htmlFrame = QgsComposerFrame(self.mComposition, composerHtml,
10, 10, 100, 50)
10, 10, 100, 52)
composerHtml.addFrame(htmlFrame)
composerHtml.setResizeMode(
QgsComposerMultiFrame.RepeatUntilFinished)
Expand All @@ -113,7 +113,7 @@ def testHtmlSmartBreaks(self):
print "Checking page 1"
myPage = 0
checker1 = QgsCompositionChecker('composerhtml_smartbreaks1', self.mComposition)
myTestResult, myMessage = checker1.testComposition( myPage )
myTestResult, myMessage = checker1.testComposition( myPage, 200 )
assert myTestResult, myMessage

print "Checking page 2"
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 48edab4

Please sign in to comment.