QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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  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->setColor( mTextColor );
304  mLineSymbol->startRender( context );
305  }
306 
307  int i = 0;
308  for ( const SizeClass &c : qgis::as_const( classes ) )
309  {
310  // line from symbol to the text
311  if ( mLineSymbol )
312  {
313  mLineSymbol->renderPolyline( QPolygonF() << QPointF( outputLargestSize / 2, symbolTopY[i] )
314  << QPointF( outputLargestSize + hLengthLine, textCenterY[i] ), nullptr, context );
315  }
316 
317  // draw label
318  QRect rect( outputLargestSize + hLengthLine + hSpaceLineText, textCenterY[i] - textHeight / 2,
319  maxTextWidth, textHeight );
320 
322  QStringList() << c.label, context, format );
323  i++;
324  }
325 
326  if ( mLineSymbol )
327  mLineSymbol->stopRender( context );
328 }
329 
330 
331 QImage QgsDataDefinedSizeLegend::collapsedLegendImage( QgsRenderContext &context, const QColor &backgroundColor, double paddingMM ) const
332 {
333  if ( mType != LegendCollapsed || mSizeClasses.isEmpty() || !mSymbol )
334  return QImage();
335 
336  // find out the size first
337  QSizeF contentSize;
338  drawCollapsedLegend( context, &contentSize );
339 
340  double padding = context.convertToPainterUnits( paddingMM, QgsUnitTypes::RenderMillimeters );
341  int dpm = std::round( context.scaleFactor() * 1000 ); // scale factor = dots per millimeter
342 
343  QImage img( contentSize.width() + padding * 2, contentSize.height() + padding * 2, QImage::Format_ARGB32_Premultiplied );
344  img.setDotsPerMeterX( dpm );
345  img.setDotsPerMeterY( dpm );
346  img.fill( backgroundColor );
347 
348  QPainter painter( &img );
349  painter.setRenderHint( QPainter::Antialiasing, true );
350 
351  painter.translate( padding, padding ); // so we do not need to care about padding at all
352 
353  // now do the rendering
354  QPainter *oldPainter = context.painter();
355  context.setPainter( &painter );
356  drawCollapsedLegend( context );
357  context.setPainter( oldPainter );
358 
359  painter.end();
360  return img;
361 }
362 
364 {
365  if ( elem.isNull() )
366  return nullptr;
368  ddsLegend->setLegendType( elem.attribute( QStringLiteral( "type" ) ) == QLatin1String( "collapsed" ) ? LegendCollapsed : LegendSeparated );
369  ddsLegend->setVerticalAlignment( elem.attribute( QStringLiteral( "valign" ) ) == QLatin1String( "center" ) ? AlignCenter : AlignBottom );
370  ddsLegend->setTitle( elem.attribute( QStringLiteral( "title" ) ) );
371 
372  QDomElement elemSymbol = elem.firstChildElement( QStringLiteral( "symbol" ) );
373  if ( !elemSymbol.isNull() )
374  {
375  ddsLegend->setSymbol( QgsSymbolLayerUtils::loadSymbol<QgsMarkerSymbol>( elemSymbol, context ) );
376  }
377 
378  QDomElement lineSymbol = elem.firstChildElement( QStringLiteral( "lineSymbol" ) );
379  if ( !lineSymbol.isNull() )
380  {
381  ddsLegend->setLineSymbol( QgsSymbolLayerUtils::loadSymbol<QgsLineSymbol>( lineSymbol, context ) );
382  }
383 
384  QgsSizeScaleTransformer *transformer = nullptr;
385  QDomElement elemTransformer = elem.firstChildElement( QStringLiteral( "transformer" ) );
386  if ( !elemTransformer.isNull() )
387  {
388  transformer = new QgsSizeScaleTransformer;
389  transformer->loadVariant( QgsXmlUtils::readVariant( elemTransformer ) );
390  }
391  ddsLegend->setSizeScaleTransformer( transformer );
392 
393  QDomElement elemTextStyle = elem.firstChildElement( QStringLiteral( "text-style" ) );
394  if ( !elemTextStyle.isNull() )
395  {
396  QDomElement elemFont = elemTextStyle.firstChildElement( QStringLiteral( "font" ) );
397  if ( !elemFont.isNull() )
398  {
399  ddsLegend->setFont( QFont( elemFont.attribute( QStringLiteral( "family" ) ), elemFont.attribute( QStringLiteral( "size" ) ).toInt(),
400  elemFont.attribute( QStringLiteral( "weight" ) ).toInt(), elemFont.attribute( QStringLiteral( "italic" ) ).toInt() ) );
401  }
402  ddsLegend->setTextColor( QgsSymbolLayerUtils::decodeColor( elemTextStyle.attribute( QStringLiteral( "color" ) ) ) );
403  ddsLegend->setTextAlignment( static_cast<Qt::AlignmentFlag>( elemTextStyle.attribute( QStringLiteral( "align" ) ).toInt() ) );
404  }
405 
406  QDomElement elemClasses = elem.firstChildElement( QStringLiteral( "classes" ) );
407  if ( !elemClasses.isNull() )
408  {
409  QList<SizeClass> classes;
410  QDomElement elemClass = elemClasses.firstChildElement( QStringLiteral( "class" ) );
411  while ( !elemClass.isNull() )
412  {
413  classes << SizeClass( elemClass.attribute( QStringLiteral( "size" ) ).toDouble(), elemClass.attribute( QStringLiteral( "label" ) ) );
414  elemClass = elemClass.nextSiblingElement();
415  }
416  ddsLegend->setClasses( classes );
417  }
418 
419  return ddsLegend;
420 }
421 
422 void QgsDataDefinedSizeLegend::writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const
423 {
424  QDomDocument doc = elem.ownerDocument();
425 
426  elem.setAttribute( QStringLiteral( "type" ), mType == LegendCollapsed ? "collapsed" : "separated" );
427  elem.setAttribute( QStringLiteral( "valign" ), mVAlign == AlignCenter ? "center" : "bottom" );
428  elem.setAttribute( QStringLiteral( "title" ), mTitleLabel );
429 
430  if ( mSymbol )
431  {
432  QDomElement elemSymbol = QgsSymbolLayerUtils::saveSymbol( QStringLiteral( "source" ), mSymbol.get(), doc, context );
433  elem.appendChild( elemSymbol );
434  }
435 
436  if ( mLineSymbol )
437  {
438  QDomElement elemSymbol = QgsSymbolLayerUtils::saveSymbol( QStringLiteral( "lineSymbol" ), mLineSymbol.get(), doc, context );
439  elem.appendChild( elemSymbol );
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 }
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:318
QgsProperty
A store for object properties.
Definition: qgsproperty.h:232
QgsDataDefinedSizeLegend::AlignBottom
@ AlignBottom
Symbols are aligned to the bottom.
Definition: qgsdatadefinedsizelegend.h:67
QgsTextRenderer::drawText
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.
Definition: qgstextrenderer.cpp:75
QgsSizeScaleTransformer::clone
QgsSizeScaleTransformer * clone() const override
Returns a clone of the transformer.
Definition: qgspropertytransformer.cpp:314
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:35
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:1638
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:331
QgsRenderContext::setPainter
void setPainter(QPainter *p)
Sets the destination QPainter for the render operation.
Definition: qgsrendercontext.h:491
qgssymbollayerutils.h
QgsDataDefinedSizeLegend
Object that keeps configuration of appearance of marker symbol's data-defined size in legend.
Definition: qgsdatadefinedsizelegend.h:42
QgsRenderContext
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:58
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:333
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:1937
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:72
QgsDataDefinedSizeLegend::LegendCollapsed
@ LegendCollapsed
All classes are rendered within one legend node.
Definition: qgsdatadefinedsizelegend.h:60
QgsTextFormat
Container for all settings relating to text rendering.
Definition: qgstextformat.h:40
QgsLegendSymbolItem
The class stores information about one class/rule of a vector layer renderer in a unified way that ca...
Definition: qgslegendsymbolitem.h:37
QgsTextFormat::setColor
void setColor(const QColor &color)
Sets the color that text will be rendered in.
Definition: qgstextformat.cpp:237
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
A marker symbol type, for rendering Point and MultiPoint geometries.
Definition: qgssymbol.h:931
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:462
QgsLineSymbol
A line symbol type, for rendering LineString and MultiLineString geometries.
Definition: qgssymbol.h:1131
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:4266
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:607
QgsScopedQPainterState
Scoped object for saving and restoring a QPainter object's state.
Definition: qgsrendercontext.h:1120
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:422
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:363
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:179
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
QgsTextRenderer::convertQtHAlignment
static HAlignment convertQtHAlignment(Qt::Alignment alignment)
Converts a Qt horizontal alignment flag to a QgsTextRenderer::HAlignment value.
Definition: qgstextrenderer.cpp:40
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:1182
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:1614
QgsDataDefinedSizeLegend::setFont
void setFont(const QFont &font)
Sets font used for rendering of labels - only valid for collapsed legend.
Definition: qgsdatadefinedsizelegend.h:127