QGIS API Documentation  2.99.0-Master (dc72e14)
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 "qgis_core.h"
20 #include <QPointF>
21 
22 class QRectF;
23 class QStandardItem;
24 
25 class QgsLayerTreeGroup;
26 class QgsLayerTreeLayer;
27 class QgsLayerTreeModel;
29 class QgsLayerTreeNode;
30 class QgsSymbol;
31 
32 #include "qgslegendsettings.h"
33 
43 class CORE_EXPORT QgsLegendRenderer
44 {
45  public:
47  QgsLegendRenderer( QgsLayerTreeModel *legendModel, const QgsLegendSettings &settings );
48 
50  QSizeF minimumSize();
51 
53  void setLegendSize( QSizeF s ) { mLegendSize = s; }
54 
56  QSizeF legendSize() const { return mLegendSize; }
57 
61  void drawLegend( QPainter *painter );
62 
63 
64  static void setNodeLegendStyle( QgsLayerTreeNode *node, QgsLegendStyle::Style style );
65  static QgsLegendStyle::Style nodeLegendStyle( QgsLayerTreeNode *node, QgsLayerTreeModel *model );
66 
67  private:
68 
69 #ifndef SIP_RUN
70 
75  class Nucleon
76  {
77  public:
78  Nucleon()
79  : item( nullptr )
80  , labelXOffset( 0.0 )
81  {}
82  QObject *item = nullptr;
83  // Symbol size size without any space around for symbol item
84  QSizeF symbolSize;
85  // Label size without any space around for symbol item
86  QSizeF labelSize;
87  QSizeF size;
88  // Offset of symbol label, this offset is the same for all symbol labels
89  // of the same layer in the same column
90  double labelXOffset;
91  };
92 
102  class Atom
103  {
104  public:
105  Atom(): size( QSizeF( 0, 0 ) ), column( 0 ) {}
106  QList<Nucleon> nucleons;
107  // Atom size including nucleons interspaces but without any space around atom.
108  QSizeF size;
109  int column;
110  };
111 
112  QSizeF paintAndDetermineSize( QPainter *painter );
113 
115  QList<Atom> createAtomList( QgsLayerTreeGroup *parentGroup, bool splitLayer );
116 
118  void setColumns( QList<Atom> &atomList );
119 
123  QSizeF drawTitle( QPainter *painter = nullptr, QPointF point = QPointF(), Qt::AlignmentFlag halignment = Qt::AlignLeft, double legendWidth = 0 );
124 
125  double spaceAboveAtom( const Atom &atom );
126 
130  QSizeF drawAtom( const Atom &atom, QPainter *painter = nullptr, QPointF point = QPointF() );
131 
132  Nucleon drawSymbolItem( QgsLayerTreeModelLegendNode *symbolItem, QPainter *painter = nullptr, QPointF point = QPointF(), double labelXOffset = 0 );
133 
135  QSizeF drawLayerTitle( QgsLayerTreeLayer *nodeLayer, QPainter *painter = nullptr, QPointF point = QPointF() );
136 
140  QSizeF drawGroupTitle( QgsLayerTreeGroup *nodeGroup, QPainter *painter = nullptr, QPointF point = QPointF() );
141 
142  QgsLegendStyle::Style nodeLegendStyle( QgsLayerTreeNode *node );
143 
144  private:
145  QgsLayerTreeModel *mLegendModel = nullptr;
146 
147  QgsLegendSettings mSettings;
148 
149  QSizeF mLegendSize;
150 
151 #endif
152 };
153 
154 #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. If null, the legend will be drawn with the minimum ...
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.