27 mControlPathPrefix = prefix;
32 mMapSettings = mapSettings;
37 bool successful =
false;
41 QStringList subDirs = QDir( baseDir ).entryList( QDir::Dirs | QDir::NoDotAndDotDot );
43 if ( subDirs.isEmpty() )
48 QVector<QgsDartMeasurement> dartMeasurements;
50 for (
const QString &suffix : qgis::as_const( subDirs ) )
52 if ( subDirs.count() > 1 )
54 qDebug() <<
"Checking subdir " << suffix;
66 if ( !mRenderedImage.isNull() )
69 result = checker.
compareImages( testName, mismatchCount, mRenderedImage );
73 result = checker.
runTest( testName, mismatchCount );
81 mReport += checker.
report();
86 const auto constDartMeasurements = dartMeasurements;
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 );
101 QString myControlImageDir = myDataDir + QDir::separator() +
"control_images" +
102 QDir::separator() + mControlPathPrefix + QDir::separator() + mControlName + QDir::separator();
103 return myControlImageDir;
112 QgsLayoutChecker::QgsLayoutChecker(
const QString &testName,
QgsLayout *layout )
113 : mTestName( testName )
116 , mDotsPerMeter( 96 / 25.4 * 1000 )
122 bool QgsLayoutChecker::testLayout( QString &checkedReport,
int page,
int pixelDiff,
bool createReferenceImage )
132 setControlName(
"expected_" + mTestName );
135 if ( createReferenceImage )
141 QImage _outputImage( mSize, QImage::Format_RGB32 );
142 _outputImage.setDotsPerMeterX( 96 / 25.4 * 1000 );
143 _outputImage.setDotsPerMeterY( 96 / 25.4 * 1000 );
144 QPainter _p( &_outputImage );
146 _exporter.renderPage( &_p, page );
149 if ( ! QDir( controlImagePath() ).exists() )
151 QDir().mkdir( controlImagePath() );
153 _outputImage.save( controlImagePath() + QDir::separator() +
"expected_" + mTestName +
".png",
"PNG" );
154 qDebug( ) <<
"Reference image saved to : " + controlImagePath() + QDir::separator() +
"expected_" + mTestName +
".png";
158 QImage outputImage( mSize, QImage::Format_RGB32 );
159 outputImage.setDotsPerMeterX( mDotsPerMeter );
160 outputImage.setDotsPerMeterY( mDotsPerMeter );
161 drawBackground( &outputImage );
162 QPainter p( &outputImage );
164 exporter.renderPage( &p, page );
167 QString renderedFilePath = QDir::tempPath() +
'/' + QFileInfo( mTestName ).baseName() +
"_rendered.png";
168 outputImage.save( renderedFilePath,
"PNG" );
170 setRenderedImage( renderedFilePath );
172 bool testResult = runTest( mTestName, pixelDiff );
174 checkedReport += report();
177 #endif // QT_NO_PRINTER