QGIS API Documentation  3.0.2-Girona (307d082)
qgsdatadefinedsizelegend.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsdatadefinedsizelegend.h
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 
16 #ifndef QGSDATADEFINEDSIZELEGEND_H
17 #define QGSDATADEFINEDSIZELEGEND_H
18 
19 #include "qgslegendsymbolitem.h"
20 
21 #include <QColor>
22 #include <QFont>
23 
24 class QDomElement;
25 class QgsMarkerSymbol;
26 class QgsProperty;
28 class QgsRenderContext;
30 
31 
40 class CORE_EXPORT QgsDataDefinedSizeLegend
41 {
42  public:
43 
47  QgsDataDefinedSizeLegend() = default;
48 
51  QgsDataDefinedSizeLegend &operator=( const QgsDataDefinedSizeLegend &other );
52 
55  {
58  };
59 
62  {
65  };
66 
68  struct SizeClass
69  {
70  SizeClass( double size, const QString &label ): size( size ), label( label ) {}
71 
72  double size;
73  QString label;
74  };
75 
77  void setLegendType( LegendType type ) { mType = type; }
79  LegendType legendType() const { return mType; }
80 
82  void setSymbol( QgsMarkerSymbol *symbol SIP_TRANSFER );
84  QgsMarkerSymbol *symbol() const;
85 
87  void setSizeScaleTransformer( QgsSizeScaleTransformer *transformer SIP_TRANSFER );
89  QgsSizeScaleTransformer *sizeScaleTransformer() const;
90 
92  void setClasses( const QList< QgsDataDefinedSizeLegend::SizeClass > &classes ) { mSizeClasses = classes; }
94  QList< QgsDataDefinedSizeLegend::SizeClass > classes() const { return mSizeClasses; }
95 
97  void setTitle( const QString &title ) { mTitleLabel = title; }
99  QString title() const { return mTitleLabel; }
100 
102  void setVerticalAlignment( VerticalAlignment vAlign ) { mVAlign = vAlign; }
104  VerticalAlignment verticalAlignment() const { return mVAlign; }
105 
107  void setFont( const QFont &font ) { mFont = font; }
109  QFont font() const { return mFont; }
110 
112  void setTextColor( const QColor &color ) { mTextColor = color; }
114  QColor textColor() const { return mTextColor; }
115 
117  void setTextAlignment( Qt::AlignmentFlag flag ) { mTextAlignment = flag; }
119  Qt::AlignmentFlag textAlignment() const { return mTextAlignment; }
120 
121  //
122 
124  void updateFromSymbolAndProperty( const QgsMarkerSymbol *symbol, const QgsProperty &ddSize );
125 
127  QgsLegendSymbolList legendSymbolList() const;
128 
134  void drawCollapsedLegend( QgsRenderContext &context, QSize *outputSize SIP_OUT = nullptr, int *labelXOffset SIP_OUT = nullptr ) const;
135 
137  QImage collapsedLegendImage( QgsRenderContext &context, const QColor &backgroundColor = Qt::transparent, double paddingMM = 1 ) const;
138 
140  static QgsDataDefinedSizeLegend *readXml( const QDomElement &elem, const QgsReadWriteContext &context ) SIP_FACTORY;
141 
143  void writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const;
144 
145  private:
146  LegendType mType = LegendSeparated;
147  QString mTitleLabel;
148  QList< SizeClass > mSizeClasses;
149  std::unique_ptr<QgsMarkerSymbol> mSymbol;
150  std::unique_ptr<QgsSizeScaleTransformer> mSizeScaleTransformer;
151  VerticalAlignment mVAlign = AlignBottom;
152  QFont mFont;
153  QColor mTextColor = Qt::black;
154  Qt::AlignmentFlag mTextAlignment = Qt::AlignLeft;
155 };
156 
157 #endif // QGSDATADEFINEDSIZELEGEND_H
The class is used as a container of context for various read/write operations on other objects...
Symbols are aligned to the center.
Each class (size value) has a separate legend node.
QString label
Label to be shown with the particular symbol size.
QList< QgsLegendSymbolItem > QgsLegendSymbolList
void setTextAlignment(Qt::AlignmentFlag flag)
Sets horizontal text alignment for rendering of labels - only valid for collapsed legend...
QFont font() const
Returns font used for rendering of labels - only valid for collapsed legend.
void setFont(const QFont &font)
Sets font used for rendering of labels - only valid for collapsed legend.
Definition of one class for the legend.
QColor textColor() const
Returns text color for rendering of labels - only valid for collapsed legend.
void setTitle(const QString &title)
Sets title label for data-defined size legend.
void setLegendType(LegendType type)
Sets how the legend should be rendered.
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...
#define SIP_TRANSFER
Definition: qgis_sip.h:36
double size
Marker size in units used by the symbol (usually millimeters). May be further scaled before rendering...
#define SIP_FACTORY
Definition: qgis_sip.h:69
A store for object properties.
Definition: qgsproperty.h:229
SizeClass(double size, const QString &label)
void setVerticalAlignment(VerticalAlignment vAlign)
Sets vertical alignment of symbols - only valid for collapsed legend.
Symbols are aligned to the bottom.
LegendType
Determines how to display data-defined size legend.
Contains information about the context of a rendering operation.
VerticalAlignment
How to vertically align symbols when all classes go into one node.
QString title() const
Returns title label for data-defined size legend.
#define SIP_OUT
Definition: qgis_sip.h:51
LegendType legendType() const
Returns how the legend should be rendered.
QgsPropertyTransformer subclass for scaling a value into a size according to various scaling methods...
VerticalAlignment verticalAlignment() const
Returns vertical alignment of symbols - only valid for collapsed legend.
void setTextColor(const QColor &color)
Sets text color for rendering of labels - only valid for collapsed legend.
Qt::AlignmentFlag textAlignment() const
Returns horizontal text alignment for rendering of labels - only valid for collapsed legend...
Object that keeps configuration of appearance of marker symbol&#39;s data-defined size in legend...
All classes are rendered within one legend node.
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...