Skip to content
Permalink
Browse files

Fix #11126 (Make up/down buttons work also for layer tree nodes)

  • Loading branch information
wonder-sk committed Sep 5, 2014
1 parent e2f1ceb commit 854730bb59caa2d4267aa4addd236d120c790981
Showing with 26 additions and 6 deletions.
  1. +26 −6 src/app/composer/qgscomposerlegendwidget.cpp
@@ -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 ) );

@@ -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 ) );

0 comments on commit 854730b

Please sign in to comment.
You can’t perform that action at this time.