Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add setCurrentNode to qgslayertreeview #58822

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions python/PyQt6/gui/auto_generated/layertree/qgslayertreeview.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ for mapping the view indexes through the view's proxy model to the source model.

QModelIndex node2index( QgsLayerTreeNode *node ) const;
%Docstring
Returns proxy model index for a given node. If the node does not belong to the layer tree, the result is undefined
Returns proxy model index for a given node. If the node does not belong to the layer tree, the result is undefined

Unlike :py:func:`QgsLayerTreeModel.node2index()`, calling this method correctly accounts
for mapping the view indexes through the view's proxy model to the source model.
Expand All @@ -150,7 +150,7 @@ for mapping the view indexes through the view's proxy model to the source model.

QModelIndex node2sourceIndex( QgsLayerTreeNode *node ) const;
%Docstring
Returns source model index for a given node. If the node does not belong to the layer tree, the result is undefined
Returns source model index for a given node. If the node does not belong to the layer tree, the result is undefined

.. versionadded:: 3.18
%End
Expand Down Expand Up @@ -213,6 +213,17 @@ Convenience methods which sets the visible state of the specified map ``layer``.
.. seealso:: :py:func:`QgsLayerTreeNode.setItemVisibilityChecked`

.. versionadded:: 3.10
%End

void setCurrentNode( QgsLayerTreeNode *node );
%Docstring
Sets the currently selected ``node``.

If ``node`` is ``None`` then all nodes will be deselected.

.. seealso:: :py:func:`currentNode`

.. versionadded:: 3.40
%End

void setCurrentLayer( QgsMapLayer *layer );
Expand Down Expand Up @@ -361,7 +372,7 @@ Returns if valid layers should be hidden (i.e. only invalid layers are shown).
public slots:
void refreshLayerSymbology( const QString &layerId );
%Docstring
Force refresh of layer symbology. Normally not needed as the changes of layer's renderer are monitored by the model
Force refresh of layer symbology. Normally not needed as the changes of layer's renderer are monitored by the model
%End

void expandAllNodes();
Expand Down
13 changes: 12 additions & 1 deletion src/gui/layertree/qgslayertreeview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,17 @@ QgsMapLayer *QgsLayerTreeView::currentLayer() const
return layerForIndex( currentIndex() );
}

void QgsLayerTreeView::setCurrentNode( QgsLayerTreeNode *node )
{
if ( !node )
{
setCurrentIndex( QModelIndex() );
return;
}

setCurrentIndex( node2index( node ) );
}

void QgsLayerTreeView::setCurrentLayer( QgsMapLayer *layer )
{
if ( !layer )
Expand All @@ -163,7 +174,7 @@ void QgsLayerTreeView::setCurrentLayer( QgsMapLayer *layer )
if ( !nodeLayer )
return;

setCurrentIndex( node2index( nodeLayer ) );
setCurrentNode( nodeLayer );
}

void QgsLayerTreeView::setLayerVisible( QgsMapLayer *layer, bool visible )
Expand Down
10 changes: 10 additions & 0 deletions src/gui/layertree/qgslayertreeview.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,16 @@ class GUI_EXPORT QgsLayerTreeView : public QTreeView
*/
void setLayerVisible( QgsMapLayer *layer, bool visible );

/**
* Sets the currently selected \a node.
*
* If \a node is NULLPTR then all nodes will be deselected.
*
* \see currentNode()
* \since QGIS 3.40
*/
void setCurrentNode( QgsLayerTreeNode *node );

/**
* Sets the currently selected \a layer.
*
Expand Down
Loading