QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
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
17#include "qgscolorrampimpl.h"
18#include "qgslegendsettings.h"
19#include "qgslayertreemodel.h"
20#include "qgslayertreelayer.h"
21#include "qgssymbollayerutils.h"
23#include "qgstextrenderer.h"
24#include "qgsnumericformat.h"
25
26QgsColorRampLegendNode::QgsColorRampLegendNode( QgsLayerTreeLayer *nodeLayer, QgsColorRamp *ramp, const QString &minimumLabel, const QString &maximumLabel, QObject *parent )
27 : QgsLayerTreeModelLegendNode( nodeLayer, parent )
28 , mRamp( ramp )
29{
30 mSettings.setMinimumLabel( minimumLabel );
31 mSettings.setMaximumLabel( maximumLabel );
32
33 init( nodeLayer );
34}
35
36QgsColorRampLegendNode::QgsColorRampLegendNode( QgsLayerTreeLayer *nodeLayer, QgsColorRamp *ramp, const QgsColorRampLegendNodeSettings &settings, double minimumValue, double maximumValue, QObject *parent )
37 : QgsLayerTreeModelLegendNode( nodeLayer, parent )
38 , mRamp( ramp )
39 , mSettings( settings )
40 , mMinimumValue( minimumValue )
41 , mMaximumValue( maximumValue )
42{
43 init( nodeLayer );
44}
45
46void QgsColorRampLegendNode::init( QgsLayerTreeLayer *nodeLayer )
47{
49 mIconSize = mSettings.orientation() == Qt::Vertical ? QSize( iconSize, iconSize * 6 ) : QSize( iconSize * 6, iconSize );
50
51 connect( nodeLayer, &QObject::destroyed, this, [ = ]() { mLayerNode = nullptr; } );
52}
53
55{
56 return mRamp.get();
57}
58
60{
61 return mSettings;
62}
63
65{
66 mSettings = settings;
67}
68
69QString QgsColorRampLegendNode::labelForMinimum() const
70{
71 if ( !mSettings.minimumLabel().isEmpty() )
72 return mSettings.prefix() + mSettings.minimumLabel() + mSettings.suffix();
73
74 const QgsNumericFormatContext numericContext;
75 return mSettings.prefix() + mSettings.numericFormat()->formatDouble( mMinimumValue, numericContext ) + mSettings.suffix();
76}
77
78QString QgsColorRampLegendNode::labelForMaximum() const
79{
80 if ( !mSettings.maximumLabel().isEmpty() )
81 return mSettings.prefix() + mSettings.maximumLabel() + mSettings.suffix();
82
83 const QgsNumericFormatContext numericContext;
84 return mSettings.prefix() + mSettings.numericFormat()->formatDouble( mMaximumValue, numericContext ) + mSettings.suffix();
85}
86
87QVariant QgsColorRampLegendNode::data( int role ) const
88{
89 if ( role == Qt::DisplayRole )
90 {
91 return QString();
92 }
93 else if ( role == Qt::EditRole )
94 {
95 return QString();
96 }
97 else if ( role == Qt::DecorationRole )
98 {
99 if ( mPixmap.isNull() || mPixmap.size() != mIconSize )
100 {
101 const QFont font = data( Qt::FontRole ).value< QFont >();
102
103 const QString minLabel = labelForMinimum();
104 const QString maxLabel = labelForMaximum();
105
106 const QFontMetrics fm( font );
107
108 const QRect minBoundingRect = fm.boundingRect( minLabel );
109 const QRect maxBoundingRect = fm.boundingRect( maxLabel );
110
111 const int minLabelWidth = minBoundingRect.width();
112 const int maxLabelWidth = maxBoundingRect.width();
113 const int maxTextWidth = std::max( minLabelWidth, maxLabelWidth );
114 const int labelGapFromRamp = fm.boundingRect( QStringLiteral( "x" ) ).width();
115 const int extraAllowance = labelGapFromRamp * 0.4; // extra allowance to avoid text clipping on right
116 QRect labelRect;
117 QSize rampSize;
118 switch ( mSettings.orientation() )
119 {
120 case Qt::Vertical:
121 labelRect = QRect( mIconSize.width() + labelGapFromRamp, 0, maxTextWidth + extraAllowance, mIconSize.height() );
122 mPixmap = QPixmap( mIconSize.width() + maxTextWidth + labelGapFromRamp + extraAllowance, mIconSize.height() );
123 rampSize = mIconSize;
124 break;
125
126 case Qt::Horizontal:
127 labelRect = QRect( 0, mIconSize.height() + labelGapFromRamp, std::max( mIconSize.width(), minLabelWidth + maxLabelWidth + labelGapFromRamp ), std::max( minBoundingRect.height(),
128 maxBoundingRect.height() ) + extraAllowance );
129 mPixmap = QPixmap( std::max( mIconSize.width(), minLabelWidth + maxLabelWidth + labelGapFromRamp ), mIconSize.height() + maxTextWidth + labelGapFromRamp + extraAllowance );
130 rampSize = QSize( labelRect.width(), mIconSize.height() );
131 break;
132 }
133
134 mPixmap.fill( Qt::transparent );
135
136 QPixmap pix;
137
138 if ( mRamp )
139 {
140 pix = QgsSymbolLayerUtils::colorRampPreviewPixmap( mRamp.get(), rampSize, 0, mSettings.orientation(),
141 mSettings.orientation() == Qt::Vertical ? mSettings.direction() != QgsColorRampLegendNodeSettings::MaximumToMinimum
143 false );
144 }
145 else
146 {
147 pix = QPixmap( rampSize );
148 pix.fill( Qt::transparent );
149 }
150
151 QPainter p( &mPixmap );
152 p.drawPixmap( 0, 0, pix );
153 p.setFont( font );
154
155 switch ( mSettings.orientation() )
156 {
157 case Qt::Vertical:
158 p.drawText( labelRect, Qt::AlignBottom | Qt::AlignLeft, mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? minLabel : maxLabel );
159 p.drawText( labelRect, Qt::AlignTop | Qt::AlignLeft, mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? maxLabel : minLabel );
160 break;
161
162 case Qt::Horizontal:
163 p.drawText( labelRect, Qt::AlignTop | Qt::AlignLeft, mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? minLabel : maxLabel );
164 p.drawText( labelRect, Qt::AlignTop | Qt::AlignRight, mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? maxLabel : minLabel );
165 break;
166 }
167
168 p.end();
169 }
170 return mPixmap;
171 }
173 {
175 }
176
177 return QVariant();
178}
179
180QSizeF QgsColorRampLegendNode::drawSymbol( const QgsLegendSettings &settings, ItemContext *ctx, double ) const
181{
182 if ( !mRamp )
183 {
184 return QSizeF();
185 }
186
187 // setup temporary render context
188 QgsRenderContext *context = nullptr;
189 std::unique_ptr< QgsRenderContext > tempRenderContext;
190 if ( ctx && ctx->context )
191 context = ctx->context;
192 else
193 {
194 tempRenderContext = std::make_unique< QgsRenderContext >();
195 // QGIS 4.0 - make ItemContext compulsory, so we don't have to construct temporary render contexts here
197 tempRenderContext->setScaleFactor( settings.dpi() / 25.4 );
198 tempRenderContext->setRendererScale( settings.mapScale() );
199 tempRenderContext->setFlag( Qgis::RenderContextFlag::Antialiasing, true );
200 tempRenderContext->setMapToPixel( QgsMapToPixel( 1 / ( settings.mmPerMapUnit() * tempRenderContext->scaleFactor() ) ) );
202 tempRenderContext->setForceVectorOutput( true );
203 tempRenderContext->setPainter( ctx ? ctx->painter : nullptr );
204
205 // setup a minimal expression context
206 QgsExpressionContext expContext;
208 tempRenderContext->setExpressionContext( expContext );
209 context = tempRenderContext.get();
210 }
211
212 const QgsTextFormat format = mSettings.textFormat().isValid() ? mSettings.textFormat() : settings.style( QgsLegendStyle::SymbolLabel ).textFormat();
213 const QString minLabel = labelForMinimum();
214 const QString maxLabel = labelForMaximum();
215
216 const double patchWidth = ctx && ctx->patchSize.width() > 0 ? ctx->patchSize.width() : settings.symbolSize().width();
217 const double patchHeight = ctx && ctx->patchSize.height() > 0 ? ctx->patchSize.height() : settings.symbolSize().height();
218
219 double minHeightMm = 0;
220 double minWidthMm = 0;
221 double rampHeight = 0;
222 double rampWidth = 0;
223 switch ( mSettings.orientation() )
224 {
225 case Qt::Vertical:
226 // vertical bar, min height is the text height of the min and max labels
227 minHeightMm = QgsTextRenderer::textHeight( *context, format, QStringList() << minLabel << maxLabel, Qgis::TextLayoutMode::Rectangle ) / context->scaleFactor();
228 rampHeight = ctx && ctx->patchSize.height() > 0 ? std::max( minHeightMm / 2, ctx->patchSize.height() ) : std::max( minHeightMm, settings.symbolSize().height() );
229 rampWidth = patchWidth;
230 break;
231
232 case Qt::Horizontal:
233 // horizontal bar, min width is text width of the min and max labels
234 minWidthMm = ( QgsTextRenderer::textWidth( *context, format, QStringList() << minLabel ) +
235 QgsTextRenderer::textWidth( *context, format, QStringList() << maxLabel ) ) / context->scaleFactor();
236 rampHeight = patchHeight;
237 rampWidth = std::max( minWidthMm, patchWidth );
238 break;
239 }
240
241 if ( ctx && ctx->painter )
242 {
243 const double currentYCoord = ctx->top;
244 QPainter *p = ctx->painter;
245
246 //setup painter scaling to dots so that raster symbology is drawn to scale
247 const double dotsPerMM = context->scaleFactor();
248
249 double opacity = 1;
250 if ( QgsMapLayer *layer = layerNode()->layer() )
251 opacity = layer->opacity();
252
253 const QgsScopedQPainterState painterState( p );
254 context->setPainterFlagsUsingContext( p );
255
256 double rampLeftMm = 0;
257 const double rampTopMm = currentYCoord;
258 switch ( settings.symbolAlignment() )
259 {
260 case Qt::AlignLeft:
261 default:
262 rampLeftMm = ctx->columnLeft;
263 break;
264
265 case Qt::AlignRight:
266 rampLeftMm = ctx->columnRight - rampWidth;
267 break;
268 }
269
270 p->scale( 1.0 / dotsPerMM, 1.0 / dotsPerMM );
271
272 QLinearGradient gradient;
273 switch ( mSettings.orientation() )
274 {
275 case Qt::Vertical:
276 {
277 const double gradientTop = rampTopMm * dotsPerMM;
278 const double gradientBottom = gradientTop + rampHeight * dotsPerMM;
279 gradient = QLinearGradient( 0, mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? gradientBottom : gradientTop,
280 0, mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? gradientTop : gradientBottom );
281 break;
282 }
283
284 case Qt::Horizontal:
285 {
286 const double gradientLeft = rampLeftMm * dotsPerMM;
287 const double gradientRight = gradientLeft + rampWidth * dotsPerMM;
288 gradient = QLinearGradient( mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? gradientLeft : gradientRight, 0,
289 mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? gradientRight : gradientLeft, 0 );
290 break;
291 }
292 }
293
294
295 if ( mRamp->type() == QgsGradientColorRamp::typeString() || mRamp->type() == QgsCptCityColorRamp::typeString() )
296 {
297 //color ramp gradient
298 QgsGradientColorRamp *gradRamp = static_cast<QgsGradientColorRamp *>( mRamp.get() );
299 gradRamp->addStopsToGradient( &gradient, opacity );
300 }
301
302 if ( settings.drawRasterStroke() )
303 {
304 QPen pen;
305 pen.setColor( settings.rasterStrokeColor() );
306 pen.setWidthF( settings.rasterStrokeWidth() * dotsPerMM );
307 pen.setJoinStyle( Qt::MiterJoin );
308 ctx->painter->setPen( pen );
309 }
310 else
311 {
312 ctx->painter->setPen( Qt::NoPen );
313 }
314
315 p->setBrush( QBrush( gradient ) );
316 p->drawRect( rampLeftMm * dotsPerMM, rampTopMm * dotsPerMM, rampWidth * dotsPerMM, rampHeight * dotsPerMM );
317 }
318
319 double labelHeight = 0;
320 if ( mSettings.orientation() == Qt::Horizontal )
321 {
322 // we treat the text as part of the symbol for horizontal bar items
323 if ( ctx && ctx->painter )
324 {
325 const double currentYCoord = ctx->top;
326 QPainter *p = ctx->painter;
327
328 //setup painter scaling to dots so that raster symbology is drawn to scale
329 const double dotsPerMM = context->scaleFactor();
330
331 const QgsScopedQPainterState painterState( p );
332 context->setPainterFlagsUsingContext( p );
333
334 p->scale( 1.0 / dotsPerMM, 1.0 / dotsPerMM );
335
336 double labelXMin = 0;
337 double labelXMax = 0;
338 // NOTE -- while the below calculations use the flipped margins from the style, that's only done because
339 // those are the only margins we expose and use for now! (and we expose them as generic margins, not side-specific
340 // ones) TODO when/if we expose other margin settings, these should be reversed...
341 const double labelYMin = currentYCoord + rampHeight + settings.style( QgsLegendStyle::Symbol ).margin( QgsLegendStyle::Right )
343 const double labelHeight = std::max( QgsTextRenderer::textHeight( *context, format, QStringList() << minLabel ),
344 QgsTextRenderer::textHeight( *context, format, QStringList() << maxLabel ) ) / dotsPerMM;
345 switch ( settings.symbolAlignment() )
346 {
347 case Qt::AlignLeft:
348 default:
349 labelXMin = ctx->columnLeft;
350 labelXMax = ctx->columnLeft + rampWidth;
351 break;
352
353 case Qt::AlignRight:
354 labelXMin = ctx->columnRight - rampWidth;
355 labelXMin = ctx->columnRight;
356 break;
357 }
358
359 const QRectF textRect( labelXMin * dotsPerMM, labelYMin * dotsPerMM, ( labelXMax - labelXMin ) * dotsPerMM, labelHeight * dotsPerMM );
360 QgsTextRenderer::drawText( textRect, 0, Qgis::TextHorizontalAlignment::Left,
361 QStringList() << ( mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? minLabel : maxLabel ),
362 *context, format, true, Qgis::TextVerticalAlignment::Top );
363 QgsTextRenderer::drawText( textRect, 0, Qgis::TextHorizontalAlignment::Right,
364 QStringList() << ( mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? maxLabel : minLabel ),
365 *context, format, true, Qgis::TextVerticalAlignment::Bottom );
366 }
367 else
368 {
369 // we only need this when we are calculating the size of the node, not at render time
370 labelHeight = std::max( QgsTextRenderer::textHeight( *context, format, QStringList() << minLabel ),
371 QgsTextRenderer::textHeight( *context, format, QStringList() << maxLabel ) ) / context->scaleFactor()
374 }
375 }
376
377 return QSizeF( rampWidth, rampHeight + labelHeight );
378}
379
381{
382 if ( !mRamp || mSettings.orientation() == Qt::Horizontal )
383 {
384 return QSizeF();
385 }
386
387 // setup temporary render context
388 QgsRenderContext *context = nullptr;
389 std::unique_ptr< QgsRenderContext > tempRenderContext;
390 if ( ctx && ctx->context )
391 context = ctx->context;
392 else
393 {
394 tempRenderContext = std::make_unique< QgsRenderContext >();
395 // QGIS 4.0 - make ItemContext compulsory, so we don't have to construct temporary render contexts here
397 tempRenderContext->setScaleFactor( settings.dpi() / 25.4 );
398 tempRenderContext->setRendererScale( settings.mapScale() );
399 tempRenderContext->setFlag( Qgis::RenderContextFlag::Antialiasing, true );
400 tempRenderContext->setMapToPixel( QgsMapToPixel( 1 / ( settings.mmPerMapUnit() * tempRenderContext->scaleFactor() ) ) );
402 tempRenderContext->setForceVectorOutput( true );
403 tempRenderContext->setPainter( ctx ? ctx->painter : nullptr );
404
405 // setup a minimal expression context
406 QgsExpressionContext expContext;
408 tempRenderContext->setExpressionContext( expContext );
409 context = tempRenderContext.get();
410 }
411
412 const QgsTextFormat format = mSettings.textFormat().isValid() ? mSettings.textFormat() : settings.style( QgsLegendStyle::SymbolLabel ).textFormat();
413
414 const QString minLabel = labelForMinimum();
415 const QString maxLabel = labelForMaximum();
416
417 const double rampHeight = symbolSize.height();
418 const double rampWidth = symbolSize.width();
419 double textWidth = 0;
420 double textHeight = 0;
421
422 if ( ctx && ctx->painter )
423 {
424 const double currentYCoord = ctx->top;
425 QPainter *p = ctx->painter;
426
427 //setup painter scaling to dots so that raster symbology is drawn to scale
428 const double dotsPerMM = context->scaleFactor();
429
430 const QgsScopedQPainterState painterState( p );
431 context->setPainterFlagsUsingContext( p );
432
433 p->scale( 1.0 / dotsPerMM, 1.0 / dotsPerMM );
434
435 double labelXMin = 0;
436 double labelXMax = 0;
437 switch ( settings.symbolAlignment() )
438 {
439 case Qt::AlignLeft:
440 default:
441 labelXMin = ctx->columnLeft + std::max( rampWidth, ctx->maxSiblingSymbolWidth )
444 labelXMax = ctx->columnRight;
445 break;
446
447 case Qt::AlignRight:
448 labelXMin = ctx->columnLeft;
449 // NOTE -- while the below calculations use the flipped margins from the style, that's only done because
450 // those are the only margins we expose and use for now! (and we expose them as generic margins, not side-specific
451 // ones) TODO when/if we expose other margin settings, these should be reversed...
452 labelXMax = ctx->columnRight - std::max( rampWidth, ctx->maxSiblingSymbolWidth )
455 break;
456 }
457
458 const QRectF textRect( labelXMin * dotsPerMM, currentYCoord * dotsPerMM, ( labelXMax - labelXMin ) * dotsPerMM, rampHeight * dotsPerMM );
460 QStringList() << ( mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? maxLabel : minLabel ),
461 *context, format, true, Qgis::TextVerticalAlignment::Top );
463 QStringList() << ( mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? minLabel : maxLabel ),
464 *context, format, true, Qgis::TextVerticalAlignment::Bottom );
465 }
466 else
467 {
468 // we only need this when we are calculating the size of the node, not at render time
469 textWidth = QgsTextRenderer::textWidth( *context, format, QStringList() << minLabel << maxLabel ) / context->scaleFactor();
470 textHeight = rampHeight;
471 }
472
473 return QSizeF( textWidth, textHeight );
474}
@ Antialiasing
Use antialiasing while drawing.
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.
Definition: qgscolorramp.h:30
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:73
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:39
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.
Definition: qgstextformat.h:41
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:4093
#define Q_NOWARN_DEPRECATED_PUSH
Definition: qgis.h:4092
double top
Top y-position of legend item.
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.