QGIS API Documentation 3.41.0-Master (3440c17df1d)
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;
34
35#include "qgslegendsettings.h"
36
47class CORE_EXPORT QgsLegendRenderer
48{
49 public:
50
55 QgsLegendRenderer( QgsLayerTreeModel *legendModel, const QgsLegendSettings &settings );
57
58#ifndef SIP_RUN
59 QgsLegendRenderer( const QgsLegendRenderer &other ) = delete;
62#endif
63
72 QgsLayerTreeFilterProxyModel *proxyModel();
73
79 QSizeF minimumSize( QgsRenderContext *renderContext = nullptr );
80
89 void setLegendSize( QSizeF s ) { mLegendSize = s; }
90
99 QSizeF legendSize() const { return mLegendSize; }
100
107 Q_DECL_DEPRECATED void drawLegend( QPainter *painter ) SIP_DEPRECATED;
108
114 void drawLegend( QgsRenderContext &context );
115
121 QJsonObject exportLegendToJson( const QgsRenderContext &context );
122
128 static void setNodeLegendStyle( QgsLayerTreeNode *node, QgsLegendStyle::Style style );
129
135 static QgsLegendStyle::Style nodeLegendStyle( QgsLayerTreeNode *node, QgsLayerTreeModel *model );
136
137 private:
138
139#ifndef SIP_RUN
140
148 class LegendComponent
149 {
150 public:
151
152 LegendComponent() = default;
153
154 QObject *item = nullptr;
155
157 QSizeF symbolSize;
158
160 QSizeF labelSize;
161
163 QSizeF size;
164
169 double indent = 0;
170
177 double labelXOffset = 0.0;
178
183 double maxSiblingSymbolWidth = 0.0;
184 };
185
200 class LegendComponentGroup
201 {
202 public:
203
205 QList<LegendComponent> components;
206
208 QSizeF size = QSizeF( 0, 0 );
209
211 int column = 0;
212
216 bool placeColumnBreakBeforeGroup = false;
217
218 };
219
223 class ColumnContext
224 {
225 public:
226
227 ColumnContext()
228 : left( 0 )
229 , right( 0 )
230 {}
231
233 double left = 0;
235 double right = 0;
236 };
237
242 QList<LegendComponentGroup> createComponentGroupList( QgsLayerTreeGroup *parentGroup, QgsRenderContext &context, double indent = 0 );
243
249 int setColumns( QList<LegendComponentGroup> &groupList );
250
254 double spaceAboveGroup( const LegendComponentGroup &group );
255
261 QJsonObject exportLegendToJson( const QgsRenderContext &context, QgsLayerTreeGroup *nodeGroup );
262
269 QSizeF paintAndDetermineSize( QgsRenderContext &context );
270
278 QSizeF drawTitle( QgsRenderContext &context, double top, Qt::AlignmentFlag halignment = Qt::AlignLeft, double legendWidth = 0 ) const;
279
288 QSizeF drawGroup( const LegendComponentGroup &group, QgsRenderContext &context, ColumnContext columnContext, double top = 0 );
289
293 LegendComponent drawSymbolItem( QgsLayerTreeModelLegendNode *symbolItem, QgsRenderContext &context, ColumnContext columnContext, double top, double maxSiblingSymbolWidth = 0 );
294
302 QSizeF drawLayerTitle( QgsLayerTreeLayer *nodeLayer, QgsRenderContext &context, ColumnContext columnContext = ColumnContext(), double top = 0 );
303
309 QSizeF drawGroupTitle( QgsLayerTreeGroup *nodeGroup, QgsRenderContext &context, ColumnContext columnContext = ColumnContext(), double top = 0 );
310
314 QgsLegendStyle::Style nodeLegendStyle( QgsLayerTreeNode *node );
315
316 QgsLayerTreeModel *mLegendModel = nullptr;
317 std::unique_ptr< QgsLayerTreeFilterProxyModel >mProxyModel;
318
319 QgsLegendSettings mSettings;
320
321 QSizeF mLegendSize;
322
323#endif
324
325#ifdef SIP_RUN
326 QgsLegendRenderer( const QgsLegendRenderer &other );
327#endif
328
329 void widthAndOffsetForTitleText( const Qt::AlignmentFlag halignment, double legendWidth, double &width, double &offset ) const;
330};
331
332#endif // QGSLEGENDRENDERER_H
QgsLayerTreeFilterProxyModel is a sort filter proxy model to easily reproduce the legend/layer tree i...
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.
Handles automatic layout and rendering of legends.
void setLegendSize(QSizeF s)
Sets the preferred resulting legend size.
QSizeF legendSize() const
Returns the preferred legend size set by the client.
QgsLegendRenderer & operator=(const QgsLegendRenderer &other)=delete
QgsLegendRenderer(const QgsLegendRenderer &other)=delete
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:231
#define SIP_DEPRECATED
Definition qgis_sip.h:106