Skip to content
Permalink
Browse files

Allow plugins to set control image path for QgsRenderChecker, so that

they can reuse this class for plugin specific tests
  • Loading branch information
nyalldawson committed Jan 5, 2021
1 parent 736dff5 commit bb05c3bcfb6e00208bb00a6c577f2d99e9799faa
Showing with 119 additions and 29 deletions.
  1. +54 −12 python/core/auto_generated/qgsrenderchecker.sip.in
  2. +11 −3 src/core/qgsrenderchecker.cpp
  3. +54 −14 src/core/qgsrenderchecker.h
@@ -29,26 +29,66 @@ Constructor for QgsRenderChecker.
%End

QString controlImagePath() const;
%Docstring
Returns the base path containing the reference images.

This defaults to an internal QGIS test data path, but can be changed via :py:func:`~QgsRenderChecker.setControlImagePath`.

.. seealso:: :py:func:`setControlImagePath`
%End

void setControlImagePath( const QString &path );
%Docstring
Sets the base ``path`` containing the reference images.

.. seealso:: :py:func:`controlImagePath`

.. versionadded:: 3.18
%End

QString report();
%Docstring
Returns the HTML report describing the results of the test run.
%End

float matchPercent() const;
%Docstring
Returns the percent of pixels which matched the control image.
%End

unsigned int mismatchCount() const;
%Docstring
Returns the number of pixels which did not match the control image.
%End

unsigned int matchTarget() const;
%Docstring
Returns the total number of pixels in the control image.
%End

float matchPercent();
unsigned int mismatchCount();
unsigned int matchTarget();
int elapsedTime();
%Docstring
Returns the total elapsed time for the rendering test.

.. note::

this only records time for actual render part.
%End
void setElapsedTimeTarget( int target );

void setControlName( const QString &name );
%Docstring
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'
Sets the base directory ``name`` for the control image (with control image path
suffixed).

The path to the image will be constructed like this:
:py:func:`~QgsRenderChecker.controlImagePath` + '/' + control name + '/' + control name + '.png'
%End

void setControlPathPrefix( const QString &name );
%Docstring
Prefix where the control images are kept.
This will be appended to controlImagePath
Sets the path prefix where the control images are kept.
This will be appended to :py:func:`~QgsRenderChecker.controlImagePath`.
%End

void setControlPathSuffix( const QString &name );
@@ -59,13 +99,15 @@ Gets an md5 hash that uniquely identifies an image
%End

void setRenderedImage( const QString &imageFileName );
%Docstring
Sets the file name of the rendered image generated by the test.
%End

QString renderedImage();
QString renderedImage() const;
%Docstring
The path of the rendered image can be retrieved through that method.
Will return the path set with :py:func:`~QgsRenderChecker.setRenderedImage` or generated in :py:func:`~QgsRenderChecker.runTest`
Returns the path of the rendered image generated by the test.

:return: The path to the rendered image
This method will return either the path set with :py:func:`~QgsRenderChecker.setRenderedImage` or generated in :py:func:`~QgsRenderChecker.runTest`.
%End

void setMapSettings( const QgsMapSettings &mapSettings );
@@ -28,11 +28,19 @@
#include <QBuffer>


QgsRenderChecker::QgsRenderChecker()
: mBasePath( QStringLiteral( TEST_DATA_DIR ) + QStringLiteral( "/control_images/" ) ) //defined in CmakeLists.txt
{
}

QString QgsRenderChecker::controlImagePath() const
{
QString myDataDir( TEST_DATA_DIR ); //defined in CmakeLists.txt
QString myControlImageDir = myDataDir + "/control_images/" + mControlPathPrefix;
return myControlImageDir;
return mBasePath + ( mBasePath.endsWith( '/' ) ? QString() : QStringLiteral( "/" ) ) + mControlPathPrefix;
}

void QgsRenderChecker::setControlImagePath( const QString &path )
{
mBasePath = path;
}

void QgsRenderChecker::setControlName( const QString &name )
@@ -42,33 +42,69 @@ class CORE_EXPORT QgsRenderChecker
/**
* Constructor for QgsRenderChecker.
*/
QgsRenderChecker() = default;
QgsRenderChecker();

/**
* Returns the base path containing the reference images.
*
* This defaults to an internal QGIS test data path, but can be changed via setControlImagePath().
*
* \see setControlImagePath()
*/
QString controlImagePath() const;

/**
* Sets the base \a path containing the reference images.
*
* \see controlImagePath()
* \since QGIS 3.18
*/
void setControlImagePath( const QString &path );

/**
* Returns the HTML report describing the results of the test run.
*/
QString report() { return mReport; }

float matchPercent()
/**
* Returns the percent of pixels which matched the control image.
*/
float matchPercent() const
{
return static_cast<float>( mMismatchCount ) /
static_cast<float>( mMatchTarget ) * 100;
}
unsigned int mismatchCount() { return mMismatchCount; }
unsigned int matchTarget() { return mMatchTarget; }
//only records time for actual render part

/**
* Returns the number of pixels which did not match the control image.
*/
unsigned int mismatchCount() const { return mMismatchCount; }

/**
* Returns the total number of pixels in the control image.
*/
unsigned int matchTarget() const { return mMatchTarget; }

/**
* Returns the total elapsed time for the rendering test.
*
* \note this only records time for actual render part.
*/
int elapsedTime() { return mElapsedTime; }
void setElapsedTimeTarget( int target ) { mElapsedTimeTarget = target; }

/**
* 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'
* Sets the base directory \a name for the control image (with control image path
* suffixed).
*
* The path to the image will be constructed like this:
* controlImagePath() + '/' + control name + '/' + control name + '.png'
*/
void setControlName( const QString &name );

/**
* Prefix where the control images are kept.
* This will be appended to controlImagePath
* Sets the path prefix where the control images are kept.
* This will be appended to controlImagePath().
*/
void setControlPathPrefix( const QString &name ) { mControlPathPrefix = name + '/'; }

@@ -77,15 +113,17 @@ class CORE_EXPORT QgsRenderChecker
//! Gets an md5 hash that uniquely identifies an image
QString imageToHash( const QString &imageFile );

/**
* Sets the file name of the rendered image generated by the test.
*/
void setRenderedImage( const QString &imageFileName ) { mRenderedImageFile = imageFileName; }

/**
* 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 of the rendered image generated by the test.
*
* \returns The path to the rendered image
* This method will return either the path set with setRenderedImage() or generated in runTest().
*/
QString renderedImage() { return mRenderedImageFile; }
QString renderedImage() const { return mRenderedImageFile; }

//! \since QGIS 2.4
void setMapSettings( const QgsMapSettings &mapSettings );
@@ -183,6 +221,8 @@ class CORE_EXPORT QgsRenderChecker
void emitDashMessage( const QgsDartMeasurement &dashMessage );
void emitDashMessage( const QString &name, QgsDartMeasurement::Type type, const QString &value );

QString mBasePath;

QString mControlName;
unsigned int mMismatchCount = 0;
unsigned int mColorTolerance = 0;

0 comments on commit bb05c3b

Please sign in to comment.
You can’t perform that action at this time.