Skip to content

Commit

Permalink
Also link new legends to selected map item
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 24, 2017
1 parent 2c85182 commit 63f14bd
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/app/layout/qgslayoutapputils.cpp
Expand Up @@ -132,9 +132,25 @@ void QgsLayoutAppUtils::registerGuiForKnownItemTypes()
QList<QgsLayoutItemMap *> mapItems;
legend->layout()->layoutItems( mapItems );

if ( !mapItems.isEmpty() )
// try to find a good map to link the legend with by default
// start by trying to find a selected map
QgsLayoutItemMap *targetMap = nullptr;
for ( QgsLayoutItemMap *map : qgis::as_const( mapItems ) )
{
if ( map->isSelected() )
{
targetMap = map;
break;
}
}
// otherwise just use first map
if ( !targetMap && !mapItems.isEmpty() )
{
targetMap = mapItems.at( 0 );
}
if ( targetMap )
{
legend->setMap( mapItems.at( 0 ) );
legend->setMap( targetMap );
}

legend->updateLegend();
Expand Down

0 comments on commit 63f14bd

Please sign in to comment.