Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for composer item transparency and blending
- Loading branch information
1 parent
6e90ba3
commit e19079d
Showing
4 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 added
BIN
+39.6 KB
tests/testdata/control_images/expected_composereffects/composereffect_blend.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+39.7 KB
...estdata/control_images/expected_composereffects/composereffect_transparency.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.