QGIS API Documentation  2.99.0-Master (e077efd)
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 
21 class QgsLayerTreeGroup;
22 class QgsLayerTreeLayer;
23 class QgsLayerTreeModel;
24 class QgsLayerTreeNode;
28 class QgsMapLayer;
29 
46 class GUI_EXPORT QgsLayerTreeView : public QTreeView
47 {
48  Q_OBJECT
49  public:
50  explicit QgsLayerTreeView( QWidget *parent = nullptr );
52 
54  virtual void setModel( QAbstractItemModel* model ) override;
55 
57  QgsLayerTreeModel* layerTreeModel() const;
58 
60  QgsLayerTreeViewDefaultActions* defaultActions();
61 
63  void setMenuProvider( QgsLayerTreeViewMenuProvider* menuProvider );
65  QgsLayerTreeViewMenuProvider* menuProvider() const { return mMenuProvider; }
66 
68  QgsMapLayer* currentLayer() const;
70  void setCurrentLayer( QgsMapLayer* layer );
71 
73  QgsLayerTreeNode* currentNode() const;
75  QgsLayerTreeGroup* currentGroupNode() const;
76 
80  QgsLayerTreeModelLegendNode* currentLegendNode() const;
81 
84  QList<QgsLayerTreeNode*> selectedNodes( bool skipInternal = false ) const;
86  QList<QgsLayerTreeLayer*> selectedLayerNodes() const;
87 
89  QList<QgsMapLayer*> selectedLayers() const;
90 
91  public slots:
93  void refreshLayerSymbology( const QString& layerId );
94 
97  void expandAllNodes();
98 
101  void collapseAllNodes();
102 
103  signals:
105  void currentLayerChanged( QgsMapLayer* layer );
106 
107  protected:
108  void contextMenuEvent( QContextMenuEvent* event ) override;
109 
110  void updateExpandedStateFromNode( QgsLayerTreeNode* node );
111 
112  QgsMapLayer* layerForIndex( const QModelIndex& index ) const;
113 
114  protected slots:
115 
116  void modelRowsInserted( const QModelIndex& index, int start, int end );
117  void modelRowsRemoved();
118 
119  void updateExpandedStateToNode( const QModelIndex& index );
120 
121  void onCurrentChanged();
122  void onExpandedChanged( QgsLayerTreeNode* node, bool expanded );
123  void onModelReset();
124 
125  protected:
132 };
133 
134 
143 {
144  public:
146 
148  virtual QMenu* createContextMenu() = 0;
149 };
150 
151 
152 #endif // QGSLAYERTREEVIEW_H
Layer tree group node serves as a container for layers and further groups.
static unsigned index
Base class for all map layer types.
Definition: qgsmaplayer.h:49
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...
QgsLayerTreeViewMenuProvider * mMenuProvider
Context menu provider. Owned by the view.
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.
This class is a base class for nodes in a layer tree.
QgsLayerTreeViewDefaultActions * mDefaultActions
helper class with default actions. Lazily initialized.
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.