26QgsExpressionUtils::TVL QgsExpressionUtils::AND[3][3] =
29 { False, False, False },
33QgsExpressionUtils::TVL QgsExpressionUtils::OR[3][3] =
40QgsExpressionUtils::TVL QgsExpressionUtils::NOT[3] = { True, False,
Unknown };
45 if ( value.userType() == QMetaType::type(
"QgsGradientColorRamp" ) )
50 parent->
setEvalErrorString( QObject::tr(
"Cannot convert '%1' to gradient ramp" ).arg( value.toString() ) );
57 return getMapLayerPrivate( value, context, parent );
66#ifdef __clang_analyzer__
76 qWarning(
"Raw map layer pointer stored in expression evaluation, switch to QgsWeakMapLayerPointer instead" );
83 const QString identifier = value.toString();
88 const QList< QgsMapLayerStore * > stores = context->
layerStores();
92 QPointer< QgsMapLayerStore > storePointer( store );
93 auto findLayerInStoreFunction = [ storePointer, &ml, identifier ]
98 ml = store->mapLayer( identifier );
104 ml = store->mapLayersByName( identifier ).value( 0 );
110 if ( QThread::currentThread() == store->thread() )
111 findLayerInStoreFunction();
113 QMetaObject::invokeMethod( store, findLayerInStoreFunction, Qt::BlockingQueuedConnection );
120 auto getMapLayerFromProjectInstance = [ &ml, identifier ]
125 ml = project->
mapLayer( identifier );
133 if ( QThread::currentThread() == qApp->thread() )
134 getMapLayerFromProjectInstance();
136 QMetaObject::invokeMethod( qApp, getMapLayerFromProjectInstance, Qt::BlockingQueuedConnection );
147#ifndef __clang_analyzer__
157 qWarning(
"Raw map layer pointer stored in expression evaluation, switch to QgsWeakMapLayerPointer instead" );
163 QPointer< QgsMapLayer > layerPointer( ml );
164 auto runFunction = [ layerPointer, &function, &foundLayer ]
176 if ( QThread::currentThread() == ml->thread() )
179 QMetaObject::invokeMethod( ml, runFunction, Qt::BlockingQueuedConnection );
187 auto runFunction = [ value, context, expression, &function, &foundLayer ]
189 if (
QgsMapLayer *layer = getMapLayerPrivate( value, context, expression ) )
212 const QString identifier = value.toString();
215 const QList< QgsMapLayerStore * > stores = context->layerStores();
219 QPointer< QgsMapLayerStore > storePointer( store );
220 auto findLayerInStoreFunction = [ storePointer, identifier, function, &foundLayer ]
226 ml = store->mapLayer( identifier );
230 ml = store->mapLayersByName( identifier ).value( 0 );
243 if ( QThread::currentThread() == store->thread() )
244 findLayerInStoreFunction();
246 QMetaObject::invokeMethod( store, findLayerInStoreFunction, Qt::BlockingQueuedConnection );
253 auto getMapLayerFromProjectInstance = [ value, identifier, &function, &foundLayer ]
274 getMapLayerFromProjectInstance();
276 QMetaObject::invokeMethod(
QgsProject::instance(), getMapLayerFromProjectInstance, Qt::BlockingQueuedConnection );
281QVariant QgsExpressionUtils::runMapLayerFunctionThreadSafe(
const QVariant &value,
const QgsExpressionContext *context,
QgsExpression *expression,
const std::function<QVariant(
QgsMapLayer * )> &function,
bool &foundLayer )
286 executeLambdaForMapLayer( value, context, expression, [&res, function](
QgsMapLayer * layer )
289 res = function( layer );
295std::unique_ptr<QgsVectorLayerFeatureSource> QgsExpressionUtils::getFeatureSource(
const QVariant &value,
const QgsExpressionContext *context,
QgsExpression *e,
bool &foundLayer )
297 std::unique_ptr<QgsVectorLayerFeatureSource> featureSource;
299 executeLambdaForMapLayer( value, context, e, [&featureSource](
QgsMapLayer * layer )
301 if (
QgsVectorLayer *vl = qobject_cast< QgsVectorLayer *>( layer ) )
307 return featureSource;
312 return qobject_cast<QgsVectorLayer *>( getMapLayerPrivate( value, context, e ) );
320 if (
QgsMapLayer *layer = getMapLayer( value, context, parent ) )
323 res = parts.value( QStringLiteral(
"path" ) ).toString();
328 res = value.toString();
352 for (
int i = 0; i < fields.
count(); i++ )
364 *foundFeatures = hasFeature;
368 const QVariant value = exp.
evaluate( &context );
371 return std::make_tuple(
static_cast<QMetaType::Type
>( value.userType() ), value.userType() );
376 return std::make_tuple(
static_cast<QMetaType::Type
>( value.userType() ), value.userType() );
@ NoGeometry
Geometry is not required. It may still be returned if e.g. required for a filter condition.
@ NoFlags
No flags are set.
@ Expression
Field is calculated from an expression.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QList< QgsMapLayerStore * > layerStores() const
Returns the list of layer stores associated with the context.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
static std::tuple< QMetaType::Type, int > determineResultType(const QString &expression, const QgsVectorLayer *layer, QgsFeatureRequest request=QgsFeatureRequest(), QgsExpressionContext context=QgsExpressionContext(), bool *foundFeatures=nullptr)
Returns a value type and user type for a given expression.
Class for parsing and evaluation of expressions (formerly called "search strings").
void setEvalErrorString(const QString &str)
Sets evaluation error (used internally by evaluation functions)
bool needsGeometry() const
Returns true if the expression uses feature geometry for some computation.
QVariant evaluate()
Evaluate the feature and return the result.
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
Fetch next feature and stores in f, returns true on success.
This class wraps a request for features to a vector layer (or directly its vector data provider).
QgsFeatureRequest & setFlags(Qgis::FeatureRequestFlags flags)
Sets flags that affect how features will be fetched.
QgsFeatureRequest & setLimit(long long limit)
Set the maximum number of features to request.
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
QgsFeatureRequest & setExpressionContext(const QgsExpressionContext &context)
Sets the expression context used to evaluate filter expressions.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Container of fields for a vector layer.
Qgis::FieldOrigin fieldOrigin(int fieldIdx) const
Returns the field's origin (value from an enumeration).
Gradient color ramp, which smoothly interpolates between two colors and also supports optional extra ...
double value(int index) const override
Returns relative value between [0,1] of color at specified index.
A storage object for map layers, in which the layers are owned by the store and have their lifetime b...
Base class for all map layer types.
QString source() const
Returns the source for the layer.
QString providerType() const
Returns the provider type (provider key) for this layer.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
static QgsProject * instance()
Returns the QgsProject singleton instance.
Q_INVOKABLE QgsMapLayer * mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layer ID.
Q_INVOKABLE QList< QgsMapLayer * > mapLayersByName(const QString &layerName) const
Retrieve a list of matching registered layers by layer name.
QVariantMap decodeUri(const QString &providerKey, const QString &uri)
Breaks a provider data source URI into its component paths (e.g.
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.
Partial snapshot of vector layer's state (only the members necessary for access to features)
Represents a vector layer which manages a vector based data sets.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Queries the layer for features specified in request.
@ Unknown
Unknown/invalid format.
#define Q_NOWARN_DEPRECATED_POP
#define Q_NOWARN_DEPRECATED_PUSH
QList< int > QgsAttributeList
QPointer< QgsMapLayer > QgsWeakMapLayerPointer
Weak pointer for QgsMapLayer.