QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgslegendrenderer.h
Go to the documentation of this file.
1 #ifndef QGSLEGENDRENDERER_H
2 #define QGSLEGENDRENDERER_H
3 
4 #include <QPointF>
5 
6 class QRectF;
7 class QStandardItem;
8 
9 class QgsLegendModel;
13 class QgsSymbolV2;
14 
15 #include "qgslegendsettings.h"
16 
26 class CORE_EXPORT QgsLegendRenderer
27 {
28  public:
30  QgsLegendRenderer( QgsLegendModel* legendModel, const QgsLegendSettings& settings );
31 
33  QSizeF minimumSize();
34 
36  void setLegendSize( QSizeF s ) { mLegendSize = s; }
37 
39  QSizeF legendSize() const { return mLegendSize; }
40 
44  void drawLegend( QPainter* painter );
45 
46  private:
52  class Nucleon
53  {
54  public:
56  // Symbol size size without any space around for symbol item
57  QSizeF symbolSize;
58  // Label size without any space around for symbol item
59  QSizeF labelSize;
60  QSizeF size;
61  // Offset of symbol label, this offset is the same for all symbol labels
62  // of the same layer in the same column
63  double labelXOffset;
64  };
65 
75  class Atom
76  {
77  public:
78  Atom(): size( QSizeF( 0, 0 ) ), column( 0 ) {}
79  QList<Nucleon> nucleons;
80  // Atom size including nucleons interspaces but without any space around atom.
81  QSizeF size;
82  int column;
83  };
84 
85  QSizeF paintAndDetermineSize( QPainter* painter );
86 
88  QList<Atom> createAtomList( QStandardItem* rootItem, bool splitLayer );
89 
91  void setColumns( QList<Atom>& atomList );
92 
96  QSizeF drawTitle( QPainter* painter = 0, QPointF point = QPointF(), Qt::AlignmentFlag halignment = Qt::AlignLeft, double legendWidth = 0 );
97 
98  double spaceAboveAtom( Atom atom );
99 
103  QSizeF drawAtom( Atom atom, QPainter* painter = 0, QPointF point = QPointF() );
104 
107  QStringList splitStringForWrapping( QString stringToSplt );
108 
111  void drawText( QPainter* p, double x, double y, const QString& text, const QFont& font ) const;
112 
122  void drawText( QPainter* p, const QRectF& rect, const QString& text, const QFont& font, Qt::AlignmentFlag halignment = Qt::AlignLeft, Qt::AlignmentFlag valignment = Qt::AlignTop, int flags = Qt::TextWordWrap ) const;
123 
125  QFont scaledFontPixelSize( const QFont& font ) const;
126 
128  double pixelFontSize( double pointSize ) const;
129 
131  double textWidthMillimeters( const QFont& font, const QString& text ) const;
132 
134  double fontHeightCharacterMM( const QFont& font, const QChar& c ) const;
135 
137  double fontAscentMillimeters( const QFont& font ) const;
138 
140  double fontDescentMillimeters( const QFont& font ) const;
141 
142 
146  QSizeF drawGroupItemTitle( QgsComposerGroupItem* groupItem, QPainter* painter = 0, QPointF point = QPointF() );
147 
149  QSizeF drawLayerItemTitle( QgsComposerLayerItem* layerItem, QPainter* painter = 0, QPointF point = QPointF() );
150 
151  Nucleon drawSymbolItem( QgsComposerLegendItem* symbolItem, QPainter* painter = 0, QPointF point = QPointF(), double labelXOffset = 0. );
152 
155  void drawSymbolV2( QPainter* p, QgsSymbolV2* s, double currentYCoord, double& currentXPosition, double& symbolHeight, int opacity = 255 ) const;
156 
157 
158  private:
160 
162 
163  QSizeF mLegendSize;
164 
165 };
166 
167 #endif // QGSLEGENDRENDERER_H
void setLegendSize(QSizeF s)
Set the preferred resulting legend size.
A model that provides group, layer and classification items.
QgsLegendModel * mLegendModel
Atom is indivisible set (indivisible into more columns).
Nucleon is either group title, layer title or layer child item.
QList< Nucleon > nucleons
The QgsLegendSettings class stores the appearance and layout settings for legend drawing with QgsLege...
Abstract base class for the legend item types.
QgsComposerLegendItem * item
QSizeF legendSize() const
Find out preferred legend size set by the client.
QgsLegendSettings mSettings
double size
Definition: qgssvgcache.cpp:77
The QgsLegendRenderer class handles automatic layout and rendering of legend.