QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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()
77  : item( nullptr )
78  , labelXOffset( 0.0 )
79  {}
80  QObject* item;
81  // Symbol size size without any space around for symbol item
82  QSizeF symbolSize;
83  // Label size without any space around for symbol item
84  QSizeF labelSize;
85  QSizeF size;
86  // Offset of symbol label, this offset is the same for all symbol labels
87  // of the same layer in the same column
88  double labelXOffset;
89  };
90 
100  class Atom
101  {
102  public:
103  Atom(): size( QSizeF( 0, 0 ) ), column( 0 ) {}
104  QList<Nucleon> nucleons;
105  // Atom size including nucleons interspaces but without any space around atom.
106  QSizeF size;
107  int column;
108  };
109 
110  QSizeF paintAndDetermineSize( QPainter* painter );
111 
113  QList<Atom> createAtomList( QgsLayerTreeGroup* parentGroup, bool splitLayer );
114 
116  void setColumns( QList<Atom>& atomList );
117 
121  QSizeF drawTitle( QPainter* painter = nullptr, QPointF point = QPointF(), Qt::AlignmentFlag halignment = Qt::AlignLeft, double legendWidth = 0 );
122 
123  double spaceAboveAtom( const Atom& atom );
124 
128  QSizeF drawAtom( const Atom& atom, QPainter* painter = nullptr, QPointF point = QPointF() );
129 
130  Nucleon drawSymbolItem( QgsLayerTreeModelLegendNode* symbolItem, QPainter* painter = nullptr, QPointF point = QPointF(), double labelXOffset = 0 );
131 
133  QSizeF drawLayerTitle( QgsLayerTreeLayer* nodeLayer, QPainter* painter = nullptr, QPointF point = QPointF() );
134 
138  QSizeF drawGroupTitle( QgsLayerTreeGroup* nodeGroup, QPainter* painter = nullptr, QPointF point = QPointF() );
139 
140  QgsComposerLegendStyle::Style nodeLegendStyle( QgsLayerTreeNode* node );
141 
142  private:
143  QgsLayerTreeModel* mLegendModel;
144 
145  QgsLegendSettings mSettings;
146 
147  QSizeF mLegendSize;
148 
149 };
150 
151 #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.
QSizeF legendSize() const
Find out preferred legend size set by the client.
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.
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.