File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -132,9 +132,25 @@ void QgsLayoutAppUtils::registerGuiForKnownItemTypes()
132
132
QList<QgsLayoutItemMap *> mapItems;
133
133
legend->layout ()->layoutItems ( mapItems );
134
134
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 )
136
152
{
137
- legend->setMap ( mapItems. at ( 0 ) );
153
+ legend->setMap ( targetMap );
138
154
}
139
155
140
156
legend->updateLegend ();
You can’t perform that action at this time.
0 commit comments