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