Skip to content

Commit

Permalink
Silence clang false positive warning
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Dec 13, 2022
1 parent 824cc42 commit 950c89f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
27 changes: 27 additions & 0 deletions src/core/expression/qgsexpressionutils.cpp
Expand Up @@ -117,6 +117,33 @@ QVariant QgsExpressionUtils::runMapLayerFunctionThreadSafe( const QVariant &valu
return res;
}

std::unique_ptr<QgsVectorLayerFeatureSource> QgsExpressionUtils::getFeatureSource( const QVariant &value, const QgsExpressionContext *context, QgsExpression *e )
{
std::unique_ptr<QgsVectorLayerFeatureSource> featureSource;

#ifndef __clang_analyzer__
auto getFeatureSource = [ &value, context, e, &featureSource ]
{
QgsVectorLayer *layer = getVectorLayer( value, context, e );

if ( layer )
{
featureSource.reset( new QgsVectorLayerFeatureSource( layer ) );
}
};

// Make sure we only deal with the vector layer on the main thread where it lives.
// Anything else risks a crash.

if ( QThread::currentThread() == qApp->thread() )
getFeatureSource();
else
QMetaObject::invokeMethod( qApp, getFeatureSource, Qt::BlockingQueuedConnection );
#endif

return featureSource;
}

QString QgsExpressionUtils::getFilePathValue( const QVariant &value, const QgsExpressionContext *context, QgsExpression *parent )
{
// if it's a map layer, return the file path of that layer...
Expand Down
24 changes: 1 addition & 23 deletions src/core/expression/qgsexpressionutils.h
Expand Up @@ -361,29 +361,7 @@ class CORE_EXPORT QgsExpressionUtils
*/
static QVariant runMapLayerFunctionThreadSafe( const QVariant &value, const QgsExpressionContext *context, QgsExpression *expression, const std::function<QVariant( QgsMapLayer * ) > &function );

static std::unique_ptr<QgsVectorLayerFeatureSource> getFeatureSource( const QVariant &value, const QgsExpressionContext *context, QgsExpression *e )
{
std::unique_ptr<QgsVectorLayerFeatureSource> featureSource;

auto getFeatureSource = [ &value, context, e, &featureSource ]
{
QgsVectorLayer *layer = getVectorLayer( value, context, e );

if ( layer )
{
featureSource.reset( new QgsVectorLayerFeatureSource( layer ) );
}
};

// Make sure we only deal with the vector layer on the main thread where it lives.
// Anything else risks a crash.
if ( QThread::currentThread() == qApp->thread() )
getFeatureSource();
else
QMetaObject::invokeMethod( qApp, getFeatureSource, Qt::BlockingQueuedConnection );

return featureSource;
}
static std::unique_ptr<QgsVectorLayerFeatureSource> getFeatureSource( const QVariant &value, const QgsExpressionContext *context, QgsExpression *e );

static QgsVectorLayer *getVectorLayer( const QVariant &value, const QgsExpressionContext *context, QgsExpression *e )
{
Expand Down

0 comments on commit 950c89f

Please sign in to comment.