Skip to content

Commit

Permalink
Fix #11126 (Make up/down buttons work also for layer tree nodes)
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Sep 5, 2014
1 parent e2f1ceb commit 854730b
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions src/app/composer/qgscomposerlegendwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,14 +516,24 @@ void QgsComposerLegendWidget::on_mMoveDownToolButton_clicked()
if ( !index.isValid() || index.row() == mItemTreeView->model()->rowCount( parentIndex ) - 1 )
return;

QgsLayerTreeNode* node = mItemTreeView->layerTreeModel()->index2node( index );
QgsLayerTreeModelLegendNode* legendNode = mItemTreeView->layerTreeModel()->index2symnode( index );
if ( !legendNode )
if ( !node && !legendNode )
return;

mLegend->beginCommand( "Moved legend item down" );

_moveLegendNode( legendNode->parent(), index.row(), 1 );
mItemTreeView->layerTreeModel()->refreshLayerSymbology( legendNode->parent() );
if ( node )
{
QgsLayerTreeGroup* parentGroup = QgsLayerTree::toGroup( node->parent() );
parentGroup->insertChildNode( index.row() + 2, node->clone() );
parentGroup->removeChildNode( node );
}
else // legend node
{
_moveLegendNode( legendNode->parent(), index.row(), 1 );
mItemTreeView->layerTreeModel()->refreshLayerSymbology( legendNode->parent() );
}

mItemTreeView->setCurrentIndex( mItemTreeView->layerTreeModel()->index( index.row() + 1, 0, parentIndex ) );

Expand All @@ -543,14 +553,24 @@ void QgsComposerLegendWidget::on_mMoveUpToolButton_clicked()
if ( !index.isValid() || index.row() == 0 )
return;

QgsLayerTreeNode* node = mItemTreeView->layerTreeModel()->index2node( index );
QgsLayerTreeModelLegendNode* legendNode = mItemTreeView->layerTreeModel()->index2symnode( index );
if ( !legendNode )
if ( !node && !legendNode )
return;

mLegend->beginCommand( "Moved legend item up" );

_moveLegendNode( legendNode->parent(), index.row(), -1 );
mItemTreeView->layerTreeModel()->refreshLayerSymbology( legendNode->parent() );
if ( node )
{
QgsLayerTreeGroup* parentGroup = QgsLayerTree::toGroup( node->parent() );
parentGroup->insertChildNode( index.row() - 1, node->clone() );
parentGroup->removeChildNode( node );
}
else // legend node
{
_moveLegendNode( legendNode->parent(), index.row(), -1 );
mItemTreeView->layerTreeModel()->refreshLayerSymbology( legendNode->parent() );
}

mItemTreeView->setCurrentIndex( mItemTreeView->layerTreeModel()->index( index.row() - 1, 0, parentIndex ) );

Expand Down

0 comments on commit 854730b

Please sign in to comment.