Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly move layout legend nodes when they are filtered #60536

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions src/gui/layout/qgslayoutlegendwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -726,9 +726,10 @@ void QgsLayoutLegendWidget::mColumnSpaceSpinBox_valueChanged( double d )
}
}

static void _moveLegendNode( QgsLayerTreeLayer *nodeLayer, int legendNodeIndex, int offset )
static void _moveLegendNode( QgsLayerTreeLayer *nodeLayer, int legendNodeIndex, int destLegendNodeIndex )
{
QList<int> order = QgsMapLayerLegendUtils::legendNodeOrder( nodeLayer );
const int offset = destLegendNodeIndex - legendNodeIndex;

if ( legendNodeIndex < 0 || legendNodeIndex >= order.count() )
return;
Expand Down Expand Up @@ -770,8 +771,17 @@ void QgsLayoutLegendWidget::mMoveDownToolButton_clicked()
}
else // legend node
{
_moveLegendNode( legendNode->layerNode(), _unfilteredLegendNodeIndex( legendNode ), 1 );
mItemTreeView->layerTreeModel()->refreshLayerLegend( legendNode->layerNode() );
// get the next index, the one that will have to be above our index,
const QModelIndex nextIndex = index.siblingAtRow( index.row() + 1 );
if ( nextIndex.isValid() )
{
QgsLayerTreeModelLegendNode *nextLegendNode = mItemTreeView->index2legendNode( nextIndex );
if ( nextLegendNode )
{
_moveLegendNode( legendNode->layerNode(), _unfilteredLegendNodeIndex( legendNode ), _unfilteredLegendNodeIndex( nextLegendNode ) );
mItemTreeView->layerTreeModel()->refreshLayerLegend( legendNode->layerNode() );
}
}
}

mItemTreeView->setCurrentIndex( mItemTreeView->proxyModel()->mapFromSource( mItemTreeView->layerTreeModel()->index( sourceIndex.row() + 1, 0, parentIndex ) ) );
Expand Down Expand Up @@ -808,8 +818,17 @@ void QgsLayoutLegendWidget::mMoveUpToolButton_clicked()
}
else // legend node
{
_moveLegendNode( legendNode->layerNode(), _unfilteredLegendNodeIndex( legendNode ), -1 );
mItemTreeView->layerTreeModel()->refreshLayerLegend( legendNode->layerNode() );
// get the previous index, the one that will have to be below our index,
const QModelIndex prevIndex = index.siblingAtRow( index.row() - 1 );
if ( prevIndex.isValid() )
{
QgsLayerTreeModelLegendNode *prevLegendNode = mItemTreeView->index2legendNode( prevIndex );
if ( prevLegendNode )
{
_moveLegendNode( legendNode->layerNode(), _unfilteredLegendNodeIndex( legendNode ), _unfilteredLegendNodeIndex( prevLegendNode ) );
mItemTreeView->layerTreeModel()->refreshLayerLegend( legendNode->layerNode() );
}
}
}

mItemTreeView->setCurrentIndex( mItemTreeView->proxyModel()->mapFromSource( mItemTreeView->layerTreeModel()->index( sourceIndex.row() - 1, 0, parentIndex ) ) );
Expand Down
Loading