/
testqgscomposereffects.cpp
125 lines (102 loc) · 4.03 KB
/
testqgscomposereffects.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/***************************************************************************
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/QtTest>
#include <QColor>
#include <QPainter>
class TestQgsComposerEffects : public QObject
{
Q_OBJECT
public:
TestQgsComposerEffects()
: mComposition( 0 )
, mComposerRect1( 0 )
, mComposerRect2( 0 )
, mMapSettings( 0 )
{}
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;
QgsMapSettings *mMapSettings;
QString mReport;
};
void TestQgsComposerEffects::initTestCase()
{
QgsApplication::init();
QgsApplication::initQgis();
mMapSettings = new QgsMapSettings();
//create composition with two rectangles
mComposition = new QgsComposition( *mMapSettings );
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 );
mReport = "<h1>Composer Effects Tests</h1>\n";
}
void TestQgsComposerEffects::cleanupTestCase()
{
delete mComposition;
delete mMapSettings;
QString myReportFile = QDir::tempPath() + "/qgistest.html";
QFile myFile( myReportFile );
if ( myFile.open( QIODevice::WriteOnly | QIODevice::Append ) )
{
QTextStream myQTextStream( &myFile );
myQTextStream << mReport;
myFile.close();
}
QgsApplication::exitQgis();
}
void TestQgsComposerEffects::init()
{
}
void TestQgsComposerEffects::cleanup()
{
}
void TestQgsComposerEffects::blend_modes()
{
mComposerRect2->setBlendMode( QPainter::CompositionMode_Multiply );
QgsCompositionChecker checker( "composereffects_blend", mComposition );
QVERIFY( checker.testComposition( mReport ) );
// reset blending
mComposerRect2->setBlendMode( QPainter::CompositionMode_SourceOver );
}
void TestQgsComposerEffects::transparency()
{
mComposerRect2->setTransparency( 50 );
QgsCompositionChecker checker( "composereffects_transparency", mComposition );
QVERIFY( checker.testComposition( mReport ) );
}
QTEST_MAIN( TestQgsComposerEffects )
#include "testqgscomposereffects.moc"