Skip to content

Commit

Permalink
Fix for composer legend issues, e.g. ticket #3346
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Hugentobler committed Jun 17, 2011
1 parent 99b584e commit a083c5e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
19 changes: 16 additions & 3 deletions src/core/composer/qgscomposerlegend.cpp
Expand Up @@ -243,7 +243,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;

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

if ( symbol ) //item with symbol?
{
Expand All @@ -292,12 +295,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;
}
Expand All @@ -307,7 +320,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;
Expand Down
9 changes: 6 additions & 3 deletions src/core/composer/qgscomposerlegenditem.cpp
Expand Up @@ -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 );
}

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

Expand Down

0 comments on commit a083c5e

Please sign in to comment.