QGIS API Documentation 3.37.0-Master (c2d15952569)
Loading...
Searching...
No Matches
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
22class QRectF;
23class QStandardItem;
24class QJsonObject;
25
31class QgsSymbol;
33
34#include "qgslegendsettings.h"
35
45class 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
88 Q_DECL_DEPRECATED void drawLegend( QPainter *painter ) SIP_DEPRECATED;
89
95 void drawLegend( QgsRenderContext &context );
96
102 QJsonObject exportLegendToJson( const QgsRenderContext &context );
103
109 static void setNodeLegendStyle( QgsLayerTreeNode *node, QgsLegendStyle::Style style );
110
116 static QgsLegendStyle::Style nodeLegendStyle( QgsLayerTreeNode *node, QgsLayerTreeModel *model );
117
118 private:
119
120#ifndef SIP_RUN
121
129 class LegendComponent
130 {
131 public:
132
133 LegendComponent() = default;
134
135 QObject *item = nullptr;
136
138 QSizeF symbolSize;
139
141 QSizeF labelSize;
142
144 QSizeF size;
145
150 double indent = 0;
151
158 double labelXOffset = 0.0;
159
164 double maxSiblingSymbolWidth = 0.0;
165 };
166
181 class LegendComponentGroup
182 {
183 public:
184
186 QList<LegendComponent> components;
187
189 QSizeF size = QSizeF( 0, 0 );
190
192 int column = 0;
193
197 bool placeColumnBreakBeforeGroup = false;
198
199 };
200
204 class ColumnContext
205 {
206 public:
207
208 ColumnContext()
209 : left( 0 )
210 , right( 0 )
211 {}
212
214 double left = 0;
216 double right = 0;
217 };
218
223 QList<LegendComponentGroup> createComponentGroupList( QgsLayerTreeGroup *parentGroup, QgsRenderContext &context, double indent = 0 );
224
230 int setColumns( QList<LegendComponentGroup> &groupList );
231
235 double spaceAboveGroup( const LegendComponentGroup &group );
236
242 QJsonObject exportLegendToJson( const QgsRenderContext &context, QgsLayerTreeGroup *nodeGroup );
243
250 QSizeF paintAndDetermineSize( QgsRenderContext &context );
251
259 QSizeF drawTitle( QgsRenderContext &context, double top, Qt::AlignmentFlag halignment = Qt::AlignLeft, double legendWidth = 0 ) const;
260
269 QSizeF drawGroup( const LegendComponentGroup &group, QgsRenderContext &context, ColumnContext columnContext, double top = 0 );
270
274 LegendComponent drawSymbolItem( QgsLayerTreeModelLegendNode *symbolItem, QgsRenderContext &context, ColumnContext columnContext, double top, double maxSiblingSymbolWidth = 0 );
275
283 QSizeF drawLayerTitle( QgsLayerTreeLayer *nodeLayer, QgsRenderContext &context, ColumnContext columnContext = ColumnContext(), double top = 0 );
284
290 QSizeF drawGroupTitle( QgsLayerTreeGroup *nodeGroup, QgsRenderContext &context, ColumnContext columnContext = ColumnContext(), double top = 0 );
291
295 QgsLegendStyle::Style nodeLegendStyle( QgsLayerTreeNode *node );
296
297 QgsLayerTreeModel *mLegendModel = nullptr;
298
299 QgsLegendSettings mSettings;
300
301 QSizeF mLegendSize;
302
303#endif
304
305 void widthAndOffsetForTitleText( const Qt::AlignmentFlag halignment, double legendWidth, double &width, double &offset ) const;
306};
307
308#endif // QGSLEGENDRENDERER_H
Layer tree group node serves as a container for layers and further groups.
Layer tree node points to a map layer.
The QgsLegendRendererItem class is abstract interface for legend items returned from QgsMapLayerLegen...
The QgsLayerTreeModel class is model implementation for Qt item views framework.
This class is a base class for nodes in a layer tree.
The QgsLegendRenderer class handles automatic layout and rendering of legend.
void setLegendSize(QSizeF s)
Sets the preferred resulting legend size.
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...
Style
Component of legends which can be styled.
Contains information about the context of a rendering operation.
Abstract base class for all rendered symbols.
Definition qgssymbol.h:94
#define SIP_DEPRECATED
Definition qgis_sip.h:106