Skip to content
Permalink
Browse files
restore previous Qgs(App)LegendInterface behaviour
  • Loading branch information
jef-n committed May 26, 2014
1 parent 02e1e12 commit 2c20afd303068d27baa3ce0233cb18272337d7ec
Showing with 14 additions and 5 deletions.
  1. +13 −4 src/app/legend/qgsapplegendinterface.cpp
  2. +1 −1 src/app/legend/qgsapplegendinterface.h
@@ -45,14 +45,23 @@ int QgsAppLegendInterface::addGroup( QString name, bool expand, QTreeWidgetItem*
return addGroup( name, expand, -1 );
}

void QgsAppLegendInterface::setExpanded( QgsLayerTreeNode *node, bool expand )
{
QModelIndex idx = mLayerTreeView->layerTreeModel()->node2index( node );
if ( expand )
mLayerTreeView->expand( idx );
else
mLayerTreeView->collapse( idx );
}

int QgsAppLegendInterface::addGroup( QString name, bool expand, int parentIndex )
{
QgsLayerTreeGroup* parentGroup = parentIndex == -1 ? mLayerTreeView->layerTreeModel()->rootGroup() : groupIndexToNode( parentIndex );
if ( !parentGroup )
return -1;

QgsLayerTreeGroup* group = parentGroup->addGroup( name );
group->setExpanded( expand );
setExpanded( group, expand );
return groupNodeToIndex( group );
}

@@ -76,7 +85,7 @@ void QgsAppLegendInterface::moveLayer( QgsMapLayer * ml, int groupIndex )
if ( !nodeLayer || !QgsLayerTree::isGroup( nodeLayer->parent() ) )
return;

group->addLayer( ml );
group->insertLayer( 0, ml );

QgsLayerTreeGroup* nodeLayerParentGroup = QgsLayerTree::toGroup( nodeLayer->parent() );
nodeLayerParentGroup->removeChildNode( nodeLayer );
@@ -85,7 +94,7 @@ void QgsAppLegendInterface::moveLayer( QgsMapLayer * ml, int groupIndex )
void QgsAppLegendInterface::setGroupExpanded( int groupIndex, bool expand )
{
if ( QgsLayerTreeGroup* group = groupIndexToNode( groupIndex ) )
group->setExpanded( expand );
setExpanded( group, expand );
}

void QgsAppLegendInterface::setGroupVisible( int groupIndex, bool visible )
@@ -155,7 +164,7 @@ void QgsAppLegendInterface::setLayerVisible( QgsMapLayer * ml, bool visible )
void QgsAppLegendInterface::setLayerExpanded( QgsMapLayer * ml, bool expand )
{
if ( QgsLayerTreeLayer* nodeLayer = mLayerTreeView->layerTreeModel()->rootGroup()->findLayer( ml->id() ) )
nodeLayer->setExpanded( expand );
setExpanded( nodeLayer, expand );
}

static void _collectGroups( QgsLayerTreeGroup* parentGroup, QStringList& list )
@@ -111,11 +111,11 @@ class QgsAppLegendInterface : public QgsLegendInterface
void onRemovedChildren();

private:

//! Pointer to QgsLegend object
QgsLayerTreeView* mLayerTreeView;
QgsLayerTreeGroup* groupIndexToNode( int itemIndex );
int groupNodeToIndex( QgsLayerTreeGroup* group );
void setExpanded( QgsLayerTreeNode *node, bool expand );
};

#endif //QGSLEGENDAPPIFACE_H

0 comments on commit 2c20afd

Please sign in to comment.