Skip to content
Permalink
Browse files

Also link new legends to selected map item

  • Loading branch information
nyalldawson committed Nov 24, 2017
1 parent 2c85182 commit 63f14bd955f7f6a4c9c88826246beee54ae35273
Showing with 18 additions and 2 deletions.
  1. +18 −2 src/app/layout/qgslayoutapputils.cpp
@@ -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();

0 comments on commit 63f14bd

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