QGIS API Documentation  2.99.0-Master (23ddace)
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 
93  QgsLayerTreeModelLegendNode *currentLegendNode() const;
94 
97  QList<QgsLayerTreeNode *> selectedNodes( bool skipInternal = false ) const;
99  QList<QgsLayerTreeLayer *> selectedLayerNodes() const;
100 
102  QList<QgsMapLayer *> selectedLayers() const;
103 
104  public slots:
106  void refreshLayerSymbology( const QString &layerId );
107 
110  void expandAllNodes();
111 
114  void collapseAllNodes();
115 
116  signals:
118  void currentLayerChanged( QgsMapLayer *layer );
119 
120  protected:
121  void contextMenuEvent( QContextMenuEvent *event ) override;
122 
123  void updateExpandedStateFromNode( QgsLayerTreeNode *node );
124 
125  QgsMapLayer *layerForIndex( const QModelIndex &index ) const;
126 
127  void mouseReleaseEvent( QMouseEvent *event ) override;
128  void keyPressEvent( QKeyEvent *event ) override;
129 
130  protected slots:
131 
132  void modelRowsInserted( const QModelIndex &index, int start, int end );
133  void modelRowsRemoved();
134 
135  void updateExpandedStateToNode( const QModelIndex &index );
136 
137  void onCurrentChanged();
138  void onExpandedChanged( QgsLayerTreeNode *node, bool expanded );
139  void onModelReset();
140 
141  protected:
143  QgsLayerTreeViewDefaultActions *mDefaultActions = nullptr;
145  QgsLayerTreeViewMenuProvider *mMenuProvider = nullptr;
148 };
149 
150 
159 {
160  public:
161  virtual ~QgsLayerTreeViewMenuProvider() = default;
162 
164  virtual QMenu *createContextMenu() = 0 SIP_FACTORY;
165 };
166 
167 
168 #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:54
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:34
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:24
#define SIP_END
Definition: qgis_sip.h:163
This class is a base class for nodes in a layer tree.
#define SIP_FACTORY
Definition: qgis_sip.h:57
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:153
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.