QGIS API Documentation  2.99.0-Master (d55fa22)
qgslayertreeview.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgslayertreeview.h
3  --------------------------------------
4  Date : May 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 QGSLAYERTREEVIEW_H
17 #define QGSLAYERTREEVIEW_H
18 
19 #include <QTreeView>
20 #include "qgis.h"
21 #include "qgis_gui.h"
22 
23 class QgsLayerTreeGroup;
24 class QgsLayerTreeLayer;
25 class QgsLayerTreeModel;
26 class QgsLayerTreeNode;
30 class QgsMapLayer;
31 
48 class GUI_EXPORT QgsLayerTreeView : public QTreeView
49 {
50  Q_OBJECT
51  public:
52  explicit QgsLayerTreeView( QWidget *parent SIP_TRANSFERTHIS = 0 );
54 
56  virtual void setModel( QAbstractItemModel *model ) override;
57 
59  QgsLayerTreeModel *layerTreeModel() const;
60 
62  QgsLayerTreeViewDefaultActions *defaultActions();
63 
65  void setMenuProvider( QgsLayerTreeViewMenuProvider *menuProvider SIP_TRANSFER );
67  QgsLayerTreeViewMenuProvider *menuProvider() const { return mMenuProvider; }
68 
70  QgsMapLayer *currentLayer() const;
72  void setCurrentLayer( QgsMapLayer *layer );
73 
75  QgsLayerTreeNode *currentNode() const;
77  QgsLayerTreeGroup *currentGroupNode() const;
78 
82  QgsLayerTreeModelLegendNode *currentLegendNode() const;
83 
86  QList<QgsLayerTreeNode *> selectedNodes( bool skipInternal = false ) const;
88  QList<QgsLayerTreeLayer *> selectedLayerNodes() const;
89 
91  QList<QgsMapLayer *> selectedLayers() const;
92 
93  public slots:
95  void refreshLayerSymbology( const QString &layerId );
96 
99  void expandAllNodes();
100 
103  void collapseAllNodes();
104 
105  signals:
107  void currentLayerChanged( QgsMapLayer *layer );
108 
109  protected:
110  void contextMenuEvent( QContextMenuEvent *event ) override;
111 
112  void updateExpandedStateFromNode( QgsLayerTreeNode *node );
113 
114  QgsMapLayer *layerForIndex( const QModelIndex &index ) const;
115 
116  void mouseReleaseEvent( QMouseEvent *event ) override;
117  void keyPressEvent( QKeyEvent *event ) override;
118 
119  protected slots:
120 
121  void modelRowsInserted( const QModelIndex &index, int start, int end );
122  void modelRowsRemoved();
123 
124  void updateExpandedStateToNode( const QModelIndex &index );
125 
126  void onCurrentChanged();
127  void onExpandedChanged( QgsLayerTreeNode *node, bool expanded );
128  void onModelReset();
129 
130  protected:
132  QgsLayerTreeViewDefaultActions *mDefaultActions = nullptr;
134  QgsLayerTreeViewMenuProvider *mMenuProvider = nullptr;
137 };
138 
139 
148 {
149  public:
150  virtual ~QgsLayerTreeViewMenuProvider() = default;
151 
153  virtual QMenu *createContextMenu() = 0 SIP_FACTORY;
154 };
155 
156 
157 #endif // QGSLAYERTREEVIEW_H
Layer tree group node serves as a container for layers and further groups.
Base class for all map layer types.
Definition: qgsmaplayer.h:54
The QgsLayerTreeView class extends QTreeView and provides some additional functionality when working ...
Implementation of this interface can be implemented to allow QgsLayerTreeView instance to provide cus...
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:34
QString mCurrentLayerID
Keeps track of current layer ID (to check when to emit signal about change of current layer) ...
The QgsLayerTreeViewDefaultActions class serves as a factory of actions that can be used together wit...
The QgsLayerTreeModel class is model implementation for Qt item views framework.
#define SIP_TRANSFER
Definition: qgis_sip.h:24
This class is a base class for nodes in a layer tree.
#define SIP_FACTORY
Definition: qgis_sip.h:57
QgsLayerTreeViewMenuProvider * menuProvider() const
Return pointer to the context menu provider. May be null.
The QgsLegendRendererItem class is abstract interface for legend items returned from QgsMapLayerLegen...
Layer tree node points to a map layer.