Skip to content

Commit

Permalink
Implement addDrawingOrder for wms server under consideration of embed…
Browse files Browse the repository at this point in the history
…ded groups
  • Loading branch information
mhugent committed Nov 20, 2012
1 parent e017442 commit de2c671
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 29 deletions.
101 changes: 72 additions & 29 deletions src/mapserver/qgsprojectparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
3 changes: 3 additions & 0 deletions src/mapserver/qgsprojectparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit de2c671

Please sign in to comment.