Skip to content
Permalink
Browse files

More fixes to support embedded groups

  • Loading branch information
mhugent committed Mar 4, 2014
1 parent 8ed4114 commit 9774abdb0516a00242cc23406cddd3f09371219e
Showing with 47 additions and 10 deletions.
  1. +32 −8 src/app/legend/qgslegend.cpp
  2. +4 −0 src/mapserver/qgis_map_serv.cpp
  3. +11 −2 src/mapserver/qgsprojectparser.cpp
@@ -988,11 +988,11 @@ QgsLegendGroup* QgsLegend::addEmbeddedGroup( const QString& groupName, const QSt
QDomNodeList legendGroupList = legendElem.elementsByTagName( "legendgroup" );
for ( int i = 0; i < legendGroupList.size(); ++i )
{
QDomElement legendElem = legendGroupList.at( i ).toElement();
if ( legendElem.attribute( "name" ) == groupName )
QDomElement legendGroupElem = legendGroupList.at( i ).toElement();
if ( legendGroupElem.attribute( "name" ) == groupName )
{
//embedded groups cannot be embedded again
if ( legendElem.attribute( "embedded" ) == "1" )
if ( legendGroupElem.attribute( "embedded" ) == "1" )
{
mEmbeddedGroups.remove( groupName );
return 0;
@@ -1017,7 +1017,8 @@ QgsLegendGroup* QgsLegend::addEmbeddedGroup( const QString& groupName, const QSt
group->setFont( 0, groupFont );
setCurrentItem( group );

QDomNodeList groupChildren = legendElem.childNodes();
bool updateDrawingOrder = legendElem.attribute( "updateDrawingOrder" ) == "true";
QDomNodeList groupChildren = legendGroupElem.childNodes();
for ( int j = 0; j < groupChildren.size(); ++j )
{
QDomElement childElem = groupChildren.at( j ).toElement();
@@ -1040,6 +1041,14 @@ QgsLegendGroup* QgsLegend::addEmbeddedGroup( const QString& groupName, const QSt

if ( cItem )
{
//add drawing order
int drawingOrder = ( updateDrawingOrder ? -1 : childElem.attribute( "drawingOrder", "-1" ).toInt() );
QgsLegendLayer* llI = dynamic_cast<QgsLegendLayer*>( cItem );
if ( llI )
{
llI->setDrawingOrder( drawingOrder );
}

group->insertChild( group->childCount(), cItem );
}

@@ -1474,24 +1483,39 @@ QList<QgsMapCanvasLayer> QgsLegend::canvasLayers()
{
qSort( groupLayers.begin(), groupLayers.end(), inReverseDrawingOrder );
}
for ( int i = groupLayers.size() - 1; i >= 0; --i )

QMap<int, QgsMapCanvasLayer > orderedLayers;
for ( int i = 0; i < groupLayers.size(); ++i )
{
QgsLegendLayer* ll = groupLayers.at( i );
int drawingOrder = ll->drawingOrder();
if ( !ll || embeddedGroupChildren.contains( ll ) )
{
continue;
}

if ( mUpdateDrawingOrder )
if ( drawingOrder == -1 )
{
layers.insertMulti( nEntries, ll->canvasLayer() );
orderedLayers.insert( orderedLayers.size(), ll->canvasLayer() );
}
else
{
layers.insertMulti( groupDrawingOrder, ll->canvasLayer() );
orderedLayers.insert( drawingOrder, ll->canvasLayer() );
}
embeddedGroupChildren.insert( ll );
}
QMap<int, QgsMapCanvasLayer >::iterator orderedLayersIt = orderedLayers.begin();
for ( ; orderedLayersIt != orderedLayers.end(); ++orderedLayersIt )
{
if ( mUpdateDrawingOrder )
{
layers.insert( layers.size(), orderedLayersIt.value() );
}
else
{
layers.insertMulti( groupDrawingOrder, orderedLayersIt.value() );
}
}
}
}
++it;
@@ -177,6 +177,10 @@ int main( int argc, char * argv[] )

//Default prefix path may be altered by environment variable
QgsApplication::init();
#if !defined(Q_OS_WIN)
// init QGIS's paths - true means that all path will be inited from prefix
QgsApplication::setPrefixPath( CMAKE_INSTALL_PREFIX, TRUE );
#endif

#if defined(MAPSERVER_SKIP_ECW)
QgsDebugMsg( "Skipping GDAL ECW drivers in server." );
@@ -1851,6 +1851,7 @@ void QgsProjectParser::addLayersFromGroup( const QDomElement& legendGroupElem, Q
}
else //normal group
{
bool updateDrawingOrder = ( legendGroupElem.parentNode().toElement().attribute( "updateDrawingOrder" ) == "true" );
QMap< int, QDomElement > layerOrderList;
QDomNodeList groupElemChildren = legendGroupElem.childNodes();
for ( int i = 0; i < groupElemChildren.size(); ++i )
@@ -1862,7 +1863,7 @@ void QgsProjectParser::addLayersFromGroup( const QDomElement& legendGroupElem, Q
}
else if ( elem.tagName() == "legendlayer" )
{
int drawingOrder = elem.attribute( "drawingOrder", "-1" ).toInt();
int drawingOrder = updateDrawingOrder ? -1 : elem.attribute( "drawingOrder", "-1" ).toInt();
if ( drawingOrder == -1 )
{
addLayerFromLegendLayer( elem, layerList, useCache );
@@ -4123,6 +4124,14 @@ void QgsProjectParser::addDrawingOrderEmbeddedGroup( const QDomElement& groupEle
return;
}

//legend or custom drawing order in embedded project?
bool updateDrawingOrder = true;
QDomNodeList legendNode = doc->elementsByTagName( "legend" );
if ( legendNode.size() > 0 )
{
updateDrawingOrder = ( legendNode.at( 0 ).toElement().attribute( "updateDrawingOrder" ) == "true" );
}

QDomNodeList layerNodeList = embeddedGroupElem.elementsByTagName( "legendlayer" );
QDomElement layerElem;
QMap<int, QString > layerNames;
@@ -4132,7 +4141,7 @@ void QgsProjectParser::addDrawingOrderEmbeddedGroup( const QDomElement& groupEle
layerElem = layerNodeList.at( i ).toElement();
layerName = layerElem.attribute( "name" );

int layerDrawingOrder = layerElem.attribute( "drawingOrder", "-1" ).toInt();
int layerDrawingOrder = updateDrawingOrder ? -1 : layerElem.attribute( "drawingOrder", "-1" ).toInt();
if ( layerDrawingOrder == -1 )
{
layerNames.insert( layerNames.size(), layerName );

0 comments on commit 9774abd

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