Skip to content
Permalink
Browse files

Export layer drawing order to extended capabilities

  • Loading branch information
Marco Hugentobler
Marco Hugentobler committed Sep 6, 2012
1 parent 91a06b3 commit 0d61dfec47b69ed3228cf6424862b02f72c3107d
Showing with 55 additions and 0 deletions.
  1. +53 −0 src/mapserver/qgsprojectparser.cpp
  2. +2 −0 src/mapserver/qgsprojectparser.h
@@ -96,6 +96,11 @@ void QgsProjectParser::layersAndStylesCapabilities( QDomElement& parentElement,
return;
}

if ( fullProjectSettings )
{
addDrawingOrder( parentElement, doc );
}

QMap<QString, QgsMapLayer *> layerMap;

foreach ( const QDomElement &elem, mProjectLayerElements )
@@ -1701,3 +1706,51 @@ QgsRectangle QgsProjectParser::layerBoundingBoxInProjectCRS( const QDomElement&
BBox = t.transformBoundingBox( BBox );
return BBox;
}

void QgsProjectParser::addDrawingOrder( QDomElement& parentElem, QDomDocument& doc ) const
{
if ( !mXMLDoc )
{
return;
}

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

QStringList layerList;

bool useDrawingOrder = ( legendElement.attribute( "updateDrawingOrder" ) == "false" );
QDomNodeList layerNodeList = legendElement.elementsByTagName( "legendlayer" );
if ( !useDrawingOrder ) //bottom to top
{
for ( int i = 0; i < layerNodeList.size(); ++i )
{
layerList.prepend( layerNodeList.at( i ).toElement().attribute( "name" ) );
}
}
else
{
QVector<QString> orderedLayerNames;
orderedLayerNames.resize( layerNodeList.size() );
for ( int i = 0; i < layerNodeList.size(); ++i )
{
QString layerName = layerNodeList.at( i ).toElement().attribute( "name" );
int order = layerNodeList.at( i ).toElement().attribute( "drawingOrder" ).toInt();
orderedLayerNames[order] = layerName;
}

QVector<QString>::const_iterator vectorIt = orderedLayerNames.constBegin();
for ( ; vectorIt != orderedLayerNames.constEnd(); ++vectorIt )
{
layerList.prepend( *vectorIt );
}
}
QDomElement layerDrawingOrderElem = doc.createElement( "LayerDrawingOrder" );
QDomText drawingOrderText = doc.createTextNode( layerList.join( "," ) );
layerDrawingOrderElem.appendChild( drawingOrderText );
parentElem.appendChild( layerDrawingOrderElem );
}
@@ -176,6 +176,8 @@ class QgsProjectParser: public QgsConfigParser
void setSelectionColor();
/**Reads maxWidth / maxHeight from project and sets it to QgsConfigParser::mMaxWidth / mMaxHeight*/
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;
};

#endif // QGSPROJECTPARSER_H

0 comments on commit 0d61dfe

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