-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
Copy pathtestqgslayoutmapoverview.cpp
254 lines (218 loc) · 10.2 KB
/
testqgslayoutmapoverview.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/***************************************************************************
testqgslayoutmapoverview.cpp
----------------------
begin : October 2017
copyright : (C) 2017 by Nyall Dawson
email : nyall dot dawson at gmail dot 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 "qgslayout.h"
#include "qgslayoutitemmap.h"
#include "qgslayoutitemmapoverview.h"
#include "qgsproject.h"
#include "qgsmultibandcolorrenderer.h"
#include "qgsrasterlayer.h"
#include "qgsrasterdataprovider.h"
#include <QObject>
#include "qgstest.h"
class TestQgsLayoutMapOverview : public QgsTest
{
Q_OBJECT
public:
TestQgsLayoutMapOverview() : QgsTest( QStringLiteral( "Layout Map Overview Tests" ), QStringLiteral( "composer_mapoverview" ) ) {}
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 overviewMap(); //test if overview map frame works
void overviewMapRotated(); //test if overview map frame works with rotated overview
void overviewMapRotated2(); //test if overview map frame works with rotated map
void overviewMapBlending(); //test if blend modes with overview map frame works
void overviewMapInvert(); //test if invert of overview map frame works
void overviewMapCenter(); //test if centering of overview map frame works
void overviewReprojected(); //test that overview frame is reprojected
private:
QgsRasterLayer *mRasterLayer = nullptr;
};
void TestQgsLayoutMapOverview::initTestCase()
{
QgsApplication::init();
QgsApplication::initQgis();
//create maplayers from testdata and add to layer registry
const QFileInfo rasterFileInfo( QStringLiteral( TEST_DATA_DIR ) + "/rgb256x256.png" );
mRasterLayer = new QgsRasterLayer( rasterFileInfo.filePath(),
rasterFileInfo.completeBaseName() );
QgsMultiBandColorRenderer *rasterRenderer = new QgsMultiBandColorRenderer( mRasterLayer->dataProvider(), 1, 2, 3 );
mRasterLayer->setRenderer( rasterRenderer );
}
void TestQgsLayoutMapOverview::cleanupTestCase()
{
delete mRasterLayer;
QgsApplication::exitQgis();
}
void TestQgsLayoutMapOverview::init()
{
}
void TestQgsLayoutMapOverview::cleanup()
{
}
void TestQgsLayoutMapOverview::overviewMap()
{
QgsLayout l( QgsProject::instance() );
l.initializeDefaults();
QgsLayoutItemMap *map = new QgsLayoutItemMap( &l );
map->attemptSetSceneRect( QRectF( 20, 20, 200, 100 ) );
map->setFrameEnabled( true );
map->setLayers( QList<QgsMapLayer *>() << mRasterLayer );
l.addLayoutItem( map );
QgsLayoutItemMap *overviewMap = new QgsLayoutItemMap( &l );
overviewMap->attemptSetSceneRect( QRectF( 20, 130, 70, 70 ) );
overviewMap->setFrameEnabled( true );
overviewMap->setLayers( QList<QgsMapLayer *>() << mRasterLayer );
l.addLayoutItem( overviewMap );
map->setExtent( QgsRectangle( 96, -152, 160, -120 ) ); //zoom in
overviewMap->setExtent( QgsRectangle( 0, -256, 256, 0 ) );
overviewMap->overview()->setLinkedMap( map );
QCOMPARE( overviewMap->overview()->linkedMap(), map );
overviewMap->overview()->setLinkedMap( nullptr );
QVERIFY( !overviewMap->overview()->linkedMap() );
overviewMap->overview()->setLinkedMap( map );
QCOMPARE( overviewMap->overview()->linkedMap(), map );
overviewMap->overview()->setLinkedMap( nullptr );
QVERIFY( !overviewMap->overview()->linkedMap() );
//render
overviewMap->overview()->setLinkedMap( map );
QGSVERIFYLAYOUTCHECK( QStringLiteral( "composermap_overview" ), &l );
}
void TestQgsLayoutMapOverview::overviewMapRotated()
{
QgsLayout l( QgsProject::instance() );
l.initializeDefaults();
QgsLayoutItemMap *map = new QgsLayoutItemMap( &l );
map->attemptSetSceneRect( QRectF( 20, 20, 200, 100 ) );
map->setFrameEnabled( true );
map->setLayers( QList<QgsMapLayer *>() << mRasterLayer );
l.addLayoutItem( map );
QgsLayoutItemMap *overviewMap = new QgsLayoutItemMap( &l );
overviewMap->attemptSetSceneRect( QRectF( 20, 130, 70, 70 ) );
overviewMap->setFrameEnabled( true );
overviewMap->setLayers( QList<QgsMapLayer *>() << mRasterLayer );
l.addLayoutItem( overviewMap );
map->setExtent( QgsRectangle( 96, -144, 160, -112 ) ); //zoom in
map->setMapRotation( 30 );
overviewMap->setExtent( QgsRectangle( 0, -256, 256, 0 ) );
overviewMap->overview()->setLinkedMap( map );
QGSVERIFYLAYOUTCHECK( QStringLiteral( "composermap_overview_rotated" ), &l, 0, 600 );
}
void TestQgsLayoutMapOverview::overviewMapRotated2()
{
QgsLayout l( QgsProject::instance() );
l.initializeDefaults();
QgsLayoutItemMap *map = new QgsLayoutItemMap( &l );
map->attemptSetSceneRect( QRectF( 20, 20, 200, 100 ) );
map->setFrameEnabled( true );
map->setLayers( QList<QgsMapLayer *>() << mRasterLayer );
l.addLayoutItem( map );
QgsLayoutItemMap *overviewMap = new QgsLayoutItemMap( &l );
overviewMap->attemptSetSceneRect( QRectF( 20, 130, 70, 70 ) );
overviewMap->setFrameEnabled( true );
overviewMap->setLayers( QList<QgsMapLayer *>() << mRasterLayer );
l.addLayoutItem( overviewMap );
map->setExtent( QgsRectangle( 96, -152, 160, -120 ) ); //zoom in
overviewMap->setMapRotation( 30 );
overviewMap->setExtent( QgsRectangle( 0, -256, 256, 0 ) );
overviewMap->overview()->setLinkedMap( map );
QGSVERIFYLAYOUTCHECK( QStringLiteral( "composermap_overview_rotated2" ), &l, 0, 600 );
}
void TestQgsLayoutMapOverview::overviewMapBlending()
{
QgsLayout l( QgsProject::instance() );
l.initializeDefaults();
QgsLayoutItemMap *map = new QgsLayoutItemMap( &l );
map->attemptSetSceneRect( QRectF( 20, 20, 200, 100 ) );
map->setFrameEnabled( true );
map->setLayers( QList<QgsMapLayer *>() << mRasterLayer );
l.addLayoutItem( map );
QgsLayoutItemMap *overviewMapBlend = new QgsLayoutItemMap( &l );
overviewMapBlend->attemptSetSceneRect( QRectF( 20, 130, 70, 70 ) );
overviewMapBlend->setFrameEnabled( true );
overviewMapBlend->setLayers( QList<QgsMapLayer *>() << mRasterLayer );
l.addLayoutItem( overviewMapBlend );
map->setExtent( QgsRectangle( 96, -152, 160, -120 ) ); //zoom in
overviewMapBlend->setExtent( QgsRectangle( 0, -256, 256, 0 ) );
overviewMapBlend->overview()->setLinkedMap( map );
overviewMapBlend->overview()->setBlendMode( QPainter::CompositionMode_Multiply );
QGSVERIFYLAYOUTCHECK( QStringLiteral( "composermap_overview_blending" ), &l );
}
void TestQgsLayoutMapOverview::overviewMapInvert()
{
QgsLayout l( QgsProject::instance() );
l.initializeDefaults();
QgsLayoutItemMap *map = new QgsLayoutItemMap( &l );
map->attemptSetSceneRect( QRectF( 20, 20, 200, 100 ) );
map->setFrameEnabled( true );
map->setLayers( QList<QgsMapLayer *>() << mRasterLayer );
l.addLayoutItem( map );
QgsLayoutItemMap *overviewMapInvert = new QgsLayoutItemMap( &l );
overviewMapInvert->attemptSetSceneRect( QRectF( 20, 130, 70, 70 ) );
overviewMapInvert->setFrameEnabled( true );
overviewMapInvert->setLayers( QList<QgsMapLayer *>() << mRasterLayer );
l.addLayoutItem( overviewMapInvert );
map->setExtent( QgsRectangle( 96, -152, 160, -120 ) ); //zoom in
overviewMapInvert->setExtent( QgsRectangle( 0, -256, 256, 0 ) );
overviewMapInvert->overview()->setLinkedMap( map );
overviewMapInvert->overview()->setInverted( true );
QGSVERIFYLAYOUTCHECK( QStringLiteral( "composermap_overview_invert" ), &l );
}
void TestQgsLayoutMapOverview::overviewMapCenter()
{
QgsLayout l( QgsProject::instance() );
l.initializeDefaults();
QgsLayoutItemMap *map = new QgsLayoutItemMap( &l );
map->attemptSetSceneRect( QRectF( 20, 20, 200, 100 ) );
map->setFrameEnabled( true );
map->setLayers( QList<QgsMapLayer *>() << mRasterLayer );
l.addLayoutItem( map );
QgsLayoutItemMap *overviewMapCenter = new QgsLayoutItemMap( &l );
overviewMapCenter->attemptSetSceneRect( QRectF( 20, 130, 70, 70 ) );
overviewMapCenter->setFrameEnabled( true );
overviewMapCenter->setLayers( QList<QgsMapLayer *>() << mRasterLayer );
l.addLayoutItem( overviewMapCenter );
map->setExtent( QgsRectangle( 192, -288, 320, -224 ) );
overviewMapCenter->setExtent( QgsRectangle( 0, -256, 256, 0 ) );
overviewMapCenter->overview()->setLinkedMap( map );
overviewMapCenter->overview()->setCentered( true );
QGSVERIFYLAYOUTCHECK( QStringLiteral( "composermap_overview_center" ), &l );
}
void TestQgsLayoutMapOverview::overviewReprojected()
{
QgsLayout l( QgsProject::instance() );
l.initializeDefaults();
QgsLayoutItemMap *map = new QgsLayoutItemMap( &l );
map->attemptSetSceneRect( QRectF( 20, 20, 200, 100 ) );
map->setFrameEnabled( true );
map->setLayers( QList<QgsMapLayer *>() << mRasterLayer );
l.addLayoutItem( map );
QgsLayoutItemMap *overviewMap = new QgsLayoutItemMap( &l );
overviewMap->attemptSetSceneRect( QRectF( 20, 130, 70, 70 ) );
overviewMap->setFrameEnabled( true );
//overviewMap->setLayers( QList<QgsMapLayer *>() << mRasterLayer );
l.addLayoutItem( overviewMap );
map->setCrs( QgsCoordinateReferenceSystem::fromEpsgId( 4326 ) );
overviewMap->setCrs( QgsCoordinateReferenceSystem::fromEpsgId( 54030 ) );
map->setExtent( QgsRectangle( 93, -64.245, 120.6, -45 ) );
overviewMap->setExtent( QgsRectangle( 4712502, -7620278, 10872777, -2531356 ) );
overviewMap->overview()->setLinkedMap( map );
QGSVERIFYLAYOUTCHECK( QStringLiteral( "composermap_overview_reprojected" ), &l );
}
QGSTEST_MAIN( TestQgsLayoutMapOverview )
#include "testqgslayoutmapoverview.moc"