Skip to content
Permalink
Browse files

[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 2c85182c3fd9348d054632ecc4fb110385a34c9e
Showing with 19 additions and 3 deletions.
  1. +19 −3 src/app/layout/qgslayoutapputils.cpp
@@ -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() );

0 comments on commit 2c85182

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