QGIS API Documentation  3.17.0-Master (a035f434f4)
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;
33 class QgsSymbol;
34 
35 #include "qgis_core.h"
36 
37 
45 class CORE_EXPORT QgsMapLayerLegend : public QObject
46 {
47  Q_OBJECT
48  public:
49 
51  explicit QgsMapLayerLegend( QObject *parent SIP_TRANSFERTHIS = nullptr );
52 
53  // TODO: type
54 
59  virtual void readXml( const QDomElement &elem, const QgsReadWriteContext &context );
60 
65  virtual QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const;
66 
71  virtual QList<QgsLayerTreeModelLegendNode *> createLayerTreeModelLegendNodes( QgsLayerTreeLayer *nodeLayer ) = 0 SIP_FACTORY;
72 
73  // TODO: support for layer tree view delegates
74 
76  static QgsMapLayerLegend *defaultVectorLegend( QgsVectorLayer *vl ) SIP_FACTORY;
77 
79  static QgsMapLayerLegend *defaultRasterLegend( QgsRasterLayer *rl ) SIP_FACTORY;
80 
82  static QgsMapLayerLegend *defaultMeshLegend( QgsMeshLayer *ml ) SIP_FACTORY;
83 
84  signals:
86  void itemsChanged();
87 };
88 
89 
96 class CORE_EXPORT QgsMapLayerLegendUtils
97 {
98  public:
99  static void setLegendNodeOrder( QgsLayerTreeLayer *nodeLayer, const QList<int> &order );
100  static QList<int> legendNodeOrder( QgsLayerTreeLayer *nodeLayer );
101  static bool hasLegendNodeOrder( QgsLayerTreeLayer *nodeLayer );
102 
103  static void setLegendNodeUserLabel( QgsLayerTreeLayer *nodeLayer, int originalIndex, const QString &newLabel );
104  static QString legendNodeUserLabel( QgsLayerTreeLayer *nodeLayer, int originalIndex );
105  static bool hasLegendNodeUserLabel( QgsLayerTreeLayer *nodeLayer, int originalIndex );
106 
113  static void setLegendNodePatchShape( QgsLayerTreeLayer *nodeLayer, int originalIndex, const QgsLegendPatchShape &shape );
114 
121  static QgsLegendPatchShape legendNodePatchShape( QgsLayerTreeLayer *nodeLayer, int originalIndex );
122 
132  static void setLegendNodeSymbolSize( QgsLayerTreeLayer *nodeLayer, int originalIndex, QSizeF size );
133 
143  static QSizeF legendNodeSymbolSize( QgsLayerTreeLayer *nodeLayer, int originalIndex );
144 
154  static void setLegendNodeCustomSymbol( QgsLayerTreeLayer *nodeLayer, int originalIndex, const QgsSymbol *symbol );
155 
167  static QgsSymbol *legendNodeCustomSymbol( QgsLayerTreeLayer *nodeLayer, int originalIndex ) SIP_FACTORY;
168 
175  static void setLegendNodeColumnBreak( QgsLayerTreeLayer *nodeLayer, int originalIndex, bool columnBreakBeforeNode );
176 
183  static bool legendNodeColumnBreak( QgsLayerTreeLayer *nodeLayer, int originalIndex );
184 
186  static void applyLayerNodeProperties( QgsLayerTreeLayer *nodeLayer, QList<QgsLayerTreeModelLegendNode *> &nodes );
187 };
188 
189 
190 #include <QHash>
191 
192 #include "qgstextformat.h"
193 
200 {
201  Q_OBJECT
202 
203  public:
205 
212  bool textOnSymbolEnabled() const { return mTextOnSymbolEnabled; }
213 
220  void setTextOnSymbolEnabled( bool enabled ) { mTextOnSymbolEnabled = enabled; }
221 
226  QgsTextFormat textOnSymbolTextFormat() const { return mTextOnSymbolTextFormat; }
227 
232  void setTextOnSymbolTextFormat( const QgsTextFormat &format ) { mTextOnSymbolTextFormat = format; }
233 
239  QHash<QString, QString> textOnSymbolContent() const { return mTextOnSymbolContent; }
240 
246  void setTextOnSymbolContent( const QHash<QString, QString> &content ) { mTextOnSymbolContent = content; }
247 
248  QList<QgsLayerTreeModelLegendNode *> createLayerTreeModelLegendNodes( QgsLayerTreeLayer *nodeLayer ) SIP_FACTORY override;
249  void readXml( const QDomElement &elem, const QgsReadWriteContext &context ) override;
250  QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const override;
251 
252  private:
253  QgsVectorLayer *mLayer = nullptr;
254 
255  // text on symbol
256  bool mTextOnSymbolEnabled = false;
257  QgsTextFormat mTextOnSymbolTextFormat;
258  QHash<QString, QString> mTextOnSymbolContent;
259 };
260 
261 
268 {
269  Q_OBJECT
270 
271  public:
273 
274  QList<QgsLayerTreeModelLegendNode *> createLayerTreeModelLegendNodes( QgsLayerTreeLayer *nodeLayer ) SIP_FACTORY override;
275 
276  private:
277  QgsRasterLayer *mLayer = nullptr;
278 };
279 
280 
287 {
288  Q_OBJECT
289 
290  public:
292  explicit QgsDefaultMeshLayerLegend( QgsMeshLayer *ml );
293 
294  QList<QgsLayerTreeModelLegendNode *> createLayerTreeModelLegendNodes( QgsLayerTreeLayer *nodeLayer ) SIP_FACTORY override;
295 
296  private:
297  QgsMeshLayer *mLayer = nullptr;
298 };
299 
300 
301 #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
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:64
QHash< QString, QString > textOnSymbolContent() const
Returns per-symbol content of labels for "text on symbol" functionality.
Represents a raster layer.
Base class for plugin layers.
Default legend implementation for mesh layers.
Default legend implementation for raster layers.
Represents a patch shape for use in map legends.
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:94
Container for all settings relating to text rendering.
Definition: qgstextformat.h:39
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.