Skip to content
Permalink
Browse files

Implement addDrawingOrder for wms server under consideration of embed…

…ded groups
  • Loading branch information
mhugent committed Nov 20, 2012
1 parent e017442 commit de2c67159144d4d35ca1a842639d91e47c6a42f4
Showing with 75 additions and 29 deletions.
  1. +72 −29 src/mapserver/qgsprojectparser.cpp
  2. +3 −0 src/mapserver/qgsprojectparser.h
@@ -2245,54 +2245,97 @@ QgsRectangle QgsProjectParser::layerBoundingBoxInProjectCRS( const QDomElement&
return BBox;
}

void QgsProjectParser::addDrawingOrder( QDomElement& parentElem, QDomDocument& doc ) const
void QgsProjectParser::addDrawingOrder( QDomElement elem, bool useDrawingOrder, QMap<int, QString>& orderedLayerList, int& nEmbeddedGroupLayers,
bool embedded ) const
{
if ( !mXMLDoc )
if ( elem.isNull() )
{
return;
}

//find legend section
QDomElement legendElement = mXMLDoc->documentElement().firstChildElement( "legend" );
if ( legendElement.isNull() )
if ( elem.tagName() == "legendlayer" )
{
return;
}

QStringList layerList;
if ( useDrawingOrder )
{
int order = elem.attribute( "drawingOrder", "-1" ).toInt();
orderedLayerList.insertMulti( order + nEmbeddedGroupLayers, elem.attribute( "name" ) );
}
else
{
orderedLayerList.insertMulti( orderedLayerList.size(), elem.attribute( "name" ) );
}

bool useDrawingOrder = ( legendElement.attribute( "updateDrawingOrder" ) == "false" );
QDomNodeList layerNodeList = legendElement.elementsByTagName( "legendlayer" );
if ( !useDrawingOrder ) //bottom to top
{
for ( int i = 0; i < layerNodeList.size(); ++i )
if ( embedded )
{
layerList.prepend( layerNodeList.at( i ).toElement().attribute( "name" ) );
++nEmbeddedGroupLayers;
}
}
else
else if ( elem.tagName() == "legendgroup" )
{
QMap<int, QString> orderedLayerNames;
for ( int i = 0; i < layerNodeList.size(); ++i )
//embedded vs. not embedded
if ( elem.attribute( "embedded" ) == "1" && !embedded )
{
QString layerName = layerNodeList.at( i ).toElement().attribute( "name" );
int order = layerNodeList.at( i ).toElement().attribute( "drawingOrder" ).toInt();
if ( order == -1 )
//load layers / elements from project file
QString project = convertToAbsolutePath( elem.attribute( "project" ) );
QString embeddedGroupName = elem.attribute( "name" );
QgsProjectParser* p = dynamic_cast<QgsProjectParser*>( QgsConfigCache::instance()->searchConfiguration( project ) );
if ( p )
{
layerList.prepend( layerName );
QList<QDomElement> embeddedGroupElements = p->mLegendGroupElements;
foreach ( const QDomElement &groupElem, embeddedGroupElements )
{
if ( groupElem.attribute( "name" ) == embeddedGroupName )
{
addDrawingOrder( groupElem, false, orderedLayerList, nEmbeddedGroupLayers, true );
break;
}
}
}
else
}
else
{
QDomNodeList childList = elem.childNodes();
QDomElement childElem;
for ( int i = 0; i < childList.size(); ++i )
{
orderedLayerNames.insert( order, layerName );
addDrawingOrder( childList.at( i ).toElement(), useDrawingOrder, orderedLayerList, nEmbeddedGroupLayers, false );
}
}
}
}

QMap<int, QString>::const_iterator orderIt = orderedLayerNames.constBegin();
for ( ; orderIt != orderedLayerNames.constEnd(); ++orderIt )
{
layerList.prepend( *orderIt );
}
void QgsProjectParser::addDrawingOrder( QDomElement& parentElem, QDomDocument& doc ) const
{
if ( !mXMLDoc )
{
return;
}

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

bool useDrawingOrder = ( legendElement.attribute( "updateDrawingOrder" ) == "false" );
int nEmbeddedGroupLayers = 0;
QMap<int, QString> orderedLayerNames;

QDomNodeList legendChildren = legendElement.childNodes();
QDomElement childElem;
for ( int i = 0; i < legendChildren.size(); ++i )
{
addDrawingOrder( legendChildren.at( i ).toElement(), useDrawingOrder, orderedLayerNames, nEmbeddedGroupLayers, false );
}

QStringList layerList;
QMap<int, QString>::const_iterator nameIt = orderedLayerNames.constBegin();
for ( ; nameIt != orderedLayerNames.constEnd(); ++nameIt )
{
layerList.prepend( nameIt.value() );
}

QDomElement layerDrawingOrderElem = doc.createElement( "LayerDrawingOrder" );
QDomText drawingOrderText = doc.createTextNode( layerList.join( "," ) );
layerDrawingOrderElem.appendChild( drawingOrderText );
@@ -207,6 +207,9 @@ class QgsProjectParser: public QgsConfigParser
void setMaxWidthHeight();
/**Reads layer drawing order from the legend section of the project file and appends it to the parent elemen (usually the <Capability> element)*/
void addDrawingOrder( QDomElement& parentElem, QDomDocument& doc ) const;
/**Adds drawing order info from layer element or group element (recursive)*/
void addDrawingOrder( QDomElement elem, bool useDrawingOrder, QMap<int, QString>& orderedLayerList, int& nEmbeddedGroupLayers,
bool embedded = false ) const;
/**Returns project layers by id*/
void projectLayerMap( QMap<QString, QgsMapLayer*>& layerMap ) const;

0 comments on commit de2c671

Please sign in to comment.
You can’t perform that action at this time.