Skip to content

Commit

Permalink
restore previous Qgs(App)LegendInterface behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed May 26, 2014
1 parent 02e1e12 commit 2c20afd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
17 changes: 13 additions & 4 deletions src/app/legend/qgsapplegendinterface.cpp
Expand Up @@ -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 );
}

Expand All @@ -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 );
Expand All @@ -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 )
Expand Down Expand Up @@ -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 )
Expand Down
2 changes: 1 addition & 1 deletion src/app/legend/qgsapplegendinterface.h
Expand Up @@ -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.