QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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  Nucleon() : item( 0 ), labelXOffset( 0.0 ) {}
77  QObject* item;
78  // Symbol size size without any space around for symbol item
79  QSizeF symbolSize;
80  // Label size without any space around for symbol item
81  QSizeF labelSize;
82  QSizeF size;
83  // Offset of symbol label, this offset is the same for all symbol labels
84  // of the same layer in the same column
85  double labelXOffset;
86  };
87 
97  class Atom
98  {
99  public:
100  Atom(): size( QSizeF( 0, 0 ) ), column( 0 ) {}
101  QList<Nucleon> nucleons;
102  // Atom size including nucleons interspaces but without any space around atom.
103  QSizeF size;
104  int column;
105  };
106 
107  QSizeF paintAndDetermineSize( QPainter* painter );
108 
110  QList<Atom> createAtomList( QgsLayerTreeGroup* parentGroup, bool splitLayer );
111 
113  void setColumns( QList<Atom>& atomList );
114 
118  QSizeF drawTitle( QPainter* painter = 0, QPointF point = QPointF(), Qt::AlignmentFlag halignment = Qt::AlignLeft, double legendWidth = 0 );
119 
120  double spaceAboveAtom( Atom atom );
121 
125  QSizeF drawAtom( Atom atom, QPainter* painter = 0, QPointF point = QPointF() );
126 
127  Nucleon drawSymbolItem( QgsLayerTreeModelLegendNode* symbolItem, QPainter* painter = 0, QPointF point = QPointF(), double labelXOffset = 0 );
128 
130  QSizeF drawLayerTitle( QgsLayerTreeLayer* nodeLayer, QPainter* painter = 0, QPointF point = QPointF() );
131 
135  QSizeF drawGroupTitle( QgsLayerTreeGroup* nodeGroup, QPainter* painter = 0, QPointF point = QPointF() );
136 
137  QgsComposerLegendStyle::Style nodeLegendStyle( QgsLayerTreeNode* node );
138 
139  private:
140  QgsLayerTreeModel* mLegendModel;
141 
142  QgsLegendSettings mSettings;
143 
144  QSizeF mLegendSize;
145 
146 };
147 
148 #endif // QGSLEGENDRENDERER_H