QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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  bool showLabelLegend() const { return mShowLabelLegend; }
264 
270  void setShowLabelLegend( bool enabled ) { mShowLabelLegend = enabled; }
271 
276  QgsTextFormat textOnSymbolTextFormat() const { return mTextOnSymbolTextFormat; }
277 
282  void setTextOnSymbolTextFormat( const QgsTextFormat &format ) { mTextOnSymbolTextFormat = format; }
283 
289  QHash<QString, QString> textOnSymbolContent() const { return mTextOnSymbolContent; }
290 
296  void setTextOnSymbolContent( const QHash<QString, QString> &content ) { mTextOnSymbolContent = content; }
297 
298  QList<QgsLayerTreeModelLegendNode *> createLayerTreeModelLegendNodes( QgsLayerTreeLayer *nodeLayer ) SIP_FACTORY override;
299  void readXml( const QDomElement &elem, const QgsReadWriteContext &context ) override;
300  QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const override;
301 
302  private:
303  QgsVectorLayer *mLayer = nullptr;
304 
305  // text on symbol
306  bool mTextOnSymbolEnabled = false;
307  bool mShowLabelLegend = false;
308  QgsTextFormat mTextOnSymbolTextFormat;
309  QHash<QString, QString> mTextOnSymbolContent;
310 };
311 
312 
319 {
320  Q_OBJECT
321 
322  public:
324 
325  QList<QgsLayerTreeModelLegendNode *> createLayerTreeModelLegendNodes( QgsLayerTreeLayer *nodeLayer ) SIP_FACTORY override;
326 
327  private:
328  QgsRasterLayer *mLayer = nullptr;
329 };
330 
331 
338 {
339  Q_OBJECT
340 
341  public:
343  explicit QgsDefaultMeshLayerLegend( QgsMeshLayer *ml );
344 
345  QList<QgsLayerTreeModelLegendNode *> createLayerTreeModelLegendNodes( QgsLayerTreeLayer *nodeLayer ) SIP_FACTORY override;
346 
347  private:
348  QgsMeshLayer *mLayer = nullptr;
349 };
350 
357 {
358  Q_OBJECT
359 
360  public:
363 
364  QList<QgsLayerTreeModelLegendNode *> createLayerTreeModelLegendNodes( QgsLayerTreeLayer *nodeLayer ) SIP_FACTORY override;
365 
366  private:
367  QgsPointCloudLayer *mLayer = nullptr;
368 };
369 
370 
371 #endif // QGSMAPLAYERLEGEND_H
QgsDefaultVectorLayerLegend
Default legend implementation for vector layers.
Definition: qgsmaplayerlegend.h:236
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:34
QgsPointCloudLayer
Represents a map layer supporting display of point clouds.
Definition: qgspointcloudlayer.h:45
QgsMapLayerLegend
The QgsMapLayerLegend class is abstract interface for implementations of legends for one map layer.
Definition: qgsmaplayerlegend.h:47
QgsMapLayerLegend::writeXml
virtual QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Writes configuration to a DOM element, to be used later with readXml()
Definition: qgsmaplayerlegend.cpp:47
QgsMapLayerLegend::createLayerTreeModelLegendNodes
virtual QList< QgsLayerTreeModelLegendNode * > createLayerTreeModelLegendNodes(QgsLayerTreeLayer *nodeLayer)=0
Returns list of legend nodes to be used for a particular layer tree layer node.
QgsSymbol
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:92
QgsDefaultRasterLayerLegend
Default legend implementation for raster layers.
Definition: qgsmaplayerlegend.h:318
QgsLegendPatchShape
Represents a patch shape for use in map legends.
Definition: qgslegendpatchshape.h:33
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsTextFormat
Container for all settings relating to text rendering.
Definition: qgstextformat.h:40
QgsDefaultVectorLayerLegend::textOnSymbolEnabled
bool textOnSymbolEnabled() const
Returns whether the "text on symbol" functionality is enabled.
Definition: qgsmaplayerlegend.h:249
QgsMeshLayer
Represents a mesh layer supporting display of data on structured or unstructured meshes.
Definition: qgsmeshlayer.h:98
QgsLayerTreeLayer
Layer tree node points to a map layer.
Definition: qgslayertreelayer.h:43
qgis_sip.h
QgsRasterLayer
Represents a raster layer.
Definition: qgsrasterlayer.h:76
QgsDefaultMeshLayerLegend
Default legend implementation for mesh layers.
Definition: qgsmaplayerlegend.h:337
QgsPluginLayer
Base class for plugin layers. These can be implemented by plugins and registered in QgsPluginLayerReg...
Definition: qgspluginlayer.h:31
QgsDefaultVectorLayerLegend::setTextOnSymbolEnabled
void setTextOnSymbolEnabled(bool enabled)
Sets whether the "text on symbol" functionality is enabled.
Definition: qgsmaplayerlegend.h:257
QgsDefaultVectorLayerLegend::setTextOnSymbolContent
void setTextOnSymbolContent(const QHash< QString, QString > &content)
Sets per-symbol content of labels for "text on symbol" functionality.
Definition: qgsmaplayerlegend.h:296
QgsMapLayerLegendUtils
Miscellaneous utility functions for handling of map layer legend.
Definition: qgsmaplayerlegend.h:104
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsDefaultVectorLayerLegend::showLabelLegend
bool showLabelLegend() const
Returns whether the legend for the labeling is shown.
Definition: qgsmaplayerlegend.h:263
QgsDefaultVectorLayerLegend::setTextOnSymbolTextFormat
void setTextOnSymbolTextFormat(const QgsTextFormat &format)
Sets text format of symbol labels for "text on symbol" functionality.
Definition: qgsmaplayerlegend.h:282
QgsDefaultVectorLayerLegend::textOnSymbolContent
QHash< QString, QString > textOnSymbolContent() const
Returns per-symbol content of labels for "text on symbol" functionality.
Definition: qgsmaplayerlegend.h:289
qgstextformat.h
QgsDefaultPointCloudLayerLegend
Default legend implementation for point cloud layers.
Definition: qgsmaplayerlegend.h:356
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
QgsDefaultVectorLayerLegend::textOnSymbolTextFormat
QgsTextFormat textOnSymbolTextFormat() const
Returns text format of symbol labels for "text on symbol" functionality.
Definition: qgsmaplayerlegend.h:276
QgsDefaultVectorLayerLegend::setShowLabelLegend
void setShowLabelLegend(bool enabled)
Sets if a legend for the labeling should be shown.
Definition: qgsmaplayerlegend.h:270
QgsColorRampLegendNodeSettings
Settings for a color ramp legend node.
Definition: qgscolorramplegendnodesettings.h:37
QgsMapLayerLegend::readXml
virtual void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Reads configuration from a DOM element previously written by writeXml()
Definition: qgsmaplayerlegend.cpp:41
QgsLayerTreeModelLegendNode
The QgsLegendRendererItem class is abstract interface for legend items returned from QgsMapLayerLegen...
Definition: qgslayertreemodellegendnode.h:49