Skip to content

Commit

Permalink
Use a non-transparent background for composition checker
Browse files Browse the repository at this point in the history
Fix composerhtml tests on precise
  • Loading branch information
nyalldawson authored and m-kuhn committed Nov 14, 2014
1 parent eaf0d34 commit 2cfcca1
Show file tree
Hide file tree
Showing 113 changed files with 31 additions and 5 deletions.
25 changes: 23 additions & 2 deletions tests/src/core/qgscompositionchecker.cpp
Expand Up @@ -40,6 +40,27 @@ QgsCompositionChecker::~QgsCompositionChecker()
{
}

void QgsCompositionChecker::drawBackround( QImage* image )
{
// create a 2x2 checker-board image
uchar pixDataRGB[] = { 255, 255, 255, 255,
127, 127, 127, 255,
127, 127, 127, 255,
255, 255, 255, 255
};

QImage img( pixDataRGB, 2, 2, 8, QImage::Format_ARGB32 );
QPixmap pix = QPixmap::fromImage( img.scaled( 20, 20 ) );

// fill image with texture
QBrush brush;
brush.setTexture( pix );
QPainter p( image );
p.setRenderHint( QPainter::Antialiasing, false );
p.fillRect( QRect( 0, 0, image->width(), image->height() ), brush );
p.end();
}

bool QgsCompositionChecker::testComposition( QString &theReport, int page, int pixelDiff )
{
if ( !mComposition )
Expand All @@ -56,7 +77,7 @@ bool QgsCompositionChecker::testComposition( QString &theReport, int page, int p
mComposition->setPlotStyle( QgsComposition::Print );
newImage.setDotsPerMeterX( 96 / 25.4 * 1000 );
newImage.setDotsPerMeterY( 96 / 25.4 * 1000 );
newImage.fill( 0 );
drawBackround( &newImage );
QPainter expectedPainter( &newImage );
//QRectF sourceArea( 0, 0, mComposition->paperWidth(), mComposition->paperHeight() );
//QRectF targetArea( 0, 0, 3507, 2480 );
Expand All @@ -71,7 +92,7 @@ bool QgsCompositionChecker::testComposition( QString &theReport, int page, int p
mComposition->setPlotStyle( QgsComposition::Print );
outputImage.setDotsPerMeterX( mDotsPerMeter );
outputImage.setDotsPerMeterY( mDotsPerMeter );
outputImage.fill( 0 );
drawBackround( &outputImage );
QPainter p( &outputImage );
mComposition->renderPage( &p, page );
p.end();
Expand Down
7 changes: 6 additions & 1 deletion tests/src/core/qgscompositionchecker.h
Expand Up @@ -29,11 +29,16 @@ class QgsCompositionChecker : public QgsMultiRenderChecker
QgsCompositionChecker( const QString& testName, QgsComposition* composition );
~QgsCompositionChecker();

bool testComposition( QString &report, int page = 0, int pixelDiff = 0 );
bool testComposition( QString &theReport, int page = 0, int pixelDiff = 0 );

private:
QgsCompositionChecker(); //forbidden

/**Draws a checkboard pattern for image backgrounds, so that transparency is visible
* without requiring a transparent background for the image
*/
void drawBackround( QImage* image );

QString mTestName;
QgsComposition* mComposition;
QSize mSize;
Expand Down
4 changes: 2 additions & 2 deletions tests/src/core/testqgscomposerhtml.cpp
Expand Up @@ -95,7 +95,7 @@ void TestQgsComposerHtml::sourceMode()
htmlItem->loadHtml();

QgsCompositionChecker checker( "composerhtml_manual", mComposition );
bool result = checker.testComposition( mReport );
bool result = checker.testComposition( mReport, 0, 100 );
mComposition->removeMultiFrame( htmlItem );
delete htmlItem;
QVERIFY( result );
Expand All @@ -116,7 +116,7 @@ void TestQgsComposerHtml::userStylesheets()
htmlItem->setUserStylesheetEnabled( true );

QgsCompositionChecker checker( "composerhtml_userstylesheet", mComposition );
bool result = checker.testComposition( mReport );
bool result = checker.testComposition( mReport, 0, 100 );
mComposition->removeMultiFrame( htmlItem );
delete htmlItem;
QVERIFY( result );
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 2cfcca1

Please sign in to comment.