1 /***************************************************************************
2                          testprojectionissues.cpp
3                          ---------------------------
4     begin                : September 2012
5     copyright            : (C) 2012 by Magnus Homann
6     email                : magnus at homann dot se
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 "qgsmapcanvas.h"
20 #include "qgsproject.h"
21 #include "qgsmultibandcolorrenderer.h"
22 #include "qgsrasterdataprovider.h"
23 #include "qgsrasterlayer.h"
24 #include <QObject>
25 #include "qgstest.h"
26 
27 class TestProjectionIssues : public QObject
28 {
29     Q_OBJECT
30   public:
31     TestProjectionIssues() = default;
32 
33   private slots:
34     void initTestCase();// will be called before the first testfunction is executed.
35     void cleanupTestCase();// will be called after the last testfunction was executed.
36     void init();// will be called before each testfunction is executed.
37     void cleanup();// will be called after every testfunction.
38     void issue5895();// test for #5895
39 
40   private:
41     QgsRasterLayer *mRasterLayer = nullptr;
42     QgsMapCanvas   *mMapCanvas = nullptr;
43 };
44 
initTestCase()45 void TestProjectionIssues::initTestCase()
46 {
47   QgsApplication::init();
48   QgsApplication::initQgis();
49 
50   //create maplayer from testdata and add to layer registry
51   const QFileInfo rasterFileInfo( QStringLiteral( TEST_DATA_DIR ) + '/' +  "checker360by180.asc" );
52   mRasterLayer = new QgsRasterLayer( rasterFileInfo.filePath(),
53                                      rasterFileInfo.completeBaseName() );
54   // Set to WGS84
55   const QgsCoordinateReferenceSystem sourceCRS( QStringLiteral( "EPSG:4326" ) );
56   mRasterLayer->setCrs( sourceCRS, false );
57 
58   QgsMultiBandColorRenderer *rasterRenderer = new QgsMultiBandColorRenderer( mRasterLayer->dataProvider(), 2, 3, 4 );
59   mRasterLayer->setRenderer( rasterRenderer );
60 
61   QList<QgsMapLayer *> mapLayers;
62   mapLayers.append( mRasterLayer );
63   QgsProject::instance()->addMapLayers( mapLayers );
64 
65   // Add all layers in registry to the canvas
66   QList<QgsMapLayer *> canvasLayers;
67   for ( QgsMapLayer *layer : QgsProject::instance()->mapLayers() )
68   {
69     canvasLayers.append( layer );
70   }
71 
72   // create canvas
73   mMapCanvas = new QgsMapCanvas();
74   mMapCanvas->setLayers( canvasLayers );
75 
76   //reproject to SWEDREF 99 TM
77   const QgsCoordinateReferenceSystem destCRS( QStringLiteral( "EPSG:3006" ) );
78   mMapCanvas->setDestinationCrs( destCRS );
79 
80 }
81 
cleanupTestCase()82 void TestProjectionIssues::cleanupTestCase()
83 {
84   delete mMapCanvas;
85 
86   QgsApplication::exitQgis();
87 }
88 
init()89 void TestProjectionIssues::init()
90 {
91 
92 }
93 
cleanup()94 void TestProjectionIssues::cleanup()
95 {
96 
97 }
98 
issue5895()99 void TestProjectionIssues::issue5895()
100 {
101   const QgsRectangle largeExtent( -610861, 5101721, 2523921, 6795055 );
102   mMapCanvas->setExtent( largeExtent );
103   mMapCanvas->zoomByFactor( 2.0 ); // Zoom out. This should exceed the transform limits.
104 }
105 
106 QGSTEST_MAIN( TestProjectionIssues )
107 #include "testprojectionissues.moc"
108