Skip to content
Permalink
Browse files

Add unit test for QgsLayerTreeModel::setLegendFilterByMap()

  • Loading branch information
Hugo Mercier
Hugo Mercier committed Jun 19, 2015
1 parent 2202b42 commit a9c63968bf3fad45c34dc4e6845fae2422b6a6e6
@@ -17,6 +17,8 @@
#include "qgsrenderchecker.h"
#include "qgssinglesymbolrendererv2.h"
#include "qgsvectorlayer.h"
#include "qgsvectordataprovider.h"
#include "qgsgeometry.h"



@@ -85,6 +87,7 @@ class TestQgsLegendRenderer : public QObject
void testBigMarker();
void testLongSymbolText();
void testThreeColumns();
void testFilterByMap();

private:
QgsLayerTreeGroup* mRoot;
@@ -123,6 +126,29 @@ void TestQgsLegendRenderer::init()
mVL2->setRendererV2( new QgsSingleSymbolRendererV2( sym2 ) );

mVL3 = new QgsVectorLayer( "Point", "Point Layer", "memory" );
{
QgsVectorDataProvider* pr = mVL3->dataProvider();
QList<QgsField> attrs;
attrs << QgsField("test_attr", QVariant::Int);
pr->addAttributes( attrs );

QgsFields fields;
fields.append( attrs.back() );

QList<QgsFeature> features;
QgsFeature f1(fields, 1);
f1.setAttribute(0, 1);
f1.setGeometry( QgsGeometry::fromPoint(QgsPoint(1.0, 1.0)) );
QgsFeature f2(fields, 2);
f2.setAttribute(0, 2);
f2.setGeometry( QgsGeometry::fromPoint(QgsPoint(9.0, 1.0)) );
QgsFeature f3(fields, 3);
f3.setAttribute(0, 3);
f3.setGeometry( QgsGeometry::fromPoint(QgsPoint(5.0, 5.0)) );
features << f1 << f2 << f3;
pr->addFeatures( features );
mVL3->updateFields();
}
QgsMapLayerRegistry::instance()->addMapLayer( mVL3 );

static char raster_array[] = { 1, 2, 2, 1 };
@@ -249,6 +275,31 @@ void TestQgsLegendRenderer::testThreeColumns()
_verifyImage( testName );
}

void TestQgsLegendRenderer::testFilterByMap()
{
QString testName = "legend_filter_by_map";

QgsLayerTreeModel legendModel( mRoot );

QgsMapSettings mapSettings;
// extent and size to include only the red and green points
mapSettings.setExtent( QgsRectangle( 0, 0, 10.0, 4.0 ) );
mapSettings.setOutputSize( QSize(400,100) );
mapSettings.setOutputDpi( 96 );
QStringList ll;
foreach( auto l, QgsMapLayerRegistry::instance()->mapLayers() )
{
ll << l->id();
}
mapSettings.setLayers( ll );

legendModel.setLegendFilterByMap( &mapSettings );

QgsLegendSettings settings;
_setStandardTestFont( settings );
_renderLegend( testName, &legendModel, settings );
_verifyImage( testName );
}

QTEST_MAIN( TestQgsLegendRenderer )
#include "testqgslegendrenderer.moc"
Binary file not shown.

0 comments on commit a9c6396

Please sign in to comment.
You can’t perform that action at this time.