[QGIS Commit] r9667 - trunk/qgis/src/core/composer
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Tue Nov 18 11:04:12 EST 2008
Author: mhugent
Date: 2008-11-18 11:04:12 -0500 (Tue, 18 Nov 2008)
New Revision: 9667
Modified:
trunk/qgis/src/core/composer/qgscomposerlegend.cpp
Log:
Fix for ticket #1301, don't include inactive layers in legend
Modified: trunk/qgis/src/core/composer/qgscomposerlegend.cpp
===================================================================
--- trunk/qgis/src/core/composer/qgscomposerlegend.cpp 2008-11-18 15:59:03 UTC (rev 9666)
+++ trunk/qgis/src/core/composer/qgscomposerlegend.cpp 2008-11-18 16:04:12 UTC (rev 9667)
@@ -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 @@
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 );
+ //Let the user omit the layer title item by having an empty layer title string
+ if(!currentLayerItem->text().isEmpty())
+ {
+ currentYCoordinate += mLayerSpace;
+ currentYCoordinate += fontAscentMillimeters( mLayerFont );
- //draw layer Item
- if ( painter )
- {
- drawText( painter, mBoxSpace, currentYCoordinate, currentLayerItem->text(), 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 @@
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;
}
More information about the QGIS-commit
mailing list