QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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;
31 class QgsVectorLayer;
32 
33 #include "qgis_core.h"
34 
35 
43 class CORE_EXPORT QgsMapLayerLegend : public QObject
44 {
45  Q_OBJECT
46  public:
47 
49  explicit QgsMapLayerLegend( QObject *parent SIP_TRANSFERTHIS = nullptr );
50 
51  // TODO: type
52 
57  virtual void readXml( const QDomElement &elem, const QgsReadWriteContext &context );
58 
63  virtual QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const;
64 
69  virtual QList<QgsLayerTreeModelLegendNode *> createLayerTreeModelLegendNodes( QgsLayerTreeLayer *nodeLayer ) = 0 SIP_FACTORY;
70 
71  // TODO: support for layer tree view delegates
72 
74  static QgsMapLayerLegend *defaultVectorLegend( QgsVectorLayer *vl ) SIP_FACTORY;
75 
77  static QgsMapLayerLegend *defaultRasterLegend( QgsRasterLayer *rl ) SIP_FACTORY;
78 
80  static QgsMapLayerLegend *defaultMeshLegend( QgsMeshLayer *ml ) SIP_FACTORY;
81 
82  signals:
84  void itemsChanged();
85 };
86 
87 
94 class CORE_EXPORT QgsMapLayerLegendUtils
95 {
96  public:
97  static void setLegendNodeOrder( QgsLayerTreeLayer *nodeLayer, const QList<int> &order );
98  static QList<int> legendNodeOrder( QgsLayerTreeLayer *nodeLayer );
99  static bool hasLegendNodeOrder( QgsLayerTreeLayer *nodeLayer );
100 
101  static void setLegendNodeUserLabel( QgsLayerTreeLayer *nodeLayer, int originalIndex, const QString &newLabel );
102  static QString legendNodeUserLabel( QgsLayerTreeLayer *nodeLayer, int originalIndex );
103  static bool hasLegendNodeUserLabel( QgsLayerTreeLayer *nodeLayer, int originalIndex );
104 
106  static void applyLayerNodeProperties( QgsLayerTreeLayer *nodeLayer, QList<QgsLayerTreeModelLegendNode *> &nodes );
107 };
108 
109 
110 #include <QHash>
111 
112 #include "qgstextrenderer.h"
113 
120 {
121  Q_OBJECT
122 
123  public:
125 
132  bool textOnSymbolEnabled() const { return mTextOnSymbolEnabled; }
133 
140  void setTextOnSymbolEnabled( bool enabled ) { mTextOnSymbolEnabled = enabled; }
141 
146  QgsTextFormat textOnSymbolTextFormat() const { return mTextOnSymbolTextFormat; }
147 
152  void setTextOnSymbolTextFormat( const QgsTextFormat &format ) { mTextOnSymbolTextFormat = format; }
153 
159  QHash<QString, QString> textOnSymbolContent() const { return mTextOnSymbolContent; }
160 
166  void setTextOnSymbolContent( const QHash<QString, QString> &content ) { mTextOnSymbolContent = content; }
167 
168  QList<QgsLayerTreeModelLegendNode *> createLayerTreeModelLegendNodes( QgsLayerTreeLayer *nodeLayer ) SIP_FACTORY override;
169  void readXml( const QDomElement &elem, const QgsReadWriteContext &context ) override;
170  QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const override;
171 
172  private:
173  QgsVectorLayer *mLayer = nullptr;
174 
175  // text on symbol
176  bool mTextOnSymbolEnabled = false;
177  QgsTextFormat mTextOnSymbolTextFormat;
178  QHash<QString, QString> mTextOnSymbolContent;
179 };
180 
181 
188 {
189  Q_OBJECT
190 
191  public:
193 
194  QList<QgsLayerTreeModelLegendNode *> createLayerTreeModelLegendNodes( QgsLayerTreeLayer *nodeLayer ) SIP_FACTORY override;
195 
196  private:
197  QgsRasterLayer *mLayer = nullptr;
198 };
199 
200 
207 {
208  Q_OBJECT
209 
210  public:
212  explicit QgsDefaultMeshLayerLegend( QgsMeshLayer *ml );
213 
214  QList<QgsLayerTreeModelLegendNode *> createLayerTreeModelLegendNodes( QgsLayerTreeLayer *nodeLayer ) SIP_FACTORY override;
215 
216  private:
217  QgsMeshLayer *mLayer = nullptr;
218 };
219 
220 
221 #endif // QGSMAPLAYERLEGEND_H
The class is used as a container of context for various read/write operations on other objects...
virtual QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Writes configuration to a DOM element, to be used later with readXml()
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
QHash< QString, QString > textOnSymbolContent() const
Returns per-symbol content of labels for "text on symbol" functionality.
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
Base class for plugin layers.
Default legend implementation for mesh layers.
Default legend implementation for raster layers.
void setTextOnSymbolTextFormat(const QgsTextFormat &format)
Sets text format of symbol labels for "text on symbol" functionality.
void setTextOnSymbolContent(const QHash< QString, QString > &content)
Sets per-symbol content of labels for "text on symbol" functionality.
virtual QList< QgsLayerTreeModelLegendNode * > createLayerTreeModelLegendNodes(QgsLayerTreeLayer *nodeLayer)=0
Returns list of legend nodes to be used for a particular layer tree layer node.
The QgsMapLayerLegend class is abstract interface for implementations of legends for one map layer...
Miscellaneous utility functions for handling of map layer legend.
#define SIP_FACTORY
Definition: qgis_sip.h:76
void setTextOnSymbolEnabled(bool enabled)
Sets whether the "text on symbol" functionality is enabled.
bool textOnSymbolEnabled() const
Returns whether the "text on symbol" functionality is enabled.
The QgsLegendRendererItem class is abstract interface for legend items returned from QgsMapLayerLegen...
Represents a mesh layer supporting display of data on structured or unstructured meshes.
Definition: qgsmeshlayer.h:90
Container for all settings relating to text rendering.
Default legend implementation for vector layers.
QgsTextFormat textOnSymbolTextFormat() const
Returns text format of symbol labels for "text on symbol" functionality.
Represents a vector layer which manages a vector based data sets.
virtual void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Reads configuration from a DOM element previously written by writeXml()
Layer tree node points to a map layer.