Skip to content
Permalink
Browse files

Add test for composer grid

  • Loading branch information
mhugent committed Jul 6, 2012
1 parent f6f4474 commit 67ba1d5344548acaf2d520c9aee39dc16556f22f
@@ -53,7 +53,6 @@ bool QgsCompositionChecker::testComposition()
return false;
#endif //0

#if 1
//load expected image
QImage expectedImage( mExpectedImageFile );

@@ -63,8 +62,8 @@ bool QgsCompositionChecker::testComposition()
QImage outputImage( QSize( width, height ), QImage::Format_ARGB32 );

mComposition->setPlotStyle( QgsComposition::Print );
outputImage.setDotsPerMeterX( expectedImage.dotsPerMeterX() /*mComposition->printResolution() / 25.4 * 1000*/ );
outputImage.setDotsPerMeterY( expectedImage.dotsPerMeterX() /*mComposition->printResolution() / 25.4 * 1000*/ );
outputImage.setDotsPerMeterX( expectedImage.dotsPerMeterX() );
outputImage.setDotsPerMeterY( expectedImage.dotsPerMeterX() );
outputImage.fill( 0 );
QPainter p( &outputImage );
QRectF sourceArea( 0, 0, mComposition->paperWidth(), mComposition->paperHeight() );
@@ -73,7 +72,6 @@ bool QgsCompositionChecker::testComposition()
p.end();

return compareImages( expectedImage, outputImage );
#endif //0
}

bool QgsCompositionChecker::compareImages( const QImage& img1, const QImage& img2 ) const
@@ -21,6 +21,7 @@
#include "qgscomposermap.h"
#include "qgsmaplayerregistry.h"
#include "qgsmaprenderer.h"
#include "qgsmultibandcolorrenderer.h"
#include "qgsrasterlayer.h"
#include <QObject>
#include <QtTest>
@@ -34,6 +35,7 @@ class TestQgsComposerMap: public QObject
void init();// will be called before each testfunction is executed.
void cleanup();// will be called after every testfunction.
void render(); //test if rendering of the composition with composr map is correct
void grid(); //test if grid and grid annotation works

private:
QgsComposition* mComposition;
@@ -51,6 +53,9 @@ void TestQgsComposerMap::initTestCase()
QFileInfo rasterFileInfo( QString( TEST_DATA_DIR ) + QDir::separator() + "landsat.tif" );
mRasterLayer = new QgsRasterLayer( rasterFileInfo.filePath(),
rasterFileInfo.completeBaseName() );
QgsMultiBandColorRenderer* rasterRenderer = new QgsMultiBandColorRenderer( mRasterLayer->dataProvider(), 2, 3, 4 );
mRasterLayer->setRenderer( rasterRenderer );

QgsMapLayerRegistry::instance()->addMapLayers( QList<QgsMapLayer*>() << mRasterLayer );

//create composition with composer map
@@ -83,7 +88,27 @@ void TestQgsComposerMap::render()
{
mComposerMap->setNewExtent( QgsRectangle( 781662.375, 3339523.125, 793062.375, 3345223.125 ) );
QgsCompositionChecker checker( mComposition, QString( QString( TEST_DATA_DIR ) + QDir::separator() +
"control_images" + QDir::separator() + "composermap_landsat1.png" ) );
"control_images" + QDir::separator() + "composermap_landsat_render.png" ) );
QVERIFY( checker.testComposition() );
}

void TestQgsComposerMap::grid()
{
mComposerMap->setNewExtent( QgsRectangle( 781662.375, 3339523.125, 793062.375, 3345223.125 ) );
mComposerMap->setGridEnabled( true );
mComposerMap->setGridIntervalX( 2000 );
mComposerMap->setGridIntervalY( 2000 );
mComposerMap->setShowGridAnnotation( true );
mComposerMap->setGridPenWidth( 0.5 );
mComposerMap->setGridAnnotationPrecision( 0 );
mComposerMap->setGridAnnotationPosition( QgsComposerMap::Disabled, QgsComposerMap::Left );
mComposerMap->setGridAnnotationPosition( QgsComposerMap::OutsideMapFrame, QgsComposerMap::Right );
mComposerMap->setGridAnnotationPosition( QgsComposerMap::Disabled, QgsComposerMap::Top );
mComposerMap->setGridAnnotationPosition( QgsComposerMap::OutsideMapFrame, QgsComposerMap::Bottom );
mComposerMap->setGridAnnotationDirection( QgsComposerMap::Horizontal, QgsComposerMap::Right );
mComposerMap->setGridAnnotationDirection( QgsComposerMap::Horizontal, QgsComposerMap::Bottom );
QgsCompositionChecker checker( mComposition, QString( QString( TEST_DATA_DIR ) + QDir::separator() +
"control_images" + QDir::separator() + "composermap_landsat_grid.png" ) );
QVERIFY( checker.testComposition() );
}

Binary file not shown.
Binary file not shown.

0 comments on commit 67ba1d5

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