QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 "qgscolorramplegendnode.h"
17 #include "qgscolorrampimpl.h"
18 #include "qgslegendsettings.h"
19 #include "qgslayertreemodel.h"
20 #include "qgslayertreelayer.h"
21 #include "qgssymbollayerutils.h"
23 #include "qgstextrenderer.h"
24 #include "qgsnumericformat.h"
25 
26 QgsColorRampLegendNode::QgsColorRampLegendNode( QgsLayerTreeLayer *nodeLayer, QgsColorRamp *ramp, const QString &minimumLabel, const QString &maximumLabel, QObject *parent )
27  : QgsLayerTreeModelLegendNode( nodeLayer, parent )
28  , mRamp( ramp )
29 {
30  mSettings.setMinimumLabel( minimumLabel );
31  mSettings.setMaximumLabel( maximumLabel );
32 
33  init( nodeLayer );
34 }
35 
36 QgsColorRampLegendNode::QgsColorRampLegendNode( QgsLayerTreeLayer *nodeLayer, QgsColorRamp *ramp, const QgsColorRampLegendNodeSettings &settings, double minimumValue, double maximumValue, QObject *parent )
37  : QgsLayerTreeModelLegendNode( nodeLayer, parent )
38  , mRamp( ramp )
39  , mSettings( settings )
40  , mMinimumValue( minimumValue )
41  , mMaximumValue( maximumValue )
42 {
43  init( nodeLayer );
44 }
45 
46 void QgsColorRampLegendNode::init( QgsLayerTreeLayer *nodeLayer )
47 {
49  mIconSize = mSettings.orientation() == Qt::Vertical ? QSize( iconSize, iconSize * 6 ) : QSize( iconSize * 6, iconSize );
50 
51  connect( nodeLayer, &QObject::destroyed, this, [ = ]() { mLayerNode = nullptr; } );
52 }
53 
55 {
56  return mRamp.get();
57 }
58 
60 {
61  return mSettings;
62 }
63 
65 {
66  mSettings = settings;
67 }
68 
69 QString QgsColorRampLegendNode::labelForMinimum() const
70 {
71  if ( !mSettings.minimumLabel().isEmpty() )
72  return mSettings.prefix() + mSettings.minimumLabel() + mSettings.suffix();
73 
74  const QgsNumericFormatContext numericContext;
75  return mSettings.prefix() + mSettings.numericFormat()->formatDouble( mMinimumValue, numericContext ) + mSettings.suffix();
76 }
77 
78 QString QgsColorRampLegendNode::labelForMaximum() const
79 {
80  if ( !mSettings.maximumLabel().isEmpty() )
81  return mSettings.prefix() + mSettings.maximumLabel() + mSettings.suffix();
82 
83  const QgsNumericFormatContext numericContext;
84  return mSettings.prefix() + mSettings.numericFormat()->formatDouble( mMaximumValue, numericContext ) + mSettings.suffix();
85 }
86 
87 QVariant QgsColorRampLegendNode::data( int role ) const
88 {
89  if ( role == Qt::DisplayRole )
90  {
91  return QString();
92  }
93  else if ( role == Qt::EditRole )
94  {
95  return QString();
96  }
97  else if ( role == Qt::DecorationRole )
98  {
99  if ( mPixmap.isNull() || mPixmap.size() != mIconSize )
100  {
101  const QFont font = data( Qt::FontRole ).value< QFont >();
102 
103  const QString minLabel = labelForMinimum();
104  const QString maxLabel = labelForMaximum();
105 
106  const QFontMetrics fm( font );
107 
108  const QRect minBoundingRect = fm.boundingRect( minLabel );
109  const QRect maxBoundingRect = fm.boundingRect( maxLabel );
110 
111  const int minLabelWidth = minBoundingRect.width();
112  const int maxLabelWidth = maxBoundingRect.width();
113  const int maxTextWidth = std::max( minLabelWidth, maxLabelWidth );
114  const int labelGapFromRamp = fm.boundingRect( QStringLiteral( "x" ) ).width();
115  const int extraAllowance = labelGapFromRamp * 0.4; // extra allowance to avoid text clipping on right
116  QRect labelRect;
117  QSize rampSize;
118  switch ( mSettings.orientation() )
119  {
120  case Qt::Vertical:
121  labelRect = QRect( mIconSize.width() + labelGapFromRamp, 0, maxTextWidth + extraAllowance, mIconSize.height() );
122  mPixmap = QPixmap( mIconSize.width() + maxTextWidth + labelGapFromRamp + extraAllowance, mIconSize.height() );
123  rampSize = mIconSize;
124  break;
125 
126  case Qt::Horizontal:
127  labelRect = QRect( 0, mIconSize.height() + labelGapFromRamp, std::max( mIconSize.width(), minLabelWidth + maxLabelWidth + labelGapFromRamp ), std::max( minBoundingRect.height(),
128  maxBoundingRect.height() ) + extraAllowance );
129  mPixmap = QPixmap( std::max( mIconSize.width(), minLabelWidth + maxLabelWidth + labelGapFromRamp ), mIconSize.height() + maxTextWidth + labelGapFromRamp + extraAllowance );
130  rampSize = QSize( labelRect.width(), mIconSize.height() );
131  break;
132  }
133 
134  mPixmap.fill( Qt::transparent );
135 
136  QPixmap pix;
137 
138  if ( mRamp )
139  {
140  pix = QgsSymbolLayerUtils::colorRampPreviewPixmap( mRamp.get(), rampSize, 0, mSettings.orientation(),
141  mSettings.orientation() == Qt::Vertical ? mSettings.direction() != QgsColorRampLegendNodeSettings::MaximumToMinimum
143  false );
144  }
145  else
146  {
147  pix = QPixmap( rampSize );
148  pix.fill( Qt::transparent );
149  }
150 
151  QPainter p( &mPixmap );
152  p.drawPixmap( 0, 0, pix );
153  p.setFont( font );
154 
155  switch ( mSettings.orientation() )
156  {
157  case Qt::Vertical:
158  p.drawText( labelRect, Qt::AlignBottom | Qt::AlignLeft, mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? minLabel : maxLabel );
159  p.drawText( labelRect, Qt::AlignTop | Qt::AlignLeft, mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? maxLabel : minLabel );
160  break;
161 
162  case Qt::Horizontal:
163  p.drawText( labelRect, Qt::AlignTop | Qt::AlignLeft, mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? minLabel : maxLabel );
164  p.drawText( labelRect, Qt::AlignTop | Qt::AlignRight, mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? maxLabel : minLabel );
165  break;
166  }
167 
168  p.end();
169  }
170  return mPixmap;
171  }
173  {
175  }
176 
177  return QVariant();
178 }
179 
180 QSizeF QgsColorRampLegendNode::drawSymbol( const QgsLegendSettings &settings, ItemContext *ctx, double ) const
181 {
182  if ( !mRamp )
183  {
184  return QSizeF();
185  }
186 
187  // setup temporary render context
188  QgsRenderContext *context = nullptr;
189  std::unique_ptr< QgsRenderContext > tempRenderContext;
190  if ( ctx && ctx->context )
191  context = ctx->context;
192  else
193  {
194  tempRenderContext = std::make_unique< QgsRenderContext >();
195  // QGIS 4.0 - make ItemContext compulsory, so we don't have to construct temporary render contexts here
197  tempRenderContext->setScaleFactor( settings.dpi() / 25.4 );
198  tempRenderContext->setRendererScale( settings.mapScale() );
199  tempRenderContext->setFlag( Qgis::RenderContextFlag::Antialiasing, true );
200  tempRenderContext->setMapToPixel( QgsMapToPixel( 1 / ( settings.mmPerMapUnit() * tempRenderContext->scaleFactor() ) ) );
202  tempRenderContext->setForceVectorOutput( true );
203  tempRenderContext->setPainter( ctx ? ctx->painter : nullptr );
204 
205  // setup a minimal expression context
206  QgsExpressionContext expContext;
208  tempRenderContext->setExpressionContext( expContext );
209  context = tempRenderContext.get();
210  }
211 
212  const QFont symbolLabelFont = settings.style( QgsLegendStyle::SymbolLabel ).font();
213  QgsTextFormat format = mSettings.textFormat().isValid() ? mSettings.textFormat() : QgsTextFormat::fromQFont( symbolLabelFont );
214  if ( !mSettings.textFormat().isValid() )
215  format.setColor( settings.fontColor() );
216 
217  const QString minLabel = labelForMinimum();
218  const QString maxLabel = labelForMaximum();
219 
220  const double patchWidth = ctx && ctx->patchSize.width() > 0 ? ctx->patchSize.width() : settings.symbolSize().width();
221  const double patchHeight = ctx && ctx->patchSize.height() > 0 ? ctx->patchSize.height() : settings.symbolSize().height();
222 
223  double minHeightMm = 0;
224  double minWidthMm = 0;
225  double rampHeight = 0;
226  double rampWidth = 0;
227  switch ( mSettings.orientation() )
228  {
229  case Qt::Vertical:
230  // vertical bar, min height is the text height of the min and max labels
231  minHeightMm = QgsTextRenderer::textHeight( *context, format, QStringList() << minLabel << maxLabel, QgsTextRenderer::Rect ) / context->scaleFactor();
232  rampHeight = ctx && ctx->patchSize.height() > 0 ? std::max( minHeightMm / 2, ctx->patchSize.height() ) : std::max( minHeightMm, settings.symbolSize().height() );
233  rampWidth = patchWidth;
234  break;
235 
236  case Qt::Horizontal:
237  // horizontal bar, min width is text width of the min and max labels
238  minWidthMm = ( QgsTextRenderer::textWidth( *context, format, QStringList() << minLabel ) +
239  QgsTextRenderer::textWidth( *context, format, QStringList() << maxLabel ) ) / context->scaleFactor();
240  rampHeight = patchHeight;
241  rampWidth = std::max( minWidthMm, patchWidth );
242  break;
243  }
244 
245  if ( ctx && ctx->painter )
246  {
247  const double currentYCoord = ctx->top;
248  QPainter *p = ctx->painter;
249 
250  //setup painter scaling to dots so that raster symbology is drawn to scale
251  const double dotsPerMM = context->scaleFactor();
252 
253  double opacity = 1;
254  if ( QgsMapLayer *layer = layerNode()->layer() )
255  opacity = layer->opacity();
256 
257  const QgsScopedQPainterState painterState( p );
258  context->setPainterFlagsUsingContext( p );
259 
260  double rampLeftMm = 0;
261  const double rampTopMm = currentYCoord;
262  switch ( settings.symbolAlignment() )
263  {
264  case Qt::AlignLeft:
265  default:
266  rampLeftMm = ctx->columnLeft;
267  break;
268 
269  case Qt::AlignRight:
270  rampLeftMm = ctx->columnRight - rampWidth;
271  break;
272  }
273 
274  p->scale( 1.0 / dotsPerMM, 1.0 / dotsPerMM );
275 
276  QLinearGradient gradient;
277  switch ( mSettings.orientation() )
278  {
279  case Qt::Vertical:
280  {
281  const double gradientTop = rampTopMm * dotsPerMM;
282  const double gradientBottom = gradientTop + rampHeight * dotsPerMM;
283  gradient = QLinearGradient( 0, mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? gradientBottom : gradientTop,
284  0, mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? gradientTop : gradientBottom );
285  break;
286  }
287 
288  case Qt::Horizontal:
289  {
290  const double gradientLeft = rampLeftMm * dotsPerMM;
291  const double gradientRight = gradientLeft + rampWidth * dotsPerMM;
292  gradient = QLinearGradient( mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? gradientLeft : gradientRight, 0,
293  mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? gradientRight : gradientLeft, 0 );
294  break;
295  }
296  }
297 
298 
299  if ( mRamp->type() == QgsGradientColorRamp::typeString() || mRamp->type() == QgsCptCityColorRamp::typeString() )
300  {
301  //color ramp gradient
302  QgsGradientColorRamp *gradRamp = static_cast<QgsGradientColorRamp *>( mRamp.get() );
303  gradRamp->addStopsToGradient( &gradient, opacity );
304  }
305 
306  if ( settings.drawRasterStroke() )
307  {
308  QPen pen;
309  pen.setColor( settings.rasterStrokeColor() );
310  pen.setWidthF( settings.rasterStrokeWidth() * dotsPerMM );
311  pen.setJoinStyle( Qt::MiterJoin );
312  ctx->painter->setPen( pen );
313  }
314  else
315  {
316  ctx->painter->setPen( Qt::NoPen );
317  }
318 
319  p->setBrush( QBrush( gradient ) );
320  p->drawRect( rampLeftMm * dotsPerMM, rampTopMm * dotsPerMM, rampWidth * dotsPerMM, rampHeight * dotsPerMM );
321  }
322 
323  double labelHeight = 0;
324  if ( mSettings.orientation() == Qt::Horizontal )
325  {
326  // we treat the text as part of the symbol for horizontal bar items
327  if ( ctx && ctx->painter )
328  {
329  const double currentYCoord = ctx->top;
330  QPainter *p = ctx->painter;
331 
332  //setup painter scaling to dots so that raster symbology is drawn to scale
333  const double dotsPerMM = context->scaleFactor();
334 
335  const QgsScopedQPainterState painterState( p );
336  context->setPainterFlagsUsingContext( p );
337 
338  p->scale( 1.0 / dotsPerMM, 1.0 / dotsPerMM );
339 
340  double labelXMin = 0;
341  double labelXMax = 0;
342  // NOTE -- while the below calculations use the flipped margins from the style, that's only done because
343  // those are the only margins we expose and use for now! (and we expose them as generic margins, not side-specific
344  // ones) TODO when/if we expose other margin settings, these should be reversed...
345  const double labelYMin = currentYCoord + rampHeight + settings.style( QgsLegendStyle::Symbol ).margin( QgsLegendStyle::Right )
347  const double labelHeight = std::max( QgsTextRenderer::textHeight( *context, format, QStringList() << minLabel ),
348  QgsTextRenderer::textHeight( *context, format, QStringList() << maxLabel ) ) / dotsPerMM;
349  switch ( settings.symbolAlignment() )
350  {
351  case Qt::AlignLeft:
352  default:
353  labelXMin = ctx->columnLeft;
354  labelXMax = ctx->columnLeft + rampWidth;
355  break;
356 
357  case Qt::AlignRight:
358  labelXMin = ctx->columnRight - rampWidth;
359  labelXMin = ctx->columnRight;
360  break;
361  }
362 
363  const QRectF textRect( labelXMin * dotsPerMM, labelYMin * dotsPerMM, ( labelXMax - labelXMin ) * dotsPerMM, labelHeight * dotsPerMM );
365  QStringList() << ( mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? minLabel : maxLabel ),
366  *context, format, true, QgsTextRenderer::AlignTop );
368  QStringList() << ( mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? maxLabel : minLabel ),
369  *context, format, true, QgsTextRenderer::AlignBottom );
370  }
371  else
372  {
373  // we only need this when we are calculating the size of the node, not at render time
374  labelHeight = std::max( QgsTextRenderer::textHeight( *context, format, QStringList() << minLabel ),
375  QgsTextRenderer::textHeight( *context, format, QStringList() << maxLabel ) ) / context->scaleFactor()
378  }
379  }
380 
381  return QSizeF( rampWidth, rampHeight + labelHeight );
382 }
383 
385 {
386  if ( !mRamp || mSettings.orientation() == Qt::Horizontal )
387  {
388  return QSizeF();
389  }
390 
391  // setup temporary render context
392  QgsRenderContext *context = nullptr;
393  std::unique_ptr< QgsRenderContext > tempRenderContext;
394  if ( ctx && ctx->context )
395  context = ctx->context;
396  else
397  {
398  tempRenderContext = std::make_unique< QgsRenderContext >();
399  // QGIS 4.0 - make ItemContext compulsory, so we don't have to construct temporary render contexts here
401  tempRenderContext->setScaleFactor( settings.dpi() / 25.4 );
402  tempRenderContext->setRendererScale( settings.mapScale() );
403  tempRenderContext->setFlag( Qgis::RenderContextFlag::Antialiasing, true );
404  tempRenderContext->setMapToPixel( QgsMapToPixel( 1 / ( settings.mmPerMapUnit() * tempRenderContext->scaleFactor() ) ) );
406  tempRenderContext->setForceVectorOutput( true );
407  tempRenderContext->setPainter( ctx ? ctx->painter : nullptr );
408 
409  // setup a minimal expression context
410  QgsExpressionContext expContext;
412  tempRenderContext->setExpressionContext( expContext );
413  context = tempRenderContext.get();
414  }
415 
416  const QFont symbolLabelFont = settings.style( QgsLegendStyle::SymbolLabel ).font();
417  QgsTextFormat format = mSettings.textFormat().isValid() ? mSettings.textFormat() : QgsTextFormat::fromQFont( symbolLabelFont );
418  if ( !mSettings.textFormat().isValid() )
419  format.setColor( settings.fontColor() );
420 
421  const QString minLabel = labelForMinimum();
422  const QString maxLabel = labelForMaximum();
423 
424  const double rampHeight = symbolSize.height();
425  const double rampWidth = symbolSize.width();
426  double textWidth = 0;
427  double textHeight = 0;
428 
429  if ( ctx && ctx->painter )
430  {
431  const double currentYCoord = ctx->top;
432  QPainter *p = ctx->painter;
433 
434  //setup painter scaling to dots so that raster symbology is drawn to scale
435  const double dotsPerMM = context->scaleFactor();
436 
437  const QgsScopedQPainterState painterState( p );
438  context->setPainterFlagsUsingContext( p );
439 
440  p->scale( 1.0 / dotsPerMM, 1.0 / dotsPerMM );
441 
442  double labelXMin = 0;
443  double labelXMax = 0;
444  switch ( settings.symbolAlignment() )
445  {
446  case Qt::AlignLeft:
447  default:
448  labelXMin = ctx->columnLeft + std::max( rampWidth, ctx->maxSiblingSymbolWidth )
451  labelXMax = ctx->columnRight;
452  break;
453 
454  case Qt::AlignRight:
455  labelXMin = ctx->columnLeft;
456  // NOTE -- while the below calculations use the flipped margins from the style, that's only done because
457  // those are the only margins we expose and use for now! (and we expose them as generic margins, not side-specific
458  // ones) TODO when/if we expose other margin settings, these should be reversed...
459  labelXMax = ctx->columnRight - std::max( rampWidth, ctx->maxSiblingSymbolWidth )
462  break;
463  }
464 
465  const QRectF textRect( labelXMin * dotsPerMM, currentYCoord * dotsPerMM, ( labelXMax - labelXMin ) * dotsPerMM, rampHeight * dotsPerMM );
467  QStringList() << ( mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? maxLabel : minLabel ),
468  *context, format, true, QgsTextRenderer::AlignTop );
470  QStringList() << ( mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? minLabel : maxLabel ),
471  *context, format, true, QgsTextRenderer::AlignBottom );
472  }
473  else
474  {
475  // we only need this when we are calculating the size of the node, not at render time
476  textWidth = QgsTextRenderer::textWidth( *context, format, QStringList() << minLabel << maxLabel ) / context->scaleFactor();
477  textHeight = rampHeight;
478  }
479 
480  return QSizeF( textWidth, textHeight );
481 }
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:406
QgsColorRamp
Abstract base class for color ramps.
Definition: qgscolorramp.h:29
qgsexpressioncontextutils.h
QgsExpressionContext::appendScopes
void appendScopes(const QList< QgsExpressionContextScope * > &scopes)
Appends a list of scopes to the end of the context.
Definition: qgsexpressioncontext.cpp:499
qgscolorrampimpl.h
QgsLegendStyle::Symbol
@ Symbol
Symbol icon (excluding label)
Definition: qgslegendstyle.h:73
QgsRenderContext::setPainterFlagsUsingContext
void setPainterFlagsUsingContext(QPainter *painter=nullptr) const
Sets relevant flags on a destination painter, using the flags and settings currently defined for the ...
Definition: qgsrendercontext.cpp:169
QgsGradientColorRamp
Gradient color ramp, which smoothly interpolates between two colors and also supports optional extra ...
Definition: qgscolorrampimpl.h:136
QgsColorRampLegendNodeSettings::textFormat
QgsTextFormat textFormat() const
Returns the text format used to render text in the legend item.
Definition: qgscolorramplegendnodesettings.cpp:173
QgsLayerTreeModelLegendNode::ItemContext::columnRight
double columnRight
Right side of current legend column.
Definition: qgslayertreemodellegendnode.h:211
qgstextrenderer.h
QgsLayerTreeModelLegendNode::ItemContext::patchSize
QSizeF patchSize
Symbol patch size to render for the node.
Definition: qgslayertreemodellegendnode.h:234
QgsTextRenderer::AlignRight
@ AlignRight
Right align.
Definition: qgstextrenderer.h:62
QgsColorRampLegendNodeSettings::MinimumToMaximum
@ MinimumToMaximum
Minimum value on bottom, maximum value on top.
Definition: qgscolorramplegendnodesettings.h:46
qgssymbollayerutils.h
QgsColorRampLegendNode::settings
QgsColorRampLegendNodeSettings settings() const
Returns the node's settings.
Definition: qgscolorramplegendnode.cpp:59
qgslayertreelayer.h
QgsRenderContext
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:59
qgscolorramplegendnode.h
QgsExpressionContextUtils::globalProjectLayerScopes
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
Definition: qgsexpressioncontextutils.cpp:377
QgsColorRampLegendNode::data
QVariant data(int role) const override
Returns data associated with the item. Must be implemented in derived class.
Definition: qgscolorramplegendnode.cpp:87
QgsRenderContext::scaleFactor
double scaleFactor() const
Returns the scaling factor for the render to convert painter units to physical sizes.
Definition: qgsrendercontext.h:266
QgsLegendStyle::SymbolLabel
@ SymbolLabel
Symbol label (excluding icon)
Definition: qgslegendstyle.h:74
QgsTextRenderer::textHeight
static double textHeight(const QgsRenderContext &context, const QgsTextFormat &format, const QStringList &textLines, DrawMode mode=Point, QFontMetricsF *fontMetrics=nullptr, Qgis::TextRendererFlags flags=Qgis::TextRendererFlags(), double maxLineWidth=0)
Returns the height of a text based on a given format.
Definition: qgstextrenderer.cpp:620
QgsColorRampLegendNodeSettings::numericFormat
const QgsNumericFormat * numericFormat() const
Returns the numeric format used for numbers in the scalebar.
Definition: qgscolorramplegendnodesettings.cpp:88
QgsTextRenderer::textWidth
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.
Definition: qgstextrenderer.cpp:545
QgsTextRenderer::Rect
@ Rect
Text within rectangle draw mode.
Definition: qgstextrenderer.h:43
QgsCptCityColorRamp::typeString
static QString typeString()
Returns the string identifier for QgsCptCityColorRamp.
Definition: qgscolorrampimpl.h:750
QgsLayerTreeModel::scaleIconSize
static int scaleIconSize(int standardSize)
Scales an layer tree model icon size to compensate for display pixel density, making the icon size hi...
Definition: qgslayertreemodel.cpp:689
QgsGradientColorRamp::typeString
static QString typeString()
Returns the string identifier for QgsGradientColorRamp.
Definition: qgscolorrampimpl.h:165
Q_NOWARN_DEPRECATED_POP
#define Q_NOWARN_DEPRECATED_POP
Definition: qgis.h:2820
QgsTextFormat
Container for all settings relating to text rendering.
Definition: qgstextformat.h:40
QgsTextFormat::setColor
void setColor(const QColor &color)
Sets the color that text will be rendered in.
Definition: qgstextformat.cpp:302
QgsColorRampLegendNode::setSettings
void setSettings(const QgsColorRampLegendNodeSettings &settings)
Sets the node's settings.
Definition: qgscolorramplegendnode.cpp:64
QgsTextRenderer::AlignTop
@ AlignTop
Align to top.
Definition: qgstextrenderer.h:80
QgsLayerTreeModelLegendNode::NodeTypeRole
@ NodeTypeRole
Type of node. Added in 3.16.
Definition: qgslayertreemodellegendnode.h:85
QgsColorRampLegendNodeSettings::minimumLabel
QString minimumLabel() const
Returns the label for the minimum value on the ramp.
Definition: qgscolorramplegendnodesettings.cpp:68
QgsLayerTreeModelLegendNode::ColorRampLegend
@ ColorRampLegend
Color ramp legend (since QGIS 3.18)
Definition: qgslayertreemodellegendnode.h:98
qgslegendsettings.h
QgsLayerTreeLayer
Layer tree node points to a map layer.
Definition: qgslayertreelayer.h:43
QgsTextRenderer::drawText
static void drawText(const QRectF &rect, double rotation, HAlignment alignment, const QStringList &textLines, QgsRenderContext &context, const QgsTextFormat &format, bool drawAsOutlines=true, VAlignment vAlignment=AlignTop, Qgis::TextRendererFlags flags=Qgis::TextRendererFlags())
Draws text within a rectangle using the specified settings.
Definition: qgstextrenderer.cpp:81
QgsLegendSettings
The QgsLegendSettings class stores the appearance and layout settings for legend drawing with QgsLege...
Definition: qgslegendsettings.h:38
QgsTextRenderer::AlignLeft
@ AlignLeft
Left align.
Definition: qgstextrenderer.h:60
QgsSymbolLayerUtils::colorRampPreviewPixmap
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.
Definition: qgssymbollayerutils.cpp:1026
QgsLegendStyle::Right
@ Right
Right side.
Definition: qgslegendstyle.h:72
QgsColorRampLegendNodeSettings::prefix
QString prefix() const
Returns the prefix to show before legend text.
Definition: qgscolorramplegendnodesettings.cpp:153
QgsNumericFormat::formatDouble
virtual QString formatDouble(double value, const QgsNumericFormatContext &context) const =0
Returns a formatted string representation of a numeric double value.
QgsLayerTreeModelLegendNode::ItemContext
Definition: qgslayertreemodellegendnode.h:168
QgsTextFormat::fromQFont
static QgsTextFormat fromQFont(const QFont &font)
Returns a text format matching the settings from an input font.
Definition: qgstextformat.cpp:740
QgsScopedQPainterState
Scoped object for saving and restoring a QPainter object's state.
Definition: qgsrendercontext.h:1336
QgsTextFormat::isValid
bool isValid() const
Returns true if the format is valid.
Definition: qgstextformat.cpp:102
qgsnumericformat.h
QgsLayerTreeModelLegendNode::ItemContext::maxSiblingSymbolWidth
double maxSiblingSymbolWidth
Largest symbol width, considering all other sibling legend components associated with the current com...
Definition: qgslayertreemodellegendnode.h:218
QgsColorRampLegendNode::QgsColorRampLegendNode
QgsColorRampLegendNode(QgsLayerTreeLayer *nodeLayer, QgsColorRamp *ramp, const QString &minimumLabel, const QString &maximumLabel, QObject *parent=nullptr)
Constructor for QgsColorRampLegendNode.
Definition: qgscolorramplegendnode.cpp:26
QgsColorRampLegendNodeSettings::MaximumToMinimum
@ MaximumToMinimum
Maximum value on bottom, minimum value on top.
Definition: qgscolorramplegendnodesettings.h:47
QgsLegendStyle::Left
@ Left
Left side.
Definition: qgslegendstyle.h:71
QgsColorRampLegendNodeSettings::direction
QgsColorRampLegendNodeSettings::Direction direction() const
Returns the direction of the ramp.
Definition: qgscolorramplegendnodesettings.cpp:58
Qgis::RenderContextFlag::Antialiasing
@ Antialiasing
Use antialiasing while drawing.
QgsLayerTreeModelLegendNode::layerNode
QgsLayerTreeLayer * layerNode() const
Returns pointer to the parent layer node.
Definition: qgslayertreemodellegendnode.h:102
QgsGradientColorRamp::addStopsToGradient
void addStopsToGradient(QGradient *gradient, double opacity=1) const
Copy color ramp stops to a QGradient.
Definition: qgscolorrampimpl.cpp:540
QgsColorRampLegendNode::drawSymbol
QSizeF drawSymbol(const QgsLegendSettings &settings, ItemContext *ctx, double itemHeight) const override
Draws symbol on the left side of the item.
Definition: qgscolorramplegendnode.cpp:180
QgsMapToPixel
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:38
QgsMapLayer
Base class for all map layer types. This is the base class for all map layer types (vector,...
Definition: qgsmaplayer.h:72
QgsColorRampLegendNodeSettings::setMinimumLabel
void setMinimumLabel(const QString &label)
Sets the label for the minimum value on the ramp.
Definition: qgscolorramplegendnodesettings.cpp:73
QgsLayerTreeModelLegendNode::ItemContext::top
double top
Top y-position of legend item.
Definition: qgslayertreemodellegendnode.h:195
QgsColorRampLegendNode::drawSymbolText
QSizeF drawSymbolText(const QgsLegendSettings &settings, ItemContext *ctx, QSizeF symbolSize) const override
Draws label on the right side of the item.
Definition: qgscolorramplegendnode.cpp:384
QgsColorRampLegendNodeSettings::maximumLabel
QString maximumLabel() const
Returns the label for the maximum value on the ramp.
Definition: qgscolorramplegendnodesettings.cpp:78
qgslayertreemodel.h
QgsLayerTreeModelLegendNode::ItemContext::painter
QPainter * painter
Painter.
Definition: qgslayertreemodellegendnode.h:177
QgsColorRampLegendNodeSettings::suffix
QString suffix() const
Returns the suffix to show after legend text.
Definition: qgscolorramplegendnodesettings.cpp:163
QgsColorRampLegendNodeSettings::setMaximumLabel
void setMaximumLabel(const QString &label)
Sets the label for the maximum value on the ramp.
Definition: qgscolorramplegendnodesettings.cpp:83
QgsTextRenderer::convertQtHAlignment
static HAlignment convertQtHAlignment(Qt::Alignment alignment)
Converts a Qt horizontal alignment flag to a QgsTextRenderer::HAlignment value.
Definition: qgstextrenderer.cpp:46
Q_NOWARN_DEPRECATED_PUSH
#define Q_NOWARN_DEPRECATED_PUSH
Definition: qgis.h:2819
QgsColorRampLegendNode::ramp
const QgsColorRamp * ramp() const
Returns the color ramp used by the node.
Definition: qgscolorramplegendnode.cpp:54
QgsTextRenderer::AlignBottom
@ AlignBottom
Align to bottom.
Definition: qgstextrenderer.h:82
QgsLayerTreeModelLegendNode::ItemContext::columnLeft
double columnLeft
Left side of current legend column.
Definition: qgslayertreemodellegendnode.h:203
QgsNumericFormatContext
A context for numeric formats.
Definition: qgsnumericformat.h:34
QgsColorRampLegendNodeSettings
Settings for a color ramp legend node.
Definition: qgscolorramplegendnodesettings.h:37
QgsLayerTreeModelLegendNode::mLayerNode
QgsLayerTreeLayer * mLayerNode
Definition: qgslayertreemodellegendnode.h:331
QgsLayerTreeModelLegendNode::ItemContext::context
Q_NOWARN_DEPRECATED_POP QgsRenderContext * context
Render context, if available.
Definition: qgslayertreemodellegendnode.h:175
QgsColorRampLegendNodeSettings::orientation
Qt::Orientation orientation() const
Returns the ramp orientation (i.e.
Definition: qgscolorramplegendnodesettings.cpp:183
QgsColorRampLegendNode::iconSize
QSize iconSize() const
Returns the icon size, which is how large the ramp will render in a layer tree widget.
Definition: qgscolorramplegendnode.h:82
QgsLayerTreeModelLegendNode
The QgsLegendRendererItem class is abstract interface for legend items returned from QgsMapLayerLegen...
Definition: qgslayertreemodellegendnode.h:49