mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-27 00:33:48 -05:00
[layertree] Update layer tree view when a tree node changes the expanded state
This commit is contained in:
parent
e4dd900854
commit
b134c254f3
@ -112,6 +112,8 @@ class QgsLayerTreeNode : QObject
|
||||
void visibilityChanged( QgsLayerTreeNode* node, Qt::CheckState state );
|
||||
//! Emitted when a custom property of a node within the tree has been changed or removed
|
||||
void customPropertyChanged( QgsLayerTreeNode* node, QString key );
|
||||
//! Emitted when the collapsed/expanded state of a node within the tree has been changed
|
||||
void expandedChanged( QgsLayerTreeNode* node, bool expanded );
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -58,6 +58,23 @@ QgsLayerTreeNode* QgsLayerTreeNode::readXML( QDomElement& element )
|
||||
return node;
|
||||
}
|
||||
|
||||
|
||||
bool QgsLayerTreeNode::isExpanded() const
|
||||
{
|
||||
return mExpanded;
|
||||
}
|
||||
|
||||
|
||||
void QgsLayerTreeNode::setExpanded( bool expanded )
|
||||
{
|
||||
if ( mExpanded == expanded )
|
||||
return;
|
||||
|
||||
mExpanded = expanded;
|
||||
emit expandedChanged( this, expanded );
|
||||
}
|
||||
|
||||
|
||||
void QgsLayerTreeNode::setCustomProperty( const QString &key, const QVariant &value )
|
||||
{
|
||||
mProperties.setValue( key, value );
|
||||
@ -115,6 +132,7 @@ void QgsLayerTreeNode::insertChildrenPrivate( int index, QList<QgsLayerTreeNode*
|
||||
connect( nodes[i], SIGNAL( removedChildren( QgsLayerTreeNode*, int, int ) ), this, SIGNAL( removedChildren( QgsLayerTreeNode*, int, int ) ) );
|
||||
connect( nodes[i], SIGNAL( customPropertyChanged( QgsLayerTreeNode*, QString ) ), this, SIGNAL( customPropertyChanged( QgsLayerTreeNode*, QString ) ) );
|
||||
connect( nodes[i], SIGNAL( visibilityChanged( QgsLayerTreeNode*, Qt::CheckState ) ), this, SIGNAL( visibilityChanged( QgsLayerTreeNode*, Qt::CheckState ) ) );
|
||||
connect( nodes[i], SIGNAL( expandedChanged( QgsLayerTreeNode*, bool ) ), this, SIGNAL( expandedChanged( QgsLayerTreeNode*, bool ) ) );
|
||||
}
|
||||
emit addedChildren( this, index, indexTo );
|
||||
}
|
||||
|
@ -92,9 +92,9 @@ class CORE_EXPORT QgsLayerTreeNode : public QObject
|
||||
virtual QgsLayerTreeNode* clone() const = 0;
|
||||
|
||||
//! Return whether the node should be shown as expanded or collapsed in GUI
|
||||
bool isExpanded() const { return mExpanded; }
|
||||
bool isExpanded() const;
|
||||
//! Set whether the node should be shown as expanded or collapsed in GUI
|
||||
void setExpanded( bool expanded ) { mExpanded = expanded; }
|
||||
void setExpanded( bool expanded );
|
||||
|
||||
/** Set a custom property for the node. Properties are stored in a map and saved in project file. */
|
||||
void setCustomProperty( const QString& key, const QVariant& value );
|
||||
@ -119,6 +119,8 @@ class CORE_EXPORT QgsLayerTreeNode : public QObject
|
||||
void visibilityChanged( QgsLayerTreeNode* node, Qt::CheckState state );
|
||||
//! Emitted when a custom property of a node within the tree has been changed or removed
|
||||
void customPropertyChanged( QgsLayerTreeNode* node, QString key );
|
||||
//! Emitted when the collapsed/expanded state of a node within the tree has been changed
|
||||
void expandedChanged( QgsLayerTreeNode* node, bool expanded );
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -57,6 +57,8 @@ void QgsLayerTreeView::setModel( QAbstractItemModel* model )
|
||||
|
||||
QTreeView::setModel( model );
|
||||
|
||||
connect( layerTreeModel()->rootGroup(), SIGNAL( expandedChanged( QgsLayerTreeNode*, bool ) ), this, SLOT( onExpandedChanged( QgsLayerTreeNode*, bool ) ) );
|
||||
|
||||
connect( selectionModel(), SIGNAL( currentChanged( QModelIndex, QModelIndex ) ), this, SLOT( onCurrentChanged() ) );
|
||||
|
||||
updateExpandedStateFromNode( layerTreeModel()->rootGroup() );
|
||||
@ -163,6 +165,13 @@ void QgsLayerTreeView::onCurrentChanged()
|
||||
emit currentLayerChanged( layerCurrent );
|
||||
}
|
||||
|
||||
void QgsLayerTreeView::onExpandedChanged( QgsLayerTreeNode* node, bool expanded )
|
||||
{
|
||||
QModelIndex idx = layerTreeModel()->node2index( node );
|
||||
if ( isExpanded( idx ) != expanded )
|
||||
setExpanded( idx, expanded );
|
||||
}
|
||||
|
||||
void QgsLayerTreeView::updateExpandedStateFromNode( QgsLayerTreeNode* node )
|
||||
{
|
||||
QModelIndex idx = layerTreeModel()->node2index( node );
|
||||
|
@ -104,6 +104,7 @@ class GUI_EXPORT QgsLayerTreeView : public QTreeView
|
||||
void updateExpandedStateToNode( QModelIndex index );
|
||||
|
||||
void onCurrentChanged();
|
||||
void onExpandedChanged( QgsLayerTreeNode* node, bool expanded );
|
||||
|
||||
protected:
|
||||
//! helper class with default actions. Lazily initialized.
|
||||
|
Loading…
x
Reference in New Issue
Block a user