QGIS API Documentation  2.17.0-Master (973e4b0)
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 
95  signals:
97  void currentLayerChanged( QgsMapLayer* layer );
98 
99  protected:
100  void contextMenuEvent( QContextMenuEvent* event ) override;
101 
102  void updateExpandedStateFromNode( QgsLayerTreeNode* node );
103 
104  QgsMapLayer* layerForIndex( const QModelIndex& index ) const;
105 
106  protected slots:
107 
108  void modelRowsInserted( const QModelIndex& index, int start, int end );
109  void modelRowsRemoved();
110 
111  void updateExpandedStateToNode( const QModelIndex& index );
112 
113  void onCurrentChanged();
114  void onExpandedChanged( QgsLayerTreeNode* node, bool expanded );
115  void onModelReset();
116 
117  protected:
124 };
125 
126 
135 {
136  public:
138 
140  virtual QMenu* createContextMenu() = 0;
141 };
142 
143 
144 #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.