File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -132,9 +132,25 @@ void QgsLayoutAppUtils::registerGuiForKnownItemTypes()
132132 QList<QgsLayoutItemMap *> mapItems;
133133 legend->layout ()->layoutItems ( mapItems );
134134
135- if ( !mapItems.isEmpty () )
135+ // try to find a good map to link the legend with by default
136+ // start by trying to find a selected map
137+ QgsLayoutItemMap *targetMap = nullptr ;
138+ for ( QgsLayoutItemMap *map : qgis::as_const ( mapItems ) )
139+ {
140+ if ( map->isSelected () )
141+ {
142+ targetMap = map;
143+ break ;
144+ }
145+ }
146+ // otherwise just use first map
147+ if ( !targetMap && !mapItems.isEmpty () )
148+ {
149+ targetMap = mapItems.at ( 0 );
150+ }
151+ if ( targetMap )
136152 {
137- legend->setMap ( mapItems. at ( 0 ) );
153+ legend->setMap ( targetMap );
138154 }
139155
140156 legend->updateLegend ();
You can’t perform that action at this time.
0 commit comments