Skip to content
Permalink
Browse files
Fix for ticket #1301, don't include inactive layers in legend
git-svn-id: http://svn.osgeo.org/qgis/trunk@9667 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Nov 18, 2008
1 parent 37d30b2 commit 9568f00809b8458c5506f061b955ddf3e59c04ad
Showing with 37 additions and 13 deletions.
  1. +37 −13 src/core/composer/qgscomposerlegend.cpp
@@ -18,6 +18,7 @@
#include "qgscomposerlegend.h"
#include "qgsmaplayer.h"
#include "qgsmaplayerregistry.h"
#include "qgsmaprenderer.h"
#include "qgssymbol.h"
#include <QDomDocument>
#include <QDomElement>
@@ -91,29 +92,41 @@ QSizeF QgsComposerLegend::paintAndDetermineSize( QPainter* painter )

maxXCoord = 2 * mBoxSpace + textWidthMillimeters( mTitleFont, mTitle );

//draw layer items
//draw only visible layer items
QgsMapRenderer* theMapRenderer = mComposition->mapRenderer();
QStringList visibleLayerIds;
if(theMapRenderer)
{
visibleLayerIds = theMapRenderer->layerSet();
}


for ( int i = 0; i < numLayerItems; ++i )
{
currentLayerItem = rootItem->child( i );
if ( currentLayerItem )
{
//Let the user omit the layer title item by having an empty layer title string
if(!currentLayerItem->text().isEmpty())
QString currentLayerId = currentLayerItem->data().toString();
if(visibleLayerIds.contains(currentLayerId))
{
currentYCoordinate += mLayerSpace;
currentYCoordinate += fontAscentMillimeters( mLayerFont );

//draw layer Item
if ( painter )
//Let the user omit the layer title item by having an empty layer title string
if(!currentLayerItem->text().isEmpty())
{
drawText( painter, mBoxSpace, currentYCoordinate, currentLayerItem->text(), mLayerFont );
currentYCoordinate += mLayerSpace;
currentYCoordinate += fontAscentMillimeters( mLayerFont );

//draw layer Item
if ( painter )
{
drawText( painter, mBoxSpace, currentYCoordinate, currentLayerItem->text(), mLayerFont );
}
}
}

maxXCoord = std::max( maxXCoord, 2 * mBoxSpace + textWidthMillimeters( mLayerFont, currentLayerItem->text() ) );
maxXCoord = std::max( maxXCoord, 2 * mBoxSpace + textWidthMillimeters( mLayerFont, currentLayerItem->text() ) );

//and child items
drawLayerChildItems( painter, currentLayerItem, currentYCoordinate, maxXCoord );
//and child items
drawLayerChildItems( painter, currentLayerItem, currentYCoordinate, maxXCoord );
}
}
}

@@ -133,6 +146,17 @@ QSizeF QgsComposerLegend::paintAndDetermineSize( QPainter* painter )

size.setHeight( currentYCoordinate );
size.setWidth( maxXCoord );

//adjust box if width or height is to small
if(painter && currentYCoordinate > rect().width())
{
setSceneRect( QRectF( transform().dx(), transform().dy(), rect().width(), currentYCoordinate));
}
if(painter && maxXCoord > rect().height())
{
setSceneRect( QRectF( transform().dx(), transform().dy(), maxXCoord, rect().height()));
}

return size;
}

0 comments on commit 9568f00

Please sign in to comment.