QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
qgsmaplayerlegend.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsmaplayerlegend.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 QGSMAPLAYERLEGEND_H
17#define QGSMAPLAYERLEGEND_H
18
19#include <QObject>
20#include "qgis_sip.h"
21
22class QDomDocument;
23class QDomElement;
24
27class QgsMeshLayer;
28class QgsPluginLayer;
29class QgsRasterLayer;
32class QgsVectorLayer;
35class QgsSymbol;
36
37#include "qgis_core.h"
38
39
47class CORE_EXPORT QgsMapLayerLegend : public QObject
48{
49 Q_OBJECT
50 public:
51
53 explicit QgsMapLayerLegend( QObject *parent SIP_TRANSFERTHIS = nullptr );
54
55 // TODO: type
56
61 virtual void readXml( const QDomElement &elem, const QgsReadWriteContext &context );
62
67 virtual QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const;
68
73 virtual QList<QgsLayerTreeModelLegendNode *> createLayerTreeModelLegendNodes( QgsLayerTreeLayer *nodeLayer ) = 0 SIP_FACTORY;
74
75 // TODO: support for layer tree view delegates
76
78 static QgsMapLayerLegend *defaultVectorLegend( QgsVectorLayer *vl ) SIP_FACTORY;
79
81 static QgsMapLayerLegend *defaultRasterLegend( QgsRasterLayer *rl ) SIP_FACTORY;
82
84 static QgsMapLayerLegend *defaultMeshLegend( QgsMeshLayer *ml ) SIP_FACTORY;
85
90 static QgsMapLayerLegend *defaultPointCloudLegend( QgsPointCloudLayer *layer ) SIP_FACTORY;
91
92 signals:
95};
96
97
104class CORE_EXPORT QgsMapLayerLegendUtils
105{
106 public:
107 static void setLegendNodeOrder( QgsLayerTreeLayer *nodeLayer, const QList<int> &order );
108 static QList<int> legendNodeOrder( QgsLayerTreeLayer *nodeLayer );
109 static bool hasLegendNodeOrder( QgsLayerTreeLayer *nodeLayer );
110
111 static void setLegendNodeUserLabel( QgsLayerTreeLayer *nodeLayer, int originalIndex, const QString &newLabel );
112 static QString legendNodeUserLabel( QgsLayerTreeLayer *nodeLayer, int originalIndex );
113 static bool hasLegendNodeUserLabel( QgsLayerTreeLayer *nodeLayer, int originalIndex );
114
121 static void setLegendNodePatchShape( QgsLayerTreeLayer *nodeLayer, int originalIndex, const QgsLegendPatchShape &shape );
122
129 static QgsLegendPatchShape legendNodePatchShape( QgsLayerTreeLayer *nodeLayer, int originalIndex );
130
140 static void setLegendNodeSymbolSize( QgsLayerTreeLayer *nodeLayer, int originalIndex, QSizeF size );
141
151 static QSizeF legendNodeSymbolSize( QgsLayerTreeLayer *nodeLayer, int originalIndex );
152
162 static void setLegendNodeCustomSymbol( QgsLayerTreeLayer *nodeLayer, int originalIndex, const QgsSymbol *symbol );
163
175 static QgsSymbol *legendNodeCustomSymbol( QgsLayerTreeLayer *nodeLayer, int originalIndex ) SIP_FACTORY;
176
188 static void setLegendNodeColorRampSettings( QgsLayerTreeLayer *nodeLayer, int originalIndex, const QgsColorRampLegendNodeSettings *settings );
189
203 static QgsColorRampLegendNodeSettings *legendNodeColorRampSettings( QgsLayerTreeLayer *nodeLayer, int originalIndex ) SIP_FACTORY;
204
205
212 static void setLegendNodeColumnBreak( QgsLayerTreeLayer *nodeLayer, int originalIndex, bool columnBreakBeforeNode );
213
220 static bool legendNodeColumnBreak( QgsLayerTreeLayer *nodeLayer, int originalIndex );
221
223 static void applyLayerNodeProperties( QgsLayerTreeLayer *nodeLayer, QList<QgsLayerTreeModelLegendNode *> &nodes );
224};
225
226
227#include <QHash>
228
229#include "qgstextformat.h"
230
237{
238 Q_OBJECT
239
240 public:
242
249 bool textOnSymbolEnabled() const { return mTextOnSymbolEnabled; }
250
257 void setTextOnSymbolEnabled( bool enabled ) { mTextOnSymbolEnabled = enabled; }
258
263 bool showLabelLegend() const { return mShowLabelLegend; }
264
270 void setShowLabelLegend( bool enabled ) { mShowLabelLegend = enabled; }
271
276 QgsTextFormat textOnSymbolTextFormat() const { return mTextOnSymbolTextFormat; }
277
282 void setTextOnSymbolTextFormat( const QgsTextFormat &format ) { mTextOnSymbolTextFormat = format; }
283
289 QHash<QString, QString> textOnSymbolContent() const { return mTextOnSymbolContent; }
290
296 void setTextOnSymbolContent( const QHash<QString, QString> &content ) { mTextOnSymbolContent = content; }
297
298 QList<QgsLayerTreeModelLegendNode *> createLayerTreeModelLegendNodes( QgsLayerTreeLayer *nodeLayer ) SIP_FACTORY override;
299 void readXml( const QDomElement &elem, const QgsReadWriteContext &context ) override;
300 QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const override;
301
302 private:
303 QgsVectorLayer *mLayer = nullptr;
304
305 // text on symbol
306 bool mTextOnSymbolEnabled = false;
307 bool mShowLabelLegend = false;
308 QgsTextFormat mTextOnSymbolTextFormat;
309 QHash<QString, QString> mTextOnSymbolContent;
310};
311
312
319{
320 Q_OBJECT
321
322 public:
324
325 QList<QgsLayerTreeModelLegendNode *> createLayerTreeModelLegendNodes( QgsLayerTreeLayer *nodeLayer ) SIP_FACTORY override;
326
327 private:
328 QgsRasterLayer *mLayer = nullptr;
329};
330
331
338{
339 Q_OBJECT
340
341 public:
344
345 QList<QgsLayerTreeModelLegendNode *> createLayerTreeModelLegendNodes( QgsLayerTreeLayer *nodeLayer ) SIP_FACTORY override;
346
347 private:
348 QgsMeshLayer *mLayer = nullptr;
349};
350
357{
358 Q_OBJECT
359
360 public:
363
364 QList<QgsLayerTreeModelLegendNode *> createLayerTreeModelLegendNodes( QgsLayerTreeLayer *nodeLayer ) SIP_FACTORY override;
365
366 private:
367 QgsPointCloudLayer *mLayer = nullptr;
368};
369
370
371#endif // QGSMAPLAYERLEGEND_H
Settings for a color ramp legend node.
Default legend implementation for mesh layers.
Default legend implementation for point cloud layers.
Default legend implementation for raster layers.
Default legend implementation for vector layers.
void setTextOnSymbolEnabled(bool enabled)
Sets whether the "text on symbol" functionality is enabled.
void setTextOnSymbolContent(const QHash< QString, QString > &content)
Sets per-symbol content of labels for "text on symbol" functionality.
void setShowLabelLegend(bool enabled)
Sets if a legend for the labeling should be shown.
bool textOnSymbolEnabled() const
Returns whether the "text on symbol" functionality is enabled.
QgsTextFormat textOnSymbolTextFormat() const
Returns text format of symbol labels for "text on symbol" functionality.
bool showLabelLegend() const
Returns whether the legend for the labeling is shown.
void setTextOnSymbolTextFormat(const QgsTextFormat &format)
Sets text format of symbol labels for "text on symbol" functionality.
QHash< QString, QString > textOnSymbolContent() const
Returns per-symbol content of labels for "text on symbol" functionality.
Layer tree node points to a map layer.
The QgsLegendRendererItem class is abstract interface for legend items returned from QgsMapLayerLegen...
Represents a patch shape for use in map legends.
Miscellaneous utility functions for handling of map layer legend.
The QgsMapLayerLegend class is abstract interface for implementations of legends for one map layer.
virtual QList< QgsLayerTreeModelLegendNode * > createLayerTreeModelLegendNodes(QgsLayerTreeLayer *nodeLayer)=0
Returns list of legend nodes to be used for a particular layer tree layer node.
void itemsChanged()
Emitted when existing items/nodes got invalid and should be replaced by new ones.
Represents a mesh layer supporting display of data on structured or unstructured meshes.
Definition: qgsmeshlayer.h:100
Base class for plugin layers.
Represents a map layer supporting display of point clouds.
Represents a raster layer.
The class is used as a container of context for various read/write operations on other objects.
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:93
Container for all settings relating to text rendering.
Definition: qgstextformat.h:41
Represents a vector layer which manages a vector based data sets.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
#define SIP_FACTORY
Definition: qgis_sip.h:76