Skip to content
Permalink
Browse files
Updates to raster tests - added image writing capability. At teh mome…
…nt 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@7979 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
timlinux committed Jan 16, 2008
1 parent 7c4cf66 commit 2d4a45ef448a74d287999b1a2495e2025b513891
Showing with 42 additions and 0 deletions.
  1. +42 −0 tests/src/core/testqgsrasterlayer.cpp
@@ -21,11 +21,17 @@
#include <QApplication>
#include <QFileInfo>
#include <QDir>
#include <QPainter>
#include <QSettings>
#include <QTime>


//qgis includes...
#include <qgsrasterlayer.h>
#include <qgsrasterbandstats.h>
#include <qgsmaplayerregistry.h>
#include <qgsapplication.h>
#include <qgsmaprender.h>

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

void TestQgsRasterLayer::initTestCase()
@@ -66,11 +74,19 @@ void TestQgsRasterLayer::initTestCase()
QFileInfo myRasterFileInfo ( myFileName );
mpLayer = new QgsRasterLayer ( myRasterFileInfo.filePath(),
myRasterFileInfo.completeBaseName() );
// Register the layer with the registry
QgsMapLayerRegistry::instance()->addMapLayer(mpLayer);
// add the test layer to the maprender
mpMapRenderer = new QgsMapRender();
QStringList myLayers;
myLayers << mpLayer->getLayerID();
mpMapRenderer->setLayerSet(myLayers);
}

void TestQgsRasterLayer::isValid()
{
QVERIFY ( mpLayer->isValid() );
render("raster_test.png");
}
void TestQgsRasterLayer::checkDimensions()
{
@@ -81,6 +97,32 @@ void TestQgsRasterLayer::checkDimensions()
QVERIFY ( mpLayer->getRasterBandStats(1).elementCount == 100 );
}

void TestQgsRasterLayer::render(QString theFileName)
{

//
// Now render our layers onto a pixmap
//
QPixmap myPixmap( 100,100 );
myPixmap.fill ( QColor ( "#98dbf9" ) );
QPainter myPainter( &myPixmap );
mpMapRenderer->setOutputSize( QSize ( 100,100 ),72 );
mpMapRenderer->setExtent(mpLayer->extent());
qDebug ("Extents set to:");
qDebug (mpLayer->extent().stringRep());
QTime myTime;
myTime.start();
mpMapRenderer->render( &myPainter );
qDebug ("Elapsed time in ms for render job: " +
QString::number ( myTime.elapsed() ).toLocal8Bit());
myPainter.end();
//
// Save the pixmap to disk so the user can make a
// visual assessment if needed
//
myPixmap.save (QDir::tempPath() + QDir::separator() + theFileName);
}

QTEST_MAIN(TestQgsRasterLayer)
#include "moc_testqgsrasterlayer.cxx"

0 comments on commit 2d4a45e

Please sign in to comment.