QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
Loading...
Searching...
No Matches
qgscolorramplegendnode.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgscolorramplegendnode.cpp
3 --------------------------------------
4 Date : December 2020
5 Copyright : (C) 2020 by Nyall Dawson
6 Email : nyall dot dawson at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#include "qgsapplication.h"
18#include "qgscolorrampimpl.h"
19#include "qgslegendsettings.h"
20#include "qgslayertreemodel.h"
21#include "qgslayertreelayer.h"
22#include "qgssymbollayerutils.h"
24#include "qgstextrenderer.h"
25#include "qgsnumericformat.h"
26
27#include <QPalette>
28
29QgsColorRampLegendNode::QgsColorRampLegendNode( QgsLayerTreeLayer *nodeLayer, QgsColorRamp *ramp, const QString &minimumLabel, const QString &maximumLabel, QObject *parent )
30 : QgsLayerTreeModelLegendNode( nodeLayer, parent )
31 , mRamp( ramp )
32{
33 mSettings.setMinimumLabel( minimumLabel );
34 mSettings.setMaximumLabel( maximumLabel );
35
36 init( nodeLayer );
37}
38
39QgsColorRampLegendNode::QgsColorRampLegendNode( QgsLayerTreeLayer *nodeLayer, QgsColorRamp *ramp, const QgsColorRampLegendNodeSettings &settings, double minimumValue, double maximumValue, QObject *parent )
40 : QgsLayerTreeModelLegendNode( nodeLayer, parent )
41 , mRamp( ramp )
42 , mSettings( settings )
43 , mMinimumValue( minimumValue )
44 , mMaximumValue( maximumValue )
45{
46 init( nodeLayer );
47}
48
49void QgsColorRampLegendNode::init( QgsLayerTreeLayer *nodeLayer )
50{
52 mIconSize = mSettings.orientation() == Qt::Vertical ? QSize( iconSize, iconSize * 6 ) : QSize( iconSize * 6, iconSize );
53
54 connect( nodeLayer, &QObject::destroyed, this, [ = ]() { mLayerNode = nullptr; } );
55}
56
58{
59 return mRamp.get();
60}
61
66
68{
69 mSettings = settings;
70}
71
72QString QgsColorRampLegendNode::labelForMinimum() const
73{
74 if ( !mSettings.minimumLabel().isEmpty() )
75 return mSettings.prefix() + mSettings.minimumLabel() + mSettings.suffix();
76
77 const QgsNumericFormatContext numericContext;
78 return mSettings.prefix() + mSettings.numericFormat()->formatDouble( mMinimumValue, numericContext ) + mSettings.suffix();
79}
80
81QString QgsColorRampLegendNode::labelForMaximum() const
82{
83 if ( !mSettings.maximumLabel().isEmpty() )
84 return mSettings.prefix() + mSettings.maximumLabel() + mSettings.suffix();
85
86 const QgsNumericFormatContext numericContext;
87 return mSettings.prefix() + mSettings.numericFormat()->formatDouble( mMaximumValue, numericContext ) + mSettings.suffix();
88}
89
90QVariant QgsColorRampLegendNode::data( int role ) const
91{
92 if ( role == Qt::DisplayRole )
93 {
94 return QString();
95 }
96 else if ( role == Qt::EditRole )
97 {
98 return QString();
99 }
100 else if ( role == Qt::DecorationRole )
101 {
102 if ( mPixmap.isNull() || mPixmap.size() != mIconSize )
103 {
104 const QFont font = data( Qt::FontRole ).value< QFont >();
105
106 const QString minLabel = labelForMinimum();
107 const QString maxLabel = labelForMaximum();
108
109 const QFontMetrics fm( font );
110
111 const QRect minBoundingRect = fm.boundingRect( minLabel );
112 const QRect maxBoundingRect = fm.boundingRect( maxLabel );
113
114 const int minLabelWidth = minBoundingRect.width();
115 const int maxLabelWidth = maxBoundingRect.width();
116 const int maxTextWidth = std::max( minLabelWidth, maxLabelWidth );
117 const int labelGapFromRamp = fm.boundingRect( QStringLiteral( "x" ) ).width();
118 const int extraAllowance = labelGapFromRamp * 0.4; // extra allowance to avoid text clipping on right
119 QRect labelRect;
120 QSize rampSize;
121 switch ( mSettings.orientation() )
122 {
123 case Qt::Vertical:
124 labelRect = QRect( mIconSize.width() + labelGapFromRamp, 0, maxTextWidth + extraAllowance, mIconSize.height() );
125 mPixmap = QPixmap( mIconSize.width() + maxTextWidth + labelGapFromRamp + extraAllowance, mIconSize.height() );
126 rampSize = mIconSize;
127 break;
128
129 case Qt::Horizontal:
130 labelRect = QRect( 0, mIconSize.height() + labelGapFromRamp, std::max( mIconSize.width(), minLabelWidth + maxLabelWidth + labelGapFromRamp ), std::max( minBoundingRect.height(),
131 maxBoundingRect.height() ) + extraAllowance );
132 mPixmap = QPixmap( std::max( mIconSize.width(), minLabelWidth + maxLabelWidth + labelGapFromRamp ), mIconSize.height() + maxTextWidth + labelGapFromRamp + extraAllowance );
133 rampSize = QSize( labelRect.width(), mIconSize.height() );
134 break;
135 }
136
137 mPixmap.fill( Qt::transparent );
138
139 QPixmap pix;
140
141 if ( mRamp )
142 {
143 pix = QgsSymbolLayerUtils::colorRampPreviewPixmap( mRamp.get(), rampSize, 0, mSettings.orientation(),
144 mSettings.orientation() == Qt::Vertical ? mSettings.direction() != QgsColorRampLegendNodeSettings::MaximumToMinimum
146 false );
147 }
148 else
149 {
150 pix = QPixmap( rampSize );
151 pix.fill( Qt::transparent );
152 }
153
154 QPainter p( &mPixmap );
155 p.drawPixmap( 0, 0, pix );
156 p.setFont( font );
157 p.setPen( qApp->palette().color( QPalette::Text ) );
158
159 switch ( mSettings.orientation() )
160 {
161 case Qt::Vertical:
162 p.drawText( labelRect, Qt::AlignBottom | Qt::AlignLeft, mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? minLabel : maxLabel );
163 p.drawText( labelRect, Qt::AlignTop | Qt::AlignLeft, mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? maxLabel : minLabel );
164 break;
165
166 case Qt::Horizontal:
167 p.drawText( labelRect, Qt::AlignTop | Qt::AlignLeft, mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? minLabel : maxLabel );
168 p.drawText( labelRect, Qt::AlignTop | Qt::AlignRight, mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? maxLabel : minLabel );
169 break;
170 }
171
172 p.end();
173 }
174 return mPixmap;
175 }
177 {
179 }
180
181 return QVariant();
182}
183
184QSizeF QgsColorRampLegendNode::drawSymbol( const QgsLegendSettings &settings, ItemContext *ctx, double ) const
185{
186 if ( !mRamp )
187 {
188 return QSizeF();
189 }
190
191 // setup temporary render context
192 QgsRenderContext *context = nullptr;
193 std::unique_ptr< QgsRenderContext > tempRenderContext;
194 if ( ctx && ctx->context )
195 context = ctx->context;
196 else
197 {
198 tempRenderContext = std::make_unique< QgsRenderContext >();
199 // QGIS 4.0 - make ItemContext compulsory, so we don't have to construct temporary render contexts here
201 tempRenderContext->setScaleFactor( settings.dpi() / 25.4 );
202 tempRenderContext->setRendererScale( settings.mapScale() );
203 tempRenderContext->setFlag( Qgis::RenderContextFlag::Antialiasing, true );
204 tempRenderContext->setMapToPixel( QgsMapToPixel( 1 / ( settings.mmPerMapUnit() * tempRenderContext->scaleFactor() ) ) );
206 tempRenderContext->setForceVectorOutput( true );
207 tempRenderContext->setPainter( ctx ? ctx->painter : nullptr );
208
209 // setup a minimal expression context
210 QgsExpressionContext expContext;
212 tempRenderContext->setExpressionContext( expContext );
213 context = tempRenderContext.get();
214 }
215
216 const QgsTextFormat format = mSettings.textFormat().isValid() ? mSettings.textFormat() : settings.style( QgsLegendStyle::SymbolLabel ).textFormat();
217 const QString minLabel = labelForMinimum();
218 const QString maxLabel = labelForMaximum();
219
220 const double patchWidth = ctx && ctx->patchSize.width() > 0 ? ctx->patchSize.width() : settings.symbolSize().width();
221 const double patchHeight = ctx && ctx->patchSize.height() > 0 ? ctx->patchSize.height() : settings.symbolSize().height();
222
223 double minHeightMm = 0;
224 double minWidthMm = 0;
225 double rampHeight = 0;
226 double rampWidth = 0;
227 switch ( mSettings.orientation() )
228 {
229 case Qt::Vertical:
230 // vertical bar, min height is the text height of the min and max labels
231 minHeightMm = QgsTextRenderer::textHeight( *context, format, QStringList() << minLabel << maxLabel, Qgis::TextLayoutMode::Rectangle ) / context->scaleFactor();
232 rampHeight = ctx && ctx->patchSize.height() > 0 ? std::max( minHeightMm / 2, ctx->patchSize.height() ) : std::max( minHeightMm, settings.symbolSize().height() );
233 rampWidth = patchWidth;
234 break;
235
236 case Qt::Horizontal:
237 // horizontal bar, min width is text width of the min and max labels
238 minWidthMm = ( QgsTextRenderer::textWidth( *context, format, QStringList() << minLabel ) +
239 QgsTextRenderer::textWidth( *context, format, QStringList() << maxLabel ) ) / context->scaleFactor();
240 rampHeight = patchHeight;
241 rampWidth = std::max( minWidthMm, patchWidth );
242 break;
243 }
244
245 if ( ctx && ctx->painter )
246 {
247 const double currentYCoord = ctx->top;
248 QPainter *p = ctx->painter;
249
250 //setup painter scaling to dots so that raster symbology is drawn to scale
251 const double dotsPerMM = context->scaleFactor();
252
253 double opacity = 1;
254 if ( QgsMapLayer *layer = layerNode()->layer() )
255 opacity = layer->opacity();
256
257 const QgsScopedQPainterState painterState( p );
258 context->setPainterFlagsUsingContext( p );
259
260 double rampLeftMm = 0;
261 const double rampTopMm = currentYCoord;
262 switch ( settings.symbolAlignment() )
263 {
264 case Qt::AlignLeft:
265 default:
266 rampLeftMm = ctx->columnLeft;
267 break;
268
269 case Qt::AlignRight:
270 rampLeftMm = ctx->columnRight - rampWidth;
271 break;
272 }
273
274 p->scale( 1.0 / dotsPerMM, 1.0 / dotsPerMM );
275
276 QLinearGradient gradient;
277 switch ( mSettings.orientation() )
278 {
279 case Qt::Vertical:
280 {
281 const double gradientTop = rampTopMm * dotsPerMM;
282 const double gradientBottom = gradientTop + rampHeight * dotsPerMM;
283 gradient = QLinearGradient( 0, mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? gradientBottom : gradientTop,
284 0, mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? gradientTop : gradientBottom );
285 break;
286 }
287
288 case Qt::Horizontal:
289 {
290 const double gradientLeft = rampLeftMm * dotsPerMM;
291 const double gradientRight = gradientLeft + rampWidth * dotsPerMM;
292 gradient = QLinearGradient( mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? gradientLeft : gradientRight, 0,
293 mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? gradientRight : gradientLeft, 0 );
294 break;
295 }
296 }
297
298
299 if ( mRamp->type() == QgsGradientColorRamp::typeString() || mRamp->type() == QgsCptCityColorRamp::typeString() )
300 {
301 //color ramp gradient
302 QgsGradientColorRamp *gradRamp = static_cast<QgsGradientColorRamp *>( mRamp.get() );
303 gradRamp->addStopsToGradient( &gradient, opacity );
304 }
305
306 if ( settings.drawRasterStroke() )
307 {
308 QPen pen;
309 pen.setColor( settings.rasterStrokeColor() );
310 pen.setWidthF( settings.rasterStrokeWidth() * dotsPerMM );
311 pen.setJoinStyle( Qt::MiterJoin );
312 ctx->painter->setPen( pen );
313 }
314 else
315 {
316 ctx->painter->setPen( Qt::NoPen );
317 }
318
319 p->setBrush( QBrush( gradient ) );
320 p->drawRect( rampLeftMm * dotsPerMM, rampTopMm * dotsPerMM, rampWidth * dotsPerMM, rampHeight * dotsPerMM );
321 }
322
323 double labelHeight = 0;
324 if ( mSettings.orientation() == Qt::Horizontal )
325 {
326 // we treat the text as part of the symbol for horizontal bar items
327 if ( ctx && ctx->painter )
328 {
329 const double currentYCoord = ctx->top;
330 QPainter *p = ctx->painter;
331
332 //setup painter scaling to dots so that raster symbology is drawn to scale
333 const double dotsPerMM = context->scaleFactor();
334
335 const QgsScopedQPainterState painterState( p );
336 context->setPainterFlagsUsingContext( p );
337
338 p->scale( 1.0 / dotsPerMM, 1.0 / dotsPerMM );
339
340 double labelXMin = 0;
341 double labelXMax = 0;
342 // NOTE -- while the below calculations use the flipped margins from the style, that's only done because
343 // those are the only margins we expose and use for now! (and we expose them as generic margins, not side-specific
344 // ones) TODO when/if we expose other margin settings, these should be reversed...
345 const double labelYMin = currentYCoord + rampHeight + settings.style( QgsLegendStyle::Symbol ).margin( QgsLegendStyle::Right )
347 const double labelHeight = std::max( QgsTextRenderer::textHeight( *context, format, QStringList() << minLabel ),
348 QgsTextRenderer::textHeight( *context, format, QStringList() << maxLabel ) ) / dotsPerMM;
349 switch ( settings.symbolAlignment() )
350 {
351 case Qt::AlignLeft:
352 default:
353 labelXMin = ctx->columnLeft;
354 labelXMax = ctx->columnLeft + rampWidth;
355 break;
356
357 case Qt::AlignRight:
358 labelXMin = ctx->columnRight - rampWidth;
359 labelXMax = ctx->columnRight;
360 break;
361 }
362
363 const QRectF textRect( labelXMin * dotsPerMM, labelYMin * dotsPerMM, ( labelXMax - labelXMin ) * dotsPerMM, labelHeight * dotsPerMM );
365 QStringList() << ( mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? minLabel : maxLabel ),
366 *context, format, true, Qgis::TextVerticalAlignment::Top );
368 QStringList() << ( mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? maxLabel : minLabel ),
369 *context, format, true, Qgis::TextVerticalAlignment::Bottom );
370 }
371 else
372 {
373 // we only need this when we are calculating the size of the node, not at render time
374 labelHeight = std::max( QgsTextRenderer::textHeight( *context, format, QStringList() << minLabel ),
375 QgsTextRenderer::textHeight( *context, format, QStringList() << maxLabel ) ) / context->scaleFactor()
378 }
379 }
380
381 return QSizeF( rampWidth, rampHeight + labelHeight );
382}
383
385{
386 if ( !mRamp || mSettings.orientation() == Qt::Horizontal )
387 {
388 return QSizeF();
389 }
390
391 // setup temporary render context
392 QgsRenderContext *context = nullptr;
393 std::unique_ptr< QgsRenderContext > tempRenderContext;
394 if ( ctx && ctx->context )
395 context = ctx->context;
396 else
397 {
398 tempRenderContext = std::make_unique< QgsRenderContext >();
399 // QGIS 4.0 - make ItemContext compulsory, so we don't have to construct temporary render contexts here
401 tempRenderContext->setScaleFactor( settings.dpi() / 25.4 );
402 tempRenderContext->setRendererScale( settings.mapScale() );
403 tempRenderContext->setFlag( Qgis::RenderContextFlag::Antialiasing, true );
404 tempRenderContext->setMapToPixel( QgsMapToPixel( 1 / ( settings.mmPerMapUnit() * tempRenderContext->scaleFactor() ) ) );
406 tempRenderContext->setForceVectorOutput( true );
407 tempRenderContext->setPainter( ctx ? ctx->painter : nullptr );
408
409 // setup a minimal expression context
410 QgsExpressionContext expContext;
412 tempRenderContext->setExpressionContext( expContext );
413 context = tempRenderContext.get();
414 }
415
416 const QgsTextFormat format = mSettings.textFormat().isValid() ? mSettings.textFormat() : settings.style( QgsLegendStyle::SymbolLabel ).textFormat();
417
418 const QString minLabel = labelForMinimum();
419 const QString maxLabel = labelForMaximum();
420
421 const double rampHeight = symbolSize.height();
422 const double rampWidth = symbolSize.width();
423 double textWidth = 0;
424 double textHeight = 0;
425
426 if ( ctx && ctx->painter )
427 {
428 const double currentYCoord = ctx->top;
429 QPainter *p = ctx->painter;
430
431 //setup painter scaling to dots so that raster symbology is drawn to scale
432 const double dotsPerMM = context->scaleFactor();
433
434 const QgsScopedQPainterState painterState( p );
435 context->setPainterFlagsUsingContext( p );
436
437 p->scale( 1.0 / dotsPerMM, 1.0 / dotsPerMM );
438
439 double labelXMin = 0;
440 double labelXMax = 0;
441 switch ( settings.symbolAlignment() )
442 {
443 case Qt::AlignLeft:
444 default:
445 labelXMin = ctx->columnLeft + std::max( rampWidth, ctx->maxSiblingSymbolWidth )
448 labelXMax = ctx->columnRight;
449 break;
450
451 case Qt::AlignRight:
452 labelXMin = ctx->columnLeft;
453 // NOTE -- while the below calculations use the flipped margins from the style, that's only done because
454 // those are the only margins we expose and use for now! (and we expose them as generic margins, not side-specific
455 // ones) TODO when/if we expose other margin settings, these should be reversed...
456 labelXMax = ctx->columnRight - std::max( rampWidth, ctx->maxSiblingSymbolWidth )
459 break;
460 }
461
462 const QRectF textRect( labelXMin * dotsPerMM, currentYCoord * dotsPerMM, ( labelXMax - labelXMin ) * dotsPerMM, rampHeight * dotsPerMM );
464 QStringList() << ( mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? maxLabel : minLabel ),
465 *context, format, true, Qgis::TextVerticalAlignment::Top );
467 QStringList() << ( mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? minLabel : maxLabel ),
468 *context, format, true, Qgis::TextVerticalAlignment::Bottom );
469 }
470 else
471 {
472 // we only need this when we are calculating the size of the node, not at render time
473 textWidth = QgsTextRenderer::textWidth( *context, format, QStringList() << minLabel << maxLabel ) / context->scaleFactor();
474 textHeight = rampHeight;
475 }
476
477 return QSizeF( textWidth, textHeight );
478}
@ Rectangle
Text within rectangle layout mode.
@ Antialiasing
Use antialiasing while drawing.
@ Bottom
Align to bottom.
Settings for a color ramp legend node.
void setMaximumLabel(const QString &label)
Sets the label for the maximum value on the ramp.
const QgsNumericFormat * numericFormat() const
Returns the numeric format used for numbers in the scalebar.
QString maximumLabel() const
Returns the label for the maximum value on the ramp.
QString suffix() const
Returns the suffix to show after legend text.
@ MaximumToMinimum
Maximum value on bottom, minimum value on top.
@ MinimumToMaximum
Minimum value on bottom, maximum value on top.
QString prefix() const
Returns the prefix to show before legend text.
Qt::Orientation orientation() const
Returns the ramp orientation (i.e.
QgsColorRampLegendNodeSettings::Direction direction() const
Returns the direction of the ramp.
QgsTextFormat textFormat() const
Returns the text format used to render text in the legend item.
void setMinimumLabel(const QString &label)
Sets the label for the minimum value on the ramp.
QString minimumLabel() const
Returns the label for the minimum value on the ramp.
QSizeF drawSymbolText(const QgsLegendSettings &settings, ItemContext *ctx, QSizeF symbolSize) const override
Draws label on the right side of the item.
const QgsColorRamp * ramp() const
Returns the color ramp used by the node.
QSize iconSize() const
Returns the icon size, which is how large the ramp will render in a layer tree widget.
void setSettings(const QgsColorRampLegendNodeSettings &settings)
Sets the node's settings.
QgsColorRampLegendNodeSettings settings() const
Returns the node's settings.
QVariant data(int role) const override
Returns data associated with the item. Must be implemented in derived class.
QSizeF drawSymbol(const QgsLegendSettings &settings, ItemContext *ctx, double itemHeight) const override
Draws symbol on the left side of the item.
QgsColorRampLegendNode(QgsLayerTreeLayer *nodeLayer, QgsColorRamp *ramp, const QString &minimumLabel, const QString &maximumLabel, QObject *parent=nullptr)
Constructor for QgsColorRampLegendNode.
Abstract base class for color ramps.
static QString typeString()
Returns the string identifier for QgsCptCityColorRamp.
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void appendScopes(const QList< QgsExpressionContextScope * > &scopes)
Appends a list of scopes to the end of the context.
Gradient color ramp, which smoothly interpolates between two colors and also supports optional extra ...
static QString typeString()
Returns the string identifier for QgsGradientColorRamp.
void addStopsToGradient(QGradient *gradient, double opacity=1) const
Copy color ramp stops to a QGradient.
Layer tree node points to a map layer.
The QgsLegendRendererItem class is abstract interface for legend items returned from QgsMapLayerLegen...
@ ColorRampLegend
Color ramp legend (since QGIS 3.18)
@ NodeTypeRole
Type of node. Added in 3.16.
QgsLayerTreeLayer * layerNode() const
Returns pointer to the parent layer node.
static int scaleIconSize(int standardSize)
Scales an layer tree model icon size to compensate for display pixel density, making the icon size hi...
The QgsLegendSettings class stores the appearance and layout settings for legend drawing with QgsLege...
@ Right
Right side.
@ Left
Left side.
@ Symbol
Symbol icon (excluding label)
@ SymbolLabel
Symbol label (excluding icon)
Base class for all map layer types.
Definition qgsmaplayer.h:74
Perform transforms between map coordinates and device coordinates.
A context for numeric formats.
virtual QString formatDouble(double value, const QgsNumericFormatContext &context) const =0
Returns a formatted string representation of a numeric double value.
Contains information about the context of a rendering operation.
double scaleFactor() const
Returns the scaling factor for the render to convert painter units to physical sizes.
void setPainterFlagsUsingContext(QPainter *painter=nullptr) const
Sets relevant flags on a destination painter, using the flags and settings currently defined for the ...
Scoped object for saving and restoring a QPainter object's state.
static QPixmap colorRampPreviewPixmap(QgsColorRamp *ramp, QSize size, int padding=0, Qt::Orientation direction=Qt::Horizontal, bool flipDirection=false, bool drawTransparentBackground=true)
Returns a pixmap preview for a color ramp.
Container for all settings relating to text rendering.
bool isValid() const
Returns true if the format is valid.
static double textWidth(const QgsRenderContext &context, const QgsTextFormat &format, const QStringList &textLines, QFontMetricsF *fontMetrics=nullptr)
Returns the width of a text based on a given format.
static void drawText(const QRectF &rect, double rotation, Qgis::TextHorizontalAlignment alignment, const QStringList &textLines, QgsRenderContext &context, const QgsTextFormat &format, bool drawAsOutlines=true, Qgis::TextVerticalAlignment vAlignment=Qgis::TextVerticalAlignment::Top, Qgis::TextRendererFlags flags=Qgis::TextRendererFlags(), Qgis::TextLayoutMode mode=Qgis::TextLayoutMode::Rectangle)
Draws text within a rectangle using the specified settings.
static double textHeight(const QgsRenderContext &context, const QgsTextFormat &format, const QStringList &textLines, Qgis::TextLayoutMode mode=Qgis::TextLayoutMode::Point, QFontMetricsF *fontMetrics=nullptr, Qgis::TextRendererFlags flags=Qgis::TextRendererFlags(), double maxLineWidth=0)
Returns the height of a text based on a given format.
static Qgis::TextHorizontalAlignment convertQtHAlignment(Qt::Alignment alignment)
Converts a Qt horizontal alignment flag to a Qgis::TextHorizontalAlignment value.
#define Q_NOWARN_DEPRECATED_POP
Definition qgis.h:4916
#define Q_NOWARN_DEPRECATED_PUSH
Definition qgis.h:4915
double maxSiblingSymbolWidth
Largest symbol width, considering all other sibling legend components associated with the current com...
QSizeF patchSize
Symbol patch size to render for the node.
double columnLeft
Left side of current legend column.
double columnRight
Right side of current legend column.
Q_NOWARN_DEPRECATED_POP QgsRenderContext * context
Render context, if available.