QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
The QgsLayerTreeView class extends QTreeView and provides some additional functionality when working with a layer tree. More...
#include <qgslayertreeview.h>
Public Slots | |
void | collapseAllNodes () |
Enhancement of QTreeView::collapseAll() that also records expanded state in layer tree nodes. More... | |
void | expandAllNodes () |
Enhancement of QTreeView::expandAll() that also records expanded state in layer tree nodes. More... | |
void | refreshLayerSymbology (const QString &layerId) |
Force refresh of layer symbology. Normally not needed as the changes of layer's renderer are monitored by the model. More... | |
void | setLayerMarkWidth (int width) |
Set width of contextual menu mark, at right of layer node items. More... | |
void | setMessageBar (QgsMessageBar *messageBar) |
Set the message bar to display messages from the layer tree. More... | |
Signals | |
void | currentLayerChanged (QgsMapLayer *layer) |
Emitted when a current layer is changed. More... | |
Public Member Functions | |
QgsLayerTreeView (QWidget *parent=nullptr) | |
Constructor for QgsLayerTreeView. More... | |
~QgsLayerTreeView () override | |
void | addIndicator (QgsLayerTreeNode *node, QgsLayerTreeViewIndicator *indicator) |
Adds an indicator to the given layer tree node. More... | |
QgsLayerTreeGroup * | currentGroupNode () const |
Gets current group node. If a layer is current node, the function will return parent group. May be nullptr . More... | |
QgsMapLayer * | currentLayer () const |
Returns the currently selected layer, or nullptr if no layers is selected. More... | |
QgsLayerTreeModelLegendNode * | currentLegendNode () const |
Gets current legend node. More... | |
QgsLayerTreeNode * | currentNode () const |
Gets current node. May be nullptr . More... | |
QgsLayerTreeViewDefaultActions * | defaultActions () |
Gets access to the default actions that may be used with the tree view. More... | |
QList< QgsLayerTreeViewIndicator * > | indicators (QgsLayerTreeNode *node) const |
Returns list of indicators associated with a particular layer tree node. More... | |
int | layerMarkWidth () const |
Returns width of contextual menu mark, at right of layer node items. More... | |
QgsLayerTreeModel * | layerTreeModel () const |
Gets access to the model casted to QgsLayerTreeModel. More... | |
QgsLayerTreeViewMenuProvider * | menuProvider () const |
Returns pointer to the context menu provider. May be nullptr . More... | |
void | removeIndicator (QgsLayerTreeNode *node, QgsLayerTreeViewIndicator *indicator) |
Removes a previously added indicator to a layer tree node. More... | |
QList< QgsLayerTreeLayer * > | selectedLayerNodes () const |
Returns list of selected nodes filtered to just layer nodes. More... | |
QList< QgsMapLayer * > | selectedLayers () const |
Gets list of selected layers. More... | |
QList< QgsMapLayer * > | selectedLayersRecursive () const |
Gets list of selected layers, including those that are not directly selected, but their ancestor groups is selected. More... | |
QList< QgsLayerTreeNode * > | selectedNodes (bool skipInternal=false) const |
Returns list of selected nodes. More... | |
void | setCurrentLayer (QgsMapLayer *layer) |
Sets the currently selected layer. More... | |
void | setLayerVisible (QgsMapLayer *layer, bool visible) |
Convenience methods which sets the visible state of the specified map layer. More... | |
void | setMenuProvider (QgsLayerTreeViewMenuProvider *menuProvider) |
Sets provider for context menu. Takes ownership of the instance. More... | |
void | setModel (QAbstractItemModel *model) override |
Overridden setModel() from base class. Only QgsLayerTreeModel is an acceptable model. More... | |
Protected Slots | |
void | modelRowsInserted (const QModelIndex &index, int start, int end) |
void | modelRowsRemoved () |
void | onCurrentChanged () |
void | onExpandedChanged (QgsLayerTreeNode *node, bool expanded) |
void | onModelReset () |
void | updateExpandedStateToNode (const QModelIndex &index) |
Protected Member Functions | |
void | contextMenuEvent (QContextMenuEvent *event) override |
void | dropEvent (QDropEvent *event) override |
void | keyPressEvent (QKeyEvent *event) override |
QgsMapLayer * | layerForIndex (const QModelIndex &index) const |
void | mouseReleaseEvent (QMouseEvent *event) override |
void | resizeEvent (QResizeEvent *event) override |
void | updateExpandedStateFromNode (QgsLayerTreeNode *node) |
Protected Attributes | |
QString | mCurrentLayerID |
Keeps track of current layer ID (to check when to emit signal about change of current layer) More... | |
QgsLayerTreeViewDefaultActions * | mDefaultActions = nullptr |
helper class with default actions. Lazily initialized. More... | |
QHash< QgsLayerTreeNode *, QList< QgsLayerTreeViewIndicator * > > | mIndicators |
Storage of indicators used with the tree view. More... | |
QPoint | mLastReleaseMousePos |
Used by the item delegate for identification of which indicator has been clicked. More... | |
int | mLayerMarkWidth |
Width of contextual menu mark for layer nodes. More... | |
QgsLayerTreeViewMenuProvider * | mMenuProvider = nullptr |
Context menu provider. Owned by the view. More... | |
Friends | |
class | QgsLayerTreeViewItemDelegate |
The QgsLayerTreeView class extends QTreeView and provides some additional functionality when working with a layer tree.
The view updates expanded state of layer tree nodes and also listens to changes to expanded states in the layer tree.
The view keeps track of the current layer and emits a signal when the current layer has changed.
Allows the client to specify a context menu provider with custom actions. Also it comes with a set of default actions that can be used when building context menu.
Definition at line 51 of file qgslayertreeview.h.
|
explicit |
Constructor for QgsLayerTreeView.
Definition at line 38 of file qgslayertreeview.cpp.
|
override |
Definition at line 76 of file qgslayertreeview.cpp.
void QgsLayerTreeView::addIndicator | ( | QgsLayerTreeNode * | node, |
QgsLayerTreeViewIndicator * | indicator | ||
) |
Adds an indicator to the given layer tree node.
Indicators are icons shown next to layer/group names in the layer tree view. They can be used to show extra information with tree nodes and they allow user interaction.
Does not take ownership of the indicator. One indicator object may be used for multiple layer tree nodes.
Definition at line 425 of file qgslayertreeview.cpp.
|
slot |
Enhancement of QTreeView::collapseAll() that also records expanded state in layer tree nodes.
Definition at line 504 of file qgslayertreeview.cpp.
|
overrideprotected |
Definition at line 158 of file qgslayertreeview.cpp.
QgsLayerTreeGroup * QgsLayerTreeView::currentGroupNode | ( | ) | const |
Gets current group node. If a layer is current node, the function will return parent group. May be nullptr
.
Definition at line 362 of file qgslayertreeview.cpp.
QgsMapLayer * QgsLayerTreeView::currentLayer | ( | ) | const |
Returns the currently selected layer, or nullptr
if no layers is selected.
Definition at line 128 of file qgslayertreeview.cpp.
|
signal |
Emitted when a current layer is changed.
QgsLayerTreeModelLegendNode * QgsLayerTreeView::currentLegendNode | ( | ) | const |
Gets current legend node.
May be nullptr
if current node is not a legend node.
Definition at line 384 of file qgslayertreeview.cpp.
QgsLayerTreeNode * QgsLayerTreeView::currentNode | ( | ) | const |
Gets current node. May be nullptr
.
Definition at line 357 of file qgslayertreeview.cpp.
QgsLayerTreeViewDefaultActions * QgsLayerTreeView::defaultActions | ( | ) |
Gets access to the default actions that may be used with the tree view.
Definition at line 115 of file qgslayertreeview.cpp.
|
overrideprotected |
Definition at line 568 of file qgslayertreeview.cpp.
|
slot |
Enhancement of QTreeView::expandAll() that also records expanded state in layer tree nodes.
Definition at line 497 of file qgslayertreeview.cpp.
QList< QgsLayerTreeViewIndicator * > QgsLayerTreeView::indicators | ( | QgsLayerTreeNode * | node | ) | const |
Returns list of indicators associated with a particular layer tree node.
Definition at line 444 of file qgslayertreeview.cpp.
|
overrideprotected |
Definition at line 540 of file qgslayertreeview.cpp.
|
protected |
Definition at line 335 of file qgslayertreeview.cpp.
|
inline |
Returns width of contextual menu mark, at right of layer node items.
Definition at line 172 of file qgslayertreeview.h.
QgsLayerTreeModel * QgsLayerTreeView::layerTreeModel | ( | ) | const |
Gets access to the model casted to QgsLayerTreeModel.
Definition at line 110 of file qgslayertreeview.cpp.
|
inline |
Returns pointer to the context menu provider. May be nullptr
.
Definition at line 83 of file qgslayertreeview.h.
|
protectedslot |
Definition at line 174 of file qgslayertreeview.cpp.
|
protectedslot |
Definition at line 245 of file qgslayertreeview.cpp.
|
overrideprotected |
Definition at line 525 of file qgslayertreeview.cpp.
|
protectedslot |
Definition at line 276 of file qgslayertreeview.cpp.
|
protectedslot |
Definition at line 297 of file qgslayertreeview.cpp.
|
protectedslot |
Definition at line 320 of file qgslayertreeview.cpp.
|
slot |
Force refresh of layer symbology. Normally not needed as the changes of layer's renderer are monitored by the model.
Definition at line 456 of file qgslayertreeview.cpp.
void QgsLayerTreeView::removeIndicator | ( | QgsLayerTreeNode * | node, |
QgsLayerTreeViewIndicator * | indicator | ||
) |
Removes a previously added indicator to a layer tree node.
Does not delete the indicator.
Definition at line 438 of file qgslayertreeview.cpp.
|
overrideprotected |
Definition at line 577 of file qgslayertreeview.cpp.
QList< QgsLayerTreeLayer * > QgsLayerTreeView::selectedLayerNodes | ( | ) | const |
Returns list of selected nodes filtered to just layer nodes.
Definition at line 394 of file qgslayertreeview.cpp.
QList< QgsMapLayer * > QgsLayerTreeView::selectedLayers | ( | ) | const |
Gets list of selected layers.
Definition at line 406 of file qgslayertreeview.cpp.
QList< QgsMapLayer * > QgsLayerTreeView::selectedLayersRecursive | ( | ) | const |
Gets list of selected layers, including those that are not directly selected, but their ancestor groups is selected.
If we have a group with two layers L1, L2 and just the group node is selected, this method returns L1 and L2, while selectedLayers() returns an empty list.
Definition at line 418 of file qgslayertreeview.cpp.
QList< QgsLayerTreeNode * > QgsLayerTreeView::selectedNodes | ( | bool | skipInternal = false | ) | const |
Returns list of selected nodes.
skipInternal | If true , will ignore nodes which have an ancestor in the selection |
Definition at line 389 of file qgslayertreeview.cpp.
void QgsLayerTreeView::setCurrentLayer | ( | QgsMapLayer * | layer | ) |
Sets the currently selected layer.
If layer is nullptr
then all layers will be deselected.
Definition at line 133 of file qgslayertreeview.cpp.
|
inlineslot |
Set width of contextual menu mark, at right of layer node items.
Definition at line 209 of file qgslayertreeview.h.
void QgsLayerTreeView::setLayerVisible | ( | QgsMapLayer * | layer, |
bool | visible | ||
) |
Convenience methods which sets the visible state of the specified map layer.
Definition at line 148 of file qgslayertreeview.cpp.
void QgsLayerTreeView::setMenuProvider | ( | QgsLayerTreeViewMenuProvider * | menuProvider | ) |
Sets provider for context menu. Takes ownership of the instance.
Definition at line 122 of file qgslayertreeview.cpp.
|
slot |
Set the message bar to display messages from the layer tree.
Definition at line 511 of file qgslayertreeview.cpp.
|
override |
Overridden setModel() from base class. Only QgsLayerTreeModel is an acceptable model.
Definition at line 81 of file qgslayertreeview.cpp.
|
protected |
Definition at line 325 of file qgslayertreeview.cpp.
|
protectedslot |
Definition at line 251 of file qgslayertreeview.cpp.
|
friend |
Definition at line 272 of file qgslayertreeview.h.
|
protected |
Keeps track of current layer ID (to check when to emit signal about change of current layer)
Definition at line 259 of file qgslayertreeview.h.
|
protected |
helper class with default actions. Lazily initialized.
Definition at line 255 of file qgslayertreeview.h.
|
protected |
Storage of indicators used with the tree view.
Definition at line 261 of file qgslayertreeview.h.
|
protected |
Used by the item delegate for identification of which indicator has been clicked.
Definition at line 263 of file qgslayertreeview.h.
|
protected |
Width of contextual menu mark for layer nodes.
Definition at line 266 of file qgslayertreeview.h.
|
protected |
Context menu provider. Owned by the view.
Definition at line 257 of file qgslayertreeview.h.