QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
qgslegendrenderer.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgslegendrenderer.h
3  --------------------------------------
4  Date : July 2014
5  Copyright : (C) 2014 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 QGSLEGENDRENDERER_H
17 #define QGSLEGENDRENDERER_H
18 
19 #include <QPointF>
20 
21 class QRectF;
22 class QStandardItem;
23 
24 class QgsLayerTreeGroup;
25 class QgsLayerTreeLayer;
26 class QgsLayerTreeModel;
28 class QgsLayerTreeNode;
29 class QgsSymbolV2;
30 
31 #include "qgslegendsettings.h"
32 
42 class CORE_EXPORT QgsLegendRenderer
43 {
44  public:
46  QgsLegendRenderer( QgsLayerTreeModel* legendModel, const QgsLegendSettings& settings );
47 
49  QSizeF minimumSize();
50 
52  void setLegendSize( QSizeF s ) { mLegendSize = s; }
53 
55  QSizeF legendSize() const { return mLegendSize; }
56 
60  void drawLegend( QPainter* painter );
61 
62 
63  static void setNodeLegendStyle( QgsLayerTreeNode* node, QgsComposerLegendStyle::Style style );
64  static QgsComposerLegendStyle::Style nodeLegendStyle( QgsLayerTreeNode* node, QgsLayerTreeModel* model );
65 
66  private:
67 
73  class Nucleon
74  {
75  public:
76  QObject* item;
77  // Symbol size size without any space around for symbol item
78  QSizeF symbolSize;
79  // Label size without any space around for symbol item
80  QSizeF labelSize;
81  QSizeF size;
82  // Offset of symbol label, this offset is the same for all symbol labels
83  // of the same layer in the same column
84  double labelXOffset;
85  };
86 
96  class Atom
97  {
98  public:
99  Atom(): size( QSizeF( 0, 0 ) ), column( 0 ) {}
100  QList<Nucleon> nucleons;
101  // Atom size including nucleons interspaces but without any space around atom.
102  QSizeF size;
103  int column;
104  };
105 
106  QSizeF paintAndDetermineSize( QPainter* painter );
107 
109  QList<Atom> createAtomList( QgsLayerTreeGroup* parentGroup, bool splitLayer );
110 
112  void setColumns( QList<Atom>& atomList );
113 
117  QSizeF drawTitle( QPainter* painter = 0, QPointF point = QPointF(), Qt::AlignmentFlag halignment = Qt::AlignLeft, double legendWidth = 0 );
118 
119  double spaceAboveAtom( Atom atom );
120 
124  QSizeF drawAtom( Atom atom, QPainter* painter = 0, QPointF point = QPointF() );
125 
126  Nucleon drawSymbolItem( QgsLayerTreeModelLegendNode* symbolItem, QPainter* painter = 0, QPointF point = QPointF(), double labelXOffset = 0 );
127 
129  QSizeF drawLayerTitle( QgsLayerTreeLayer* nodeLayer, QPainter* painter = 0, QPointF point = QPointF() );
130 
134  QSizeF drawGroupTitle( QgsLayerTreeGroup* nodeGroup, QPainter* painter = 0, QPointF point = QPointF() );
135 
136  QgsComposerLegendStyle::Style nodeLegendStyle( QgsLayerTreeNode* node );
137 
138  private:
139  QgsLayerTreeModel* mLegendModel;
140 
141  QgsLegendSettings mSettings;
142 
143  QSizeF mLegendSize;
144 
145 };
146 
147 #endif // QGSLEGENDRENDERER_H
Layer tree group node serves as a container for layers and further groups.
Definition: qgslayertreegroup.h:31
void setLegendSize(QSizeF s)
Set the preferred resulting legend size.
Definition: qgslegendrenderer.h:52
The QgsLayerTreeModel class is model implementation for Qt item views framework.
Definition: qgslayertreemodel.h:46
The QgsLegendSettings class stores the appearance and layout settings for legend drawing with QgsLege...
Definition: qgslegendsettings.h:36
This class is a base class for nodes in a layer tree.
Definition: qgslayertreenode.h:63
Definition: qgssymbolv2.h:43
QSizeF legendSize() const
Find out preferred legend size set by the client.
Definition: qgslegendrenderer.h:55
Style
Definition: qgscomposerlegendstyle.h:33
The QgsLegendRendererItem class is abstract interface for legend items returned from QgsMapLayerLegen...
Definition: qgslayertreemodellegendnode.h:36
double size
Definition: qgssvgcache.cpp:77
Layer tree node points to a map layer.
Definition: qgslayertreelayer.h:41
The QgsLegendRenderer class handles automatic layout and rendering of legend.
Definition: qgslegendrenderer.h:42