File tree Expand file tree Collapse file tree 1 file changed +19
-3
lines changed Expand file tree Collapse file tree 1 file changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -157,11 +157,27 @@ void QgsLayoutAppUtils::registerGuiForKnownItemTypes()
157
157
QList<QgsLayoutItemMap *> mapItems;
158
158
scalebar->layout ()->layoutItems ( mapItems );
159
159
160
- if ( !mapItems.isEmpty () )
160
+ // try to find a good map to link the scalebar with by default
161
+ // start by trying to find a selected map
162
+ QgsLayoutItemMap *targetMap = nullptr ;
163
+ for ( QgsLayoutItemMap *map : qgis::as_const ( mapItems ) )
164
+ {
165
+ if ( map->isSelected () )
166
+ {
167
+ targetMap = map;
168
+ break ;
169
+ }
170
+ }
171
+ // otherwise just use first map
172
+ if ( !targetMap && !mapItems.isEmpty () )
173
+ {
174
+ targetMap = mapItems.at ( 0 );
175
+ }
176
+ if ( targetMap )
161
177
{
162
- scalebar->setMap ( mapItems.at ( 0 ) );
178
+ scalebar->setMap ( targetMap );
179
+ scalebar->applyDefaultSize ();
163
180
}
164
- scalebar->applyDefaultSize ();
165
181
} );
166
182
167
183
registry->addLayoutItemGuiMetadata ( scalebarItemMetadata.release () );
You can’t perform that action at this time.
0 commit comments