Skip to content

Commit

Permalink
Updates to raster tests - added image writing capability. At teh mome…
Browse files Browse the repository at this point in the history
…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/qgis@7979 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
timlinux committed Jan 16, 2008
1 parent e2022d6 commit 831a55e
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/src/core/testqgsrasterlayer.cpp
Expand Up @@ -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.
Expand All @@ -42,7 +48,9 @@ class TestQgsRasterLayer: public QObject
void isValid();
void checkDimensions();
private:
void render(QString theFileName);
QgsRasterLayer * mpLayer;
QgsMapRender * mpMapRenderer;
};

void TestQgsRasterLayer::initTestCase()
Expand All @@ -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()
{
Expand All @@ -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 831a55e

Please sign in to comment.