Skip to content

Commit 831a55e

Browse files
author
timlinux
committed
Updates to raster tests - added image writing capability. At teh moment it will write to /tmp/raster_test.png. Later I will write different files out after performing various colour and transparency operations on the test dataset.
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@7979 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent e2022d6 commit 831a55e

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

tests/src/core/testqgsrasterlayer.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,17 @@
2121
#include <QApplication>
2222
#include <QFileInfo>
2323
#include <QDir>
24+
#include <QPainter>
25+
#include <QSettings>
26+
#include <QTime>
27+
2428

2529
//qgis includes...
2630
#include <qgsrasterlayer.h>
2731
#include <qgsrasterbandstats.h>
32+
#include <qgsmaplayerregistry.h>
2833
#include <qgsapplication.h>
34+
#include <qgsmaprender.h>
2935

3036
/** \ingroup UnitTests
3137
* This is a unit test for the QgsRasterLayer class.
@@ -42,7 +48,9 @@ class TestQgsRasterLayer: public QObject
4248
void isValid();
4349
void checkDimensions();
4450
private:
51+
void render(QString theFileName);
4552
QgsRasterLayer * mpLayer;
53+
QgsMapRender * mpMapRenderer;
4654
};
4755

4856
void TestQgsRasterLayer::initTestCase()
@@ -66,11 +74,19 @@ void TestQgsRasterLayer::initTestCase()
6674
QFileInfo myRasterFileInfo ( myFileName );
6775
mpLayer = new QgsRasterLayer ( myRasterFileInfo.filePath(),
6876
myRasterFileInfo.completeBaseName() );
77+
// Register the layer with the registry
78+
QgsMapLayerRegistry::instance()->addMapLayer(mpLayer);
79+
// add the test layer to the maprender
80+
mpMapRenderer = new QgsMapRender();
81+
QStringList myLayers;
82+
myLayers << mpLayer->getLayerID();
83+
mpMapRenderer->setLayerSet(myLayers);
6984
}
7085

7186
void TestQgsRasterLayer::isValid()
7287
{
7388
QVERIFY ( mpLayer->isValid() );
89+
render("raster_test.png");
7490
}
7591
void TestQgsRasterLayer::checkDimensions()
7692
{
@@ -81,6 +97,32 @@ void TestQgsRasterLayer::checkDimensions()
8197
QVERIFY ( mpLayer->getRasterBandStats(1).elementCount == 100 );
8298
}
8399

100+
void TestQgsRasterLayer::render(QString theFileName)
101+
{
102+
103+
//
104+
// Now render our layers onto a pixmap
105+
//
106+
QPixmap myPixmap( 100,100 );
107+
myPixmap.fill ( QColor ( "#98dbf9" ) );
108+
QPainter myPainter( &myPixmap );
109+
mpMapRenderer->setOutputSize( QSize ( 100,100 ),72 );
110+
mpMapRenderer->setExtent(mpLayer->extent());
111+
qDebug ("Extents set to:");
112+
qDebug (mpLayer->extent().stringRep());
113+
QTime myTime;
114+
myTime.start();
115+
mpMapRenderer->render( &myPainter );
116+
qDebug ("Elapsed time in ms for render job: " +
117+
QString::number ( myTime.elapsed() ).toLocal8Bit());
118+
myPainter.end();
119+
//
120+
// Save the pixmap to disk so the user can make a
121+
// visual assessment if needed
122+
//
123+
myPixmap.save (QDir::tempPath() + QDir::separator() + theFileName);
124+
}
125+
84126
QTEST_MAIN(TestQgsRasterLayer)
85127
#include "moc_testqgsrasterlayer.cxx"
86128

0 commit comments

Comments
 (0)