Skip to content
Permalink
Browse files

[composer] Begin tests for composer item rotation

  • Loading branch information
nyalldawson committed Dec 30, 2013
1 parent 5262a4d commit 86b972c1544e1e51be6469828ed62a29e6891b2a
@@ -104,6 +104,7 @@ ADD_QGIS_TEST(dataitemtest testqgsdataitem.cpp)
ADD_QGIS_TEST(composermaptest testqgscomposermap.cpp)
ADD_QGIS_TEST(composereffectstest testqgscomposereffects.cpp)
ADD_QGIS_TEST(composershapestest testqgscomposershapes.cpp)
ADD_QGIS_TEST(composerrotationtest testqgscomposerrotation.cpp)
ADD_QGIS_TEST(atlascompositiontest testqgsatlascomposition.cpp)
ADD_QGIS_TEST(composerlabeltest testqgscomposerlabel.cpp)
ADD_QGIS_TEST(stylev2test testqgsstylev2.cpp)
@@ -0,0 +1,234 @@
/***************************************************************************
testqgscomposerrotation.cpp
----------------------
begin : April 2013
copyright : (C) 2013 by Marco Hugentobler, Nyall Dawson
email : nyall dot dawson at gmail.com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsapplication.h"
#include "qgscomposition.h"
#include "qgscompositionchecker.h"
#include "qgscomposershape.h"
#include "qgscomposermap.h"
#include "qgscomposerlabel.h"
#include "qgscomposerpicture.h"
#include "qgsmultibandcolorrenderer.h"
#include "qgsmaprenderer.h"
#include "qgsrasterlayer.h"
#include "qgsmaplayerregistry.h"
#include <QObject>
#include <QtTest>
#include <QColor>
#include <QPainter>

class TestQgsComposerRotation: public QObject
{
Q_OBJECT;
private slots:
void initTestCase();// will be called before the first testfunction is executed.
void cleanupTestCase();// will be called after the last testfunction was executed.
void init();// will be called before each testfunction is executed.
void cleanup();// will be called after every testfunction.
void shapeRotation(); //test if composer shape rotation is functioning
void oldShapeRotationApi(); //test if old deprecated composer shape rotation api is functioning
void labelRotation(); //test if composer label rotation is functioning
void oldLabelRotationApi(); //test if old deprectated composer label rotation api is functioning
void mapRotation(); //test if composer map mapRotation is functioning
void mapItemRotation(); //test if composer map item rotation is functioning
void oldMapRotationApi(); //test if old deprectated composer map rotation api is functioning
void pictureRotation();

private:
QgsComposition* mComposition;
QgsComposerShape* mComposerRect;
QgsComposerLabel* mComposerLabel;
QgsMapRenderer* mMapRenderer;
QgsComposerMap* mComposerMap;
QgsComposerPicture* mComposerPicture;
QgsRasterLayer* mRasterLayer;
QString mReport;
};

void TestQgsComposerRotation::initTestCase()
{
QgsApplication::init();
QgsApplication::initQgis();

//create maplayers from testdata and add to layer registry
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 );

mMapRenderer = new QgsMapRenderer();
mMapRenderer->setLayerSet( QStringList() << mRasterLayer->id() );
mMapRenderer->setProjectionsEnabled( false );

mComposition = new QgsComposition( mMapRenderer );
mComposition->setPaperSize( 297, 210 ); //A4 landscape

mComposerRect = new QgsComposerShape( 70, 70, 150, 100, mComposition );
mComposerRect->setShapeType( QgsComposerShape::Rectangle );
mComposerRect->setBackgroundColor( QColor::fromRgb( 255, 150, 0 ) );

mComposerLabel = new QgsComposerLabel( mComposition );
mComposerLabel->setText( "test label" );
mComposerLabel->setPos( 70, 70 );
mComposerLabel->adjustSizeToText();
mComposerLabel->setBackgroundColor( QColor::fromRgb( 255, 150, 0 ) );

mComposerPicture = new QgsComposerPicture( mComposition );
mComposerPicture->setPictureFile( QString( TEST_DATA_DIR ) + QDir::separator() + "sample_image.png" );
mComposerPicture->setSceneRect( QRectF( 70, 70, 100, 100 ) );
mComposerPicture->setFrameEnabled( true );

mComposerMap = new QgsComposerMap( mComposition, 20, 20, 200, 100 );
mComposerMap->setFrameEnabled( true );

mReport = "<h1>Composer Rotation Tests</h1>\n";
}
void TestQgsComposerRotation::cleanupTestCase()
{
delete mComposition;

QString myReportFile = QDir::tempPath() + QDir::separator() + "qgistest.html";
QFile myFile( myReportFile );
if ( myFile.open( QIODevice::WriteOnly | QIODevice::Append ) )
{
QTextStream myQTextStream( &myFile );
myQTextStream << mReport;
myFile.close();
}
}

void TestQgsComposerRotation::init()
{

}

void TestQgsComposerRotation::cleanup()
{

}

void TestQgsComposerRotation::shapeRotation()
{
mComposition->addComposerShape( mComposerRect );

mComposerRect->setItemRotation( 45 );

QgsCompositionChecker checker( "composerrotation_shape", mComposition );
QVERIFY( checker.testComposition( mReport ) );

mComposition->removeItem( mComposerRect );
}

void TestQgsComposerRotation::oldShapeRotationApi()
{
//test old style deprecated rotation api - remove after 2.0 series
mComposition->addComposerShape( mComposerRect );

mComposerRect->setRotation( 45 );

QgsCompositionChecker checker( "composerrotation_shape_oldapi", mComposition );
QVERIFY( checker.testComposition( mReport ) );

mComposition->removeItem( mComposerRect );
}

void TestQgsComposerRotation::labelRotation()
{
mComposition->addComposerLabel( mComposerLabel );

mComposerLabel->setItemRotation( 135 );

QgsCompositionChecker checker( "composerrotation_label", mComposition );
QVERIFY( checker.testComposition( mReport ) );

mComposition->removeItem( mComposerLabel );
}

void TestQgsComposerRotation::oldLabelRotationApi()
{
//test old style deprecated rotation api - remove test after 2.0 series
mComposition->addComposerLabel( mComposerLabel );

mComposerLabel->setRotation( 135 );

QgsCompositionChecker checker( "composerrotation_label_oldapi", mComposition );
QVERIFY( checker.testComposition( mReport ) );

mComposition->removeItem( mComposerLabel );
}

void TestQgsComposerRotation::mapRotation()
{
//test map rotation
mComposition->addComposerMap( mComposerMap );
mComposerMap->setNewExtent( QgsRectangle( 781662.375, 3339523.125, 793062.375, 3345223.125 ) );
mComposerMap->setMapRotation( 90 );

QgsCompositionChecker checker( "composerrotation_maprotation", mComposition );
QVERIFY( checker.testComposition( mReport ) );

mComposition->removeItem( mComposerMap );
mComposerMap->setMapRotation( 0 );
}

void TestQgsComposerRotation::mapItemRotation()
{
//test map item rotation
mComposition->addComposerMap( mComposerMap );
mComposerMap->setNewExtent( QgsRectangle( 781662.375, 3339523.125, 793062.375, 3345223.125 ) );
mComposerMap->setItemRotation( 90 );

QgsCompositionChecker checker( "composerrotation_mapitemrotation", mComposition );
QVERIFY( checker.testComposition( mReport ) );

mComposition->removeItem( mComposerMap );
mComposerMap->setItemRotation( 0 );
}

void TestQgsComposerRotation::oldMapRotationApi()
{
//test old style deprecated rotation api - remove test after 2.0 series
mComposition->addComposerMap( mComposerMap );
mComposerMap->setNewExtent( QgsRectangle( 781662.375, 3339523.125, 793062.375, 3345223.125 ) );
mComposerMap->setRotation( 90 );

QgsCompositionChecker checker( "composerrotation_maprotation_oldapi", mComposition );
QVERIFY( checker.testComposition( mReport ) );

mComposition->removeItem( mComposerMap );
mComposerMap->setRotation( 0 );
}

void TestQgsComposerRotation::pictureRotation()
{
//test map rotation
mComposition->addComposerPicture( mComposerPicture );
mComposerPicture->setPictureRotation( 45 );
mComposerPicture->setSceneRect( QRectF( 70, 70, 100, 100 ) );

QgsCompositionChecker checker( "composerrotation_maprotation", mComposition );
QVERIFY( checker.testComposition( mReport ) );

mComposition->removeItem( mComposerPicture );
mComposerPicture->setPictureRotation( 0 );
}

QTEST_MAIN( TestQgsComposerRotation )
#include "moc_testqgscomposerrotation.cxx"
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 86b972c

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