QGIS API Documentation  2.14.0-Essen
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( nullptr ), 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 = nullptr, QPointF point = QPointF(), Qt::AlignmentFlag halignment = Qt::AlignLeft, double legendWidth = 0 );
119 
120  double spaceAboveAtom( const Atom& atom );
121 
125  QSizeF drawAtom( const Atom& atom, QPainter* painter = nullptr, QPointF point = QPointF() );
126 
127  Nucleon drawSymbolItem( QgsLayerTreeModelLegendNode* symbolItem, QPainter* painter = nullptr, QPointF point = QPointF(), double labelXOffset = 0 );
128 
130  QSizeF drawLayerTitle( QgsLayerTreeLayer* nodeLayer, QPainter* painter = nullptr, QPointF point = QPointF() );
131 
135  QSizeF drawGroupTitle( QgsLayerTreeGroup* nodeGroup, QPainter* painter = nullptr, 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
Layer tree group node serves as a container for layers and further groups.
void setLegendSize(QSizeF s)
Set the preferred resulting legend size.
The QgsLayerTreeModel class is model implementation for Qt item views framework.
The QgsLegendSettings class stores the appearance and layout settings for legend drawing with QgsLege...
This class is a base class for nodes in a layer tree.
QSizeF legendSize() const
Find out preferred legend size set by the client.
The QgsLegendRendererItem class is abstract interface for legend items returned from QgsMapLayerLegen...
Layer tree node points to a map layer.
The QgsLegendRenderer class handles automatic layout and rendering of legend.