QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 = symbolTopY[middleIndex];
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 
275  p->save();
276  p->translate( 0, -textTopY );
277 
278  // draw symbols first so that they do not cover
279  for ( const SizeClass &c : qgis::as_const( classes ) )
280  {
281  s->setSize( c.size );
282 
283  double outputSymbolSize = context.convertToPainterUnits( c.size, s->sizeUnit(), s->sizeMapUnitScale() );
284  double tx = ( outputLargestSize - outputSymbolSize ) / 2;
285 
286  p->save();
287  switch ( mVAlign )
288  {
289  case AlignCenter:
290  p->translate( tx, ( outputLargestSize - outputSymbolSize ) / 2 );
291  break;
292  case AlignBottom:
293  p->translate( tx, outputLargestSize - outputSymbolSize );
294  break;
295  }
296  s->drawPreviewIcon( nullptr, QSize( outputSymbolSize, outputSymbolSize ), &context );
297  p->restore();
298  }
299 
300  QgsTextFormat format = QgsTextFormat::fromQFont( mFont );
301  format.setColor( mTextColor );
302 
303  if ( mLineSymbol )
304  {
305  mLineSymbol->setColor( mTextColor );
306  mLineSymbol->startRender( context );
307  }
308 
309  int i = 0;
310  for ( const SizeClass &c : qgis::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 
323  QgsTextRenderer::drawText( rect, 0, mTextAlignment == Qt::AlignRight ? QgsTextRenderer::AlignRight :
324  mTextAlignment == Qt::AlignHCenter ? QgsTextRenderer::AlignCenter : QgsTextRenderer::AlignLeft,
325  QStringList() << c.label, context, format );
326  i++;
327  }
328 
329  if ( mLineSymbol )
330  mLineSymbol->stopRender( context );
331 
332  p->restore();
333 }
334 
335 
336 QImage QgsDataDefinedSizeLegend::collapsedLegendImage( QgsRenderContext &context, const QColor &backgroundColor, double paddingMM ) const
337 {
338  if ( mType != LegendCollapsed || mSizeClasses.isEmpty() || !mSymbol )
339  return QImage();
340 
341  // find out the size first
342  QSizeF contentSize;
343  drawCollapsedLegend( context, &contentSize );
344 
345  double padding = context.convertToPainterUnits( paddingMM, QgsUnitTypes::RenderMillimeters );
346  int dpm = std::round( context.scaleFactor() * 1000 ); // scale factor = dots per millimeter
347 
348  QImage img( contentSize.width() + padding * 2, contentSize.height() + padding * 2, QImage::Format_ARGB32_Premultiplied );
349  img.setDotsPerMeterX( dpm );
350  img.setDotsPerMeterY( dpm );
351  img.fill( backgroundColor );
352 
353  QPainter painter( &img );
354  painter.setRenderHint( QPainter::Antialiasing, true );
355 
356  painter.translate( padding, padding ); // so we do not need to care about padding at all
357 
358  // now do the rendering
359  QPainter *oldPainter = context.painter();
360  context.setPainter( &painter );
361  drawCollapsedLegend( context );
362  context.setPainter( oldPainter );
363 
364  painter.end();
365  return img;
366 }
367 
369 {
370  if ( elem.isNull() )
371  return nullptr;
373  ddsLegend->setLegendType( elem.attribute( QStringLiteral( "type" ) ) == QLatin1String( "collapsed" ) ? LegendCollapsed : LegendSeparated );
374  ddsLegend->setVerticalAlignment( elem.attribute( QStringLiteral( "valign" ) ) == QLatin1String( "center" ) ? AlignCenter : AlignBottom );
375  ddsLegend->setTitle( elem.attribute( QStringLiteral( "title" ) ) );
376 
377  QDomElement elemSymbol = elem.firstChildElement( QStringLiteral( "symbol" ) );
378  if ( !elemSymbol.isNull() )
379  {
380  ddsLegend->setSymbol( QgsSymbolLayerUtils::loadSymbol<QgsMarkerSymbol>( elemSymbol, context ) );
381  }
382 
383  QDomElement lineSymbol = elem.firstChildElement( QStringLiteral( "lineSymbol" ) );
384  if ( !lineSymbol.isNull() )
385  {
386  ddsLegend->setLineSymbol( QgsSymbolLayerUtils::loadSymbol<QgsLineSymbol>( lineSymbol, context ) );
387  }
388 
389  QgsSizeScaleTransformer *transformer = nullptr;
390  QDomElement elemTransformer = elem.firstChildElement( QStringLiteral( "transformer" ) );
391  if ( !elemTransformer.isNull() )
392  {
393  transformer = new QgsSizeScaleTransformer;
394  transformer->loadVariant( QgsXmlUtils::readVariant( elemTransformer ) );
395  }
396  ddsLegend->setSizeScaleTransformer( transformer );
397 
398  QDomElement elemTextStyle = elem.firstChildElement( QStringLiteral( "text-style" ) );
399  if ( !elemTextStyle.isNull() )
400  {
401  QDomElement elemFont = elemTextStyle.firstChildElement( QStringLiteral( "font" ) );
402  if ( !elemFont.isNull() )
403  {
404  ddsLegend->setFont( QFont( elemFont.attribute( QStringLiteral( "family" ) ), elemFont.attribute( QStringLiteral( "size" ) ).toInt(),
405  elemFont.attribute( QStringLiteral( "weight" ) ).toInt(), elemFont.attribute( QStringLiteral( "italic" ) ).toInt() ) );
406  }
407  ddsLegend->setTextColor( QgsSymbolLayerUtils::decodeColor( elemTextStyle.attribute( QStringLiteral( "color" ) ) ) );
408  ddsLegend->setTextAlignment( static_cast<Qt::AlignmentFlag>( elemTextStyle.attribute( QStringLiteral( "align" ) ).toInt() ) );
409  }
410 
411  QDomElement elemClasses = elem.firstChildElement( QStringLiteral( "classes" ) );
412  if ( !elemClasses.isNull() )
413  {
414  QList<SizeClass> classes;
415  QDomElement elemClass = elemClasses.firstChildElement( QStringLiteral( "class" ) );
416  while ( !elemClass.isNull() )
417  {
418  classes << SizeClass( elemClass.attribute( QStringLiteral( "size" ) ).toDouble(), elemClass.attribute( QStringLiteral( "label" ) ) );
419  elemClass = elemClass.nextSiblingElement();
420  }
421  ddsLegend->setClasses( classes );
422  }
423 
424  return ddsLegend;
425 }
426 
427 void QgsDataDefinedSizeLegend::writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const
428 {
429  QDomDocument doc = elem.ownerDocument();
430 
431  elem.setAttribute( QStringLiteral( "type" ), mType == LegendCollapsed ? "collapsed" : "separated" );
432  elem.setAttribute( QStringLiteral( "valign" ), mVAlign == AlignCenter ? "center" : "bottom" );
433  elem.setAttribute( QStringLiteral( "title" ), mTitleLabel );
434 
435  if ( mSymbol )
436  {
437  QDomElement elemSymbol = QgsSymbolLayerUtils::saveSymbol( QStringLiteral( "source" ), mSymbol.get(), doc, context );
438  elem.appendChild( elemSymbol );
439  }
440 
441  if ( mLineSymbol )
442  {
443  QDomElement elemSymbol = QgsSymbolLayerUtils::saveSymbol( QStringLiteral( "lineSymbol" ), mLineSymbol.get(), doc, context );
444  elem.appendChild( elemSymbol );
445  }
446 
447  if ( mSizeScaleTransformer )
448  {
449  QDomElement elemTransformer = QgsXmlUtils::writeVariant( mSizeScaleTransformer->toVariant(), doc );
450  elemTransformer.setTagName( QStringLiteral( "transformer" ) );
451  elem.appendChild( elemTransformer );
452  }
453 
454  QDomElement elemFont = doc.createElement( QStringLiteral( "font" ) );
455  elemFont.setAttribute( QStringLiteral( "family" ), mFont.family() );
456  elemFont.setAttribute( QStringLiteral( "size" ), mFont.pointSize() );
457  elemFont.setAttribute( QStringLiteral( "weight" ), mFont.weight() );
458  elemFont.setAttribute( QStringLiteral( "italic" ), mFont.italic() );
459 
460  QDomElement elemTextStyle = doc.createElement( QStringLiteral( "text-style" ) );
461  elemTextStyle.setAttribute( QStringLiteral( "color" ), QgsSymbolLayerUtils::encodeColor( mTextColor ) );
462  elemTextStyle.setAttribute( QStringLiteral( "align" ), static_cast<int>( mTextAlignment ) );
463  elemTextStyle.appendChild( elemFont );
464  elem.appendChild( elemTextStyle );
465 
466  if ( !mSizeClasses.isEmpty() )
467  {
468  QDomElement elemClasses = doc.createElement( QStringLiteral( "classes" ) );
469  for ( const SizeClass &sc : qgis::as_const( mSizeClasses ) )
470  {
471  QDomElement elemClass = doc.createElement( QStringLiteral( "class" ) );
472  elemClass.setAttribute( QStringLiteral( "size" ), sc.size );
473  elemClass.setAttribute( QStringLiteral( "label" ), sc.label );
474  elemClasses.appendChild( elemClass );
475  }
476  elem.appendChild( elemClasses );
477  }
478 }
QgsLegendSymbolItem::setDataDefinedSizeLegendSettings
void setDataDefinedSizeLegendSettings(QgsDataDefinedSizeLegend *settings)
Sets extra information about data-defined size.
Definition: qgslegendsymbolitem.cpp:86
QgsSymbolLayerUtils::encodeColor
static QString encodeColor(const QColor &color)
Definition: qgssymbollayerutils.cpp:52
QgsDataDefinedSizeLegend::setSymbol
void setSymbol(QgsMarkerSymbol *symbol SIP_TRANSFER)
Sets marker symbol that will be used to draw markers in legend.
Definition: qgsdatadefinedsizelegend.cpp:66
QgsRenderContext::convertToPainterUnits
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to painter units (pixels).
Definition: qgsrendercontext.cpp:287
QgsProperty
A store for object properties.
Definition: qgsproperty.h:231
QgsDataDefinedSizeLegend::AlignBottom
@ AlignBottom
Symbols are aligned to the bottom.
Definition: qgsdatadefinedsizelegend.h:67
QgsSizeScaleTransformer::clone
QgsSizeScaleTransformer * clone() const override
Returns a clone of the transformer.
Definition: qgspropertytransformer.cpp:314
QgsReadWriteContext
Definition: qgsreadwritecontext.h:34
qgspropertytransformer.h
qgstextrenderer.h
QgsMarkerSymbol::size
double size() const
Returns the estimated size for the whole symbol, which is the maximum size of all marker symbol layer...
Definition: qgssymbol.cpp:1597
QgsDataDefinedSizeLegend::title
QString title() const
Returns title label for data-defined size legend.
Definition: qgsdatadefinedsizelegend.h:119
QgsDataDefinedSizeLegend::collapsedLegendImage
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...
Definition: qgsdatadefinedsizelegend.cpp:336
QgsTextRenderer::AlignCenter
@ AlignCenter
Center align.
Definition: qgstextrenderer.h:61
QgsTextRenderer::AlignRight
@ AlignRight
Right align.
Definition: qgstextrenderer.h:62
QgsRenderContext::setPainter
void setPainter(QPainter *p)
Sets the destination QPainter for the render operation.
Definition: qgsrendercontext.h:475
qgssymbollayerutils.h
QgsDataDefinedSizeLegend
Definition: qgsdatadefinedsizelegend.h:41
QgsRenderContext
Definition: qgsrendercontext.h:57
QgsDataDefinedSizeLegend::QgsDataDefinedSizeLegend
QgsDataDefinedSizeLegend()
Constructor for QgsDataDefinedSizeLegend.
Definition: qgsdatadefinedsizelegend.cpp:26
QgsUnitTypes::RenderMillimeters
@ RenderMillimeters
Millimeters.
Definition: qgsunittypes.h:168
QgsProperty::propertyType
Type propertyType() const
Returns the property type.
Definition: qgsproperty.cpp:261
QgsRenderContext::scaleFactor
double scaleFactor() const
Returns the scaling factor for the render to convert painter units to physical sizes.
Definition: qgsrendercontext.h:317
QgsDataDefinedSizeLegend::setClasses
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.
Definition: qgsdatadefinedsizelegend.h:112
QgsProperty::transformer
const QgsPropertyTransformer * transformer() const
Returns the existing transformer used for manipulating the calculated values for the property,...
Definition: qgsproperty.cpp:801
QgsSymbolLayerUtils::decodeColor
static QColor decodeColor(const QString &str)
Definition: qgssymbollayerutils.cpp:57
QgsProperty::expressionString
QString expressionString() const
Returns the expression used for the property value.
Definition: qgsproperty.cpp:323
QgsMarkerSymbol::clone
QgsMarkerSymbol * clone() const override
Returns a deep copy of this symbol.
Definition: qgssymbol.cpp:1896
QgsDataDefinedSizeLegend::AlignCenter
@ AlignCenter
Symbols are aligned to the center.
Definition: qgsdatadefinedsizelegend.h:66
QgsDataDefinedSizeLegend::SizeClass
Definition of one class for the legend.
Definition: qgsdatadefinedsizelegend.h:71
QgsDataDefinedSizeLegend::LegendCollapsed
@ LegendCollapsed
All classes are rendered within one legend node.
Definition: qgsdatadefinedsizelegend.h:60
QgsTextRenderer::drawText
static void drawText(const QRectF &rect, double rotation, HAlignment alignment, const QStringList &textLines, QgsRenderContext &context, const QgsTextFormat &format, bool drawAsOutlines=true)
Draws text within a rectangle using the specified settings.
Definition: qgstextrenderer.cpp:45
QgsTextFormat
Definition: qgstextformat.h:38
QgsLegendSymbolItem
Definition: qgslegendsymbolitem.h:36
QgsTextFormat::setColor
void setColor(const QColor &color)
Sets the color that text will be rendered in.
Definition: qgstextformat.cpp:131
QgsProperty::ExpressionBasedProperty
@ ExpressionBasedProperty
Expression based property (QgsExpressionBasedProperty)
Definition: qgsproperty.h:241
QgsDataDefinedSizeLegend::legendSymbolList
QgsLegendSymbolList legendSymbolList() const
Generates legend symbol items according to the configuration.
Definition: qgsdatadefinedsizelegend.cpp:120
QgsDataDefinedSizeLegend::setSizeScaleTransformer
void setSizeScaleTransformer(QgsSizeScaleTransformer *transformer SIP_TRANSFER)
Sets transformer for scaling of symbol sizes. Takes ownership of the object. Accepts nullptr to set n...
Definition: qgsdatadefinedsizelegend.cpp:86
QgsXmlUtils::readVariant
static QVariant readVariant(const QDomElement &element)
Read a QVariant from a QDomElement.
Definition: qgsxmlutils.cpp:251
QgsMarkerSymbol
Definition: qgssymbol.h:917
QgsSizeScaleTransformer::loadVariant
bool loadVariant(const QVariant &definition) override
Loads this transformer from a QVariantMap, wrapped in a QVariant.
Definition: qgspropertytransformer.cpp:341
QgsSizeScaleTransformer
QgsPropertyTransformer subclass for scaling a value into a size according to various scaling methods.
Definition: qgspropertytransformer.h:461
QgsLineSymbol
Definition: qgssymbol.h:1117
QgsTextRenderer::AlignLeft
@ AlignLeft
Left align.
Definition: qgstextrenderer.h:60
QgsSymbolLayerUtils::prettyBreaks
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...
Definition: qgssymbollayerutils.cpp:4100
QgsDataDefinedSizeLegend::LegendSeparated
@ LegendSeparated
Each class (size value) has a separate legend node.
Definition: qgsdatadefinedsizelegend.h:59
QgsDataDefinedSizeLegend::setTextColor
void setTextColor(const QColor &color)
Sets text color for rendering of labels - only valid for collapsed legend.
Definition: qgsdatadefinedsizelegend.h:132
QgsDataDefinedSizeLegend::operator=
QgsDataDefinedSizeLegend & operator=(const QgsDataDefinedSizeLegend &other)
Definition: qgsdatadefinedsizelegend.cpp:48
QgsTextFormat::fromQFont
static QgsTextFormat fromQFont(const QFont &font)
Returns a text format matching the settings from an input font.
Definition: qgstextformat.cpp:475
QgsDataDefinedSizeLegend::~QgsDataDefinedSizeLegend
~QgsDataDefinedSizeLegend()
QgsDataDefinedSizeLegend::setVerticalAlignment
void setVerticalAlignment(VerticalAlignment vAlign)
Sets vertical alignment of symbols - only valid for collapsed legend.
Definition: qgsdatadefinedsizelegend.h:122
QgsDataDefinedSizeLegend::lineSymbol
QgsLineSymbol * lineSymbol() const
Returns the line symbol that will be used to draw callout lines in legend.
Definition: qgsdatadefinedsizelegend.cpp:81
qgsxmlutils.h
QgsPropertyTransformer::maxValue
double maxValue() const
Returns the maximum value expected by the transformer.
Definition: qgspropertytransformer.h:263
QgsDataDefinedSizeLegend::updateFromSymbolAndProperty
void updateFromSymbolAndProperty(const QgsMarkerSymbol *symbol, const QgsProperty &ddSize)
Updates the list of classes, source symbol and title label from given symbol and property.
Definition: qgsdatadefinedsizelegend.cpp:97
QgsDataDefinedSizeLegend::setTitle
void setTitle(const QString &title)
Sets title label for data-defined size legend.
Definition: qgsdatadefinedsizelegend.h:117
QgsPropertyTransformer::minValue
double minValue() const
Returns the minimum value expected by the transformer.
Definition: qgspropertytransformer.h:248
QgsDataDefinedSizeLegend::sizeScaleTransformer
QgsSizeScaleTransformer * sizeScaleTransformer() const
Returns transformer for scaling of symbol sizes. Returns nullptr if no transformer is defined.
Definition: qgsdatadefinedsizelegend.cpp:91
QgsLegendSymbolItem::symbol
QgsSymbol * symbol() const
Returns associated symbol. May be nullptr.
Definition: qgslegendsymbolitem.h:56
qgslinesymbollayer.h
c
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
Definition: porting_processing.dox:1
QgsSymbolLayerList
QList< QgsSymbolLayer * > QgsSymbolLayerList
Definition: qgssymbol.h:53
QgsProperty::field
QString field() const
Returns the current field name the property references.
Definition: qgsproperty.cpp:300
qgsproperty.h
QgsDataDefinedSizeLegend::symbol
QgsMarkerSymbol * symbol() const
Returns marker symbol that will be used to draw markers in legend.
Definition: qgsdatadefinedsizelegend.cpp:71
QgsDataDefinedSizeLegend::writeXml
void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const
Writes configuration to the given XML element.
Definition: qgsdatadefinedsizelegend.cpp:427
QgsDataDefinedSizeLegend::classes
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.
Definition: qgsdatadefinedsizelegend.h:114
QgsDataDefinedSizeLegend::readXml
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...
Definition: qgsdatadefinedsizelegend.cpp:368
QgsDataDefinedSizeLegend::setLegendType
void setLegendType(LegendType type)
Sets how the legend should be rendered.
Definition: qgsdatadefinedsizelegend.h:80
qgsdatadefinedsizelegend.h
qgstextformat.h
QgsRenderContext::painter
QPainter * painter()
Returns the destination QPainter for the render operation.
Definition: qgsrendercontext.h:174
QgsDataDefinedSizeLegend::drawCollapsedLegend
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...
Definition: qgsdatadefinedsizelegend.cpp:162
QgsLegendSymbolList
QList< QgsLegendSymbolItem > QgsLegendSymbolList
Definition: qgslegendsymbolitem.h:144
QgsXmlUtils::writeVariant
static QDomElement writeVariant(const QVariant &value, QDomDocument &doc)
Write a QVariant to a QDomElement.
Definition: qgsxmlutils.cpp:106
QgsDataDefinedSizeLegend::setLineSymbol
void setLineSymbol(QgsLineSymbol *symbol SIP_TRANSFER)
Sets the line symbol that will be used to draw callout lines in legend.
Definition: qgsdatadefinedsizelegend.cpp:76
QgsSymbolLayerUtils::saveSymbol
static QDomElement saveSymbol(const QString &symbolName, const QgsSymbol *symbol, QDomDocument &doc, const QgsReadWriteContext &context)
Writes a symbol definition to XML.
Definition: qgssymbollayerutils.cpp:1180
QgsDataDefinedSizeLegend::setTextAlignment
void setTextAlignment(Qt::AlignmentFlag flag)
Sets horizontal text alignment for rendering of labels - only valid for collapsed legend.
Definition: qgsdatadefinedsizelegend.h:137
QgsMarkerSymbol::setSize
void setSize(double size)
Sets the size for the whole symbol.
Definition: qgssymbol.cpp:1573
QgsDataDefinedSizeLegend::setFont
void setFont(const QFont &font)
Sets font used for rendering of labels - only valid for collapsed legend.
Definition: qgsdatadefinedsizelegend.h:127