@@ -26,47 +26,76 @@ class QgsLayerTreeViewDefaultActions;
26
26
class QgsLayerTreeViewMenuProvider ;
27
27
class QgsMapLayer ;
28
28
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
+ */
29
44
class GUI_EXPORT QgsLayerTreeView : public QTreeView
30
45
{
31
46
Q_OBJECT
32
47
public:
33
48
explicit QgsLayerTreeView ( QWidget *parent = 0 );
34
49
~QgsLayerTreeView ();
35
50
51
+ // ! Overridden setModel() from base class. Only QgsLayerTreeModel is an acceptable model.
36
52
virtual void setModel ( QAbstractItemModel* model );
37
53
54
+ // ! Get access to the model casted to QgsLayerTreeModel
38
55
QgsLayerTreeModel* layerTreeModel () const ;
39
56
57
+ // ! Get access to the default actions that may be used with the tree view
40
58
QgsLayerTreeViewDefaultActions* defaultActions ();
41
59
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
43
63
QgsLayerTreeViewMenuProvider* menuProvider () const { return mMenuProvider ; }
44
64
65
+ // ! Get currently selected layer. May be null
45
66
QgsMapLayer* currentLayer () const ;
67
+ // ! Set currently selected layer. Null pointer will deselect any layer.
46
68
void setCurrentLayer ( QgsMapLayer* layer );
47
69
70
+ // ! Get current node. May be null
48
71
QgsLayerTreeNode* currentNode () const ;
72
+ // ! Get current group node. If a layer is current node, the function will return parent group. May be null.
49
73
QgsLayerTreeGroup* currentGroupNode () const ;
50
74
75
+ // ! Return list of selected nodes
76
+ // ! @arg skipInternal If true, will ignore nodes which have an ancestor in the selection
51
77
QList<QgsLayerTreeNode*> selectedNodes ( bool skipInternal = false ) const ;
78
+ // ! Return list of selected nodes filtered to just layer nodes
52
79
QList<QgsLayerTreeLayer*> selectedLayerNodes () const ;
53
80
81
+ // ! Get list of selected layers
54
82
QList<QgsMapLayer*> selectedLayers () const ;
55
83
56
84
public slots:
85
+ // ! Force refresh of layer symbology. Normally not needed as the changes of layer's renderer are monitored by the model
57
86
void refreshLayerSymbology ( const QString& layerId );
58
87
88
+ signals:
89
+ // ! Emitted when a current layer is changed
90
+ void currentLayerChanged ( QgsMapLayer* layer );
91
+
59
92
protected:
60
93
void contextMenuEvent ( QContextMenuEvent* event );
61
94
62
95
void updateExpandedStateFromNode ( QgsLayerTreeNode* node );
63
96
64
97
QgsMapLayer* layerForIndex ( const QModelIndex& index ) const ;
65
98
66
- signals:
67
- void currentLayerChanged ( QgsMapLayer* layer );
68
-
69
-
70
99
protected slots:
71
100
72
101
void modelRowsInserted ( QModelIndex index, int start, int end );
@@ -77,17 +106,28 @@ class GUI_EXPORT QgsLayerTreeView : public QTreeView
77
106
void onCurrentChanged ();
78
107
79
108
protected:
109
+ // ! helper class with default actions. Lazily initialized.
80
110
QgsLayerTreeViewDefaultActions* mDefaultActions ;
111
+ // ! Context menu provider. Owned by the view.
81
112
QgsLayerTreeViewMenuProvider* mMenuProvider ;
113
+ // ! Keeps track of current index (to check when to emit signal about change of current layer)
82
114
QPersistentModelIndex mCurrentIndex ;
83
115
};
84
116
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
+ */
86
125
class GUI_EXPORT QgsLayerTreeViewMenuProvider
87
126
{
88
127
public:
89
128
virtual ~QgsLayerTreeViewMenuProvider () {}
90
129
130
+ // ! Return a newly created menu instance (or null pointer on error)
91
131
virtual QMenu* createContextMenu () = 0;
92
132
};
93
133
0 commit comments