Skip to content
Permalink
Browse files

Move QgsCompositionChecker to core, speeds up compilation with

tests enabled
  • Loading branch information
nyalldawson committed Mar 6, 2016
1 parent df22d56 commit eb31e01a2f6e90bf003d589067e2c85579f64054
@@ -322,6 +322,7 @@ SET(ENABLE_MODELTEST FALSE CACHE BOOL "Enable QT ModelTest (not for production)"

IF (ENABLE_TESTS)
SET( QT_USE_QTTEST TRUE )
ADD_DEFINITIONS(-DENABLE_TESTS)
ENABLE_TESTING()
# Adds some testing specific build targets e.g. make Experimental
INCLUDE(Dart)
@@ -14,7 +14,7 @@
***************************************************************************/

#include "qgsmultirenderchecker.h"

#include "qgscomposition.h"
#include <QDebug>

QgsMultiRenderChecker::QgsMultiRenderChecker()
@@ -102,3 +102,84 @@ QString QgsMultiRenderChecker::controlImagePath() const
QDir::separator() + mControlPathPrefix + QDir::separator() + mControlName + QDir::separator();
return myControlImageDir;
}

#ifdef ENABLE_TESTS

//
// QgsCompositionChecker
//

///@cond PRIVATE

QgsCompositionChecker::QgsCompositionChecker( const QString& testName, QgsComposition* composition )
: QgsMultiRenderChecker()
, mTestName( testName )
, mComposition( composition )
, mSize( 1122, 794 )
, mDotsPerMeter( 96 / 25.4 * 1000 )
{
// The composer has some slight render inconsistencies on the whole image sometimes
setColorTolerance( 5 );
}

QgsCompositionChecker::QgsCompositionChecker()
: mComposition( nullptr )
, mDotsPerMeter( 96 / 25.4 * 1000 )
{
}

QgsCompositionChecker::~QgsCompositionChecker()
{
}

bool QgsCompositionChecker::testComposition( QString &theReport, int page, int pixelDiff )
{
if ( !mComposition )
{
return false;
}

setControlName( "expected_" + mTestName );

#if 0
//fake mode to generate expected image
//assume 96 dpi and size of the control image 1122 * 794
QImage newImage( QSize( 1122, 794 ), QImage::Format_RGB32 );
mComposition->setPlotStyle( QgsComposition::Print );
newImage.setDotsPerMeterX( 96 / 25.4 * 1000 );
newImage.setDotsPerMeterY( 96 / 25.4 * 1000 );
drawBackground( &newImage );
QPainter expectedPainter( &newImage );
//QRectF sourceArea( 0, 0, mComposition->paperWidth(), mComposition->paperHeight() );
//QRectF targetArea( 0, 0, 3507, 2480 );
mComposition->renderPage( &expectedPainter, page );
expectedPainter.end();
newImage.save( mExpectedImageFile, "PNG" );
return true;
#endif //0

QImage outputImage( mSize, QImage::Format_RGB32 );

mComposition->setPlotStyle( QgsComposition::Print );
outputImage.setDotsPerMeterX( mDotsPerMeter );
outputImage.setDotsPerMeterY( mDotsPerMeter );
drawBackground( &outputImage );
QPainter p( &outputImage );
mComposition->renderPage( &p, page );
p.end();

QString renderedFilePath = QDir::tempPath() + '/' + QFileInfo( mTestName ).baseName() + "_rendered.png";
outputImage.save( renderedFilePath, "PNG" );

setRenderedImage( renderedFilePath );

bool testResult = runTest( mTestName, pixelDiff );

theReport += report();

return testResult;
}

///@endcond

#endif
@@ -128,4 +128,29 @@ class CORE_EXPORT QgsMultiRenderChecker
QgsMapSettings mMapSettings;
};

#ifdef ENABLE_TESTS
// Renders a composition to an image and compares with an expected output
///@cond PRIVATE
class CORE_EXPORT QgsCompositionChecker : public QgsMultiRenderChecker
{
public:
QgsCompositionChecker( const QString& testName, QgsComposition* composition );
~QgsCompositionChecker();

void setSize( QSize size ) { mSize = size; }

bool testComposition( QString &theReport, int page = 0, int pixelDiff = 0 );

private:
QgsCompositionChecker(); //forbidden

QString mTestName;
QgsComposition* mComposition;
QSize mSize;
int mDotsPerMeter;
};
///@endcond
#endif


#endif // QGSMULTIRENDERCHECKER_H
@@ -1,5 +1,5 @@
# Standard includes and utils to compile into all tests.
SET (util_SRCS qgscompositionchecker.cpp)
#SET (util_SRCS qgscompositionchecker.cpp)


#####################################################

This file was deleted.

This file was deleted.

@@ -17,7 +17,7 @@

#include "qgsapplication.h"
#include "qgscomposition.h"
#include "qgscompositionchecker.h"
#include "qgsmultirenderchecker.h"
#include "qgscomposermap.h"
#include "qgscomposermapoverview.h"
#include "qgsatlascomposition.h"
@@ -17,7 +17,7 @@

#include "qgsapplication.h"
#include "qgscomposition.h"
#include "qgscompositionchecker.h"
#include "qgsmultirenderchecker.h"
#include "qgscomposershape.h"
#include "qgsmaprenderer.h"
#include <QObject>
@@ -18,7 +18,7 @@
#include "qgscomposeritemgroup.h"
#include "qgscomposerlabel.h"
#include "qgscomposition.h"
#include "qgscompositionchecker.h"
#include "qgsmultirenderchecker.h"
#include "qgsapplication.h"

#include <QObject>
@@ -19,7 +19,7 @@
#include "qgscomposerhtml.h"
#include "qgscomposerframe.h"
#include "qgscomposition.h"
#include "qgscompositionchecker.h"
#include "qgsmultirenderchecker.h"
#include "qgsfontutils.h"
#include <QObject>
#include <QtTest/QtTest>
@@ -17,7 +17,7 @@

#include "qgsapplication.h"
#include "qgscomposition.h"
#include "qgscompositionchecker.h"
#include "qgsmultirenderchecker.h"
#include "qgscomposermap.h"
#include "qgsmaplayerregistry.h"
#include "qgsmaprenderer.h"
@@ -17,7 +17,7 @@

#include "qgsapplication.h"
#include "qgscomposition.h"
#include "qgscompositionchecker.h"
#include "qgsmultirenderchecker.h"
#include "qgscomposermap.h"
#include "qgscomposermapgrid.h"
#include "qgsmaplayerregistry.h"
@@ -17,7 +17,7 @@

#include "qgsapplication.h"
#include "qgscomposition.h"
#include "qgscompositionchecker.h"
#include "qgsmultirenderchecker.h"
#include "qgscomposermap.h"
#include "qgscomposermapoverview.h"
#include "qgsmaplayerregistry.h"
@@ -19,7 +19,7 @@
#include "qgscomposerframe.h"
#include "qgscomposerlabel.h"
#include "qgscomposition.h"
#include "qgscompositionchecker.h"
#include "qgsmultirenderchecker.h"
#include "qgsapplication.h"

#include <QObject>
@@ -17,7 +17,7 @@

#include "qgscomposerobject.h"
#include "qgscomposition.h"
#include "qgscompositionchecker.h"
#include "qgsmultirenderchecker.h"
#include "qgsdatadefined.h"
#include "qgsexpression.h"
#include "qgsapplication.h"
@@ -17,7 +17,7 @@

#include "qgsapplication.h"
#include "qgscomposition.h"
#include "qgscompositionchecker.h"
#include "qgsmultirenderchecker.h"
#include "qgscomposershape.h"
#include "qgssymbolv2.h"
#include "qgssinglesymbolrendererv2.h"
@@ -17,7 +17,7 @@

#include "qgsapplication.h"
#include "qgscomposition.h"
#include "qgscompositionchecker.h"
#include "qgsmultirenderchecker.h"
#include "qgscomposerpicture.h"
#include <QObject>
#include <QtTest/QtTest>
@@ -17,7 +17,7 @@

#include "qgsapplication.h"
#include "qgscomposition.h"
#include "qgscompositionchecker.h"
#include "qgsmultirenderchecker.h"
#include "qgscomposershape.h"
#include "qgscomposermap.h"
#include "qgscomposerlabel.h"
@@ -17,7 +17,7 @@

#include "qgsapplication.h"
#include "qgscomposition.h"
#include "qgscompositionchecker.h"
#include "qgsmultirenderchecker.h"
#include "qgscomposermap.h"
#include "qgscomposerscalebar.h"
#include "qgsmaplayerregistry.h"
@@ -17,7 +17,7 @@

#include "qgsapplication.h"
#include "qgscomposition.h"
#include "qgscompositionchecker.h"
#include "qgsmultirenderchecker.h"
#include "qgscomposershape.h"
#include "qgsmapsettings.h"
#include "qgssymbolv2.h"

0 comments on commit eb31e01

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