QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
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
18#include "qgsproperty.h"
20#include "qgssymbollayerutils.h"
21#include "qgsxmlutils.h"
22#include "qgslinesymbollayer.h"
23#include "qgstextformat.h"
24#include "qgstextrenderer.h"
25#include "qgsmarkersymbol.h"
26#include "qgslinesymbol.h"
27#include "qgsfontutils.h"
28
30{
31 std::unique_ptr< QgsSimpleLineSymbolLayer > lineSymbolLayer = std::make_unique< QgsSimpleLineSymbolLayer >( QColor( 0, 0, 0 ), 0.2 );
32 mLineSymbol = std::make_unique< QgsLineSymbol >( QgsSymbolLayerList() << lineSymbolLayer.release() );
33}
34
36
38 : mType( other.mType )
39 , mTitleLabel( other.mTitleLabel )
40 , mSizeClasses( other.mSizeClasses )
41 , mSymbol( other.mSymbol.get() ? other.mSymbol->clone() : nullptr )
42 , mLineSymbol( other.mLineSymbol.get() ? other.mLineSymbol->clone() : nullptr )
43 , mSizeScaleTransformer( other.mSizeScaleTransformer.get() ? new QgsSizeScaleTransformer( *other.mSizeScaleTransformer ) : nullptr )
44 , mVAlign( other.mVAlign )
45 , mFont( other.mFont )
46 , mTextColor( other.mTextColor )
47 , mTextAlignment( other.mTextAlignment )
48{
49}
50
52{
53 if ( this != &other )
54 {
55 mType = other.mType;
56 mTitleLabel = other.mTitleLabel;
57 mSizeClasses = other.mSizeClasses;
58 mSymbol.reset( other.mSymbol.get() ? other.mSymbol->clone() : nullptr );
59 mLineSymbol.reset( other.mLineSymbol.get() ? other.mLineSymbol->clone() : nullptr );
60 mSizeScaleTransformer.reset( other.mSizeScaleTransformer.get() ? new QgsSizeScaleTransformer( *other.mSizeScaleTransformer ) : nullptr );
61 mVAlign = other.mVAlign;
62 mFont = other.mFont;
63 mTextColor = other.mTextColor;
64 mTextAlignment = other.mTextAlignment;
65 }
66 return *this;
67}
68
70{
71 mSymbol.reset( symbol );
72}
73
75{
76 return mSymbol.get();
77}
78
80{
81 mLineSymbol.reset( symbol );
82}
83
85{
86 return mLineSymbol.get();
87}
88
90{
91 mSizeScaleTransformer.reset( transformer );
92}
93
95{
96 return mSizeScaleTransformer.get();
97}
98
99
101{
102 mSymbol.reset( symbol->clone() );
103 mSymbol->setDataDefinedSize( QgsProperty() ); // original symbol may have had data-defined size associated
104
105 const QgsSizeScaleTransformer *sizeTransformer = dynamic_cast< const QgsSizeScaleTransformer * >( ddSize.transformer() );
106 mSizeScaleTransformer.reset( sizeTransformer ? sizeTransformer->clone() : nullptr );
107
108 if ( mTitleLabel.isEmpty() )
109 mTitleLabel = ddSize.propertyType() == QgsProperty::ExpressionBasedProperty ? ddSize.expressionString() : ddSize.field();
110
111 // automatically generate classes if no classes are defined
112 if ( sizeTransformer && mSizeClasses.isEmpty() )
113 {
114 mSizeClasses.clear();
115 const auto prettyBreaks { QgsSymbolLayerUtils::prettyBreaks( sizeTransformer->minValue(), sizeTransformer->maxValue(), 4 ) };
116 for ( double v : prettyBreaks )
117 {
118 mSizeClasses << SizeClass( v, QString::number( v ) );
119 }
120 }
121}
122
124{
126 if ( !mTitleLabel.isEmpty() )
127 {
128 QgsLegendSymbolItem title( nullptr, mTitleLabel, QString() );
129 lst << title;
130 }
131
132 switch ( mType )
133 {
134 case LegendCollapsed:
135 {
138 lst << i;
139 break;
140 }
141
142 case LegendSeparated:
143 {
144 lst.reserve( mSizeClasses.size() );
145 for ( const SizeClass &cl : mSizeClasses )
146 {
147 QgsLegendSymbolItem si( mSymbol.get(), cl.label, QString() );
148 QgsMarkerSymbol *s = static_cast<QgsMarkerSymbol *>( si.symbol() );
149 double size = cl.size;
150 if ( mSizeScaleTransformer )
151 {
152 size = mSizeScaleTransformer->size( size );
153 }
154
155 s->setSize( size );
156 lst << si;
157 }
158 break;
159 }
160 }
161 return lst;
162}
163
164
165void QgsDataDefinedSizeLegend::drawCollapsedLegend( QgsRenderContext &context, QSizeF *outputSize, double *labelXOffset ) const
166{
167 // this assumes the context's painter has been scaled to pixels in advance!
168
169 if ( mType != LegendCollapsed || mSizeClasses.isEmpty() || !mSymbol )
170 {
171 if ( outputSize )
172 *outputSize = QSizeF();
173 if ( labelXOffset )
174 *labelXOffset = 0;
175 return;
176 }
177
178 // parameters that could be configurable
179 double hLengthLineMM = 2; // extra horizontal space to be occupied by callout line
180 double hSpaceLineTextMM = 1; // horizontal space between end of the line and start of the text
181
182 std::unique_ptr<QgsMarkerSymbol> s( mSymbol->clone() );
183
184 QList<SizeClass> classes = mSizeClasses;
185
186 // optionally scale size values if transformer is defined
187 if ( mSizeScaleTransformer )
188 {
189 for ( SizeClass &cls : classes )
190 cls.size = mSizeScaleTransformer->size( cls.size );
191 }
192
193 // make sure we draw bigger symbols first
194 std::sort( classes.begin(), classes.end(), []( const SizeClass & a, const SizeClass & b ) { return a.size > b.size; } );
195
196 double hLengthLine = context.convertToPainterUnits( hLengthLineMM, Qgis::RenderUnit::Millimeters );
197 double hSpaceLineText = context.convertToPainterUnits( hSpaceLineTextMM, Qgis::RenderUnit::Millimeters );
198 int dpm = std::round( context.scaleFactor() * 1000 ); // scale factor = dots per millimeter
199
200 // get font metrics - we need a temporary image just to get the metrics right for the given DPI
201 QImage tmpImg( QSize( 1, 1 ), QImage::Format_ARGB32_Premultiplied );
202 tmpImg.setDotsPerMeterX( dpm );
203 tmpImg.setDotsPerMeterY( dpm );
204 QFontMetricsF fm( mFont, &tmpImg );
205 double textHeight = fm.height();
206 double leading = fm.leading();
207 double minTextDistY = textHeight + leading;
208
209 //
210 // determine layout of the rendered elements
211 //
212
213 // find out how wide the text will be
214 double maxTextWidth = 0;
215 for ( const SizeClass &c : std::as_const( classes ) )
216 {
217 maxTextWidth = std::max( maxTextWidth, fm.boundingRect( c.label ).width() );
218 }
219 // add extra width needed to handle varying rendering of font weight
220 maxTextWidth += 1;
221
222 // find out size of the largest symbol
223 double largestSize = classes.at( 0 ).size;
224 double outputLargestSize = context.convertToPainterUnits( largestSize, s->sizeUnit(), s->sizeMapUnitScale() );
225
226 // find out top Y coordinate for individual symbol sizes
227 QList<double> symbolTopY;
228 for ( const SizeClass &c : std::as_const( classes ) )
229 {
230 double outputSymbolSize = context.convertToPainterUnits( c.size, s->sizeUnit(), s->sizeMapUnitScale() );
231 switch ( mVAlign )
232 {
233 case AlignCenter:
234 symbolTopY << outputLargestSize / 2 - outputSymbolSize / 2;
235 break;
236 case AlignBottom:
237 symbolTopY << outputLargestSize - outputSymbolSize;
238 break;
239 }
240 }
241
242 // determine Y coordinate of texts: ideally they should be at the same level as symbolTopY
243 // but we need to avoid overlapping texts, so adjust the vertical positions
244 double middleIndex = 0; // classes.count() / 2; // will get the ideal position
245 QList<double> textCenterY;
246 double lastY = middleIndex < symbolTopY.size() ? symbolTopY[middleIndex] : 0;
247 textCenterY << lastY;
248 for ( int i = middleIndex + 1; i < classes.count(); ++i )
249 {
250 double symbolY = symbolTopY[i];
251 if ( symbolY - lastY < minTextDistY )
252 symbolY = lastY + minTextDistY;
253 textCenterY << symbolY;
254 lastY = symbolY;
255 }
256
257 double textTopY = textCenterY.first() - textHeight / 2;
258 double textBottomY = textCenterY.last() + textHeight / 2;
259 double totalTextHeight = textBottomY - textTopY;
260
261 double fullWidth = outputLargestSize + hLengthLine + hSpaceLineText + maxTextWidth;
262 double fullHeight = std::max( outputLargestSize - textTopY, totalTextHeight );
263
264 if ( outputSize )
265 *outputSize = QSizeF( fullWidth, fullHeight );
266 if ( labelXOffset )
267 *labelXOffset = outputLargestSize + hLengthLine + hSpaceLineText;
268
269 if ( !context.painter() )
270 return; // only layout
271
272 //
273 // drawing
274 //
275
276 QPainter *p = context.painter();
277 QgsScopedQPainterState painterState( p );
278 p->translate( 0, -textTopY );
279
280 // draw symbols first so that they do not cover
281 for ( const SizeClass &c : std::as_const( classes ) )
282 {
283 s->setSize( c.size );
284
285 double outputSymbolSize = context.convertToPainterUnits( c.size, s->sizeUnit(), s->sizeMapUnitScale() );
286 double tx = ( outputLargestSize - outputSymbolSize ) / 2;
287
288 QgsScopedQPainterState symbolPainterState( p );
289 switch ( mVAlign )
290 {
291 case AlignCenter:
292 p->translate( tx, ( outputLargestSize - outputSymbolSize ) / 2 );
293 break;
294 case AlignBottom:
295 p->translate( tx, outputLargestSize - outputSymbolSize );
296 break;
297 }
298 s->drawPreviewIcon( nullptr, QSize( outputSymbolSize, outputSymbolSize ), &context );
299 }
300
301 QgsTextFormat format = QgsTextFormat::fromQFont( mFont );
302 format.setColor( mTextColor );
303
304 if ( mLineSymbol )
305 {
306 mLineSymbol->startRender( context );
307 }
308
309 int i = 0;
310 for ( const SizeClass &c : std::as_const( classes ) )
311 {
312 // line from symbol to the text
313 if ( mLineSymbol )
314 {
315 mLineSymbol->renderPolyline( QPolygonF() << QPointF( outputLargestSize / 2, symbolTopY[i] )
316 << QPointF( outputLargestSize + hLengthLine, textCenterY[i] ), nullptr, context );
317 }
318
319 // draw label
320 QRect rect( outputLargestSize + hLengthLine + hSpaceLineText, textCenterY[i] - textHeight / 2,
321 maxTextWidth, textHeight );
322
324 QStringList() << c.label, context, format );
325 i++;
326 }
327
328 if ( mLineSymbol )
329 mLineSymbol->stopRender( context );
330}
331
332
333QImage QgsDataDefinedSizeLegend::collapsedLegendImage( QgsRenderContext &context, const QColor &backgroundColor, double paddingMM ) const
334{
335 if ( mType != LegendCollapsed || mSizeClasses.isEmpty() || !mSymbol )
336 return QImage();
337
338 // find out the size first
339 QSizeF contentSize;
340 drawCollapsedLegend( context, &contentSize );
341
342 double padding = context.convertToPainterUnits( paddingMM, Qgis::RenderUnit::Millimeters );
343 int dpm = std::round( context.scaleFactor() * 1000 ); // scale factor = dots per millimeter
344
345 QImage img( contentSize.width() + padding * 2, contentSize.height() + padding * 2, QImage::Format_ARGB32_Premultiplied );
346 img.setDotsPerMeterX( dpm );
347 img.setDotsPerMeterY( dpm );
348 img.fill( backgroundColor );
349
350 QPainter painter( &img );
351 painter.setRenderHint( QPainter::Antialiasing, true );
352
353 painter.translate( padding, padding ); // so we do not need to care about padding at all
354
355 // now do the rendering
356 QPainter *oldPainter = context.painter();
357 context.setPainter( &painter );
358 drawCollapsedLegend( context );
359 context.setPainter( oldPainter );
360
361 painter.end();
362 return img;
363}
364
366{
367 if ( elem.isNull() )
368 return nullptr;
370 ddsLegend->setLegendType( elem.attribute( QStringLiteral( "type" ) ) == QLatin1String( "collapsed" ) ? LegendCollapsed : LegendSeparated );
371 ddsLegend->setVerticalAlignment( elem.attribute( QStringLiteral( "valign" ) ) == QLatin1String( "center" ) ? AlignCenter : AlignBottom );
372 ddsLegend->setTitle( elem.attribute( QStringLiteral( "title" ) ) );
373
374 QDomElement elemSymbol = elem.firstChildElement( QStringLiteral( "symbol" ) );
375 if ( !elemSymbol.isNull() )
376 {
377 ddsLegend->setSymbol( QgsSymbolLayerUtils::loadSymbol<QgsMarkerSymbol>( elemSymbol, context ) );
378 }
379
380 const QDomElement lineSymbolElem = elem.firstChildElement( QStringLiteral( "lineSymbol" ) );
381 if ( !lineSymbolElem.isNull() )
382 {
383 ddsLegend->setLineSymbol( QgsSymbolLayerUtils::loadSymbol<QgsLineSymbol>( lineSymbolElem.firstChildElement(), context ) );
384 }
385
386 QgsSizeScaleTransformer *transformer = nullptr;
387 QDomElement elemTransformer = elem.firstChildElement( QStringLiteral( "transformer" ) );
388 if ( !elemTransformer.isNull() )
389 {
390 transformer = new QgsSizeScaleTransformer;
391 transformer->loadVariant( QgsXmlUtils::readVariant( elemTransformer ) );
392 }
393 ddsLegend->setSizeScaleTransformer( transformer );
394
395 QDomElement elemTextStyle = elem.firstChildElement( QStringLiteral( "text-style" ) );
396 if ( !elemTextStyle.isNull() )
397 {
398 QDomElement elemFont = elemTextStyle.firstChildElement( QStringLiteral( "font" ) );
399 if ( !elemFont.isNull() )
400 {
401 ddsLegend->setFont( QgsFontUtils::createFont( elemFont.attribute( QStringLiteral( "family" ) ), elemFont.attribute( QStringLiteral( "size" ) ).toInt(),
402 elemFont.attribute( QStringLiteral( "weight" ) ).toInt(), elemFont.attribute( QStringLiteral( "italic" ) ).toInt() ) );
403 }
404 ddsLegend->setTextColor( QgsSymbolLayerUtils::decodeColor( elemTextStyle.attribute( QStringLiteral( "color" ) ) ) );
405 ddsLegend->setTextAlignment( static_cast<Qt::AlignmentFlag>( elemTextStyle.attribute( QStringLiteral( "align" ) ).toInt() ) );
406 }
407
408 QDomElement elemClasses = elem.firstChildElement( QStringLiteral( "classes" ) );
409 if ( !elemClasses.isNull() )
410 {
411 QList<SizeClass> classes;
412 QDomElement elemClass = elemClasses.firstChildElement( QStringLiteral( "class" ) );
413 while ( !elemClass.isNull() )
414 {
415 classes << SizeClass( elemClass.attribute( QStringLiteral( "size" ) ).toDouble(), elemClass.attribute( QStringLiteral( "label" ) ) );
416 elemClass = elemClass.nextSiblingElement();
417 }
418 ddsLegend->setClasses( classes );
419 }
420
421 return ddsLegend;
422}
423
424void QgsDataDefinedSizeLegend::writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const
425{
426 QDomDocument doc = elem.ownerDocument();
427
428 elem.setAttribute( QStringLiteral( "type" ), mType == LegendCollapsed ? "collapsed" : "separated" );
429 elem.setAttribute( QStringLiteral( "valign" ), mVAlign == AlignCenter ? "center" : "bottom" );
430 elem.setAttribute( QStringLiteral( "title" ), mTitleLabel );
431
432 if ( mSymbol )
433 {
434 QDomElement elemSymbol = QgsSymbolLayerUtils::saveSymbol( QStringLiteral( "source" ), mSymbol.get(), doc, context );
435 elem.appendChild( elemSymbol );
436 }
437
438 if ( mLineSymbol )
439 {
440 QDomElement lineSymbolElem = doc.createElement( QStringLiteral( "lineSymbol" ) );
441 lineSymbolElem.appendChild( QgsSymbolLayerUtils::saveSymbol( QStringLiteral( "lineSymbol" ), mLineSymbol.get(), doc, context ) );
442 elem.appendChild( lineSymbolElem );
443 }
444
445 if ( mSizeScaleTransformer )
446 {
447 QDomElement elemTransformer = QgsXmlUtils::writeVariant( mSizeScaleTransformer->toVariant(), doc );
448 elemTransformer.setTagName( QStringLiteral( "transformer" ) );
449 elem.appendChild( elemTransformer );
450 }
451
452 QDomElement elemFont = doc.createElement( QStringLiteral( "font" ) );
453 elemFont.setAttribute( QStringLiteral( "family" ), mFont.family() );
454 elemFont.setAttribute( QStringLiteral( "size" ), mFont.pointSize() );
455 elemFont.setAttribute( QStringLiteral( "weight" ), mFont.weight() );
456 elemFont.setAttribute( QStringLiteral( "italic" ), mFont.italic() );
457
458 QDomElement elemTextStyle = doc.createElement( QStringLiteral( "text-style" ) );
459 elemTextStyle.setAttribute( QStringLiteral( "color" ), QgsSymbolLayerUtils::encodeColor( mTextColor ) );
460 elemTextStyle.setAttribute( QStringLiteral( "align" ), static_cast<int>( mTextAlignment ) );
461 elemTextStyle.appendChild( elemFont );
462 elem.appendChild( elemTextStyle );
463
464 if ( !mSizeClasses.isEmpty() )
465 {
466 QDomElement elemClasses = doc.createElement( QStringLiteral( "classes" ) );
467 for ( const SizeClass &sc : std::as_const( mSizeClasses ) )
468 {
469 QDomElement elemClass = doc.createElement( QStringLiteral( "class" ) );
470 elemClass.setAttribute( QStringLiteral( "size" ), sc.size );
471 elemClass.setAttribute( QStringLiteral( "label" ), sc.label );
472 elemClasses.appendChild( elemClass );
473 }
474 elem.appendChild( elemClasses );
475 }
476}
@ Millimeters
Millimeters.
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.
The class stores information about one class/rule of a vector layer renderer in a unified way that ca...
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.
@ ExpressionBasedProperty
Expression based property (QgsExpressionBasedProperty)
QString expressionString() const
Returns the expression used for the property value.
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,...
Type propertyType() const
Returns the property type.
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 QColor decodeColor(const QString &str)
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 QString encodeColor(const QColor &color)
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.