Skip to content

Commit ee3e378

Browse files
committedDec 15, 2022
Remove unnecessary check
1 parent 5c1e312 commit ee3e378

File tree

1 file changed

+29
-31
lines changed

1 file changed

+29
-31
lines changed
 

‎src/core/expression/qgsexpressionutils.cpp

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -210,45 +210,43 @@ void QgsExpressionUtils::executeLambdaForMapLayer( const QVariant &value, const
210210
// So we need to fetch the layer and then run the function on the layer's thread.
211211

212212
const QString identifier = value.toString();
213+
213214
// check through layer stores from context
214-
if ( context )
215-
{
216-
const QList< QgsMapLayerStore * > stores = context->layerStores();
215+
const QList< QgsMapLayerStore * > stores = context->layerStores();
217216

218-
for ( QgsMapLayerStore *store : stores )
217+
for ( QgsMapLayerStore *store : stores )
218+
{
219+
QPointer< QgsMapLayerStore > storePointer( store );
220+
auto findLayerInStoreFunction = [ storePointer, identifier, function, &foundLayer ]
219221
{
220-
QPointer< QgsMapLayerStore > storePointer( store );
221-
auto findLayerInStoreFunction = [ storePointer, identifier, function, &foundLayer ]
222+
QgsMapLayer *ml = nullptr;
223+
if ( QgsMapLayerStore *store = storePointer.data() )
222224
{
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 )
225234
{
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;
239237
}
240-
};
238+
}
239+
};
241240

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 );
248247

249-
if ( foundLayer )
250-
return;
251-
}
248+
if ( foundLayer )
249+
return;
252250
}
253251

254252
// last resort - QgsProject instance. This is bad, we need to remove this!

0 commit comments

Comments
 (0)
Please sign in to comment.