QGIS API Documentation  3.6.0-Noosa (5873452)
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 class QgsRenderContext;
32 
33 #include "qgslegendsettings.h"
34 
45 class CORE_EXPORT QgsLegendRenderer
46 {
47  public:
48 
53  QgsLegendRenderer( QgsLayerTreeModel *legendModel, const QgsLegendSettings &settings );
54 
60  QSizeF minimumSize( QgsRenderContext *renderContext = nullptr );
61 
70  void setLegendSize( QSizeF s ) { mLegendSize = s; }
71 
80  QSizeF legendSize() const { return mLegendSize; }
81 
86  void drawLegend( QPainter *painter );
87 
93  void drawLegend( QgsRenderContext &context );
94 
100  static void setNodeLegendStyle( QgsLayerTreeNode *node, QgsLegendStyle::Style style );
101 
107  static QgsLegendStyle::Style nodeLegendStyle( QgsLayerTreeNode *node, QgsLayerTreeModel *model );
108 
109  private:
110 
111 #ifndef SIP_RUN
112 
120  class Nucleon
121  {
122  public:
124  Nucleon() = default;
125 
126  QObject *item = nullptr;
127 
129  QSizeF symbolSize;
130 
132  QSizeF labelSize;
133 
135  QSizeF size;
136 
143  double labelXOffset = 0.0;
144  };
145 
160  class Atom
161  {
162  public:
163 
165  QList<Nucleon> nucleons;
166 
168  QSizeF size = QSizeF( 0, 0 );
169 
171  int column = 0;
172  };
173 
180  QSizeF paintAndDetermineSize( QPainter *painter = nullptr );
181 
186  QList<Atom> createAtomList( QgsLayerTreeGroup *parentGroup, bool splitLayer );
187 
191  void setColumns( QList<Atom> &atomList );
192 
200  QSizeF drawTitle( QPainter *painter = nullptr, QPointF point = QPointF(), Qt::AlignmentFlag halignment = Qt::AlignLeft, double legendWidth = 0 );
201 
205  double spaceAboveAtom( const Atom &atom );
206 
213  QSizeF drawAtom( const Atom &atom, QPainter *painter = nullptr, QPointF point = QPointF() );
214 
218  Nucleon drawSymbolItem( QgsLayerTreeModelLegendNode *symbolItem, QPainter *painter = nullptr, QPointF point = QPointF(), double labelXOffset = 0 );
219 
227  QSizeF drawLayerTitle( QgsLayerTreeLayer *nodeLayer, QPainter *painter = nullptr, QPointF point = QPointF() );
228 
233  QSizeF drawGroupTitle( QgsLayerTreeGroup *nodeGroup, QPainter *painter = nullptr, QPointF point = QPointF() );
234 
241  QSizeF paintAndDetermineSize( QgsRenderContext *context );
242 
250  QSizeF drawTitle( QgsRenderContext *context, QPointF point = QPointF(), Qt::AlignmentFlag halignment = Qt::AlignLeft, double legendWidth = 0 );
251 
260  QSizeF drawAtom( const Atom &atom, QgsRenderContext *rendercontext, QPointF point = QPointF() );
261 
265  Nucleon drawSymbolItem( QgsLayerTreeModelLegendNode *symbolItem, QgsRenderContext *context, QPointF point = QPointF(), double labelXOffset = 0 );
266 
274  QSizeF drawLayerTitle( QgsLayerTreeLayer *nodeLayer, QgsRenderContext *context, QPointF point = QPointF() );
275 
281  QSizeF drawGroupTitle( QgsLayerTreeGroup *nodeGroup, QgsRenderContext *context, QPointF point = QPointF() );
282 
286  QgsLegendStyle::Style nodeLegendStyle( QgsLayerTreeNode *node );
287 
288  private:
289  QgsLayerTreeModel *mLegendModel = nullptr;
290 
291  QgsLegendSettings mSettings;
292 
293  QSizeF mLegendSize;
294 
295 #endif
296  QSizeF drawTitleInternal( QgsRenderContext *context, QPainter *painter, QPointF point, Qt::AlignmentFlag halignment, double legendWidth );
297  QSizeF drawAtomInternal( const Atom &atom, QgsRenderContext *context, QPainter *painter, QPointF point );
298  QgsLegendRenderer::Nucleon drawSymbolItemInternal( QgsLayerTreeModelLegendNode *symbolItem, QgsRenderContext *context, QPainter *painter, QPointF point, double labelXOffset );
299  QSizeF drawLayerTitleInternal( QgsLayerTreeLayer *nodeLayer, QgsRenderContext *context, QPainter *painter, QPointF point );
300  QSizeF drawGroupTitleInternal( QgsLayerTreeGroup *nodeGroup, QgsRenderContext *context, QPainter *painter, QPointF point );
301  QSizeF paintAndDetermineSizeInternal( QgsRenderContext *context, QPainter *painter );
302 };
303 
304 #endif // QGSLEGENDRENDERER_H
Layer tree group node serves as a container for layers and further groups.
void setLegendSize(QSizeF s)
Sets the preferred resulting legend size.
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:61
The QgsLayerTreeModel class is model implementation for Qt item views framework.
QSizeF legendSize() const
Returns the 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.
Contains information about the context of a rendering operation.
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.