Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[layouts] Link new scalebars to selected map item, if there is one
Fixes #13851
  • Loading branch information
nyalldawson committed Nov 24, 2017
1 parent 060270c commit 2c85182
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/app/layout/qgslayoutapputils.cpp
Expand Up @@ -157,11 +157,27 @@ void QgsLayoutAppUtils::registerGuiForKnownItemTypes()
QList<QgsLayoutItemMap *> mapItems;
scalebar->layout()->layoutItems( mapItems );

if ( !mapItems.isEmpty() )
// try to find a good map to link the scalebar 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 )
{
scalebar->setMap( mapItems.at( 0 ) );
scalebar->setMap( targetMap );
scalebar->applyDefaultSize();
}
scalebar->applyDefaultSize();
} );

registry->addLayoutItemGuiMetadata( scalebarItemMetadata.release() );
Expand Down

0 comments on commit 2c85182

Please sign in to comment.