Skip to content

Commit

Permalink
Merge pull request #9997 from qgis/backport-9993-to-release-3_4
Browse files Browse the repository at this point in the history
[Backport release-3_4] fix issues with embedded layers
  • Loading branch information
3nids committed May 14, 2019
2 parents 35def84 + 7fa95e7 commit ca89b30
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 46 deletions.
2 changes: 1 addition & 1 deletion src/core/qgsproject.cpp
Expand Up @@ -2336,7 +2336,7 @@ QgsLayerTreeGroup *QgsProject::createEmbeddedGroup( const QString &groupName, co
if ( layer )
{
layer->resolveReferences( this );
layer->setItemVisibilityChecked( invisibleLayers.contains( layerId ) );
layer->setItemVisibilityChecked( !invisibleLayers.contains( layerId ) );
}
}

Expand Down
14 changes: 6 additions & 8 deletions tests/src/python/test_qgsproject.py
Expand Up @@ -194,15 +194,13 @@ def testEmbeddedGroup(self):
prj.read(prj_path)

layer_tree_group = prj.layerTreeRoot()
layers_ids = layer_tree_group.findLayerIds()

layers_names = []
for layer_id in layers_ids:
for layer_id in layer_tree_group.findLayerIds():
name = prj.mapLayer(layer_id).name()
layers_names.append(name)

expected = ['polys', 'lines']
self.assertEqual(sorted(layers_names), sorted(expected))
self.assertTrue(name in ['polys', 'lines'])
if name == 'polys':
self.assertTrue(layer_tree_group.findLayer(layer_id).itemVisibilityChecked())
elif name == 'lines':
self.assertFalse(layer_tree_group.findLayer(layer_id).itemVisibilityChecked())

def testInstance(self):
""" test retrieving global instance """
Expand Down
113 changes: 76 additions & 37 deletions tests/testdata/embedded_groups/project2.qgs
@@ -1,32 +1,47 @@
<!DOCTYPE qgis PUBLIC 'http://mrcc.com/qgis.dtd' 'SYSTEM'>
<qgis projectname="" version="2.99.0-Master">
<qgis projectname="" version="3.7.0-Master">
<homePath path=""/>
<title></title>
<autotransaction active="0"/>
<evaluateDefaultValues active="0"/>
<layer-tree-group checked="Qt::Checked" name="" expanded="1">
<trust active="0"/>
<projectCrs>
<spatialrefsys>
<proj4>+proj=longlat +datum=WGS84 +no_defs</proj4>
<srsid>3452</srsid>
<srid>4326</srid>
<authid>EPSG:4326</authid>
<description>WGS 84</description>
<projectionacronym>longlat</projectionacronym>
<ellipsoidacronym>WGS84</ellipsoidacronym>
<geographicflag>true</geographicflag>
</spatialrefsys>
</projectCrs>
<layer-tree-group>
<customproperties/>
<layer-tree-group checked="Qt::Checked" name="group1" expanded="1">
<layer-tree-group checked="Qt::Checked" expanded="1" name="group1">
<customproperties>
<property key="embedded" value="1"/>
<property key="embedded-invisible-layers"/>
<property key="embedded-invisible-layers" value="lines20170310142652255"/>
<property key="embedded_project" value="./project1.qgs"/>
</customproperties>
</layer-tree-group>
<custom-order enabled="0"/>
</layer-tree-group>
<snapping-settings type="1" mode="2" unit="2" enabled="0" tolerance="0" intersection-snapping="0">
<snapping-settings enabled="0" tolerance="0" intersection-snapping="0" type="1" mode="2" unit="2">
<individual-layer-settings>
<layer-setting type="1" id="polys20170310142652234" enabled="0" tolerance="0" units="2"/>
<layer-setting type="1" id="lines20170310142652255" enabled="0" tolerance="0" units="2"/>
<layer-setting enabled="0" tolerance="0" units="2" id="polys20170310142652234" type="1"/>
<layer-setting enabled="0" tolerance="0" units="2" id="lines20170310142652255" type="1"/>
</individual-layer-settings>
</snapping-settings>
<relations/>
<mapcanvas>
<mapcanvas annotationsVisible="1" name="theMapCanvas">
<units>degrees</units>
<extent>
<xmin>-119.83786762594776576</xmin>
<ymin>22.62025663373795226</ymin>
<xmax>-81.40764418773530053</xmax>
<ymax>47.3141218219175812</ymax>
<xmin>-116.65168838681026386</xmin>
<ymin>15.75771673405715845</ymin>
<xmax>-78.22146494859779864</xmax>
<ymax>40.45158192223678384</ymax>
</extent>
<rotation>0</rotation>
<destinationsrs>
Expand All @@ -42,51 +57,75 @@
</spatialrefsys>
</destinationsrs>
<rendermaptile>0</rendermaptile>
<layer_coordinate_transform_info/>
<expressionContextScope/>
</mapcanvas>
<layer-tree-canvas>
<custom-order enabled="0">
<item>polys20170310142652234</item>
<item>lines20170310142652255</item>
</custom-order>
</layer-tree-canvas>
<legend updateDrawingOrder="true">
<legendgroup project="./project1.qgs" embedded="1" checked="Qt::Checked" name="group1" open="true"/>
<legendgroup embedded="1" open="true" checked="Qt::Checked" project="./project1.qgs" name="group1"/>
</legend>
<mapViewDocks/>
<projectlayers/>
<layerorder>
<layer id="polys20170310142652234"/>
<layer id="lines20170310142652255"/>
</layerorder>
<properties>
<Gui>
<CanvasColorBluePart type="int">255</CanvasColorBluePart>
<CanvasColorGreenPart type="int">255</CanvasColorGreenPart>
<CanvasColorRedPart type="int">255</CanvasColorRedPart>
<SelectionColorAlphaPart type="int">255</SelectionColorAlphaPart>
<CanvasColorGreenPart type="int">255</CanvasColorGreenPart>
<SelectionColorGreenPart type="int">255</SelectionColorGreenPart>
<SelectionColorBluePart type="int">0</SelectionColorBluePart>
<CanvasColorBluePart type="int">255</CanvasColorBluePart>
<SelectionColorGreenPart type="int">255</SelectionColorGreenPart>
<SelectionColorRedPart type="int">255</SelectionColorRedPart>
</Gui>
<PositionPrecision>
<DecimalPlaces type="int">2</DecimalPlaces>
<Automatic type="bool">true</Automatic>
</PositionPrecision>
<Paths>
<Absolute type="bool">false</Absolute>
</Paths>
<Legend>
<filterByMap type="bool">false</filterByMap>
</Legend>
<Identify>
<disabledLayers type="QStringList"/>
</Identify>
<Legend>
<filterByMap type="bool">false</filterByMap>
</Legend>
<Measurement>
<AreaUnits type="QString">m2</AreaUnits>
<DistanceUnits type="QString">meters</DistanceUnits>
</Measurement>
<PAL>
<CandidatesLine type="int">50</CandidatesLine>
<CandidatesPoint type="int">16</CandidatesPoint>
<CandidatesPolygon type="int">30</CandidatesPolygon>
<DrawRectOnly type="bool">false</DrawRectOnly>
<SearchMethod type="int">0</SearchMethod>
<ShowingAllLabels type="bool">false</ShowingAllLabels>
<ShowingCandidates type="bool">false</ShowingCandidates>
<ShowingPartialsLabels type="bool">true</ShowingPartialsLabels>
<TextFormat type="int">0</TextFormat>
</PAL>
<Paths>
<Absolute type="bool">false</Absolute>
</Paths>
<PositionPrecision>
<Automatic type="bool">true</Automatic>
<DecimalPlaces type="int">2</DecimalPlaces>
</PositionPrecision>
<SpatialRefSys>
<ProjectCRSID type="int">3452</ProjectCRSID>
<ProjectCRSProj4String type="QString">+proj=longlat +datum=WGS84 +no_defs</ProjectCRSProj4String>
<ProjectCrs type="QString">EPSG:4326</ProjectCrs>
<ProjectionsEnabled type="int">1</ProjectionsEnabled>
</SpatialRefSys>
<Measurement>
<AreaUnits type="QString">m2</AreaUnits>
<DistanceUnits type="QString">meters</DistanceUnits>
</Measurement>
</properties>
<visibility-presets/>
<transformContext/>
<projectMetadata>
<identifier></identifier>
<parentidentifier></parentidentifier>
<language></language>
<type></type>
<title></title>
<abstract></abstract>
<links/>
<author></author>
<creation></creation>
</projectMetadata>
<Annotations/>
<Layouts/>
</qgis>

0 comments on commit ca89b30

Please sign in to comment.