QGIS API Documentation 3.39.0-Master (be2050b798e)
Loading...
Searching...
No Matches
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
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
102class CORE_EXPORT QgsMapLayerLegendUtils
103{
104 public:
105 static void setLegendNodeOrder( QgsLayerTreeLayer *nodeLayer, const QList<int> &order );
106 static QList<int> legendNodeOrder( QgsLayerTreeLayer *nodeLayer );
107 static bool hasLegendNodeOrder( QgsLayerTreeLayer *nodeLayer );
108
109 static void setLegendNodeUserLabel( QgsLayerTreeLayer *nodeLayer, int originalIndex, const QString &newLabel );
110 static QString legendNodeUserLabel( QgsLayerTreeLayer *nodeLayer, int originalIndex );
111 static bool hasLegendNodeUserLabel( QgsLayerTreeLayer *nodeLayer, int originalIndex );
112
119 static void setLegendNodePatchShape( QgsLayerTreeLayer *nodeLayer, int originalIndex, const QgsLegendPatchShape &shape );
120
127 static QgsLegendPatchShape legendNodePatchShape( QgsLayerTreeLayer *nodeLayer, int originalIndex );
128
138 static void setLegendNodeSymbolSize( QgsLayerTreeLayer *nodeLayer, int originalIndex, QSizeF size );
139
149 static QSizeF legendNodeSymbolSize( QgsLayerTreeLayer *nodeLayer, int originalIndex );
150
160 static void setLegendNodeCustomSymbol( QgsLayerTreeLayer *nodeLayer, int originalIndex, const QgsSymbol *symbol );
161
173 static QgsSymbol *legendNodeCustomSymbol( QgsLayerTreeLayer *nodeLayer, int originalIndex ) SIP_FACTORY;
174
186 static void setLegendNodeColorRampSettings( QgsLayerTreeLayer *nodeLayer, int originalIndex, const QgsColorRampLegendNodeSettings *settings );
187
201 static QgsColorRampLegendNodeSettings *legendNodeColorRampSettings( QgsLayerTreeLayer *nodeLayer, int originalIndex ) SIP_FACTORY;
202
203
210 static void setLegendNodeColumnBreak( QgsLayerTreeLayer *nodeLayer, int originalIndex, bool columnBreakBeforeNode );
211
218 static bool legendNodeColumnBreak( QgsLayerTreeLayer *nodeLayer, int originalIndex );
219
221 static void applyLayerNodeProperties( QgsLayerTreeLayer *nodeLayer, QList<QgsLayerTreeModelLegendNode *> &nodes );
222};
223
224
225#include <QHash>
226
227#include "qgstextformat.h"
228
234{
235 Q_OBJECT
236
237 public:
239
246 bool textOnSymbolEnabled() const { return mTextOnSymbolEnabled; }
247
254 void setTextOnSymbolEnabled( bool enabled ) { mTextOnSymbolEnabled = enabled; }
255
260 bool showLabelLegend() const { return mShowLabelLegend; }
261
267 void setShowLabelLegend( bool enabled ) { mShowLabelLegend = enabled; }
268
273 QgsTextFormat textOnSymbolTextFormat() const { return mTextOnSymbolTextFormat; }
274
279 void setTextOnSymbolTextFormat( const QgsTextFormat &format ) { mTextOnSymbolTextFormat = format; }
280
286 QHash<QString, QString> textOnSymbolContent() const { return mTextOnSymbolContent; }
287
293 void setTextOnSymbolContent( const QHash<QString, QString> &content ) { mTextOnSymbolContent = content; }
294
295 QList<QgsLayerTreeModelLegendNode *> createLayerTreeModelLegendNodes( QgsLayerTreeLayer *nodeLayer ) SIP_FACTORY override;
296 void readXml( const QDomElement &elem, const QgsReadWriteContext &context ) override;
297 QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const override;
298
299 private:
300 QgsVectorLayer *mLayer = nullptr;
301
302 // text on symbol
303 bool mTextOnSymbolEnabled = false;
304 bool mShowLabelLegend = false;
305 QgsTextFormat mTextOnSymbolTextFormat;
306 QHash<QString, QString> mTextOnSymbolContent;
307};
308
309
315{
316 Q_OBJECT
317
318 public:
320
321 QList<QgsLayerTreeModelLegendNode *> createLayerTreeModelLegendNodes( QgsLayerTreeLayer *nodeLayer ) SIP_FACTORY override;
322
323 private:
324 QgsRasterLayer *mLayer = nullptr;
325};
326
327
334{
335 Q_OBJECT
336
337 public:
340
341 QList<QgsLayerTreeModelLegendNode *> createLayerTreeModelLegendNodes( QgsLayerTreeLayer *nodeLayer ) SIP_FACTORY override;
342
343 private:
344 QgsMeshLayer *mLayer = nullptr;
345};
346
353{
354 Q_OBJECT
355
356 public:
359
360 QList<QgsLayerTreeModelLegendNode *> createLayerTreeModelLegendNodes( QgsLayerTreeLayer *nodeLayer ) SIP_FACTORY override;
361
362 private:
363 QgsPointCloudLayer *mLayer = nullptr;
364};
365
366
367#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.
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:94
Container for all settings relating to text rendering.
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