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