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