Skip to content

Commit

Permalink
Fix for accessing groups in mapserver
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@15069 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Jan 24, 2011
1 parent 0a76ab4 commit e7043c4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
36 changes: 29 additions & 7 deletions src/mapserver/qgsprojectparser.cpp
Expand Up @@ -310,23 +310,24 @@ QList<QgsMapLayer*> QgsProjectParser::mapLayerFromStyle( const QString& lName, c
//maybe the layer is a goup. Check if lName is contained in the group list
QMap< QString, QDomElement > idLayerMap = projectLayerElementsById();

QList< GroupLayerInfo > groupInfo = groupLayerRelationshipFromProject();
QList< GroupLayerInfo >::const_iterator groupIt = groupInfo.constBegin();
for ( ; groupIt != groupInfo.constEnd(); ++groupIt )
QList<QDomElement> legendGroups = legendGroupElements();
QList<QDomElement>::const_iterator groupIt = legendGroups.constBegin();
for ( ; groupIt != legendGroups.constEnd(); ++groupIt )
{
if ( groupIt->first == lName )
if ( groupIt->attribute( "name" ) == lName )
{
QList< QString >::const_iterator layerIdIt = groupIt->second.constBegin();
for ( ; layerIdIt != groupIt->second.constEnd(); ++layerIdIt )
QDomNodeList layerFileList = groupIt->elementsByTagName( "legendlayerfile" );
for ( int i = 0; i < layerFileList.size(); ++i )
{
QMap< QString, QDomElement >::const_iterator layerEntry = idLayerMap.find( *layerIdIt );
QMap< QString, QDomElement >::const_iterator layerEntry = idLayerMap.find( layerFileList.at( i ).toElement().attribute( "layerid" ) );
if ( layerEntry != idLayerMap.constEnd() )
{
layerList.push_back( createLayerFromElement( layerEntry.value() ) );
}
}
}
}

return layerList;
}

Expand Down Expand Up @@ -609,6 +610,27 @@ QList<QDomElement> QgsProjectParser::projectLayerElements() const
return layerElemList;
}

QList<QDomElement> QgsProjectParser::legendGroupElements() const
{
QList<QDomElement> groupList;
if ( !mXMLDoc )
{
return groupList;
}

QDomElement legendElement = mXMLDoc->documentElement().firstChildElement( "legend" );
if ( legendElement.isNull() )
{
return groupList;
}

QDomNodeList groupNodeList = legendElement.elementsByTagName( "legendgroup" );
for ( int i = 0; i < groupNodeList.size(); ++i )
{
groupList.push_back( groupNodeList.at( i ).toElement() );
}
}

QMap< QString, QDomElement > QgsProjectParser::projectLayerElementsById() const
{
QMap< QString, QDomElement > layerMap;
Expand Down
2 changes: 2 additions & 0 deletions src/mapserver/qgsprojectparser.h
Expand Up @@ -102,6 +102,8 @@ class QgsProjectParser: public QgsConfigParser

/**Get all layers of the project (ordered same as in the project file)*/
QList<QDomElement> projectLayerElements() const;
/**Returns all legend group elements*/
QList<QDomElement> legendGroupElements() const;
/**Get all layers of the project, accessible by layer id*/
QMap< QString, QDomElement > projectLayerElementsById() const;
/**Get all layers of the project, accessible by layer name*/
Expand Down

0 comments on commit e7043c4

Please sign in to comment.