Skip to content
Permalink
Browse files

Fix for composer legend issues, e.g. ticket #3346

  • Loading branch information
Marco Hugentobler authored and mhugent committed Jul 2, 2011
1 parent 52ca39c commit 49f4591905b8013a6d51b8f0a44c43e7931d0073
Showing with 22 additions and 6 deletions.
  1. +16 −3 src/core/composer/qgscomposerlegend.cpp
  2. +6 −3 src/core/composer/qgscomposerlegenditem.cpp
@@ -241,7 +241,9 @@ void QgsComposerLegend::drawLayerChildItems( QPainter* p, QStandardItem* layerIt
}

//standerd item height
double itemHeight = qMax( mSymbolHeight, fontAscentMillimeters( mItemFont ) );

double textHeight = fontHeightCharacterMM( mItemFont, QChar( '0' ) );
double itemHeight = qMax( mSymbolHeight, textHeight );

QStandardItem* currentItem;

@@ -276,6 +278,7 @@ void QgsComposerLegend::drawLayerChildItems( QPainter* p, QStandardItem* layerIt
{
symbolNg = symbolV2Item->symbolV2();
}
QgsComposerRasterSymbolItem* rasterItem = dynamic_cast<QgsComposerRasterSymbolItem*>( currentItem );

if ( symbol ) //item with symbol?
{
@@ -290,12 +293,22 @@ void QgsComposerLegend::drawLayerChildItems( QPainter* p, QStandardItem* layerIt
realItemHeight = qMax( realSymbolHeight, itemHeight );
currentXCoord += mIconLabelSpace;
}
else if ( rasterItem )
{
if ( p )
{
p->setBrush( rasterItem->color() );
p->drawRect( QRectF( currentXCoord, currentYCoord + ( itemHeight - mSymbolHeight ) / 2, mSymbolWidth, mSymbolHeight ) );
}
currentXCoord += mSymbolWidth;
currentXCoord += mIconLabelSpace;
}
else //item with icon?
{
QIcon symbolIcon = currentItem->icon();
if ( !symbolIcon.isNull() && p )
{
symbolIcon.paint( p, currentXCoord, currentYCoord, mSymbolWidth, mSymbolHeight );
symbolIcon.paint( p, currentXCoord, currentYCoord + ( itemHeight - mSymbolHeight ) / 2, mSymbolWidth, mSymbolHeight );
currentXCoord += mSymbolWidth;
currentXCoord += mIconLabelSpace;
}
@@ -305,7 +318,7 @@ void QgsComposerLegend::drawLayerChildItems( QPainter* p, QStandardItem* layerIt
if ( p )
{
p->setPen( QColor( 0, 0, 0 ) );
drawText( p, currentXCoord, currentYCoord + fontAscentMillimeters( mItemFont ) + ( realItemHeight - fontAscentMillimeters( mItemFont ) ) / 2, currentItem->text(), mItemFont );
drawText( p, currentXCoord, currentYCoord + textHeight + ( realItemHeight - textHeight ) / 2, currentItem->text(), mItemFont );
currentXCoord += textWidthMillimeters( mItemFont, currentItem->text() );
}
currentXCoord += mBoxSpace;
@@ -263,6 +263,7 @@ void QgsComposerRasterSymbolItem::writeXML( QDomElement& elem, QDomDocument& doc
QDomElement rasterClassElem = doc.createElement( "RasterClassificationItem" );
rasterClassElem.setAttribute( "layerId", mLayerID );
rasterClassElem.setAttribute( "text", text() );
rasterClassElem.setAttribute( "color", mColor.name() );
elem.appendChild( rasterClassElem );
}

@@ -274,11 +275,13 @@ void QgsComposerRasterSymbolItem::readXML( const QDomElement& itemElem, bool xSe
}
setText( itemElem.attribute( "text", "" ) );
setLayerID( itemElem.attribute( "layerId", "" ) );
setColor( QColor( itemElem.attribute( "color" ) ) );

QgsRasterLayer* rLayer = qobject_cast<QgsRasterLayer*>( QgsMapLayerRegistry::instance()->mapLayer( mLayerID ) );
if ( rLayer && xServerAvailable )
if ( xServerAvailable )
{
setIcon( QIcon( rLayer->legendAsPixmap( true ) ) );
QPixmap itemPixmap( 20, 20 );
itemPixmap.fill( mColor );
setIcon( QIcon( itemPixmap ) );
}
}

0 comments on commit 49f4591

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