Skip to content
Permalink
Browse files

Add tests for composer item transparency and blending

  • Loading branch information
nyalldawson committed Apr 30, 2013
1 parent 6e90ba3 commit e19079d60a054def112d9500961e260a5b30ad5b
@@ -101,6 +101,7 @@ ADD_QGIS_TEST(rulebasedrenderertest testqgsrulebasedrenderer.cpp)
ADD_QGIS_TEST(ziplayertest testziplayer.cpp)
ADD_QGIS_TEST(dataitemtest testqgsdataitem.cpp)
ADD_QGIS_TEST(composermaptest testqgscomposermap.cpp)
ADD_QGIS_TEST(composereffectstest testqgscomposereffects.cpp)
ADD_QGIS_TEST(atlascompositiontest testqgsatlascomposition.cpp)
ADD_QGIS_TEST(composerlabeltest testqgscomposerlabel.cpp)
ADD_QGIS_TEST(stylev2test testqgsstylev2.cpp)
@@ -0,0 +1,103 @@
/***************************************************************************
testqgscomposereffects.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 "qgsmaprenderer.h"
#include <QObject>
#include <QtTest>
#include <QColor>
#include <QPainter>

class TestQgsComposerEffects: 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 blend_modes(); //test if composer item blending is functioning
void transparency(); //test if composer transparency is functioning

private:
QgsComposition* mComposition;
QgsComposerShape* mComposerRect1;
QgsComposerShape* mComposerRect2;
QgsMapRenderer* mMapRenderer;
};

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

//create composition with two rectangles
mMapRenderer = new QgsMapRenderer();

mComposition = new QgsComposition( mMapRenderer );
mComposition->setPaperSize( 297, 210 ); //A4 landscape
mComposerRect1 = new QgsComposerShape( 20, 20, 150, 100, mComposition );
mComposerRect1->setShapeType( QgsComposerShape::Rectangle );
mComposerRect1->setBackgroundColor( QColor::fromRgb( 255, 150, 0 ) );
mComposition->addComposerShape( mComposerRect1 );
mComposerRect2 = new QgsComposerShape( 50, 50, 150, 100, mComposition );
mComposerRect2->setBackgroundColor( QColor::fromRgb( 0, 100, 150 ) );
mComposerRect2->setShapeType( QgsComposerShape::Rectangle );
mComposition->addComposerShape( mComposerRect2 );

}

void TestQgsComposerEffects::cleanupTestCase()
{
delete mComposition;
}

void TestQgsComposerEffects::init()
{

}

void TestQgsComposerEffects::cleanup()
{

}

void TestQgsComposerEffects::blend_modes()
{
mComposerRect2->setBlendMode( QPainter::CompositionMode_Multiply );

QgsCompositionChecker checker( "Composer effects blending", mComposition, QString( QString( TEST_DATA_DIR ) + QDir::separator() +
"control_images" + QDir::separator() + "expected_composereffects" + QDir::separator() + "composereffect_blend.png" ) );
QVERIFY( checker.testComposition() );
// reset blending
mComposerRect2->setBlendMode( QPainter::CompositionMode_SourceOver );
}

void TestQgsComposerEffects::transparency()
{
mComposerRect2->setTransparency( 50 );

QgsCompositionChecker checker( "Composer item transparency", mComposition, QString( QString( TEST_DATA_DIR ) + QDir::separator() +
"control_images" + QDir::separator() + "expected_composereffects" + QDir::separator() + "composereffect_transparency.png" ) );
QVERIFY( checker.testComposition() );
}

QTEST_MAIN( TestQgsComposerEffects )
#include "moc_testqgscomposereffects.cxx"
Binary file not shown.
Binary file not shown.

0 comments on commit e19079d

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