@@ -210,45 +210,43 @@ void QgsExpressionUtils::executeLambdaForMapLayer( const QVariant &value, const
210
210
// So we need to fetch the layer and then run the function on the layer's thread.
211
211
212
212
const QString identifier = value.toString ();
213
+
213
214
// check through layer stores from context
214
- if ( context )
215
- {
216
- const QList< QgsMapLayerStore * > stores = context->layerStores ();
215
+ const QList< QgsMapLayerStore * > stores = context->layerStores ();
217
216
218
- for ( QgsMapLayerStore *store : stores )
217
+ for ( QgsMapLayerStore *store : stores )
218
+ {
219
+ QPointer< QgsMapLayerStore > storePointer ( store );
220
+ auto findLayerInStoreFunction = [ storePointer, identifier, function, &foundLayer ]
219
221
{
220
- QPointer< QgsMapLayerStore > storePointer ( store ) ;
221
- auto findLayerInStoreFunction = [ storePointer, identifier, function, &foundLayer ]
222
+ QgsMapLayer *ml = nullptr ;
223
+ if ( QgsMapLayerStore *store = storePointer. data () )
222
224
{
223
- QgsMapLayer *ml = nullptr ;
224
- if ( QgsMapLayerStore *store = storePointer.data () )
225
+ // look for matching layer by id
226
+ ml = store->mapLayer ( identifier );
227
+ if ( !ml )
228
+ {
229
+ // Still nothing? Check for layer name
230
+ ml = store->mapLayersByName ( identifier ).value ( 0 );
231
+ }
232
+
233
+ if ( ml )
225
234
{
226
- // look for matching layer by id
227
- ml = store->mapLayer ( identifier );
228
- if ( !ml )
229
- {
230
- // Still nothing? Check for layer name
231
- ml = store->mapLayersByName ( identifier ).value ( 0 );
232
- }
233
-
234
- if ( ml )
235
- {
236
- function ( ml );
237
- foundLayer = true ;
238
- }
235
+ function ( ml );
236
+ foundLayer = true ;
239
237
}
240
- };
238
+ }
239
+ };
241
240
242
- // Make sure we only deal with the store on the thread where it lives.
243
- // Anything else risks a crash.
244
- if ( QThread::currentThread () == store->thread () )
245
- findLayerInStoreFunction ();
246
- else
247
- QMetaObject::invokeMethod ( store, findLayerInStoreFunction, Qt::BlockingQueuedConnection );
241
+ // Make sure we only deal with the store on the thread where it lives.
242
+ // Anything else risks a crash.
243
+ if ( QThread::currentThread () == store->thread () )
244
+ findLayerInStoreFunction ();
245
+ else
246
+ QMetaObject::invokeMethod ( store, findLayerInStoreFunction, Qt::BlockingQueuedConnection );
248
247
249
- if ( foundLayer )
250
- return ;
251
- }
248
+ if ( foundLayer )
249
+ return ;
252
250
}
253
251
254
252
// last resort - QgsProject instance. This is bad, we need to remove this!
0 commit comments