QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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
QgsDefaultVectorLayerLegend
Definition: qgsmaplayerlegend.h:199
QgsReadWriteContext
Definition: qgsreadwritecontext.h:34
QgsMapLayerLegend
Definition: qgsmaplayerlegend.h:45
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:40
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
Definition: qgssymbol.h:63
QgsDefaultRasterLayerLegend
Definition: qgsmaplayerlegend.h:267
QgsLegendPatchShape
Definition: qgslegendpatchshape.h:30
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsTextFormat
Definition: qgstextformat.h:38
QgsDefaultVectorLayerLegend::textOnSymbolEnabled
bool textOnSymbolEnabled() const
Returns whether the "text on symbol" functionality is enabled.
Definition: qgsmaplayerlegend.h:212
QgsMeshLayer
Definition: qgsmeshlayer.h:94
QgsLayerTreeLayer
Definition: qgslayertreelayer.h:43
qgis_sip.h
QgsRasterLayer
Definition: qgsrasterlayer.h:72
QgsDefaultMeshLayerLegend
Definition: qgsmaplayerlegend.h:286
QgsPluginLayer
Definition: qgspluginlayer.h:31
QgsDefaultVectorLayerLegend::setTextOnSymbolEnabled
void setTextOnSymbolEnabled(bool enabled)
Sets whether the "text on symbol" functionality is enabled.
Definition: qgsmaplayerlegend.h:220
QgsDefaultVectorLayerLegend::setTextOnSymbolContent
void setTextOnSymbolContent(const QHash< QString, QString > &content)
Sets per-symbol content of labels for "text on symbol" functionality.
Definition: qgsmaplayerlegend.h:246
QgsMapLayerLegendUtils
Definition: qgsmaplayerlegend.h:96
QgsVectorLayer
Definition: qgsvectorlayer.h:385
QgsDefaultVectorLayerLegend::setTextOnSymbolTextFormat
void setTextOnSymbolTextFormat(const QgsTextFormat &format)
Sets text format of symbol labels for "text on symbol" functionality.
Definition: qgsmaplayerlegend.h:232
QgsDefaultVectorLayerLegend::textOnSymbolContent
QHash< QString, QString > textOnSymbolContent() const
Returns per-symbol content of labels for "text on symbol" functionality.
Definition: qgsmaplayerlegend.h:239
qgstextformat.h
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:226
QgsMapLayerLegend::readXml
virtual void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Reads configuration from a DOM element previously written by writeXml()
Definition: qgsmaplayerlegend.cpp:34
QgsLayerTreeModelLegendNode
Definition: qgslayertreemodellegendnode.h:50