QGIS API Documentation 3.43.0-Master (c67cf405802)
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 <memory>
20#include <QObject>
21#include "qgis_sip.h"
22
23class QDomDocument;
24class QDomElement;
25
28class QgsMeshLayer;
29class QgsPluginLayer;
30class QgsRasterLayer;
33class QgsVectorLayer;
36class QgsSymbol;
37
38#include "qgis_core.h"
39
40
46class CORE_EXPORT QgsMapLayerLegend : public QObject
47{
48 Q_OBJECT
49 public:
50
52 explicit QgsMapLayerLegend( QObject *parent SIP_TRANSFERTHIS = nullptr );
53
54 // TODO: type
55
60 virtual void readXml( const QDomElement &elem, const QgsReadWriteContext &context );
61
66 virtual QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const;
67
72 virtual QList<QgsLayerTreeModelLegendNode *> createLayerTreeModelLegendNodes( QgsLayerTreeLayer *nodeLayer ) = 0 SIP_FACTORY;
73
74 // TODO: support for layer tree view delegates
75
77 static QgsMapLayerLegend *defaultVectorLegend( QgsVectorLayer *vl ) SIP_FACTORY;
78
80 static QgsMapLayerLegend *defaultRasterLegend( QgsRasterLayer *rl ) SIP_FACTORY;
81
83 static QgsMapLayerLegend *defaultMeshLegend( QgsMeshLayer *ml ) SIP_FACTORY;
84
89 static QgsMapLayerLegend *defaultPointCloudLegend( QgsPointCloudLayer *layer ) SIP_FACTORY;
90
91 signals:
94};
95
96
101class CORE_EXPORT QgsMapLayerLegendUtils
102{
103 public:
104 static void setLegendNodeOrder( QgsLayerTreeLayer *nodeLayer, const QList<int> &order );
105 static QList<int> legendNodeOrder( QgsLayerTreeLayer *nodeLayer );
106 static bool hasLegendNodeOrder( QgsLayerTreeLayer *nodeLayer );
107
108 static void setLegendNodeUserLabel( QgsLayerTreeLayer *nodeLayer, int originalIndex, const QString &newLabel );
109 static QString legendNodeUserLabel( QgsLayerTreeLayer *nodeLayer, int originalIndex );
110 static bool hasLegendNodeUserLabel( QgsLayerTreeLayer *nodeLayer, int originalIndex );
111
118 static void setLegendNodePatchShape( QgsLayerTreeLayer *nodeLayer, int originalIndex, const QgsLegendPatchShape &shape );
119
126 static QgsLegendPatchShape legendNodePatchShape( QgsLayerTreeLayer *nodeLayer, int originalIndex );
127
137 static void setLegendNodeSymbolSize( QgsLayerTreeLayer *nodeLayer, int originalIndex, QSizeF size );
138
148 static QSizeF legendNodeSymbolSize( QgsLayerTreeLayer *nodeLayer, int originalIndex );
149
159 static void setLegendNodeCustomSymbol( QgsLayerTreeLayer *nodeLayer, int originalIndex, const QgsSymbol *symbol );
160
172 static std::unique_ptr< QgsSymbol > legendNodeCustomSymbol( QgsLayerTreeLayer *nodeLayer, int originalIndex );
173
185 static void setLegendNodeColorRampSettings( QgsLayerTreeLayer *nodeLayer, int originalIndex, const QgsColorRampLegendNodeSettings *settings );
186
200 static QgsColorRampLegendNodeSettings *legendNodeColorRampSettings( QgsLayerTreeLayer *nodeLayer, int originalIndex ) SIP_FACTORY;
201
202
209 static void setLegendNodeColumnBreak( QgsLayerTreeLayer *nodeLayer, int originalIndex, bool columnBreakBeforeNode );
210
217 static bool legendNodeColumnBreak( QgsLayerTreeLayer *nodeLayer, int originalIndex );
218
220 static void applyLayerNodeProperties( QgsLayerTreeLayer *nodeLayer, QList<QgsLayerTreeModelLegendNode *> &nodes );
221};
222
223
224#include <QHash>
225
226#include "qgstextformat.h"
227
233{
234 Q_OBJECT
235
236 public:
238
245 bool textOnSymbolEnabled() const { return mTextOnSymbolEnabled; }
246
253 void setTextOnSymbolEnabled( bool enabled ) { mTextOnSymbolEnabled = enabled; }
254
259 bool showLabelLegend() const { return mShowLabelLegend; }
260
266 void setShowLabelLegend( bool enabled ) { mShowLabelLegend = enabled; }
267
272 QgsTextFormat textOnSymbolTextFormat() const { return mTextOnSymbolTextFormat; }
273
278 void setTextOnSymbolTextFormat( const QgsTextFormat &format ) { mTextOnSymbolTextFormat = format; }
279
285 QHash<QString, QString> textOnSymbolContent() const { return mTextOnSymbolContent; }
286
292 void setTextOnSymbolContent( const QHash<QString, QString> &content ) { mTextOnSymbolContent = content; }
293
294 QList<QgsLayerTreeModelLegendNode *> createLayerTreeModelLegendNodes( QgsLayerTreeLayer *nodeLayer ) SIP_FACTORY override;
295 void readXml( const QDomElement &elem, const QgsReadWriteContext &context ) override;
296 QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const override;
297
298 private:
299 QgsVectorLayer *mLayer = nullptr;
300
301 // text on symbol
302 bool mTextOnSymbolEnabled = false;
303 bool mShowLabelLegend = false;
304 QgsTextFormat mTextOnSymbolTextFormat;
305 QHash<QString, QString> mTextOnSymbolContent;
306};
307
308
314{
315 Q_OBJECT
316
317 public:
319
320 QList<QgsLayerTreeModelLegendNode *> createLayerTreeModelLegendNodes( QgsLayerTreeLayer *nodeLayer ) SIP_FACTORY override;
321
322 private:
323 QgsRasterLayer *mLayer = nullptr;
324};
325
326
333{
334 Q_OBJECT
335
336 public:
339
340 QList<QgsLayerTreeModelLegendNode *> createLayerTreeModelLegendNodes( QgsLayerTreeLayer *nodeLayer ) SIP_FACTORY override;
341
342 private:
343 QgsMeshLayer *mLayer = nullptr;
344};
345
352{
353 Q_OBJECT
354
355 public:
358
359 QList<QgsLayerTreeModelLegendNode *> createLayerTreeModelLegendNodes( QgsLayerTreeLayer *nodeLayer ) SIP_FACTORY override;
360
361 private:
362 QgsPointCloudLayer *mLayer = nullptr;
363};
364
365
366#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.
An abstract interface for legend items returned from QgsMapLayerLegend implementation.
Represents a patch shape for use in map legends.
Miscellaneous utility functions for handling of map layer legend.
An 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.
Base class for plugin layers.
Represents a map layer supporting display of point clouds.
Represents a raster layer.
A container for the context for various read/write operations on objects.
Abstract base class for all rendered symbols.
Definition qgssymbol.h:231
Container for all settings relating to text rendering.
Represents a vector layer which manages a vector based dataset.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_FACTORY
Definition qgis_sip.h:76