mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-08 00:02:35 -05:00
[layouts] Link new scalebars to selected map item, if there is one
Fixes #13851
This commit is contained in:
parent
060270c0be
commit
2c85182c3f
@ -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 ) )
|
||||
{
|
||||
scalebar->setMap( mapItems.at( 0 ) );
|
||||
if ( map->isSelected() )
|
||||
{
|
||||
targetMap = map;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// otherwise just use first map
|
||||
if ( !targetMap && !mapItems.isEmpty() )
|
||||
{
|
||||
targetMap = mapItems.at( 0 );
|
||||
}
|
||||
if ( targetMap )
|
||||
{
|
||||
scalebar->setMap( targetMap );
|
||||
scalebar->applyDefaultSize();
|
||||
}
|
||||
scalebar->applyDefaultSize();
|
||||
} );
|
||||
|
||||
registry->addLayoutItemGuiMetadata( scalebarItemMetadata.release() );
|
||||
|
Loading…
x
Reference in New Issue
Block a user