Skip to content

Commit

Permalink
Consider embedded groups for restricted WMS layers / groups
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Hugentobler committed Oct 16, 2012
1 parent 6ef55df commit 0478d3b
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 10 deletions.
72 changes: 62 additions & 10 deletions src/mapserver/qgsprojectparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,6 @@ QList<QgsMapLayer*> QgsProjectParser::mapLayerFromStyle( const QString& lName, c
QList<QgsMapLayer*> layerList;

//first check if the layer name refers an unpublished layer / group
QSet<QString> rLayers = restrictedLayers();
if ( mRestrictedLayers.contains( lName ) )
{
return layerList;
Expand Down Expand Up @@ -2079,21 +2078,74 @@ QSet<QString> QgsProjectParser::restrictedLayers() const
//get name
QDomElement groupElem = legendGroupList.at( i ).toElement();
QString groupName = groupElem.attribute( "name" );
if ( restrictedLayerSet.contains( groupName ) )
if ( restrictedLayerSet.contains( groupName ) ) //match: add names of subgroups and sublayers to set
{
//match: add names of subgroups and sublayers to set
QDomNodeList subgroupList = groupElem.elementsByTagName( "legendgroup" );
for ( int j = 0; j < subgroupList.size(); ++j )
//embedded group? -> also get names of subgroups and sublayers from embedded projects
if ( groupElem.attribute( "embedded" ) == "1" )
{
restrictedLayerSet.insert( subgroupList.at( j ).toElement().attribute( "name" ) );
sublayersOfEmbeddedGroup( convertToAbsolutePath( groupElem.attribute( "project" ) ), groupName, restrictedLayerSet );
}
QDomNodeList sublayerList = groupElem.elementsByTagName( "legendlayer" );
for ( int k = 0; k < sublayerList.size(); ++k )
else //local group
{
restrictedLayerSet.insert( sublayerList.at( k ).toElement().attribute( "name" ) );
QDomNodeList subgroupList = groupElem.elementsByTagName( "legendgroup" );
for ( int j = 0; j < subgroupList.size(); ++j )
{
restrictedLayerSet.insert( subgroupList.at( j ).toElement().attribute( "name" ) );
}
QDomNodeList sublayerList = groupElem.elementsByTagName( "legendlayer" );
for ( int k = 0; k < sublayerList.size(); ++k )
{
restrictedLayerSet.insert( sublayerList.at( k ).toElement().attribute( "name" ) );
}
}
}
}

return restrictedLayerSet;
}

void QgsProjectParser::sublayersOfEmbeddedGroup( const QString& projectFilePath, const QString& groupName, QSet<QString>& layerSet )
{
QFile projectFile( projectFilePath );
if ( !projectFile.open( QIODevice::ReadOnly ) )
{
return;
}

QDomDocument xmlDoc;
if ( !xmlDoc.setContent( &projectFile ) )
{
return;
}

//go to legend node
QDomElement legendElem = xmlDoc.documentElement().firstChildElement( "legend" );
if ( legendElem.isNull() )
{
return;
}

//get group node list of embedded project
QDomNodeList groupNodes = legendElem.elementsByTagName( "legendgroup" );
QDomElement groupElem;
for ( int i = 0; i < groupNodes.size(); ++i )
{
groupElem = groupNodes.at( i ).toElement();
if ( groupElem.attribute( "name" ) == groupName )
{
//get all subgroups and sublayers and add to layerSet
QDomElement subElem;
QDomNodeList subGroupList = groupElem.elementsByTagName( "legendgroup" );
for ( int j = 0; j < subGroupList.size(); ++j )
{
subElem = subGroupList.at( j ).toElement();
layerSet.insert( subElem.attribute( "name" ) );
}
QDomNodeList subLayerList = groupElem.elementsByTagName( "legendlayer" );
for ( int j = 0; j < subLayerList.size(); ++j )
{
subElem = subLayerList.at( j ).toElement();
layerSet.insert( subElem.attribute( "name" ) );
}
}
}
}
2 changes: 2 additions & 0 deletions src/mapserver/qgsprojectparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ class QgsProjectParser: public QgsConfigParser

/**Returns a complete string set with all the restricted layer names (layers/groups that are not to be published)*/
QSet<QString> restrictedLayers() const;
/**Adds sublayers of an embedded group to layer set*/
static void sublayersOfEmbeddedGroup( const QString& projectFilePath, const QString& groupName, QSet<QString>& layerSet );
};

#endif // QGSPROJECTPARSER_H

0 comments on commit 0478d3b

Please sign in to comment.