QGIS API Documentation  2.99.0-Master (9fdd060)
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.h"
21 #include "qgis_gui.h"
22 
23 class QgsLayerTreeGroup;
24 class QgsLayerTreeLayer;
25 class QgsLayerTreeModel;
26 class QgsLayerTreeNode;
30 class QgsMapLayer;
31 
48 class GUI_EXPORT QgsLayerTreeView : public QTreeView
49 {
50 
51 #ifdef SIP_RUN
53  if ( sipCpp->inherits( "QgsLayerTreeView" ) )
54  sipType = sipType_QgsLayerTreeView;
55  else
56  sipType = 0;
57  SIP_END
58 #endif
59 
60 
61  Q_OBJECT
62  public:
63  explicit QgsLayerTreeView( QWidget *parent SIP_TRANSFERTHIS = 0 );
65 
67  virtual void setModel( QAbstractItemModel *model ) override;
68 
70  QgsLayerTreeModel *layerTreeModel() const;
71 
73  QgsLayerTreeViewDefaultActions *defaultActions();
74 
76  void setMenuProvider( QgsLayerTreeViewMenuProvider *menuProvider SIP_TRANSFER );
78  QgsLayerTreeViewMenuProvider *menuProvider() const { return mMenuProvider; }
79 
81  QgsMapLayer *currentLayer() const;
83  void setCurrentLayer( QgsMapLayer *layer );
84 
86  QgsLayerTreeNode *currentNode() const;
88  QgsLayerTreeGroup *currentGroupNode() const;
89 
94  QgsLayerTreeModelLegendNode *currentLegendNode() const;
95 
100  QList<QgsLayerTreeNode *> selectedNodes( bool skipInternal = false ) const;
102  QList<QgsLayerTreeLayer *> selectedLayerNodes() const;
103 
105  QList<QgsMapLayer *> selectedLayers() const;
106 
107  public slots:
109  void refreshLayerSymbology( const QString &layerId );
110 
115  void expandAllNodes();
116 
121  void collapseAllNodes();
122 
123  signals:
125  void currentLayerChanged( QgsMapLayer *layer );
126 
127  protected:
128  void contextMenuEvent( QContextMenuEvent *event ) override;
129 
130  void updateExpandedStateFromNode( QgsLayerTreeNode *node );
131 
132  QgsMapLayer *layerForIndex( const QModelIndex &index ) const;
133 
134  void mouseReleaseEvent( QMouseEvent *event ) override;
135  void keyPressEvent( QKeyEvent *event ) override;
136 
137  void dropEvent( QDropEvent *event ) override;
138 
139 
140  protected slots:
141 
142  void modelRowsInserted( const QModelIndex &index, int start, int end );
143  void modelRowsRemoved();
144 
145  void updateExpandedStateToNode( const QModelIndex &index );
146 
147  void onCurrentChanged();
148  void onExpandedChanged( QgsLayerTreeNode *node, bool expanded );
149  void onModelReset();
150 
151  protected:
153  QgsLayerTreeViewDefaultActions *mDefaultActions = nullptr;
155  QgsLayerTreeViewMenuProvider *mMenuProvider = nullptr;
158 };
159 
160 
170 {
171  public:
172  virtual ~QgsLayerTreeViewMenuProvider() = default;
173 
175  virtual QMenu *createContextMenu() = 0 SIP_FACTORY;
176 };
177 
178 
179 #endif // QGSLAYERTREEVIEW_H
Layer tree group node serves as a container for layers and further groups.
Base class for all map layer types.
Definition: qgsmaplayer.h:56
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...
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
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.
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_END
Definition: qgis_sip.h:175
This class is a base class for nodes in a layer tree.
#define SIP_FACTORY
Definition: qgis_sip.h:69
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:165
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.