Skip to content

Commit

Permalink
Switch QgsCompositionChecker to MultiRenderChecker
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Nov 14, 2014
1 parent 31c3250 commit fd95930
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 59 deletions.
4 changes: 4 additions & 0 deletions python/core/qgsmultirenderchecker.sip
Expand Up @@ -87,5 +87,9 @@ class QgsMultiRenderChecker
*/
const QString controlImagePath() const;

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

2 changes: 1 addition & 1 deletion python/core/qgsrenderchecker.sip
Expand Up @@ -88,5 +88,5 @@ class QgsRenderChecker
/**Draws a checkboard pattern for image backgrounds, so that transparency is visible
* without requiring a transparent background for the image
*/
void drawBackround( QImage* image );
static void drawBackround( QImage* image );
};
5 changes: 5 additions & 0 deletions src/core/qgsmultirenderchecker.h
Expand Up @@ -114,6 +114,11 @@ class CORE_EXPORT QgsMultiRenderChecker
*/
const QString controlImagePath() const;

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

private:
QString mReport;
QString mRenderedImage;
Expand Down
12 changes: 6 additions & 6 deletions src/core/qgsrenderchecker.h
Expand Up @@ -127,7 +127,12 @@ class CORE_EXPORT QgsRenderChecker
*/
bool isKnownAnomaly( QString theDiffImageFile );

QString expectedImageFile() { return mExpectedImageFile; };
QString expectedImageFile() { return mExpectedImageFile; }

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

protected:
QString mReport;
Expand All @@ -136,11 +141,6 @@ class CORE_EXPORT QgsRenderChecker
QString mRenderedImageFile;
QString mExpectedImageFile;

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

private:
QString mControlName;
unsigned int mMismatchCount;
Expand Down
21 changes: 0 additions & 21 deletions tests/src/core/qgscompositionchecker.cpp
Expand Up @@ -40,27 +40,6 @@ 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 Down
43 changes: 12 additions & 31 deletions tests/src/python/qgscompositionchecker.py
Expand Up @@ -20,12 +20,14 @@
from PyQt4.QtGui import *
from qgis.core import *

class QgsCompositionChecker(QgsRenderChecker):
class QgsCompositionChecker(QgsMultiRenderChecker):
def __init__(self, mTestName, mComposition ):
self.mExpectedImageFile = ""
super(QgsCompositionChecker, self).__init__()
self.mComposition = mComposition
self.mTestName = mTestName
super(QgsCompositionChecker, self).__init__()
self.mDotsPerMeter = 96 / 25.4 * 1000
self.mSize = QSize( 1122, 794 )
self.setColorTolerance( 1 )

def testComposition(self, page=0, pixelDiff=0 ):
if ( self.mComposition == None):
Expand All @@ -34,45 +36,24 @@ def testComposition(self, page=0, pixelDiff=0 ):

#load expected image
self.setControlName("expected_"+self.mTestName);
expectedImage = QImage( self.expectedImageFile() )

#get width/height, create image and render the composition to it
width = expectedImage.width();
height = expectedImage.height();
outputImage = QImage( QSize( width, height ), QImage.Format_RGB32 )
outputImage = QImage( self.mSize, QImage.Format_RGB32 )

self.mComposition.setPlotStyle( QgsComposition.Print )
outputImage.setDotsPerMeterX( expectedImage.dotsPerMeterX() )
outputImage.setDotsPerMeterY( expectedImage.dotsPerMeterX() )
self.drawBackround( outputImage )
outputImage.setDotsPerMeterX( self.mDotsPerMeter )
outputImage.setDotsPerMeterY( self.mDotsPerMeter )
QgsMultiRenderChecker.drawBackround( outputImage )
p = QPainter( outputImage )
self.mComposition.renderPage( p, page )
p.end()

renderedFilePath = QDir.tempPath() + QDir.separator() + QFileInfo(self.mTestName).baseName() + "_rendered.png"
outputImage.save( renderedFilePath, "PNG" )

diffFilePath = QDir.tempPath() + QDir.separator() + QFileInfo(self.mTestName).baseName() + "_result_diff.png"
testResult = self.compareImages( self.mTestName, pixelDiff, renderedFilePath )
self.setRenderedImage( renderedFilePath )

myDashMessage = (('<DartMeasurementFile name="Rendered Image '
'%s" type="image/png">'
'%s</DartMeasurementFile>'
'<DartMeasurementFile name="Expected Image '
'%s" type="image/png">'
'%s</DartMeasurementFile>\n'
'<DartMeasurementFile name="Difference Image '
'%s" type="image/png">'
'%s</DartMeasurementFile>') %
(self.mTestName, renderedFilePath, self.mTestName,
self.expectedImageFile(), self.mTestName, diffFilePath )
)
qDebug( myDashMessage )
if not testResult:
myMessage = ('Expected: %s\nGot: %s\nDifference: %s\n' %
(self.expectedImageFile(), renderedFilePath, diffFilePath))
else:
myMessage = 'Control and test images matched.'
testResult = self.runTest( self.mTestName, pixelDiff )

return testResult, myMessage
return testResult, self.report()

0 comments on commit fd95930

Please sign in to comment.