QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 
22 class QDomDocument;
23 class QDomElement;
24 
25 class QgsLayerTreeLayer;
27 class QgsMeshLayer;
28 class QgsPluginLayer;
29 class QgsRasterLayer;
30 class QgsPointCloudLayer;
32 class QgsVectorLayer;
35 class QgsSymbol;
36 
37 #include "qgis_core.h"
38 
39 
47 class 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:
94  void itemsChanged();
95 };
96 
97 
104 class 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  QgsTextFormat textOnSymbolTextFormat() const { return mTextOnSymbolTextFormat; }
264 
269  void setTextOnSymbolTextFormat( const QgsTextFormat &format ) { mTextOnSymbolTextFormat = format; }
270 
276  QHash<QString, QString> textOnSymbolContent() const { return mTextOnSymbolContent; }
277 
283  void setTextOnSymbolContent( const QHash<QString, QString> &content ) { mTextOnSymbolContent = content; }
284 
285  QList<QgsLayerTreeModelLegendNode *> createLayerTreeModelLegendNodes( QgsLayerTreeLayer *nodeLayer ) SIP_FACTORY override;
286  void readXml( const QDomElement &elem, const QgsReadWriteContext &context ) override;
287  QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const override;
288 
289  private:
290  QgsVectorLayer *mLayer = nullptr;
291 
292  // text on symbol
293  bool mTextOnSymbolEnabled = false;
294  QgsTextFormat mTextOnSymbolTextFormat;
295  QHash<QString, QString> mTextOnSymbolContent;
296 };
297 
298 
305 {
306  Q_OBJECT
307 
308  public:
310 
311  QList<QgsLayerTreeModelLegendNode *> createLayerTreeModelLegendNodes( QgsLayerTreeLayer *nodeLayer ) SIP_FACTORY override;
312 
313  private:
314  QgsRasterLayer *mLayer = nullptr;
315 };
316 
317 
324 {
325  Q_OBJECT
326 
327  public:
329  explicit QgsDefaultMeshLayerLegend( QgsMeshLayer *ml );
330 
331  QList<QgsLayerTreeModelLegendNode *> createLayerTreeModelLegendNodes( QgsLayerTreeLayer *nodeLayer ) SIP_FACTORY override;
332 
333  private:
334  QgsMeshLayer *mLayer = nullptr;
335 };
336 
343 {
344  Q_OBJECT
345 
346  public:
349 
350  QList<QgsLayerTreeModelLegendNode *> createLayerTreeModelLegendNodes( QgsLayerTreeLayer *nodeLayer ) SIP_FACTORY override;
351 
352  private:
353  QgsPointCloudLayer *mLayer = nullptr;
354 };
355 
356 
357 #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.
QHash< QString, QString > textOnSymbolContent() const
Returns per-symbol content of labels for "text on symbol" functionality.
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.
void setTextOnSymbolTextFormat(const QgsTextFormat &format)
Sets text format of symbol 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:95
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:65
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