Skip to content
Permalink
Browse files

Switch QgsCompositionChecker to MultiRenderChecker

  • Loading branch information
m-kuhn committed Nov 14, 2014
1 parent 31c3250 commit fd95930194279fb8876334554f1f1a43939ae01b
@@ -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 );
};

@@ -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 );
};
@@ -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;
@@ -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;
@@ -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;
@@ -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 )
@@ -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):
@@ -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.
You can’t perform that action at this time.