@@ -676,7 +676,6 @@ QList<QgsMapLayer*> QgsProjectParser::mapLayerFromStyle( const QString& lName, c
676
676
QList<QgsMapLayer*> layerList;
677
677
678
678
// first check if the layer name refers an unpublished layer / group
679
- QSet<QString> rLayers = restrictedLayers ();
680
679
if ( mRestrictedLayers .contains ( lName ) )
681
680
{
682
681
return layerList;
@@ -2079,21 +2078,74 @@ QSet<QString> QgsProjectParser::restrictedLayers() const
2079
2078
// get name
2080
2079
QDomElement groupElem = legendGroupList.at ( i ).toElement ();
2081
2080
QString groupName = groupElem.attribute ( " name" );
2082
- if ( restrictedLayerSet.contains ( groupName ) )
2081
+ if ( restrictedLayerSet.contains ( groupName ) ) // match: add names of subgroups and sublayers to set
2083
2082
{
2084
- // match: add names of subgroups and sublayers to set
2085
- QDomNodeList subgroupList = groupElem.elementsByTagName ( " legendgroup" );
2086
- for ( int j = 0 ; j < subgroupList.size (); ++j )
2083
+ // embedded group? -> also get names of subgroups and sublayers from embedded projects
2084
+ if ( groupElem.attribute ( " embedded" ) == " 1" )
2087
2085
{
2088
- restrictedLayerSet. insert ( subgroupList. at ( j ). toElement (). attribute ( " name " ) );
2086
+ sublayersOfEmbeddedGroup ( convertToAbsolutePath ( groupElem. attribute ( " project " ) ), groupName, restrictedLayerSet );
2089
2087
}
2090
- QDomNodeList sublayerList = groupElem.elementsByTagName ( " legendlayer" );
2091
- for ( int k = 0 ; k < sublayerList.size (); ++k )
2088
+ else // local group
2092
2089
{
2093
- restrictedLayerSet.insert ( sublayerList.at ( k ).toElement ().attribute ( " name" ) );
2090
+ QDomNodeList subgroupList = groupElem.elementsByTagName ( " legendgroup" );
2091
+ for ( int j = 0 ; j < subgroupList.size (); ++j )
2092
+ {
2093
+ restrictedLayerSet.insert ( subgroupList.at ( j ).toElement ().attribute ( " name" ) );
2094
+ }
2095
+ QDomNodeList sublayerList = groupElem.elementsByTagName ( " legendlayer" );
2096
+ for ( int k = 0 ; k < sublayerList.size (); ++k )
2097
+ {
2098
+ restrictedLayerSet.insert ( sublayerList.at ( k ).toElement ().attribute ( " name" ) );
2099
+ }
2094
2100
}
2095
2101
}
2096
2102
}
2097
-
2098
2103
return restrictedLayerSet;
2099
2104
}
2105
+
2106
+ void QgsProjectParser::sublayersOfEmbeddedGroup ( const QString& projectFilePath, const QString& groupName, QSet<QString>& layerSet )
2107
+ {
2108
+ QFile projectFile ( projectFilePath );
2109
+ if ( !projectFile.open ( QIODevice::ReadOnly ) )
2110
+ {
2111
+ return ;
2112
+ }
2113
+
2114
+ QDomDocument xmlDoc;
2115
+ if ( !xmlDoc.setContent ( &projectFile ) )
2116
+ {
2117
+ return ;
2118
+ }
2119
+
2120
+ // go to legend node
2121
+ QDomElement legendElem = xmlDoc.documentElement ().firstChildElement ( " legend" );
2122
+ if ( legendElem.isNull () )
2123
+ {
2124
+ return ;
2125
+ }
2126
+
2127
+ // get group node list of embedded project
2128
+ QDomNodeList groupNodes = legendElem.elementsByTagName ( " legendgroup" );
2129
+ QDomElement groupElem;
2130
+ for ( int i = 0 ; i < groupNodes.size (); ++i )
2131
+ {
2132
+ groupElem = groupNodes.at ( i ).toElement ();
2133
+ if ( groupElem.attribute ( " name" ) == groupName )
2134
+ {
2135
+ // get all subgroups and sublayers and add to layerSet
2136
+ QDomElement subElem;
2137
+ QDomNodeList subGroupList = groupElem.elementsByTagName ( " legendgroup" );
2138
+ for ( int j = 0 ; j < subGroupList.size (); ++j )
2139
+ {
2140
+ subElem = subGroupList.at ( j ).toElement ();
2141
+ layerSet.insert ( subElem.attribute ( " name" ) );
2142
+ }
2143
+ QDomNodeList subLayerList = groupElem.elementsByTagName ( " legendlayer" );
2144
+ for ( int j = 0 ; j < subLayerList.size (); ++j )
2145
+ {
2146
+ subElem = subLayerList.at ( j ).toElement ();
2147
+ layerSet.insert ( subElem.attribute ( " name" ) );
2148
+ }
2149
+ }
2150
+ }
2151
+ }
0 commit comments