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