21 : mColorTolerance( 0 )
27 mControlName = theName;
32 mControlPathPrefix = prefix;
37 mMapSettings = mapSettings;
42 bool successful =
false;
55 Q_FOREACH (
const QString& suffix, subDirs )
57 qDebug() <<
"Checking subdir " << suffix;
67 if ( !mRenderedImage.
isNull() )
70 result = checker.
compareImages( theTestName, theMismatchCount, mRenderedImage );
74 result = checker.
runTest( theTestName, theMismatchCount );
82 mReport += checker.
report();
91 "If this is a rendering inconsistency, please add another control image folder, add an anomaly image or increase the color tolerance." );
100 QString myDataDir( TEST_DATA_DIR );
103 return myControlImageDir;
116 , mTestName( testName )
117 , mComposition( composition )
119 , mDotsPerMeter( 96 / 25.4 * 1000 )
125 QgsCompositionChecker::QgsCompositionChecker()
126 : mComposition(
nullptr )
127 , mDotsPerMeter( 96 / 25.4 * 1000 )
131 QgsCompositionChecker::~QgsCompositionChecker()
135 bool QgsCompositionChecker::testComposition(
QString &theReport,
int page,
int pixelDiff )
147 QImage newImage(
QSize( 1122, 794 ), QImage::Format_RGB32 );
152 QPainter expectedPainter( &newImage );
155 mComposition->renderPage( &expectedPainter, page );
156 expectedPainter.
end();
161 QImage outputImage( mSize, QImage::Format_RGB32 );
168 mComposition->renderPage( &p, page );
172 outputImage.
save( renderedFilePath,
"PNG" );
176 bool testResult =
runTest( mTestName, pixelDiff );
void setControlPathSuffix(const QString &theName)
void setColorTolerance(unsigned int theColorTolerance)
Set tolerance for color components used by runTest() and compareImages().
void setDotsPerMeterX(int x)
void setDotsPerMeterY(int y)
void enableDashBuffering(bool enable)
Call this to enable internal buffering of dash messages.
void setControlName(const QString &theName)
Base directory name for the control image (with control image path suffixed) the path to the image wi...
bool save(const QString &fileName, const char *format, int quality) const
bool runTest(const QString &theTestName, unsigned int theMismatchCount=0)
Test using renderer to generate the image to be compared.
QString report() const
Returns a report for this test.
QString renderedImage()
The path of the rendered image can be retrieved through that method.
This is a helper class for unit tests that need to write an image and compare it to an expected resul...
void setMapSettings(const QgsMapSettings &mapSettings)
The QgsMapSettings class contains configuration for rendering of the map.
void setControlName(const QString &theName)
Base directory name for the control image (with control image path suffixed) the path to the image wi...
bool compareImages(const QString &theTestName, unsigned int theMismatchCount=0, const QString &theRenderedImageFile="")
Test using two arbitary images (map renderer will not be used)
void setRenderedImage(const QString &theImageFileName)
QString controlImagePath() const
controlImagePath
void setMapSettings(const QgsMapSettings &mapSettings)
Set the map settings to use to render the image.
Graphics scene for map printing.
void setControlPathPrefix(const QString &prefix)
bool runTest(const QString &theTestName, unsigned int theMismatchCount=0)
Test using renderer to generate the image to be compared.
QVector< QgsDartMeasurement > dartMeasurements() const
Get access to buffered dash messages.
void setControlPathPrefix(const QString &theName)
Prefix where the control images are kept.
void setColorTolerance(unsigned int theColorTolerance)
Set tolerance for color components used by runTest() Default value is 0.
QStringList entryList(QFlags< QDir::Filter > filters, QFlags< QDir::SortFlag > sort) const
static void drawBackground(QImage *image)
Draws a checkboard pattern for image backgrounds, so that transparency is visible without requiring a...
void setRenderedImage(const QString &renderedImagePath)
Set the path to the rendered image.