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