QGIS API Documentation  3.2.0-Bonn (bc43194)
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 
44 class CORE_EXPORT QgsLegendRenderer
45 {
46  public:
48  QgsLegendRenderer( QgsLayerTreeModel *legendModel, const QgsLegendSettings &settings );
49 
51  QSizeF minimumSize();
52 
54  void setLegendSize( QSizeF s ) { mLegendSize = s; }
55 
57  QSizeF legendSize() const { return mLegendSize; }
58 
63  void drawLegend( QPainter *painter );
64 
65 
66  static void setNodeLegendStyle( QgsLayerTreeNode *node, QgsLegendStyle::Style style );
67  static QgsLegendStyle::Style nodeLegendStyle( QgsLayerTreeNode *node, QgsLayerTreeModel *model );
68 
69  private:
70 
71 #ifndef SIP_RUN
72 
78  class Nucleon
79  {
80  public:
82  Nucleon() = default;
83 
84  QObject *item = nullptr;
85  // Symbol size size without any space around for symbol item
86  QSizeF symbolSize;
87  // Label size without any space around for symbol item
88  QSizeF labelSize;
89  QSizeF size;
90  // Offset of symbol label, this offset is the same for all symbol labels
91  // of the same layer in the same column
92  double labelXOffset = 0.0;
93  };
94 
105  class Atom
106  {
107  public:
108  Atom(): size( QSizeF( 0, 0 ) ) {}
109  QList<Nucleon> nucleons;
110  // Atom size including nucleons interspaces but without any space around atom.
111  QSizeF size;
112  int column = 0;
113  };
114 
115  QSizeF paintAndDetermineSize( QPainter *painter );
116 
118  QList<Atom> createAtomList( QgsLayerTreeGroup *parentGroup, bool splitLayer );
119 
121  void setColumns( QList<Atom> &atomList );
122 
127  QSizeF drawTitle( QPainter *painter = nullptr, QPointF point = QPointF(), Qt::AlignmentFlag halignment = Qt::AlignLeft, double legendWidth = 0 );
128 
129  double spaceAboveAtom( const Atom &atom );
130 
135  QSizeF drawAtom( const Atom &atom, QPainter *painter = nullptr, QPointF point = QPointF() );
136 
137  Nucleon drawSymbolItem( QgsLayerTreeModelLegendNode *symbolItem, QPainter *painter = nullptr, QPointF point = QPointF(), double labelXOffset = 0 );
138 
140  QSizeF drawLayerTitle( QgsLayerTreeLayer *nodeLayer, QPainter *painter = nullptr, QPointF point = QPointF() );
141 
146  QSizeF drawGroupTitle( QgsLayerTreeGroup *nodeGroup, QPainter *painter = nullptr, QPointF point = QPointF() );
147 
148  QgsLegendStyle::Style nodeLegendStyle( QgsLayerTreeNode *node );
149 
150  private:
151  QgsLayerTreeModel *mLegendModel = nullptr;
152 
153  QgsLegendSettings mSettings;
154 
155  QSizeF mLegendSize;
156 
157 #endif
158 };
159 
160 #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.
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.