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