QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
QgsRenderChecker Class Reference

This is a helper class for unit tests that need to write an image and compare it to an expected result or render time. More...

#include <qgsrenderchecker.h>

Public Member Functions

 QgsRenderChecker ()=default
 Constructor for QgsRenderChecker. More...
 
bool compareImages (const QString &testName, unsigned int mismatchCount=0, const QString &renderedImageFile=QString())
 Test using two arbitrary images (map renderer will not be used) More...
 
QString controlImagePath () const
 
QVector< QgsDartMeasurementdartMeasurements () const
 Gets access to buffered dash messages. More...
 
int elapsedTime ()
 
void enableDashBuffering (bool enable)
 Call this to enable internal buffering of dash messages. More...
 
QString expectedImageFile () const
 Returns the path to the expected image file. More...
 
QString imageToHash (const QString &imageFile)
 Gets an md5 hash that uniquely identifies an image. More...
 
bool isKnownAnomaly (const QString &diffImageFile)
 Gets a list of all the anomalies. More...
 
float matchPercent ()
 
unsigned int matchTarget ()
 
unsigned int mismatchCount ()
 
QString renderedImage ()
 The path of the rendered image can be retrieved through that method. More...
 
QString report ()
 
bool runTest (const QString &testName, unsigned int mismatchCount=0)
 Test using renderer to generate the image to be compared. More...
 
void setColorTolerance (unsigned int colorTolerance)
 Set tolerance for color components used by runTest() and compareImages(). More...
 
void setControlName (const QString &name)
 Base directory name for the control image (with control image path suffixed) the path to the image will be constructed like this: controlImagePath + '/' + mControlName + '/' + mControlName + '.png'. More...
 
void setControlPathPrefix (const QString &name)
 Prefix where the control images are kept. More...
 
void setControlPathSuffix (const QString &name)
 
void setElapsedTimeTarget (int target)
 
void setMapSettings (const QgsMapSettings &mapSettings)
 
void setRenderedImage (const QString &imageFileName)
 
void setSizeTolerance (int xTolerance, int yTolerance)
 Sets the largest allowable difference in size between the rendered and the expected image. More...
 

Static Public Member Functions

static void drawBackground (QImage *image)
 Draws a checkboard pattern for image backgrounds, so that opacity is visible without requiring a transparent background for the image. More...
 

Protected Attributes

int mElapsedTime = 0
 
QString mExpectedImageFile
 
unsigned int mMatchTarget = 0
 
QString mRenderedImageFile
 
QString mReport
 

Detailed Description

This is a helper class for unit tests that need to write an image and compare it to an expected result or render time.

Definition at line 38 of file qgsrenderchecker.h.

Constructor & Destructor Documentation

◆ QgsRenderChecker()

QgsRenderChecker::QgsRenderChecker ( )
default

Constructor for QgsRenderChecker.

Member Function Documentation

◆ compareImages()

bool QgsRenderChecker::compareImages ( const QString &  testName,
unsigned int  mismatchCount = 0,
const QString &  renderedImageFile = QString() 
)

Test using two arbitrary images (map renderer will not be used)

Parameters
testName- to be used as the basis for writing a file to e.g. /tmp/theTestName.png
mismatchCount- defaults to 0 - the number of pixels that are allowed to be different from the control image. In some cases rendering may be non-deterministic. This parameter allows you to account for that by providing a tolerance.
renderedImageFileto optionally override the output filename
Note
: make sure to call setExpectedImage and setRenderedImage first.

Definition at line 233 of file qgsrenderchecker.cpp.

◆ controlImagePath()

QString QgsRenderChecker::controlImagePath ( ) const

Definition at line 31 of file qgsrenderchecker.cpp.

◆ dartMeasurements()

QVector<QgsDartMeasurement> QgsRenderChecker::dartMeasurements ( ) const
inline

Gets access to buffered dash messages.

Only will return something if you call enableDashBuffering( true ); before.

Returns
buffered dash messages

Definition at line 173 of file qgsrenderchecker.h.

◆ drawBackground()

void QgsRenderChecker::drawBackground ( QImage *  image)
static

Draws a checkboard pattern for image backgrounds, so that opacity is visible without requiring a transparent background for the image.

Definition at line 70 of file qgsrenderchecker.cpp.

◆ elapsedTime()

int QgsRenderChecker::elapsedTime ( )
inline

Definition at line 59 of file qgsrenderchecker.h.

◆ enableDashBuffering()

void QgsRenderChecker::enableDashBuffering ( bool  enable)
inline

Call this to enable internal buffering of dash messages.

You may later call dashMessages() to get access to the buffered messages. If disabled (default) dash messages will be sent immediately.

Parameters
enableEnable or disable buffering

Definition at line 165 of file qgsrenderchecker.h.

◆ expectedImageFile()

QString QgsRenderChecker::expectedImageFile ( ) const
inline

Returns the path to the expected image file.

Returns
Path to the expected image file

Definition at line 156 of file qgsrenderchecker.h.

◆ imageToHash()

QString QgsRenderChecker::imageToHash ( const QString &  imageFile)

Gets an md5 hash that uniquely identifies an image.

Definition at line 52 of file qgsrenderchecker.cpp.

◆ isKnownAnomaly()

bool QgsRenderChecker::isKnownAnomaly ( const QString &  diffImageFile)

Gets a list of all the anomalies.

An anomaly is a rendered difference file where there is some red pixel content (indicating a render check mismatch), but where the output was still acceptable. If the render diff matches one of these anomalies we will still consider it to be acceptable.

Returns
a bool indicating if the diff matched one of the anomaly files

Definition at line 91 of file qgsrenderchecker.cpp.

◆ matchPercent()

float QgsRenderChecker::matchPercent ( )
inline

Definition at line 51 of file qgsrenderchecker.h.

◆ matchTarget()

unsigned int QgsRenderChecker::matchTarget ( )
inline

Definition at line 57 of file qgsrenderchecker.h.

◆ mismatchCount()

unsigned int QgsRenderChecker::mismatchCount ( )
inline

Definition at line 56 of file qgsrenderchecker.h.

◆ renderedImage()

QString QgsRenderChecker::renderedImage ( )
inline

The path of the rendered image can be retrieved through that method.

Will return the path set with setRenderedImage() or generated in runTest()

Returns
The path to the rendered image

Definition at line 88 of file qgsrenderchecker.h.

◆ report()

QString QgsRenderChecker::report ( )
inline

Definition at line 49 of file qgsrenderchecker.h.

◆ runTest()

bool QgsRenderChecker::runTest ( const QString &  testName,
unsigned int  mismatchCount = 0 
)

Test using renderer to generate the image to be compared.

Parameters
testName- to be used as the basis for writing a file to e.g. /tmp/theTestName.png
mismatchCount- defaults to 0 - the number of pixels that are allowed to be different from the control image. In some cases rendering may be non-deterministic. This parameter allows you to account for that by providing a tolerance.
Note
make sure to call setExpectedImage and setMapRenderer first

Definition at line 151 of file qgsrenderchecker.cpp.

◆ setColorTolerance()

void QgsRenderChecker::setColorTolerance ( unsigned int  colorTolerance)
inline

Set tolerance for color components used by runTest() and compareImages().

Default value is 0.

Parameters
colorToleranceis maximum difference for each color component including alpha to be considered correct.
Since
QGIS 2.1

Definition at line 100 of file qgsrenderchecker.h.

◆ setControlName()

void QgsRenderChecker::setControlName ( const QString &  name)

Base directory name for the control image (with control image path suffixed) the path to the image will be constructed like this: controlImagePath + '/' + mControlName + '/' + mControlName + '.png'.

Definition at line 38 of file qgsrenderchecker.cpp.

◆ setControlPathPrefix()

void QgsRenderChecker::setControlPathPrefix ( const QString &  name)
inline

Prefix where the control images are kept.

This will be appended to controlImagePath

Definition at line 73 of file qgsrenderchecker.h.

◆ setControlPathSuffix()

void QgsRenderChecker::setControlPathSuffix ( const QString &  name)

Definition at line 44 of file qgsrenderchecker.cpp.

◆ setElapsedTimeTarget()

void QgsRenderChecker::setElapsedTimeTarget ( int  target)
inline

Definition at line 60 of file qgsrenderchecker.h.

◆ setMapSettings()

void QgsRenderChecker::setMapSettings ( const QgsMapSettings mapSettings)
Since
QGIS 2.4

Definition at line 65 of file qgsrenderchecker.cpp.

◆ setRenderedImage()

void QgsRenderChecker::setRenderedImage ( const QString &  imageFileName)
inline

Definition at line 80 of file qgsrenderchecker.h.

◆ setSizeTolerance()

void QgsRenderChecker::setSizeTolerance ( int  xTolerance,
int  yTolerance 
)
inline

Sets the largest allowable difference in size between the rendered and the expected image.

Parameters
xTolerancex tolerance in pixels
yTolerancey tolerance in pixels
Since
QGIS 2.12

Definition at line 108 of file qgsrenderchecker.h.

Member Data Documentation

◆ mElapsedTime

int QgsRenderChecker::mElapsedTime = 0
protected

Definition at line 178 of file qgsrenderchecker.h.

◆ mExpectedImageFile

QString QgsRenderChecker::mExpectedImageFile
protected

Definition at line 180 of file qgsrenderchecker.h.

◆ mMatchTarget

unsigned int QgsRenderChecker::mMatchTarget = 0
protected

Definition at line 177 of file qgsrenderchecker.h.

◆ mRenderedImageFile

QString QgsRenderChecker::mRenderedImageFile
protected

Definition at line 179 of file qgsrenderchecker.h.

◆ mReport

QString QgsRenderChecker::mReport
protected

Definition at line 176 of file qgsrenderchecker.h.


The documentation for this class was generated from the following files: