QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
qgslegendinterface.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgslegendinterface.h
3  --------------------------------------
4  Date : 19-Nov-2009
5  Copyright : (C) 2009 by Andres Manz
6  Email : manz dot andres at gmail dot com
7 ****************************************************************************/
8 /***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 
17 #ifndef QGSLEGENDINTERFACE_H
18 #define QGSLEGENDINTERFACE_H
19 
20 #include <QObject>
21 #include <QPair>
22 #include <QStringList>
23 #include <QModelIndex>
24 
25 class QgsMapLayer;
26 class QTreeWidgetItem;
27 class QAction;
28 
29 #include "qgsmaplayer.h"
30 
31 //Information about relationship between groups and layers
32 //key: group name (or null strings for single layers without groups)
33 //value: containter with layer ids contained in the group
35 
40 class GUI_EXPORT QgsLegendInterface : public QObject
41 {
42  Q_OBJECT
43 
44  public:
45 
48 
50  virtual ~QgsLegendInterface();
51 
53  virtual QStringList groups() = 0;
54 
57 
61  virtual QList<QgsMapLayer *> selectedLayers( bool inDrawOrder = false ) const = 0;
62 
64  virtual QList< QgsMapLayer * > layers() const = 0;
65 
67  virtual bool groupExists( int groupIndex ) = 0;
68 
70  virtual bool isGroupExpanded( int groupIndex ) = 0;
71 
73  virtual bool isGroupVisible( int groupIndex ) = 0;
74 
76  virtual bool isLayerExpanded( QgsMapLayer * ml ) = 0;
77 
79  virtual bool isLayerVisible( QgsMapLayer * ml ) = 0;
80 
82  virtual void addLegendLayerAction( QAction* action, QString menu, QString id,
83  QgsMapLayer::LayerType type, bool allLayers ) = 0;
84 
88  virtual void addLegendLayerActionForLayer( QAction* action, QgsMapLayer* layer ) = 0;
89 
91  virtual bool removeLegendLayerAction( QAction* action ) = 0;
92 
96  virtual QgsMapLayer* currentLayer() = 0;
97 
100  virtual bool setCurrentLayer( QgsMapLayer *layer ) = 0;
101 
102  signals:
103 
105  void groupIndexChanged( int oldIndex, int newIndex );
106 
107  /* //! emitted when group relations have changed */
108  void groupRelationsChanged();
109 
110  /* //! emitted when an item (group/layer) is added */
111  void itemAdded( const QModelIndex& index );
112 
113  /* //! emitted when an item (group/layer) is removed */
114  void itemRemoved();
115 
117  // the pointer to layer can be null if no layer is selected
118  void currentLayerChanged( QgsMapLayer * layer );
119 
120  public slots:
121 
124  virtual int addGroup( const QString& name, bool expand = true, QTreeWidgetItem* parent = nullptr ) = 0;
125 
128  virtual int addGroup( const QString& name, bool expand, int parentIndex ) = 0;
129 
131  virtual void removeGroup( int groupIndex ) = 0;
132 
134  virtual void moveLayer( QgsMapLayer * ml, int groupIndex ) = 0;
135 
137  virtual void setGroupExpanded( int groupIndex, bool expand ) = 0;
138 
140  virtual void setLayerExpanded( QgsMapLayer * ml, bool expand ) = 0;
141 
143  virtual void setGroupVisible( int groupIndex, bool visible ) = 0;
144 
146  virtual void setLayerVisible( QgsMapLayer * ml, bool visible ) = 0;
147 
149  virtual void refreshLayerSymbology( QgsMapLayer *ml ) = 0;
150 };
151 
152 #endif
QgsLegendInterface Abstract base class to make QgsLegend available to plugins.
static unsigned index
Base class for all map layer types.
Definition: qgsmaplayer.h:49
LayerType
Layers enum defining the types of layers that can be added to a map.
Definition: qgsmaplayer.h:57
virtual QList< GroupLayerInfo > groupLayerRelationship()
Return the relationship between groups and layers in the legend.
QPair< QString, QList< QString > > GroupLayerInfo