QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
Loading...
Searching...
No Matches
qgsdatadefinedsizelegend.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsdatadefinedsizelegend.cpp
3 --------------------------------------
4 Date : June 2017
5 Copyright : (C) 2017 by Martin Dobias
6 Email : wonder dot sk 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
19#include "qgsproperty.h"
21#include "qgssymbollayerutils.h"
22#include "qgsxmlutils.h"
23#include "qgslinesymbollayer.h"
24#include "qgstextformat.h"
25#include "qgstextrenderer.h"
26#include "qgsmarkersymbol.h"
27#include "qgslinesymbol.h"
28#include "qgsfontutils.h"
29#include "qgscolorutils.h"
30
32{
33 std::unique_ptr< QgsSimpleLineSymbolLayer > lineSymbolLayer = std::make_unique< QgsSimpleLineSymbolLayer >( QColor( 0, 0, 0 ), 0.2 );
34 mLineSymbol = std::make_unique< QgsLineSymbol >( QgsSymbolLayerList() << lineSymbolLayer.release() );
35}
36
38
40 : mType( other.mType )
41 , mTitleLabel( other.mTitleLabel )
42 , mSizeClasses( other.mSizeClasses )
43 , mSymbol( other.mSymbol.get() ? other.mSymbol->clone() : nullptr )
44 , mLineSymbol( other.mLineSymbol.get() ? other.mLineSymbol->clone() : nullptr )
45 , mSizeScaleTransformer( other.mSizeScaleTransformer.get() ? new QgsSizeScaleTransformer( *other.mSizeScaleTransformer ) : nullptr )
46 , mVAlign( other.mVAlign )
47 , mFont( other.mFont )
48 , mTextColor( other.mTextColor )
49 , mTextAlignment( other.mTextAlignment )
50{
51}
52
54{
55 if ( this != &other )
56 {
57 mType = other.mType;
58 mTitleLabel = other.mTitleLabel;
59 mSizeClasses = other.mSizeClasses;
60 mSymbol.reset( other.mSymbol.get() ? other.mSymbol->clone() : nullptr );
61 mLineSymbol.reset( other.mLineSymbol.get() ? other.mLineSymbol->clone() : nullptr );
62 mSizeScaleTransformer.reset( other.mSizeScaleTransformer.get() ? new QgsSizeScaleTransformer( *other.mSizeScaleTransformer ) : nullptr );
63 mVAlign = other.mVAlign;
64 mFont = other.mFont;
65 mTextColor = other.mTextColor;
66 mTextAlignment = other.mTextAlignment;
67 }
68 return *this;
69}
70
72{
73 mSymbol.reset( symbol );
74}
75
77{
78 return mSymbol.get();
79}
80
82{
83 mLineSymbol.reset( symbol );
84}
85
87{
88 return mLineSymbol.get();
89}
90
92{
93 mSizeScaleTransformer.reset( transformer );
94}
95
97{
98 return mSizeScaleTransformer.get();
99}
100
101
103{
104 mSymbol.reset( symbol->clone() );
105 mSymbol->setDataDefinedSize( QgsProperty() ); // original symbol may have had data-defined size associated
106
107 const QgsSizeScaleTransformer *sizeTransformer = dynamic_cast< const QgsSizeScaleTransformer * >( ddSize.transformer() );
108 mSizeScaleTransformer.reset( sizeTransformer ? sizeTransformer->clone() : nullptr );
109
110 if ( mTitleLabel.isEmpty() )
111 mTitleLabel = ddSize.propertyType() == Qgis::PropertyType::Expression ? ddSize.expressionString() : ddSize.field();
112
113 // automatically generate classes if no classes are defined
114 if ( sizeTransformer && mSizeClasses.isEmpty() )
115 {
116 mSizeClasses.clear();
117 const auto prettyBreaks { QgsSymbolLayerUtils::prettyBreaks( sizeTransformer->minValue(), sizeTransformer->maxValue(), 4 ) };
118 for ( double v : prettyBreaks )
119 {
120 mSizeClasses << SizeClass( v, QString::number( v ) );
121 }
122 }
123}
124
126{
128 QVariant isDataDefinedSize( true );
129 if ( !mTitleLabel.isEmpty() )
130 {
131 QgsLegendSymbolItem title( nullptr, mTitleLabel, QString() );
132 title.setUserData( static_cast<int>( QgsLayerTreeModelLegendNode::CustomRole::IsDataDefinedSize ), isDataDefinedSize );
133 lst << title;
134 }
135
136 switch ( mType )
137 {
138 case LegendCollapsed:
139 {
142 i.setUserData( static_cast<int>( QgsLayerTreeModelLegendNode::CustomRole::IsDataDefinedSize ), isDataDefinedSize );
143 lst << i;
144 break;
145 }
146
147 case LegendSeparated:
148 {
149 lst.reserve( mSizeClasses.size() );
150 for ( const SizeClass &cl : mSizeClasses )
151 {
152 QgsLegendSymbolItem si( mSymbol.get(), cl.label, QString() );
153 si.setUserData( static_cast<int>( QgsLayerTreeModelLegendNode::CustomRole::IsDataDefinedSize ), isDataDefinedSize );
154 QgsMarkerSymbol *s = static_cast<QgsMarkerSymbol *>( si.symbol() );
155 double size = cl.size;
156 if ( mSizeScaleTransformer )
157 {
158 size = mSizeScaleTransformer->size( size );
159 }
160
161 s->setSize( size );
162 lst << si;
163 }
164 break;
165 }
166 }
167 return lst;
168}
169
170
171void QgsDataDefinedSizeLegend::drawCollapsedLegend( QgsRenderContext &context, QSizeF *outputSize, double *labelXOffset ) const
172{
173 // this assumes the context's painter has been scaled to pixels in advance!
174
175 if ( mType != LegendCollapsed || mSizeClasses.isEmpty() || !mSymbol )
176 {
177 if ( outputSize )
178 *outputSize = QSizeF();
179 if ( labelXOffset )
180 *labelXOffset = 0;
181 return;
182 }
183
184 // parameters that could be configurable
185 double hLengthLineMM = 2; // extra horizontal space to be occupied by callout line
186 double hSpaceLineTextMM = 1; // horizontal space between end of the line and start of the text
187
188 std::unique_ptr<QgsMarkerSymbol> s( mSymbol->clone() );
189
190 QList<SizeClass> classes = mSizeClasses;
191
192 // optionally scale size values if transformer is defined
193 if ( mSizeScaleTransformer )
194 {
195 for ( SizeClass &cls : classes )
196 cls.size = mSizeScaleTransformer->size( cls.size );
197 }
198
199 // make sure we draw bigger symbols first
200 std::sort( classes.begin(), classes.end(), []( const SizeClass & a, const SizeClass & b ) { return a.size > b.size; } );
201
202 double hLengthLine = context.convertToPainterUnits( hLengthLineMM, Qgis::RenderUnit::Millimeters );
203 double hSpaceLineText = context.convertToPainterUnits( hSpaceLineTextMM, Qgis::RenderUnit::Millimeters );
204 int dpm = std::round( context.scaleFactor() * 1000 ); // scale factor = dots per millimeter
205
206 // get font metrics - we need a temporary image just to get the metrics right for the given DPI
207 QImage tmpImg( QSize( 1, 1 ), QImage::Format_ARGB32_Premultiplied );
208 tmpImg.setDotsPerMeterX( dpm );
209 tmpImg.setDotsPerMeterY( dpm );
210 QFontMetricsF fm( mFont, &tmpImg );
211 double textHeight = fm.height();
212 double leading = fm.leading();
213 double minTextDistY = textHeight + leading;
214
215 //
216 // determine layout of the rendered elements
217 //
218
219 // find out how wide the text will be
220 double maxTextWidth = 0;
221 for ( const SizeClass &c : std::as_const( classes ) )
222 {
223 maxTextWidth = std::max( maxTextWidth, fm.boundingRect( c.label ).width() );
224 }
225 // add extra width needed to handle varying rendering of font weight
226 maxTextWidth += 1;
227
228 // find out size of the largest symbol
229 double largestSize = classes.at( 0 ).size;
230 double outputLargestSize = context.convertToPainterUnits( largestSize, s->sizeUnit(), s->sizeMapUnitScale() );
231
232 // find out top Y coordinate for individual symbol sizes
233 QList<double> symbolTopY;
234 for ( const SizeClass &c : std::as_const( classes ) )
235 {
236 double outputSymbolSize = context.convertToPainterUnits( c.size, s->sizeUnit(), s->sizeMapUnitScale() );
237 switch ( mVAlign )
238 {
239 case AlignCenter:
240 symbolTopY << outputLargestSize / 2 - outputSymbolSize / 2;
241 break;
242 case AlignBottom:
243 symbolTopY << outputLargestSize - outputSymbolSize;
244 break;
245 }
246 }
247
248 // determine Y coordinate of texts: ideally they should be at the same level as symbolTopY
249 // but we need to avoid overlapping texts, so adjust the vertical positions
250 double middleIndex = 0; // classes.count() / 2; // will get the ideal position
251 QList<double> textCenterY;
252 double lastY = middleIndex < symbolTopY.size() ? symbolTopY[middleIndex] : 0;
253 textCenterY << lastY;
254 for ( int i = middleIndex + 1; i < classes.count(); ++i )
255 {
256 double symbolY = symbolTopY[i];
257 if ( symbolY - lastY < minTextDistY )
258 symbolY = lastY + minTextDistY;
259 textCenterY << symbolY;
260 lastY = symbolY;
261 }
262
263 double textTopY = textCenterY.first() - textHeight / 2;
264 double textBottomY = textCenterY.last() + textHeight / 2;
265 double totalTextHeight = textBottomY - textTopY;
266
267 double fullWidth = outputLargestSize + hLengthLine + hSpaceLineText + maxTextWidth;
268 double fullHeight = std::max( outputLargestSize - textTopY, totalTextHeight );
269
270 if ( outputSize )
271 *outputSize = QSizeF( fullWidth, fullHeight );
272 if ( labelXOffset )
273 *labelXOffset = outputLargestSize + hLengthLine + hSpaceLineText;
274
275 if ( !context.painter() )
276 return; // only layout
277
278 //
279 // drawing
280 //
281
282 QPainter *p = context.painter();
283 QgsScopedQPainterState painterState( p );
284 p->translate( 0, -textTopY );
285
286 // draw symbols first so that they do not cover
287 for ( const SizeClass &c : std::as_const( classes ) )
288 {
289 s->setSize( c.size );
290
291 double outputSymbolSize = context.convertToPainterUnits( c.size, s->sizeUnit(), s->sizeMapUnitScale() );
292 double tx = ( outputLargestSize - outputSymbolSize ) / 2;
293
294 QgsScopedQPainterState symbolPainterState( p );
295 switch ( mVAlign )
296 {
297 case AlignCenter:
298 p->translate( tx, ( outputLargestSize - outputSymbolSize ) / 2 );
299 break;
300 case AlignBottom:
301 p->translate( tx, outputLargestSize - outputSymbolSize );
302 break;
303 }
304 s->drawPreviewIcon( nullptr, QSize( outputSymbolSize, outputSymbolSize ), &context );
305 }
306
307 QgsTextFormat format = QgsTextFormat::fromQFont( mFont );
308 format.setColor( mTextColor );
309
310 if ( mLineSymbol )
311 {
312 mLineSymbol->startRender( context );
313 }
314
315 int i = 0;
316 for ( const SizeClass &c : std::as_const( classes ) )
317 {
318 // line from symbol to the text
319 if ( mLineSymbol )
320 {
321 mLineSymbol->renderPolyline( QPolygonF() << QPointF( outputLargestSize / 2, symbolTopY[i] )
322 << QPointF( outputLargestSize + hLengthLine, textCenterY[i] ), nullptr, context );
323 }
324
325 // draw label
326 QRect rect( outputLargestSize + hLengthLine + hSpaceLineText, textCenterY[i] - textHeight / 2,
327 maxTextWidth, textHeight );
328
330 QStringList() << c.label, context, format );
331 i++;
332 }
333
334 if ( mLineSymbol )
335 mLineSymbol->stopRender( context );
336}
337
338
339QImage QgsDataDefinedSizeLegend::collapsedLegendImage( QgsRenderContext &context, const QColor &backgroundColor, double paddingMM ) const
340{
341 if ( mType != LegendCollapsed || mSizeClasses.isEmpty() || !mSymbol )
342 return QImage();
343
344 // find out the size first
345 QSizeF contentSize;
346 drawCollapsedLegend( context, &contentSize );
347
348 double padding = context.convertToPainterUnits( paddingMM, Qgis::RenderUnit::Millimeters );
349 int dpm = std::round( context.scaleFactor() * 1000 ); // scale factor = dots per millimeter
350
351 QImage img( contentSize.width() + padding * 2, contentSize.height() + padding * 2, QImage::Format_ARGB32_Premultiplied );
352 img.setDotsPerMeterX( dpm );
353 img.setDotsPerMeterY( dpm );
354 img.fill( backgroundColor );
355
356 QPainter painter( &img );
357 painter.setRenderHint( QPainter::Antialiasing, true );
358
359 painter.translate( padding, padding ); // so we do not need to care about padding at all
360
361 // now do the rendering
362 QPainter *oldPainter = context.painter();
363 context.setPainter( &painter );
364 drawCollapsedLegend( context );
365 context.setPainter( oldPainter );
366
367 painter.end();
368 return img;
369}
370
372{
373 if ( elem.isNull() )
374 return nullptr;
376 ddsLegend->setLegendType( elem.attribute( QStringLiteral( "type" ) ) == QLatin1String( "collapsed" ) ? LegendCollapsed : LegendSeparated );
377 ddsLegend->setVerticalAlignment( elem.attribute( QStringLiteral( "valign" ) ) == QLatin1String( "center" ) ? AlignCenter : AlignBottom );
378 ddsLegend->setTitle( elem.attribute( QStringLiteral( "title" ) ) );
379
380 QDomElement elemSymbol = elem.firstChildElement( QStringLiteral( "symbol" ) );
381 if ( !elemSymbol.isNull() )
382 {
383 ddsLegend->setSymbol( QgsSymbolLayerUtils::loadSymbol<QgsMarkerSymbol>( elemSymbol, context ) );
384 }
385
386 const QDomElement lineSymbolElem = elem.firstChildElement( QStringLiteral( "lineSymbol" ) );
387 if ( !lineSymbolElem.isNull() )
388 {
389 ddsLegend->setLineSymbol( QgsSymbolLayerUtils::loadSymbol<QgsLineSymbol>( lineSymbolElem.firstChildElement(), context ) );
390 }
391
392 QgsSizeScaleTransformer *transformer = nullptr;
393 QDomElement elemTransformer = elem.firstChildElement( QStringLiteral( "transformer" ) );
394 if ( !elemTransformer.isNull() )
395 {
396 transformer = new QgsSizeScaleTransformer;
397 transformer->loadVariant( QgsXmlUtils::readVariant( elemTransformer ) );
398 }
399 ddsLegend->setSizeScaleTransformer( transformer );
400
401 QDomElement elemTextStyle = elem.firstChildElement( QStringLiteral( "text-style" ) );
402 if ( !elemTextStyle.isNull() )
403 {
404 QDomElement elemFont = elemTextStyle.firstChildElement( QStringLiteral( "font" ) );
405 if ( !elemFont.isNull() )
406 {
407 ddsLegend->setFont( QgsFontUtils::createFont( elemFont.attribute( QStringLiteral( "family" ) ), elemFont.attribute( QStringLiteral( "size" ) ).toInt(),
408 elemFont.attribute( QStringLiteral( "weight" ) ).toInt(), elemFont.attribute( QStringLiteral( "italic" ) ).toInt() ) );
409 }
410 ddsLegend->setTextColor( QgsColorUtils::colorFromString( elemTextStyle.attribute( QStringLiteral( "color" ) ) ) );
411 ddsLegend->setTextAlignment( static_cast<Qt::AlignmentFlag>( elemTextStyle.attribute( QStringLiteral( "align" ) ).toInt() ) );
412 }
413
414 QDomElement elemClasses = elem.firstChildElement( QStringLiteral( "classes" ) );
415 if ( !elemClasses.isNull() )
416 {
417 QList<SizeClass> classes;
418 QDomElement elemClass = elemClasses.firstChildElement( QStringLiteral( "class" ) );
419 while ( !elemClass.isNull() )
420 {
421 classes << SizeClass( elemClass.attribute( QStringLiteral( "size" ) ).toDouble(), elemClass.attribute( QStringLiteral( "label" ) ) );
422 elemClass = elemClass.nextSiblingElement();
423 }
424 ddsLegend->setClasses( classes );
425 }
426
427 return ddsLegend;
428}
429
430void QgsDataDefinedSizeLegend::writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const
431{
432 QDomDocument doc = elem.ownerDocument();
433
434 elem.setAttribute( QStringLiteral( "type" ), mType == LegendCollapsed ? "collapsed" : "separated" );
435 elem.setAttribute( QStringLiteral( "valign" ), mVAlign == AlignCenter ? "center" : "bottom" );
436 elem.setAttribute( QStringLiteral( "title" ), mTitleLabel );
437
438 if ( mSymbol )
439 {
440 QDomElement elemSymbol = QgsSymbolLayerUtils::saveSymbol( QStringLiteral( "source" ), mSymbol.get(), doc, context );
441 elem.appendChild( elemSymbol );
442 }
443
444 if ( mLineSymbol )
445 {
446 QDomElement lineSymbolElem = doc.createElement( QStringLiteral( "lineSymbol" ) );
447 lineSymbolElem.appendChild( QgsSymbolLayerUtils::saveSymbol( QStringLiteral( "lineSymbol" ), mLineSymbol.get(), doc, context ) );
448 elem.appendChild( lineSymbolElem );
449 }
450
451 if ( mSizeScaleTransformer )
452 {
453 QDomElement elemTransformer = QgsXmlUtils::writeVariant( mSizeScaleTransformer->toVariant(), doc );
454 elemTransformer.setTagName( QStringLiteral( "transformer" ) );
455 elem.appendChild( elemTransformer );
456 }
457
458 QDomElement elemFont = doc.createElement( QStringLiteral( "font" ) );
459 elemFont.setAttribute( QStringLiteral( "family" ), mFont.family() );
460 elemFont.setAttribute( QStringLiteral( "size" ), mFont.pointSize() );
461 elemFont.setAttribute( QStringLiteral( "weight" ), mFont.weight() );
462 elemFont.setAttribute( QStringLiteral( "italic" ), mFont.italic() );
463
464 QDomElement elemTextStyle = doc.createElement( QStringLiteral( "text-style" ) );
465 elemTextStyle.setAttribute( QStringLiteral( "color" ), QgsColorUtils::colorToString( mTextColor ) );
466 elemTextStyle.setAttribute( QStringLiteral( "align" ), static_cast<int>( mTextAlignment ) );
467 elemTextStyle.appendChild( elemFont );
468 elem.appendChild( elemTextStyle );
469
470 if ( !mSizeClasses.isEmpty() )
471 {
472 QDomElement elemClasses = doc.createElement( QStringLiteral( "classes" ) );
473 for ( const SizeClass &sc : std::as_const( mSizeClasses ) )
474 {
475 QDomElement elemClass = doc.createElement( QStringLiteral( "class" ) );
476 elemClass.setAttribute( QStringLiteral( "size" ), sc.size );
477 elemClass.setAttribute( QStringLiteral( "label" ), sc.label );
478 elemClasses.appendChild( elemClass );
479 }
480 elem.appendChild( elemClasses );
481 }
482}
@ Expression
Expression based property.
@ Millimeters
Millimeters.
static QColor colorFromString(const QString &string)
Decodes a string into a color value.
static QString colorToString(const QColor &color)
Encodes a color into a string value.
Object that keeps configuration of appearance of marker symbol's data-defined size in legend.
void setTitle(const QString &title)
Sets title label for data-defined size legend.
QList< QgsDataDefinedSizeLegend::SizeClass > classes() const
Returns list of classes: each class is a pair of symbol size (in units used by the symbol) and label.
void setSymbol(QgsMarkerSymbol *symbol SIP_TRANSFER)
Sets marker symbol that will be used to draw markers in legend.
void setVerticalAlignment(VerticalAlignment vAlign)
Sets vertical alignment of symbols - only valid for collapsed legend.
void setLineSymbol(QgsLineSymbol *symbol SIP_TRANSFER)
Sets the line symbol that will be used to draw callout lines in legend.
QgsMarkerSymbol * symbol() const
Returns marker symbol that will be used to draw markers in legend.
@ AlignCenter
Symbols are aligned to the center.
@ AlignBottom
Symbols are aligned to the bottom.
void setTextAlignment(Qt::AlignmentFlag flag)
Sets horizontal text alignment for rendering of labels - only valid for collapsed legend.
QgsDataDefinedSizeLegend & operator=(const QgsDataDefinedSizeLegend &other)
void setClasses(const QList< QgsDataDefinedSizeLegend::SizeClass > &classes)
Sets list of classes: each class is a pair of symbol size (in units used by the symbol) and label.
void setLegendType(LegendType type)
Sets how the legend should be rendered.
void setFont(const QFont &font)
Sets font used for rendering of labels - only valid for collapsed legend.
void setTextColor(const QColor &color)
Sets text color for rendering of labels - only valid for collapsed legend.
QString title() const
Returns title label for data-defined size legend.
void setSizeScaleTransformer(QgsSizeScaleTransformer *transformer SIP_TRANSFER)
Sets transformer for scaling of symbol sizes. Takes ownership of the object. Accepts nullptr to set n...
QgsDataDefinedSizeLegend()
Constructor for QgsDataDefinedSizeLegend.
static QgsDataDefinedSizeLegend * readXml(const QDomElement &elem, const QgsReadWriteContext &context) SIP_FACTORY
Creates instance from given element and returns it (caller takes ownership). Returns nullptr on error...
void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const
Writes configuration to the given XML element.
@ LegendSeparated
Each class (size value) has a separate legend node.
@ LegendCollapsed
All classes are rendered within one legend node.
QgsLineSymbol * lineSymbol() const
Returns the line symbol that will be used to draw callout lines in legend.
void updateFromSymbolAndProperty(const QgsMarkerSymbol *symbol, const QgsProperty &ddSize)
Updates the list of classes, source symbol and title label from given symbol and property.
QgsSizeScaleTransformer * sizeScaleTransformer() const
Returns transformer for scaling of symbol sizes. Returns nullptr if no transformer is defined.
QImage collapsedLegendImage(QgsRenderContext &context, const QColor &backgroundColor=Qt::transparent, double paddingMM=1) const
Returns output image that would be shown in the legend. Returns invalid image if legend is not config...
QgsLegendSymbolList legendSymbolList() const
Generates legend symbol items according to the configuration.
void drawCollapsedLegend(QgsRenderContext &context, QSizeF *outputSize SIP_OUT=nullptr, double *labelXOffset SIP_OUT=nullptr) const
Draw the legend if using LegendOneNodeForAll and optionally output size of the legend and x offset of...
static QFont createFont(const QString &family, int pointSize=-1, int weight=-1, bool italic=false)
Creates a font with the specified family.
@ IsDataDefinedSize
Set when a node is related to data defined size (title or separated legend items)....
The class stores information about one class/rule of a vector layer renderer in a unified way that ca...
void setUserData(int key, QVariant &value)
Adds a key - value pair to the item's user data.
void setDataDefinedSizeLegendSettings(QgsDataDefinedSizeLegend *settings)
Sets extra information about data-defined size.
QgsSymbol * symbol() const
Returns associated symbol. May be nullptr.
A line symbol type, for rendering LineString and MultiLineString geometries.
A marker symbol type, for rendering Point and MultiPoint geometries.
void setSize(double size) const
Sets the size for the whole symbol.
double size() const
Returns the estimated size for the whole symbol, which is the maximum size of all marker symbol layer...
QgsMarkerSymbol * clone() const override
Returns a deep copy of this symbol.
double maxValue() const
Returns the maximum value expected by the transformer.
double minValue() const
Returns the minimum value expected by the transformer.
A store for object properties.
QString expressionString() const
Returns the expression used for the property value.
Qgis::PropertyType propertyType() const
Returns the property type.
QString field() const
Returns the current field name the property references.
const QgsPropertyTransformer * transformer() const
Returns the existing transformer used for manipulating the calculated values for the property,...
The class is used as a container of context for various read/write operations on other objects.
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.
double convertToPainterUnits(double size, Qgis::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale(), Qgis::RenderSubcomponentProperty property=Qgis::RenderSubcomponentProperty::Generic) const
Converts a size from the specified units to painter units (pixels).
QPainter * painter()
Returns the destination QPainter for the render operation.
void setPainter(QPainter *p)
Sets the destination QPainter for the render operation.
Scoped object for saving and restoring a QPainter object's state.
QgsPropertyTransformer subclass for scaling a value into a size according to various scaling methods.
bool loadVariant(const QVariant &definition) override
Loads this transformer from a QVariantMap, wrapped in a QVariant.
QgsSizeScaleTransformer * clone() const override
Returns a clone of the transformer.
static QList< double > prettyBreaks(double minimum, double maximum, int classes)
Computes a sequence of about 'classes' equally spaced round values which cover the range of values fr...
static QDomElement saveSymbol(const QString &symbolName, const QgsSymbol *symbol, QDomDocument &doc, const QgsReadWriteContext &context)
Writes a symbol definition to XML.
Container for all settings relating to text rendering.
void setColor(const QColor &color)
Sets the color that text will be rendered in.
static QgsTextFormat fromQFont(const QFont &font)
Returns a text format matching the settings from an input font.
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 Qgis::TextHorizontalAlignment convertQtHAlignment(Qt::Alignment alignment)
Converts a Qt horizontal alignment flag to a Qgis::TextHorizontalAlignment value.
static QDomElement writeVariant(const QVariant &value, QDomDocument &doc)
Write a QVariant to a QDomElement.
static QVariant readVariant(const QDomElement &element)
Read a QVariant from a QDomElement.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
QList< QgsLegendSymbolItem > QgsLegendSymbolList
QList< QgsSymbolLayer * > QgsSymbolLayerList
Definition qgssymbol.h:30
Definition of one class for the legend.