QGIS API Documentation
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 
45 class GUI_EXPORT QgsLayerTreeView : public QTreeView
46 {
47  Q_OBJECT
48  public:
49  explicit QgsLayerTreeView( QWidget *parent = nullptr );
51 
53  virtual void setModel( QAbstractItemModel* model ) override;
54 
56  QgsLayerTreeModel* layerTreeModel() const;
57 
59  QgsLayerTreeViewDefaultActions* defaultActions();
60 
62  void setMenuProvider( QgsLayerTreeViewMenuProvider* menuProvider );
64  QgsLayerTreeViewMenuProvider* menuProvider() const { return mMenuProvider; }
65 
67  QgsMapLayer* currentLayer() const;
69  void setCurrentLayer( QgsMapLayer* layer );
70 
72  QgsLayerTreeNode* currentNode() const;
74  QgsLayerTreeGroup* currentGroupNode() const;
75 
79  QgsLayerTreeModelLegendNode* currentLegendNode() const;
80 
83  QList<QgsLayerTreeNode*> selectedNodes( bool skipInternal = false ) const;
85  QList<QgsLayerTreeLayer*> selectedLayerNodes() const;
86 
88  QList<QgsMapLayer*> selectedLayers() const;
89 
90  public slots:
92  void refreshLayerSymbology( const QString& layerId );
93 
94  signals:
96  void currentLayerChanged( QgsMapLayer* layer );
97 
98  protected:
99  void contextMenuEvent( QContextMenuEvent* event ) override;
100 
101  void updateExpandedStateFromNode( QgsLayerTreeNode* node );
102 
103  QgsMapLayer* layerForIndex( const QModelIndex& index ) const;
104 
105  protected slots:
106 
107  void modelRowsInserted( const QModelIndex& index, int start, int end );
108  void modelRowsRemoved();
109 
110  void updateExpandedStateToNode( const QModelIndex& index );
111 
112  void onCurrentChanged();
113  void onExpandedChanged( QgsLayerTreeNode* node, bool expanded );
114  void onModelReset();
115 
116  protected:
123 };
124 
125 
134 {
135  public:
137 
139  virtual QMenu* createContextMenu() = 0;
140 };
141 
142 
143 #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.
QgsLayerTreeViewMenuProvider * menuProvider() const
Return pointer to the context menu provider. May be null.
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)
The QgsLegendRendererItem class is abstract interface for legend items returned from QgsMapLayerLegen...
Layer tree node points to a map layer.