Skip to content

Commit 86b972c

Browse files
committed
[composer] Begin tests for composer item rotation
1 parent 5262a4d commit 86b972c

File tree

9 files changed

+235
-0
lines changed

9 files changed

+235
-0
lines changed

tests/src/core/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ ADD_QGIS_TEST(dataitemtest testqgsdataitem.cpp)
104104
ADD_QGIS_TEST(composermaptest testqgscomposermap.cpp)
105105
ADD_QGIS_TEST(composereffectstest testqgscomposereffects.cpp)
106106
ADD_QGIS_TEST(composershapestest testqgscomposershapes.cpp)
107+
ADD_QGIS_TEST(composerrotationtest testqgscomposerrotation.cpp)
107108
ADD_QGIS_TEST(atlascompositiontest testqgsatlascomposition.cpp)
108109
ADD_QGIS_TEST(composerlabeltest testqgscomposerlabel.cpp)
109110
ADD_QGIS_TEST(stylev2test testqgsstylev2.cpp)
+234
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
/***************************************************************************
2+
testqgscomposerrotation.cpp
3+
----------------------
4+
begin : April 2013
5+
copyright : (C) 2013 by Marco Hugentobler, Nyall Dawson
6+
email : nyall dot dawson at gmail.com
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#include "qgsapplication.h"
19+
#include "qgscomposition.h"
20+
#include "qgscompositionchecker.h"
21+
#include "qgscomposershape.h"
22+
#include "qgscomposermap.h"
23+
#include "qgscomposerlabel.h"
24+
#include "qgscomposerpicture.h"
25+
#include "qgsmultibandcolorrenderer.h"
26+
#include "qgsmaprenderer.h"
27+
#include "qgsrasterlayer.h"
28+
#include "qgsmaplayerregistry.h"
29+
#include <QObject>
30+
#include <QtTest>
31+
#include <QColor>
32+
#include <QPainter>
33+
34+
class TestQgsComposerRotation: public QObject
35+
{
36+
Q_OBJECT;
37+
private slots:
38+
void initTestCase();// will be called before the first testfunction is executed.
39+
void cleanupTestCase();// will be called after the last testfunction was executed.
40+
void init();// will be called before each testfunction is executed.
41+
void cleanup();// will be called after every testfunction.
42+
void shapeRotation(); //test if composer shape rotation is functioning
43+
void oldShapeRotationApi(); //test if old deprecated composer shape rotation api is functioning
44+
void labelRotation(); //test if composer label rotation is functioning
45+
void oldLabelRotationApi(); //test if old deprectated composer label rotation api is functioning
46+
void mapRotation(); //test if composer map mapRotation is functioning
47+
void mapItemRotation(); //test if composer map item rotation is functioning
48+
void oldMapRotationApi(); //test if old deprectated composer map rotation api is functioning
49+
void pictureRotation();
50+
51+
private:
52+
QgsComposition* mComposition;
53+
QgsComposerShape* mComposerRect;
54+
QgsComposerLabel* mComposerLabel;
55+
QgsMapRenderer* mMapRenderer;
56+
QgsComposerMap* mComposerMap;
57+
QgsComposerPicture* mComposerPicture;
58+
QgsRasterLayer* mRasterLayer;
59+
QString mReport;
60+
};
61+
62+
void TestQgsComposerRotation::initTestCase()
63+
{
64+
QgsApplication::init();
65+
QgsApplication::initQgis();
66+
67+
//create maplayers from testdata and add to layer registry
68+
QFileInfo rasterFileInfo( QString( TEST_DATA_DIR ) + QDir::separator() + "landsat.tif" );
69+
mRasterLayer = new QgsRasterLayer( rasterFileInfo.filePath(),
70+
rasterFileInfo.completeBaseName() );
71+
QgsMultiBandColorRenderer* rasterRenderer = new QgsMultiBandColorRenderer( mRasterLayer->dataProvider(), 2, 3, 4 );
72+
mRasterLayer->setRenderer( rasterRenderer );
73+
74+
QgsMapLayerRegistry::instance()->addMapLayers( QList<QgsMapLayer*>() << mRasterLayer );
75+
76+
mMapRenderer = new QgsMapRenderer();
77+
mMapRenderer->setLayerSet( QStringList() << mRasterLayer->id() );
78+
mMapRenderer->setProjectionsEnabled( false );
79+
80+
mComposition = new QgsComposition( mMapRenderer );
81+
mComposition->setPaperSize( 297, 210 ); //A4 landscape
82+
83+
mComposerRect = new QgsComposerShape( 70, 70, 150, 100, mComposition );
84+
mComposerRect->setShapeType( QgsComposerShape::Rectangle );
85+
mComposerRect->setBackgroundColor( QColor::fromRgb( 255, 150, 0 ) );
86+
87+
mComposerLabel = new QgsComposerLabel( mComposition );
88+
mComposerLabel->setText( "test label" );
89+
mComposerLabel->setPos( 70, 70 );
90+
mComposerLabel->adjustSizeToText();
91+
mComposerLabel->setBackgroundColor( QColor::fromRgb( 255, 150, 0 ) );
92+
93+
mComposerPicture = new QgsComposerPicture( mComposition );
94+
mComposerPicture->setPictureFile( QString( TEST_DATA_DIR ) + QDir::separator() + "sample_image.png" );
95+
mComposerPicture->setSceneRect( QRectF( 70, 70, 100, 100 ) );
96+
mComposerPicture->setFrameEnabled( true );
97+
98+
mComposerMap = new QgsComposerMap( mComposition, 20, 20, 200, 100 );
99+
mComposerMap->setFrameEnabled( true );
100+
101+
mReport = "<h1>Composer Rotation Tests</h1>\n";
102+
}
103+
void TestQgsComposerRotation::cleanupTestCase()
104+
{
105+
delete mComposition;
106+
107+
QString myReportFile = QDir::tempPath() + QDir::separator() + "qgistest.html";
108+
QFile myFile( myReportFile );
109+
if ( myFile.open( QIODevice::WriteOnly | QIODevice::Append ) )
110+
{
111+
QTextStream myQTextStream( &myFile );
112+
myQTextStream << mReport;
113+
myFile.close();
114+
}
115+
}
116+
117+
void TestQgsComposerRotation::init()
118+
{
119+
120+
}
121+
122+
void TestQgsComposerRotation::cleanup()
123+
{
124+
125+
}
126+
127+
void TestQgsComposerRotation::shapeRotation()
128+
{
129+
mComposition->addComposerShape( mComposerRect );
130+
131+
mComposerRect->setItemRotation( 45 );
132+
133+
QgsCompositionChecker checker( "composerrotation_shape", mComposition );
134+
QVERIFY( checker.testComposition( mReport ) );
135+
136+
mComposition->removeItem( mComposerRect );
137+
}
138+
139+
void TestQgsComposerRotation::oldShapeRotationApi()
140+
{
141+
//test old style deprecated rotation api - remove after 2.0 series
142+
mComposition->addComposerShape( mComposerRect );
143+
144+
mComposerRect->setRotation( 45 );
145+
146+
QgsCompositionChecker checker( "composerrotation_shape_oldapi", mComposition );
147+
QVERIFY( checker.testComposition( mReport ) );
148+
149+
mComposition->removeItem( mComposerRect );
150+
}
151+
152+
void TestQgsComposerRotation::labelRotation()
153+
{
154+
mComposition->addComposerLabel( mComposerLabel );
155+
156+
mComposerLabel->setItemRotation( 135 );
157+
158+
QgsCompositionChecker checker( "composerrotation_label", mComposition );
159+
QVERIFY( checker.testComposition( mReport ) );
160+
161+
mComposition->removeItem( mComposerLabel );
162+
}
163+
164+
void TestQgsComposerRotation::oldLabelRotationApi()
165+
{
166+
//test old style deprecated rotation api - remove test after 2.0 series
167+
mComposition->addComposerLabel( mComposerLabel );
168+
169+
mComposerLabel->setRotation( 135 );
170+
171+
QgsCompositionChecker checker( "composerrotation_label_oldapi", mComposition );
172+
QVERIFY( checker.testComposition( mReport ) );
173+
174+
mComposition->removeItem( mComposerLabel );
175+
}
176+
177+
void TestQgsComposerRotation::mapRotation()
178+
{
179+
//test map rotation
180+
mComposition->addComposerMap( mComposerMap );
181+
mComposerMap->setNewExtent( QgsRectangle( 781662.375, 3339523.125, 793062.375, 3345223.125 ) );
182+
mComposerMap->setMapRotation( 90 );
183+
184+
QgsCompositionChecker checker( "composerrotation_maprotation", mComposition );
185+
QVERIFY( checker.testComposition( mReport ) );
186+
187+
mComposition->removeItem( mComposerMap );
188+
mComposerMap->setMapRotation( 0 );
189+
}
190+
191+
void TestQgsComposerRotation::mapItemRotation()
192+
{
193+
//test map item rotation
194+
mComposition->addComposerMap( mComposerMap );
195+
mComposerMap->setNewExtent( QgsRectangle( 781662.375, 3339523.125, 793062.375, 3345223.125 ) );
196+
mComposerMap->setItemRotation( 90 );
197+
198+
QgsCompositionChecker checker( "composerrotation_mapitemrotation", mComposition );
199+
QVERIFY( checker.testComposition( mReport ) );
200+
201+
mComposition->removeItem( mComposerMap );
202+
mComposerMap->setItemRotation( 0 );
203+
}
204+
205+
void TestQgsComposerRotation::oldMapRotationApi()
206+
{
207+
//test old style deprecated rotation api - remove test after 2.0 series
208+
mComposition->addComposerMap( mComposerMap );
209+
mComposerMap->setNewExtent( QgsRectangle( 781662.375, 3339523.125, 793062.375, 3345223.125 ) );
210+
mComposerMap->setRotation( 90 );
211+
212+
QgsCompositionChecker checker( "composerrotation_maprotation_oldapi", mComposition );
213+
QVERIFY( checker.testComposition( mReport ) );
214+
215+
mComposition->removeItem( mComposerMap );
216+
mComposerMap->setRotation( 0 );
217+
}
218+
219+
void TestQgsComposerRotation::pictureRotation()
220+
{
221+
//test map rotation
222+
mComposition->addComposerPicture( mComposerPicture );
223+
mComposerPicture->setPictureRotation( 45 );
224+
mComposerPicture->setSceneRect( QRectF( 70, 70, 100, 100 ) );
225+
226+
QgsCompositionChecker checker( "composerrotation_maprotation", mComposition );
227+
QVERIFY( checker.testComposition( mReport ) );
228+
229+
mComposition->removeItem( mComposerPicture );
230+
mComposerPicture->setPictureRotation( 0 );
231+
}
232+
233+
QTEST_MAIN( TestQgsComposerRotation )
234+
#include "moc_testqgscomposerrotation.cxx"

0 commit comments

Comments
 (0)