Skip to content
Permalink
Browse files

Add test for embedded groups

  • Loading branch information
m-kuhn committed Jun 8, 2018
1 parent 8ef0d1f commit e315ed6de5c78704ac62ebb5fb010eda9ab5eaba
Showing with 48 additions and 0 deletions.
  1. +48 −0 tests/src/core/testqgslayertree.cpp
@@ -46,6 +46,7 @@ class TestQgsLayerTree : public QObject
void testLegendSymbolGraduated();
void testLegendSymbolRuleBased();
void testResolveReferences();
void testEmbeddedGroup();

private:

@@ -525,5 +526,52 @@ void TestQgsLayerTree::testRendererLegend( QgsFeatureRenderer *renderer )
}


void TestQgsLayerTree::testEmbeddedGroup()
{
QString dataDir( TEST_DATA_DIR ); //defined in CmakeLists.txt
QString layerPath = dataDir + QStringLiteral( "/points.shp" );

// build a project with 3 layers, each having a simple renderer with SVG marker
// - existing SVG file in project dir
// - existing SVG file in QGIS dir
// - non-exsiting SVG file

QTemporaryDir dir;
QVERIFY( dir.isValid() );
// on mac the returned path was not canonical and the resolver failed to convert paths properly
QString dirPath = QFileInfo( dir.path() ).canonicalFilePath();

QString projectFilename = dirPath + QStringLiteral( "/project.qgs" );

QgsVectorLayer *layer1 = new QgsVectorLayer( layerPath, QStringLiteral( "points 1" ), QStringLiteral( "ogr" ) );
QgsVectorLayer *layer2 = new QgsVectorLayer( layerPath, QStringLiteral( "points 2" ), QStringLiteral( "ogr" ) );
QgsVectorLayer *layer3 = new QgsVectorLayer( layerPath, QStringLiteral( "points 3" ), QStringLiteral( "ogr" ) );

QVERIFY( layer1->isValid() );

QgsProject project;
project.addMapLayers( QList<QgsMapLayer *>() << layer1 << layer2 << layer3, false );
QgsLayerTreeGroup *grp = project.layerTreeRoot()->addGroup( QStringLiteral( "Embed" ) );
grp->addLayer( layer1 );
grp->addLayer( layer2 );
grp->addLayer( layer3 );
project.write( projectFilename );

//
// now let's use the layer group embedded in another project...
//

QgsProject projectMaster;
QgsLayerTreeGroup *embeddedGroup = projectMaster.createEmbeddedGroup( grp->name(), projectFilename, QStringList() );
QVERIFY( embeddedGroup );
QCOMPARE( embeddedGroup->children().size(), 3 );

for ( QgsLayerTreeNode *child : embeddedGroup->children() )
{
QVERIFY( QgsLayerTree::toLayer( child )->layer() );
}
}


QGSTEST_MAIN( TestQgsLayerTree )
#include "testqgslayertree.moc"

0 comments on commit e315ed6

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