@@ -46,6 +46,7 @@ class TestQgsLayerTree : public QObject
46
46
void testLegendSymbolGraduated ();
47
47
void testLegendSymbolRuleBased ();
48
48
void testResolveReferences ();
49
+ void testEmbeddedGroup ();
49
50
50
51
private:
51
52
@@ -525,5 +526,52 @@ void TestQgsLayerTree::testRendererLegend( QgsFeatureRenderer *renderer )
525
526
}
526
527
527
528
529
+ void TestQgsLayerTree::testEmbeddedGroup ()
530
+ {
531
+ QString dataDir ( TEST_DATA_DIR ); // defined in CmakeLists.txt
532
+ QString layerPath = dataDir + QStringLiteral ( " /points.shp" );
533
+
534
+ // build a project with 3 layers, each having a simple renderer with SVG marker
535
+ // - existing SVG file in project dir
536
+ // - existing SVG file in QGIS dir
537
+ // - non-exsiting SVG file
538
+
539
+ QTemporaryDir dir;
540
+ QVERIFY ( dir.isValid () );
541
+ // on mac the returned path was not canonical and the resolver failed to convert paths properly
542
+ QString dirPath = QFileInfo ( dir.path () ).canonicalFilePath ();
543
+
544
+ QString projectFilename = dirPath + QStringLiteral ( " /project.qgs" );
545
+
546
+ QgsVectorLayer *layer1 = new QgsVectorLayer ( layerPath, QStringLiteral ( " points 1" ), QStringLiteral ( " ogr" ) );
547
+ QgsVectorLayer *layer2 = new QgsVectorLayer ( layerPath, QStringLiteral ( " points 2" ), QStringLiteral ( " ogr" ) );
548
+ QgsVectorLayer *layer3 = new QgsVectorLayer ( layerPath, QStringLiteral ( " points 3" ), QStringLiteral ( " ogr" ) );
549
+
550
+ QVERIFY ( layer1->isValid () );
551
+
552
+ QgsProject project;
553
+ project.addMapLayers ( QList<QgsMapLayer *>() << layer1 << layer2 << layer3, false );
554
+ QgsLayerTreeGroup *grp = project.layerTreeRoot ()->addGroup ( QStringLiteral ( " Embed" ) );
555
+ grp->addLayer ( layer1 );
556
+ grp->addLayer ( layer2 );
557
+ grp->addLayer ( layer3 );
558
+ project.write ( projectFilename );
559
+
560
+ //
561
+ // now let's use the layer group embedded in another project...
562
+ //
563
+
564
+ QgsProject projectMaster;
565
+ QgsLayerTreeGroup *embeddedGroup = projectMaster.createEmbeddedGroup ( grp->name (), projectFilename, QStringList () );
566
+ QVERIFY ( embeddedGroup );
567
+ QCOMPARE ( embeddedGroup->children ().size (), 3 );
568
+
569
+ for ( QgsLayerTreeNode *child : embeddedGroup->children () )
570
+ {
571
+ QVERIFY ( QgsLayerTree::toLayer ( child )->layer () );
572
+ }
573
+ }
574
+
575
+
528
576
QGSTEST_MAIN ( TestQgsLayerTree )
529
577
#include " testqgslayertree.moc"
0 commit comments