QGIS API Documentation  3.2.0-Bonn (bc43194)
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.h"
21 
22 class QDomDocument;
23 class QDomElement;
24 
25 class QgsLayerTreeLayer;
27 class QgsPluginLayer;
28 class QgsRasterLayer;
30 class QgsVectorLayer;
31 
32 #include "qgis_core.h"
33 
34 
42 class CORE_EXPORT QgsMapLayerLegend : public QObject
43 {
44  Q_OBJECT
45  public:
46 
48  explicit QgsMapLayerLegend( QObject *parent SIP_TRANSFERTHIS = nullptr );
49 
50  // TODO: type
51 
56  virtual void readXml( const QDomElement &elem, const QgsReadWriteContext &context );
57 
62  virtual QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const;
63 
68  virtual QList<QgsLayerTreeModelLegendNode *> createLayerTreeModelLegendNodes( QgsLayerTreeLayer *nodeLayer ) = 0 SIP_FACTORY;
69 
70  // TODO: support for layer tree view delegates
71 
73  static QgsMapLayerLegend *defaultVectorLegend( QgsVectorLayer *vl ) SIP_FACTORY;
74 
76  static QgsMapLayerLegend *defaultRasterLegend( QgsRasterLayer *rl ) SIP_FACTORY;
77 
78  signals:
80  void itemsChanged();
81 };
82 
83 
90 class CORE_EXPORT QgsMapLayerLegendUtils
91 {
92  public:
93  static void setLegendNodeOrder( QgsLayerTreeLayer *nodeLayer, const QList<int> &order );
94  static QList<int> legendNodeOrder( QgsLayerTreeLayer *nodeLayer );
95  static bool hasLegendNodeOrder( QgsLayerTreeLayer *nodeLayer );
96 
97  static void setLegendNodeUserLabel( QgsLayerTreeLayer *nodeLayer, int originalIndex, const QString &newLabel );
98  static QString legendNodeUserLabel( QgsLayerTreeLayer *nodeLayer, int originalIndex );
99  static bool hasLegendNodeUserLabel( QgsLayerTreeLayer *nodeLayer, int originalIndex );
100 
102  static void applyLayerNodeProperties( QgsLayerTreeLayer *nodeLayer, QList<QgsLayerTreeModelLegendNode *> &nodes );
103 };
104 
105 
106 #include <QHash>
107 
108 #include "qgstextrenderer.h"
109 
116 {
117  Q_OBJECT
118 
119  public:
121 
128  bool textOnSymbolEnabled() const { return mTextOnSymbolEnabled; }
129 
136  void setTextOnSymbolEnabled( bool enabled ) { mTextOnSymbolEnabled = enabled; }
137 
142  QgsTextFormat textOnSymbolTextFormat() const { return mTextOnSymbolTextFormat; }
143 
148  void setTextOnSymbolTextFormat( const QgsTextFormat &format ) { mTextOnSymbolTextFormat = format; }
149 
155  QHash<QString, QString> textOnSymbolContent() const { return mTextOnSymbolContent; }
156 
162  void setTextOnSymbolContent( const QHash<QString, QString> &content ) { mTextOnSymbolContent = content; }
163 
164  QList<QgsLayerTreeModelLegendNode *> createLayerTreeModelLegendNodes( QgsLayerTreeLayer *nodeLayer ) SIP_FACTORY override;
165  void readXml( const QDomElement &elem, const QgsReadWriteContext &context ) override;
166  QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const override;
167 
168  private:
169  QgsVectorLayer *mLayer = nullptr;
170 
171  // text on symbol
172  bool mTextOnSymbolEnabled = false;
173  QgsTextFormat mTextOnSymbolTextFormat;
174  QHash<QString, QString> mTextOnSymbolContent;
175 };
176 
177 
184 {
185  Q_OBJECT
186 
187  public:
189 
190  QList<QgsLayerTreeModelLegendNode *> createLayerTreeModelLegendNodes( QgsLayerTreeLayer *nodeLayer ) SIP_FACTORY override;
191 
192  private:
193  QgsRasterLayer *mLayer = nullptr;
194 };
195 
196 
197 #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:46
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 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:69
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...
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.