Skip to content

Commit 101d3c4

Browse files
committed
[layertree] Doxygen docs for QgsLayerTreeView
1 parent 9cd70c5 commit 101d3c4

File tree

2 files changed

+52
-6
lines changed

2 files changed

+52
-6
lines changed

src/gui/layertree/qgslayertreeview.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ QgsMapLayer* QgsLayerTreeView::currentLayer() const
8787

8888
void QgsLayerTreeView::setCurrentLayer( QgsMapLayer* layer )
8989
{
90+
if ( !layer )
91+
{
92+
setCurrentIndex( QModelIndex() );
93+
return;
94+
}
95+
9096
QgsLayerTreeLayer* nodeLayer = layerTreeModel()->rootGroup()->findLayer( layer->id() );
9197
if ( !nodeLayer )
9298
return;

src/gui/layertree/qgslayertreeview.h

+46-6
Original file line numberDiff line numberDiff line change
@@ -26,47 +26,76 @@ class QgsLayerTreeViewDefaultActions;
2626
class QgsLayerTreeViewMenuProvider;
2727
class QgsMapLayer;
2828

29+
/**
30+
* The QgsLayerTreeView class extends QTreeView and provides some additional functionality
31+
* when working with a layer tree.
32+
*
33+
* The view updates expanded state of layer tree nodes and also listens to changes
34+
* to expanded states in the layer tree.
35+
*
36+
* The view keeps track of the current layer and emits a signal when the current layer has changed.
37+
*
38+
* Allows the client to specify a context menu provider with custom actions. Also it comes
39+
* with a set of default actions that can be used when building context menu.
40+
*
41+
* @see QgsLayerTreeModel
42+
* @note added in 2.4
43+
*/
2944
class GUI_EXPORT QgsLayerTreeView : public QTreeView
3045
{
3146
Q_OBJECT
3247
public:
3348
explicit QgsLayerTreeView( QWidget *parent = 0 );
3449
~QgsLayerTreeView();
3550

51+
//! Overridden setModel() from base class. Only QgsLayerTreeModel is an acceptable model.
3652
virtual void setModel( QAbstractItemModel* model );
3753

54+
//! Get access to the model casted to QgsLayerTreeModel
3855
QgsLayerTreeModel* layerTreeModel() const;
3956

57+
//! Get access to the default actions that may be used with the tree view
4058
QgsLayerTreeViewDefaultActions* defaultActions();
4159

42-
void setMenuProvider( QgsLayerTreeViewMenuProvider* menuProvider ); // takes ownership
60+
//! Set provider for context menu. Takes ownership of the instance
61+
void setMenuProvider( QgsLayerTreeViewMenuProvider* menuProvider );
62+
//! Return pointer to the context menu provider. May be null
4363
QgsLayerTreeViewMenuProvider* menuProvider() const { return mMenuProvider; }
4464

65+
//! Get currently selected layer. May be null
4566
QgsMapLayer* currentLayer() const;
67+
//! Set currently selected layer. Null pointer will deselect any layer.
4668
void setCurrentLayer( QgsMapLayer* layer );
4769

70+
//! Get current node. May be null
4871
QgsLayerTreeNode* currentNode() const;
72+
//! Get current group node. If a layer is current node, the function will return parent group. May be null.
4973
QgsLayerTreeGroup* currentGroupNode() const;
5074

75+
//! Return list of selected nodes
76+
//! @arg skipInternal If true, will ignore nodes which have an ancestor in the selection
5177
QList<QgsLayerTreeNode*> selectedNodes( bool skipInternal = false ) const;
78+
//! Return list of selected nodes filtered to just layer nodes
5279
QList<QgsLayerTreeLayer*> selectedLayerNodes() const;
5380

81+
//! Get list of selected layers
5482
QList<QgsMapLayer*> selectedLayers() const;
5583

5684
public slots:
85+
//! Force refresh of layer symbology. Normally not needed as the changes of layer's renderer are monitored by the model
5786
void refreshLayerSymbology( const QString& layerId );
5887

88+
signals:
89+
//! Emitted when a current layer is changed
90+
void currentLayerChanged( QgsMapLayer* layer );
91+
5992
protected:
6093
void contextMenuEvent( QContextMenuEvent* event );
6194

6295
void updateExpandedStateFromNode( QgsLayerTreeNode* node );
6396

6497
QgsMapLayer* layerForIndex( const QModelIndex& index ) const;
6598

66-
signals:
67-
void currentLayerChanged( QgsMapLayer* layer );
68-
69-
7099
protected slots:
71100

72101
void modelRowsInserted( QModelIndex index, int start, int end );
@@ -77,17 +106,28 @@ class GUI_EXPORT QgsLayerTreeView : public QTreeView
77106
void onCurrentChanged();
78107

79108
protected:
109+
//! helper class with default actions. Lazily initialized.
80110
QgsLayerTreeViewDefaultActions* mDefaultActions;
111+
//! Context menu provider. Owned by the view.
81112
QgsLayerTreeViewMenuProvider* mMenuProvider;
113+
//! Keeps track of current index (to check when to emit signal about change of current layer)
82114
QPersistentModelIndex mCurrentIndex;
83115
};
84116

85-
/** interface to allow custom menus */
117+
118+
/**
119+
* Implementation of this interface can be implemented to allow QgsLayerTreeView
120+
* instance to provide custom context menus (opened upon right-click).
121+
*
122+
* @see QgsLayerTreeView
123+
* @note added in 2.4
124+
*/
86125
class GUI_EXPORT QgsLayerTreeViewMenuProvider
87126
{
88127
public:
89128
virtual ~QgsLayerTreeViewMenuProvider() {}
90129

130+
//! Return a newly created menu instance (or null pointer on error)
91131
virtual QMenu* createContextMenu() = 0;
92132
};
93133

0 commit comments

Comments
 (0)