QGIS API Documentation 4.3.0-Master (bf28115e945)
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() )
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 QgsScreenProperties targetScreen = model() && !model()->targetScreenProperties().isEmpty() ? *model()->targetScreenProperties().begin() : QgsScreenProperties();
130 double devicePixelRatio = 1;
131 if ( targetScreen.isValid() )
132 {
133 devicePixelRatio = targetScreen.devicePixelRatio();
134 }
135
136 const double minLabelWidth = minBoundingRect.width() * devicePixelRatio;
137 const double maxLabelWidth = maxBoundingRect.width() * devicePixelRatio;
138 const double maxTextWidth = std::max( minLabelWidth, maxLabelWidth );
139 const double labelGapFromRamp = fm.boundingRect( u"x"_s ).width() * devicePixelRatio;
140 const double extraAllowance = labelGapFromRamp * 0.4; // extra allowance to avoid text clipping on right
141 QRectF labelRect;
142 QSize rampSize;
143 switch ( mSettings.orientation() )
144 {
145 case Qt::Vertical:
146 labelRect = QRectF( ( mIconSize.width() + labelGapFromRamp ) / devicePixelRatio, 0, ( maxTextWidth + extraAllowance ) / devicePixelRatio, mIconSize.height() / devicePixelRatio );
147 mPixmap = QPixmap( mIconSize.width() + maxTextWidth + labelGapFromRamp + extraAllowance, mIconSize.height() );
148 rampSize = mIconSize;
149 break;
150
151 case Qt::Horizontal:
152 labelRect = QRectF(
153 0,
154 ( mIconSize.height() + labelGapFromRamp ) / devicePixelRatio,
155 std::max( static_cast<double>( mIconSize.width() ), minLabelWidth + maxLabelWidth + labelGapFromRamp ) / devicePixelRatio,
156 ( std::max( minBoundingRect.height() * devicePixelRatio, maxBoundingRect.height() * devicePixelRatio ) + extraAllowance ) / devicePixelRatio
157 );
158 mPixmap = QPixmap( std::max( static_cast< double >( mIconSize.width() ), minLabelWidth + maxLabelWidth + labelGapFromRamp ), mIconSize.height() + maxTextWidth + labelGapFromRamp + extraAllowance );
159 rampSize = QSize( labelRect.width(), mIconSize.height() );
160 break;
161 }
162
163 mPixmap.fill( Qt::transparent );
164 mPixmap.setDevicePixelRatio( devicePixelRatio );
165
166 QPixmap pix;
167
168 if ( mRamp )
169 {
171 mRamp.get(),
172 rampSize,
173 0,
174 mSettings.orientation(),
175 mSettings.orientation() == Qt::Vertical ? mSettings.direction() != QgsColorRampLegendNodeSettings::MaximumToMinimum : mSettings.direction() != QgsColorRampLegendNodeSettings::MinimumToMaximum,
176 false
177 );
178 }
179 else
180 {
181 pix = QPixmap( rampSize );
182 pix.fill( Qt::transparent );
183 }
184
185 pix.setDevicePixelRatio( devicePixelRatio );
186
187 QPainter p( &mPixmap );
188 p.drawPixmap( 0, 0, pix );
189 p.setFont( font );
190 p.setPen( qApp->palette().color( QPalette::Text ) );
191
192 switch ( mSettings.orientation() )
193 {
194 case Qt::Vertical:
195 p.drawText( labelRect, Qt::AlignBottom | Qt::AlignLeft, mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? minLabel : maxLabel );
196 p.drawText( labelRect, Qt::AlignTop | Qt::AlignLeft, mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? maxLabel : minLabel );
197 break;
198
199 case Qt::Horizontal:
200 p.drawText( labelRect, Qt::AlignTop | Qt::AlignLeft, mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? minLabel : maxLabel );
201 p.drawText( labelRect, Qt::AlignTop | Qt::AlignRight, mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? maxLabel : minLabel );
202 break;
203 }
204
205 p.end();
206 }
207 return mPixmap;
208 }
209 else if ( role == static_cast< int >( QgsLayerTreeModelLegendNode::CustomRole::NodeType ) )
210 {
212 }
213 else if ( role == static_cast< int >( QgsLayerTreeModelLegendNode::CustomRole::RuleKey ) )
214 return mKey;
215 else if ( role == static_cast< int >( QgsLayerTreeModelLegendNode::CustomRole::ParentRuleKey ) )
216 return mParentKey;
217 return QVariant();
218}
219
221{
222 if ( !mRamp )
223 {
224 return QSizeF();
225 }
226
227 // setup temporary render context
228 QgsRenderContext *context = nullptr;
229 std::unique_ptr< QgsRenderContext > tempRenderContext;
230 if ( ctx && ctx->context )
231 context = ctx->context;
232 else
233 {
234 tempRenderContext = std::make_unique< QgsRenderContext >();
235 // QGIS 5.0 - make ItemContext compulsory, so we don't have to construct temporary render contexts here
237 tempRenderContext->setScaleFactor( settings.dpi() / 25.4 );
238 tempRenderContext->setRendererScale( settings.mapScale() );
239 tempRenderContext->setFlag( Qgis::RenderContextFlag::Antialiasing, true );
240 tempRenderContext->setMapToPixel( QgsMapToPixel( 1 / ( settings.mmPerMapUnit() * tempRenderContext->scaleFactor() ) ) );
242 tempRenderContext->setRasterizedRenderingPolicy( Qgis::RasterizedRenderingPolicy::PreferVector );
243 tempRenderContext->setPainter( ctx ? ctx->painter : nullptr );
244
245 // setup a minimal expression context
246 QgsExpressionContext expContext;
248 tempRenderContext->setExpressionContext( expContext );
249 context = tempRenderContext.get();
250 }
251
252 const QgsTextFormat format = mSettings.textFormat().isValid() ? mSettings.textFormat() : settings.style( Qgis::LegendComponent::SymbolLabel ).textFormat();
253 const QString minLabel = labelForMinimum();
254 const QString maxLabel = labelForMaximum();
255
256 const double patchWidth = ctx && ctx->patchSize.width() > 0 ? ctx->patchSize.width() : settings.symbolSize().width();
257 const double patchHeight = ctx && ctx->patchSize.height() > 0 ? ctx->patchSize.height() : settings.symbolSize().height();
258
259 double minHeightMm = 0;
260 double minWidthMm = 0;
261 double rampHeight = 0;
262 double rampWidth = 0;
263 switch ( mSettings.orientation() )
264 {
265 case Qt::Vertical:
266 // vertical bar, min height is the text height of the min and max labels
267 minHeightMm = QgsTextRenderer::textHeight( *context, format, QStringList() << minLabel << maxLabel, Qgis::TextLayoutMode::Rectangle ) / context->scaleFactor();
268 rampHeight = ctx && ctx->patchSize.height() > 0 ? std::max( minHeightMm / 2, ctx->patchSize.height() ) : std::max( minHeightMm, settings.symbolSize().height() );
269 rampWidth = patchWidth;
270 break;
271
272 case Qt::Horizontal:
273 // horizontal bar, min width is text width of the min and max labels
274 minWidthMm = ( QgsTextRenderer::textWidth( *context, format, QStringList() << minLabel ) + QgsTextRenderer::textWidth( *context, format, QStringList() << maxLabel ) ) / context->scaleFactor();
275 rampHeight = patchHeight;
276 rampWidth = std::max( minWidthMm, patchWidth );
277 break;
278 }
279
280 if ( ctx && ctx->painter )
281 {
282 const double currentYCoord = ctx->top;
283 QPainter *p = ctx->painter;
284
285 //setup painter scaling to dots so that raster symbology is drawn to scale
286 const double dotsPerMM = context->scaleFactor();
287
288 double opacity = 1;
289 if ( QgsMapLayer *layer = layerNode()->layer() )
290 opacity = layer->opacity();
291
292 const QgsScopedQPainterState painterState( p );
293 context->setPainterFlagsUsingContext( p );
294
295 double rampLeftMm = 0;
296 const double rampTopMm = currentYCoord;
297 switch ( settings.symbolAlignment() )
298 {
299 case Qt::AlignLeft:
300 default:
301 rampLeftMm = ctx->columnLeft;
302 break;
303
304 case Qt::AlignRight:
305 rampLeftMm = ctx->columnRight - rampWidth;
306 break;
307 }
308
309 p->scale( 1.0 / dotsPerMM, 1.0 / dotsPerMM );
310
311 QLinearGradient gradient;
312 switch ( mSettings.orientation() )
313 {
314 case Qt::Vertical:
315 {
316 const double gradientTop = rampTopMm * dotsPerMM;
317 const double gradientBottom = gradientTop + rampHeight * dotsPerMM;
318 gradient
319 = QLinearGradient( 0, mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? gradientBottom : gradientTop, 0, mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? gradientTop : gradientBottom );
320 break;
321 }
322
323 case Qt::Horizontal:
324 {
325 const double gradientLeft = rampLeftMm * dotsPerMM;
326 const double gradientRight = gradientLeft + rampWidth * dotsPerMM;
327 gradient
328 = QLinearGradient( mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? gradientLeft : gradientRight, 0, mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? gradientRight : gradientLeft, 0 );
329 break;
330 }
331 }
332
333
334 if ( mRamp->type() == QgsGradientColorRamp::typeString() || mRamp->type() == QgsCptCityColorRamp::typeString() )
335 {
336 //color ramp gradient
337 QgsGradientColorRamp *gradRamp = static_cast<QgsGradientColorRamp *>( mRamp.get() );
338 gradRamp->addStopsToGradient( &gradient, opacity );
339 }
340
341 if ( settings.drawRasterStroke() )
342 {
343 QPen pen;
344 pen.setColor( settings.rasterStrokeColor() );
345 pen.setWidthF( settings.rasterStrokeWidth() * dotsPerMM );
346 pen.setJoinStyle( Qt::MiterJoin );
347 ctx->painter->setPen( pen );
348 }
349 else
350 {
351 ctx->painter->setPen( Qt::NoPen );
352 }
353
354 p->setBrush( QBrush( gradient ) );
355 p->drawRect( rampLeftMm * dotsPerMM, rampTopMm * dotsPerMM, rampWidth * dotsPerMM, rampHeight * dotsPerMM );
356 }
357
358 double labelHeight = 0;
359 if ( mSettings.orientation() == Qt::Horizontal )
360 {
361 // we treat the text as part of the symbol for horizontal bar items
362 if ( ctx && ctx->painter )
363 {
364 const double currentYCoord = ctx->top;
365 QPainter *p = ctx->painter;
366
367 //setup painter scaling to dots so that raster symbology is drawn to scale
368 const double dotsPerMM = context->scaleFactor();
369
370 const QgsScopedQPainterState painterState( p );
371 context->setPainterFlagsUsingContext( p );
372
373 p->scale( 1.0 / dotsPerMM, 1.0 / dotsPerMM );
374
375 double labelXMin = 0;
376 double labelXMax = 0;
377 // NOTE -- while the below calculations use the flipped margins from the style, that's only done because
378 // those are the only margins we expose and use for now! (and we expose them as generic margins, not side-specific
379 // ones) TODO when/if we expose other margin settings, these should be reversed...
380 const double labelYMin = currentYCoord
381 + rampHeight
384 const double labelHeight = std::max( QgsTextRenderer::textHeight( *context, format, QStringList() << minLabel ), QgsTextRenderer::textHeight( *context, format, QStringList() << maxLabel ) )
385 / dotsPerMM;
386 switch ( settings.symbolAlignment() )
387 {
388 case Qt::AlignLeft:
389 default:
390 labelXMin = ctx->columnLeft;
391 labelXMax = ctx->columnLeft + rampWidth;
392 break;
393
394 case Qt::AlignRight:
395 labelXMin = ctx->columnRight - rampWidth;
396 labelXMax = ctx->columnRight;
397 break;
398 }
399
400 const QRectF textRect( labelXMin * dotsPerMM, labelYMin * dotsPerMM, ( labelXMax - labelXMin ) * dotsPerMM, labelHeight * dotsPerMM );
402 drawText( textRect, 0, Qgis::TextHorizontalAlignment::Left, QStringList() << ( mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? minLabel : maxLabel ), *context, format, true, Qgis::TextVerticalAlignment::Top );
404 drawText( textRect, 0, Qgis::TextHorizontalAlignment::Right, QStringList() << ( mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? maxLabel : minLabel ), *context, format, true, Qgis::TextVerticalAlignment::Bottom );
405 }
406 else
407 {
408 // we only need this when we are calculating the size of the node, not at render time
409 labelHeight = std::max( QgsTextRenderer::textHeight( *context, format, QStringList() << minLabel ), QgsTextRenderer::textHeight( *context, format, QStringList() << maxLabel ) )
410 / context->scaleFactor()
413 }
414 }
415
416 return QSizeF( rampWidth, rampHeight + labelHeight );
417}
418
420{
421 if ( !mRamp || mSettings.orientation() == Qt::Horizontal )
422 {
423 return QSizeF();
424 }
425
426 // setup temporary render context
427 QgsRenderContext *context = nullptr;
428 std::unique_ptr< QgsRenderContext > tempRenderContext;
429 if ( ctx && ctx->context )
430 context = ctx->context;
431 else
432 {
433 tempRenderContext = std::make_unique< QgsRenderContext >();
434 // QGIS 5.0 - make ItemContext compulsory, so we don't have to construct temporary render contexts here
436 tempRenderContext->setScaleFactor( settings.dpi() / 25.4 );
437 tempRenderContext->setRendererScale( settings.mapScale() );
438 tempRenderContext->setFlag( Qgis::RenderContextFlag::Antialiasing, true );
439 tempRenderContext->setMapToPixel( QgsMapToPixel( 1 / ( settings.mmPerMapUnit() * tempRenderContext->scaleFactor() ) ) );
441 tempRenderContext->setRasterizedRenderingPolicy( Qgis::RasterizedRenderingPolicy::PreferVector );
442 tempRenderContext->setPainter( ctx ? ctx->painter : nullptr );
443
444 // setup a minimal expression context
445 QgsExpressionContext expContext;
447 tempRenderContext->setExpressionContext( expContext );
448 context = tempRenderContext.get();
449 }
450
451 const QgsTextFormat format = mSettings.textFormat().isValid() ? mSettings.textFormat() : settings.style( Qgis::LegendComponent::SymbolLabel ).textFormat();
452
453 const QString minLabel = labelForMinimum();
454 const QString maxLabel = labelForMaximum();
455
456 const double rampHeight = symbolSize.height();
457 const double rampWidth = symbolSize.width();
458 double textWidth = 0;
459 double textHeight = 0;
460
461 if ( ctx && ctx->painter )
462 {
463 const double currentYCoord = ctx->top;
464 QPainter *p = ctx->painter;
465
466 //setup painter scaling to dots so that raster symbology is drawn to scale
467 const double dotsPerMM = context->scaleFactor();
468
469 const QgsScopedQPainterState painterState( p );
470 context->setPainterFlagsUsingContext( p );
471
472 p->scale( 1.0 / dotsPerMM, 1.0 / dotsPerMM );
473
474 double labelXMin = 0;
475 double labelXMax = 0;
476 switch ( settings.symbolAlignment() )
477 {
478 case Qt::AlignLeft:
479 default:
480 labelXMin = ctx->columnLeft
481 + std::max( rampWidth, ctx->maxSiblingSymbolWidth )
484 labelXMax = ctx->columnRight;
485 break;
486
487 case Qt::AlignRight:
488 labelXMin = ctx->columnLeft;
489 // NOTE -- while the below calculations use the flipped margins from the style, that's only done because
490 // those are the only margins we expose and use for now! (and we expose them as generic margins, not side-specific
491 // ones) TODO when/if we expose other margin settings, these should be reversed...
492 labelXMax = ctx->columnRight
493 - std::max( rampWidth, ctx->maxSiblingSymbolWidth )
496 break;
497 }
498
499 const QRectF textRect( labelXMin * dotsPerMM, currentYCoord * dotsPerMM, ( labelXMax - labelXMin ) * dotsPerMM, rampHeight * dotsPerMM );
501 textRect,
502 0,
504 QStringList() << ( mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? maxLabel : minLabel ),
505 *context,
506 format,
507 true,
509 );
511 textRect,
512 0,
514 QStringList() << ( mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? minLabel : maxLabel ),
515 *context,
516 format,
517 true,
519 );
520 }
521 else
522 {
523 // we only need this when we are calculating the size of the node, not at render time
524 textWidth = QgsTextRenderer::textWidth( *context, format, QStringList() << minLabel << maxLabel ) / context->scaleFactor();
525 textHeight = rampHeight;
526 }
527
528 return QSizeF( textWidth, textHeight );
529}
530
532{
533 Q_UNUSED( settings );
534 Q_UNUSED( context );
535
536 QJsonObject json;
537
538 const QPixmap icon = data( Qt::DecorationRole ).value<QPixmap>();
539
540 if ( !icon.isNull() )
541 {
542 const QImage image( icon.toImage() );
543 QByteArray byteArray;
544 QBuffer buffer( &byteArray );
545 image.save( &buffer, "PNG" );
546 const QString base64 = QString::fromLatin1( byteArray.toBase64().data() );
547 json[u"icon"_s] = base64;
548 }
549
550 json[u"min"_s] = mMinimumValue;
551 json[u"max"_s] = mMaximumValue;
552
553 return json;
554}
555
557{
558 mPixmap = QPixmap();
560 mIconSize = mSettings.orientation() == Qt::Vertical ? QSize( iconSize, iconSize * 6 ) : QSize( iconSize * 6, iconSize );
561}
@ PreferVector
Prefer vector-based rendering, when the result will still be visually near-identical to a raster-base...
Definition qgis.h:2881
@ Symbol
Symbol icon (excluding label).
Definition qgis.h:5005
@ SymbolLabel
Symbol label (excluding icon).
Definition qgis.h:5006
@ Rectangle
Text within rectangle layout mode.
Definition qgis.h:3084
@ Antialiasing
Use antialiasing while drawing.
Definition qgis.h:2934
@ Bottom
Align to bottom.
Definition qgis.h:3146
@ Top
Align to top.
Definition qgis.h:3144
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".
void invalidateDisplayData() override
Invalidates cached display data for the node.
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.
QgsLayerTreeModel * model() const
Returns pointer to model owning this legend node.
QgsLayerTreeLayer * layerNode() const
Returns pointer to the parent layer node.
QSet< QgsScreenProperties > targetScreenProperties() const
Returns the target screen properties to use when generating icons.
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.
Stores properties relating to a screen.
double devicePixelRatio() const
Returns the ratio between physical pixels and device-independent pixels for the screen.
bool isValid() const
Returns true if the properties are valid.
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:7979
#define Q_NOWARN_DEPRECATED_PUSH
Definition qgis.h:7978
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.