QGIS API Documentation  2.11.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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;
27 class QgsMapLayer;
28 
44 class GUI_EXPORT QgsLayerTreeView : public QTreeView
45 {
46  Q_OBJECT
47  public:
48  explicit QgsLayerTreeView( QWidget *parent = 0 );
50 
52  virtual void setModel( QAbstractItemModel* model ) override;
53 
55  QgsLayerTreeModel* layerTreeModel() const;
56 
58  QgsLayerTreeViewDefaultActions* defaultActions();
59 
61  void setMenuProvider( QgsLayerTreeViewMenuProvider* menuProvider );
63  QgsLayerTreeViewMenuProvider* menuProvider() const { return mMenuProvider; }
64 
66  QgsMapLayer* currentLayer() const;
68  void setCurrentLayer( QgsMapLayer* layer );
69 
71  QgsLayerTreeNode* currentNode() const;
73  QgsLayerTreeGroup* currentGroupNode() const;
74 
77  QList<QgsLayerTreeNode*> selectedNodes( bool skipInternal = false ) const;
79  QList<QgsLayerTreeLayer*> selectedLayerNodes() const;
80 
82  QList<QgsMapLayer*> selectedLayers() const;
83 
84  public slots:
86  void refreshLayerSymbology( const QString& layerId );
87 
88  signals:
90  void currentLayerChanged( QgsMapLayer* layer );
91 
92  protected:
93  void contextMenuEvent( QContextMenuEvent* event ) override;
94 
95  void updateExpandedStateFromNode( QgsLayerTreeNode* node );
96 
97  QgsMapLayer* layerForIndex( const QModelIndex& index ) const;
98 
99  protected slots:
100 
101  void modelRowsInserted( QModelIndex index, int start, int end );
102  void modelRowsRemoved();
103 
104  void updateExpandedStateToNode( QModelIndex index );
105 
106  void onCurrentChanged();
107  void onExpandedChanged( QgsLayerTreeNode* node, bool expanded );
108  void onModelReset();
109 
110  protected:
117 };
118 
119 
128 {
129  public:
131 
133  virtual QMenu* createContextMenu() = 0;
134 };
135 
136 
137 #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)
Layer tree node points to a map layer.