QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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  void dropEvent( QDropEvent *event ) override;
115 
116 
117  protected slots:
118 
119  void modelRowsInserted( const QModelIndex& index, int start, int end );
120  void modelRowsRemoved();
121 
122  void updateExpandedStateToNode( const QModelIndex& index );
123 
124  void onCurrentChanged();
125  void onExpandedChanged( QgsLayerTreeNode* node, bool expanded );
126  void onModelReset();
127 
128  protected:
135 };
136 
137 
146 {
147  public:
149 
151  virtual QMenu* createContextMenu() = 0;
152 };
153 
154 
155 #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.
virtual void contextMenuEvent(QContextMenuEvent *e)
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.
virtual void setModel(QAbstractItemModel *model)
virtual void dropEvent(QDropEvent *event)
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.