QGIS API Documentation  2.99.0-Master (0a63d1f)
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_gui.h"
21 
22 class QgsLayerTreeGroup;
23 class QgsLayerTreeLayer;
24 class QgsLayerTreeModel;
25 class QgsLayerTreeNode;
29 class QgsMapLayer;
30 
47 class GUI_EXPORT QgsLayerTreeView : public QTreeView
48 {
49  Q_OBJECT
50  public:
51  explicit QgsLayerTreeView( QWidget *parent = nullptr );
53 
55  virtual void setModel( QAbstractItemModel* model ) override;
56 
58  QgsLayerTreeModel* layerTreeModel() const;
59 
61  QgsLayerTreeViewDefaultActions* defaultActions();
62 
64  void setMenuProvider( QgsLayerTreeViewMenuProvider* menuProvider );
66  QgsLayerTreeViewMenuProvider* menuProvider() const { return mMenuProvider; }
67 
69  QgsMapLayer* currentLayer() const;
71  void setCurrentLayer( QgsMapLayer* layer );
72 
74  QgsLayerTreeNode* currentNode() const;
76  QgsLayerTreeGroup* currentGroupNode() const;
77 
81  QgsLayerTreeModelLegendNode* currentLegendNode() const;
82 
85  QList<QgsLayerTreeNode*> selectedNodes( bool skipInternal = false ) const;
87  QList<QgsLayerTreeLayer*> selectedLayerNodes() const;
88 
90  QList<QgsMapLayer*> selectedLayers() const;
91 
92  public slots:
94  void refreshLayerSymbology( const QString& layerId );
95 
98  void expandAllNodes();
99 
102  void collapseAllNodes();
103 
104  signals:
106  void currentLayerChanged( QgsMapLayer* layer );
107 
108  protected:
109  void contextMenuEvent( QContextMenuEvent* event ) override;
110 
111  void updateExpandedStateFromNode( QgsLayerTreeNode* node );
112 
113  QgsMapLayer* layerForIndex( const QModelIndex& index ) const;
114 
115  void mouseReleaseEvent( QMouseEvent *event ) override;
116  void keyPressEvent( QKeyEvent *event ) override;
117 
118  protected slots:
119 
120  void modelRowsInserted( const QModelIndex& index, int start, int end );
121  void modelRowsRemoved();
122 
123  void updateExpandedStateToNode( const QModelIndex& index );
124 
125  void onCurrentChanged();
126  void onExpandedChanged( QgsLayerTreeNode* node, bool expanded );
127  void onModelReset();
128 
129  protected:
136 };
137 
138 
147 {
148  public:
149  virtual ~QgsLayerTreeViewMenuProvider() = default;
150 
152  virtual QMenu* createContextMenu() = 0;
153 };
154 
155 
156 #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:50
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.