Skip to content

Commit

Permalink
Fix for ticket #1301, don't include inactive layers in legend
Browse files Browse the repository at this point in the history
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 9568f00
Showing 1 changed file with 37 additions and 13 deletions.
50 changes: 37 additions & 13 deletions src/core/composer/qgscomposerlegend.cpp
Expand Up @@ -18,6 +18,7 @@
#include "qgscomposerlegend.h"
#include "qgsmaplayer.h"
#include "qgsmaplayerregistry.h"
#include "qgsmaprenderer.h"
#include "qgssymbol.h"
#include <QDomDocument>
#include <QDomElement>
Expand Down Expand Up @@ -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 );
}
}
}

Expand All @@ -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;
}

Expand Down

0 comments on commit 9568f00

Please sign in to comment.