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