QSizeF QgsLayerTreeModelLegendNode::drawSymbolText( const QgsLegendSettings &settings, ItemContext *ctx, QSizeF symbolSize ) const { QSizeF labelSize( 0, 0 ); QFont symbolLabelFont = settings.style( QgsLegendStyle::SymbolLabel ).font(); double textHeight = settings.fontHeightCharacterMM( symbolLabelFont, QChar( '0' ) ); double textDescent = settings.fontDescentMillimeters( symbolLabelFont ); QStringList lines = settings.splitStringForWrapping( data( Qt::DisplayRole ).toString() ); labelSize.rheight() = lines.count() * textHeight + ( lines.count() - 1 ) * ( settings.lineSpacing() + textDescent ); double labelX = 0.0, labelY = 0.0; if ( ctx ) { ctx->painter->setPen( settings.fontColor() ); labelX = ctx->point.x() + std::max( static_cast< double >( symbolSize.width() ), ctx->labelXOffset ); labelY = ctx->point.y(); // Vertical alignment of label with symbol if ( labelSize.height() < symbolSize.height() ) labelY += symbolSize.height() / 2 - labelSize.height() / 2; // label centered with symbol labelY += textHeight; } for ( QStringList::Iterator itemPart = lines.begin(); itemPart != lines.end(); ++itemPart ) { labelSize.rwidth() = std::max( settings.textWidthMillimeters( symbolLabelFont, *itemPart ), double( labelSize.width() ) ); if ( ctx ) { settings.drawText( ctx->painter, labelX, labelY, *itemPart, symbolLabelFont ); if ( itemPart != ( lines.end() - 1 ) ) labelY += textDescent + settings.lineSpacing() + textHeight; } } return labelSize; }