50using namespace Qt::StringLiterals;
58 for ( QVariantMap::const_iterator it = customVariables.constBegin(); it != customVariables.constEnd(); ++it )
90 if ( vars.remove( name ) )
104 QVariant
func(
const QVariantList &values,
const QgsExpressionContext *, QgsExpression *,
const QgsExpressionNodeFunction * )
override
109 const QString
id = values.at( 0 ).toString();
111 const QgsLayoutItem *item = mLayout->itemById(
id );
120 QgsScopedExpressionFunction *
clone()
const override {
return new GetLayoutItemVariables( mLayout ); }
123 const QgsLayout *mLayout =
nullptr;
130 GetLayoutMapLayerCredits(
const QgsLayout *
c )
131 : QgsScopedExpressionFunction(
133 QgsExpressionFunction::ParameterList()
134 << QgsExpressionFunction::Parameter( u
"id"_s, true )
135 << QgsExpressionFunction::Parameter( u
"include_layer_names"_s, true, false )
136 << QgsExpressionFunction::Parameter( u
"layer_name_separator"_s, true, u
": "_s ),
142 QVariant
func(
const QVariantList &values,
const QgsExpressionContext *, QgsExpression *,
const QgsExpressionNodeFunction * )
override
147 const QString
id = values.value( 0 ).toString();
148 const bool includeLayerNames = values.value( 1 ).toBool();
149 const QString layerNameSeparator = values.value( 2 ).toString();
151 QList< QgsLayoutItemMap * > maps;
152 mLayout->layoutItems( maps );
155 QList< const QgsMapLayer * > layers;
156 bool foundMap =
false;
157 for ( QgsLayoutItemMap *map : std::as_const( maps ) )
159 if ( !
id.isEmpty() && map->id() !=
id )
164 const QgsExpressionContext
c = map->createExpressionContext();
165 const QVariantList mapLayers =
c.variable( u
"map_layers"_s ).toList();
168 for (
const QVariant &value : mapLayers )
170 if (
const QgsMapLayer *layer = qobject_cast< const QgsMapLayer * >( value.value< QObject * >() ) )
172 if ( !layers.contains( layer ) )
181 res.reserve( layers.size() );
182 for (
const QgsMapLayer *layer : std::as_const( layers ) )
184 const QStringList credits = !layer->metadata().rights().isEmpty() ? layer->metadata().rights() : QStringList() << layer->serverProperties()->attribution();
185 for (
const QString &credit : credits )
187 if ( credit.trimmed().isEmpty() )
190 const QString creditString = includeLayerNames ? layer->name() + layerNameSeparator + credit : credit;
192 if ( !res.contains( creditString ) )
200 QgsScopedExpressionFunction *
clone()
const override {
return new GetLayoutMapLayerCredits( mLayout ); }
203 const QgsLayout *mLayout =
nullptr;
209 GetCurrentFormFieldValue()
210 : QgsScopedExpressionFunction( u
"current_value"_s, QgsExpressionFunction::ParameterList() << u
"field_name"_s, u
"Form"_s )
213 QVariant
func(
const QVariantList &values,
const QgsExpressionContext *context, QgsExpression *,
const QgsExpressionNodeFunction * )
override
215 const QString fieldName( values.at( 0 ).toString() );
216 const QgsFeature feat( context->
variable( u
"current_feature"_s ).value<QgsFeature>() );
217 if ( fieldName.isEmpty() || !feat.isValid() )
221 return feat.attribute( fieldName );
224 QgsScopedExpressionFunction *
clone()
const override {
return new GetCurrentFormFieldValue(); }
226 bool isStatic(
const QgsExpressionNodeFunction *, QgsExpression *,
const QgsExpressionContext * )
const override {
return false; };
232 GetCurrentParentFormFieldValue()
233 : QgsScopedExpressionFunction( u
"current_parent_value"_s, QgsExpressionFunction::ParameterList() << u
"field_name"_s, u
"Form"_s )
236 QVariant
func(
const QVariantList &values,
const QgsExpressionContext *context, QgsExpression *,
const QgsExpressionNodeFunction * )
override
238 const QString fieldName( values.at( 0 ).toString() );
239 const QgsFeature feat( context->
variable( u
"current_parent_feature"_s ).value<QgsFeature>() );
240 if ( fieldName.isEmpty() || !feat.isValid() )
244 return feat.attribute( fieldName );
247 QgsScopedExpressionFunction *
clone()
const override {
return new GetCurrentParentFormFieldValue(); }
249 bool isStatic(
const QgsExpressionNodeFunction *, QgsExpression *,
const QgsExpressionContext * )
const override {
return false; };
256 GetProcessingParameterValue(
const QVariantMap ¶ms )
257 : QgsScopedExpressionFunction( u
"parameter"_s, QgsExpressionFunction::ParameterList() << QgsExpressionFunction::Parameter( u
"name"_s ), u
"Processing"_s )
261 QVariant
func(
const QVariantList &values,
const QgsExpressionContext *, QgsExpression *,
const QgsExpressionNodeFunction * )
override {
return mParams.value( values.at( 0 ).toString() ); }
263 QgsScopedExpressionFunction *
clone()
const override {
return new GetProcessingParameterValue( mParams ); }
266 const QVariantMap mParams;
275 scope->
addFunction( u
"current_value"_s,
new GetCurrentFormFieldValue() );
277 scope->
setVariable( u
"current_feature"_s, formFeature,
true );
278 scope->
setVariable( u
"form_mode"_s, formMode,
true );
286 scope->
addFunction( u
"current_parent_value"_s,
new GetCurrentParentFormFieldValue() );
288 scope->
setVariable( u
"current_parent_feature"_s, parentFormFeature,
true );
289 scope->
setVariable( u
"parent_form_mode"_s, parentFormMode,
true );
311 vars.insert( name, value );
332 if ( vars.remove( name ) )
344 const QStringList variableNames = layer->
customProperty( u
"variableNames"_s ).toStringList();
345 const QStringList variableValues = layer->
customProperty( u
"variableValues"_s ).toStringList();
348 for (
const QString &variableName : variableNames )
350 if ( varIndex >= variableValues.length() )
355 const QVariant varValue = variableValues.at( varIndex );
357 scope->
setVariable( variableName, varValue,
true );
378 if (
const QgsVectorLayer *vLayer = qobject_cast< const QgsVectorLayer * >( layer ) )
382 else if (
const QgsPointCloudLayer *pcLayer = qobject_cast< const QgsPointCloudLayer * >( layer ) )
388 switch ( attr.type() )
396 value = QVariant( 0 );
400 value = QVariant(
static_cast<qlonglong
>( 0 ) );
404 value = QVariant( 0.0 );
421 QList<QgsExpressionContextScope *> scopes;
440 QStringList variableNames = layer->
customProperty( u
"variableNames"_s ).toStringList();
441 QStringList variableValues = layer->
customProperty( u
"variableValues"_s ).toStringList();
444 const int index = variableNames.indexOf( name );
447 variableValues[index] = value.toString();
452 variableNames << name;
453 variableValues << value.toString();
465 QStringList variableNames;
466 QStringList variableValues;
468 QVariantMap::const_iterator it = variables.constBegin();
469 for ( ; it != variables.constEnd(); ++it )
471 variableNames << it.key();
472 variableValues << it.value().toString();
526 QVariantList layersIds;
528 const QList<QgsMapLayer *> layersInMap = mapSettings.
layers(
true );
529 layersIds.reserve( layersInMap.count() );
530 layers.reserve( layersInMap.count() );
533 layersIds << layer->id();
546 scope->
addFunction( u
"is_layer_visible"_s,
new GetLayerVisibility( mapSettings.
layers(
true ), mapSettings.
scale() ) );
579 QVariantList matchList;
583 QVariantMap matchMap;
585 matchMap.insert( u
"valid"_s, match.isValid() );
586 matchMap.insert( u
"layer"_s, QVariant::fromValue<QgsWeakMapLayerPointer>(
QgsWeakMapLayerPointer( match.layer() ) ) );
587 matchMap.insert( u
"feature_id"_s, match.featureId() );
588 matchMap.insert( u
"vertex_index"_s, match.vertexIndex() );
589 matchMap.insert( u
"distance"_s, match.distance() );
591 matchList.append( matchMap );
617 angle = markerSymbol->
angle();
626 auto scope = std::make_unique<QgsExpressionContextScope>( QObject::tr(
"Layout" ) );
628 return scope.release();
631 const QStringList variableNames = layout->
customProperty( u
"variableNames"_s ).toStringList();
632 const QStringList variableValues = layout->
customProperty( u
"variableValues"_s ).toStringList();
636 for (
const QString &variableName : variableNames )
638 if ( varIndex >= variableValues.length() )
643 const QVariant varValue = variableValues.at( varIndex );
645 scope->setVariable( variableName, varValue );
671 QVariantList offsets;
674 if ( pages.contains( i ) )
684 scope->addFunction( u
"item_variables"_s,
new GetLayoutItemVariables( layout ) );
685 scope->addFunction( u
"map_credits"_s,
new GetLayoutMapLayerCredits( layout ) );
697 scope->setFeature( atlasFeature );
703 return scope.release();
712 QStringList variableNames = layout->
customProperty( u
"variableNames"_s ).toStringList();
713 QStringList variableValues = layout->
customProperty( u
"variableValues"_s ).toStringList();
715 variableNames << name;
716 variableValues << value.toString();
727 QStringList variableNames;
728 QStringList variableValues;
730 QVariantMap::const_iterator it = variables.constBegin();
731 for ( ; it != variables.constEnd(); ++it )
733 variableNames << it.key();
734 variableValues << it.value().toString();
787 const QStringList variableNames = item->
customProperty( u
"variableNames"_s ).toStringList();
788 const QStringList variableValues = item->
customProperty( u
"variableValues"_s ).toStringList();
791 for (
const QString &variableName : variableNames )
793 if ( varIndex >= variableValues.length() )
798 const QVariant varValue = variableValues.at( varIndex );
804 bool itemPageFound =
false;
807 for (
int i = 0; i < item->
layout()->pageCollection()->pageCount(); i++ )
811 if ( i == item->
page() )
813 itemPageFound =
true;
821 if ( !itemPageFound )
856 QStringList variableNames = item->
customProperty( u
"variableNames"_s ).toStringList();
857 QStringList variableValues = item->
customProperty( u
"variableValues"_s ).toStringList();
859 variableNames << name;
860 variableValues << value.toString();
871 QStringList variableNames;
872 QStringList variableValues;
874 QVariantMap::const_iterator it = variables.constBegin();
875 for ( ; it != variables.constEnd(); ++it )
877 variableNames << it.key();
878 variableValues << it.value().toString();
892 const QStringList variableNames = frame->
customProperty( u
"variableNames"_s ).toStringList();
893 const QStringList variableValues = frame->
customProperty( u
"variableValues"_s ).toStringList();
896 for (
const QString &variableName : variableNames )
898 if ( varIndex >= variableValues.length() )
903 const QVariant varValue = variableValues.at( varIndex );
917 QStringList variableNames = frame->
customProperty( u
"variableNames"_s ).toStringList();
918 QStringList variableValues = frame->
customProperty( u
"variableValues"_s ).toStringList();
920 variableNames << name;
921 variableValues << value.toString();
932 QStringList variableNames;
933 QStringList variableValues;
935 QVariantMap::const_iterator it = variables.constBegin();
936 for ( ; it != variables.constEnd(); ++it )
938 variableNames << it.key();
939 variableValues << it.value().toString();
959 auto scope = std::make_unique<QgsExpressionContextScope>( QObject::tr(
"Algorithm" ) );
960 scope->addFunction( u
"parameter"_s,
new GetProcessingParameterValue( parameters ) );
963 return scope.release();
968 return scope.release();
973 auto modelScope = std::make_unique<QgsExpressionContextScope>( QObject::tr(
"Model" ) );
975 if ( !model->sourceFilePath().isEmpty() )
977 modelPath = model->sourceFilePath();
986 const QString modelFolder = !modelPath.isEmpty() ? QFileInfo( modelPath ).path() : QString();
993 const QVariantMap customVariables = model->variables();
994 for (
auto it = customVariables.constBegin(); it != customVariables.constEnd(); ++it )
999 return modelScope.release();
1004 auto scope = std::make_unique<QgsExpressionContextScope>();
1006 return scope.release();
1026 return mUsesGeometry;
1032 return mReferencedColumns;
1044QgsExpressionContextUtils::GetLayerVisibility::GetLayerVisibility(
const QList<QgsMapLayer *> &layers,
double scale )
1046 , mLayers( _qgis_listRawToQPointer( layers ) )
1049 for (
const auto &layer : mLayers )
1051 if ( layer->hasScaleBasedVisibility() )
1053 mScaleBasedVisibilityDetails[layer] = qMakePair( layer->minimumScale(), layer->maximumScale() );
1058QgsExpressionContextUtils::GetLayerVisibility::GetLayerVisibility()
1064 if ( mLayers.isEmpty() )
1069 bool isVisible =
false;
1071 QgsMapLayer *layer = QgsExpressionUtils::getMapLayer( values.at( 0 ), context, parent );
1073 if ( layer && mLayers.contains( layer ) )
1076 if ( mScaleBasedVisibilityDetails.contains( layer ) && !
qgsDoubleNear( mScale, 0.0 ) )
1078 if ( ( !
qgsDoubleNear( mScaleBasedVisibilityDetails[layer].first, 0.0 ) && mScale > mScaleBasedVisibilityDetails[layer].first )
1079 || ( !
qgsDoubleNear( mScaleBasedVisibilityDetails[layer].second, 0.0 ) && mScale < mScaleBasedVisibilityDetails[layer].second ) )
1091 GetLayerVisibility *func =
new GetLayerVisibility();
1092 func->mLayers = mLayers;
1093 func->mScale = mScale;
1094 func->mScaleBasedVisibilityDetails = mScaleBasedVisibilityDetails;
1103class CurrentVertexZValueExpressionFunction :
public QgsScopedExpressionFunction
1106 CurrentVertexZValueExpressionFunction()
1107 : QgsScopedExpressionFunction(
"$vertex_z", 0, u
"Meshes"_s )
1110 QgsScopedExpressionFunction *clone()
const override {
return new CurrentVertexZValueExpressionFunction(); }
1112 QVariant func(
const QVariantList &,
const QgsExpressionContext *context, QgsExpression *,
const QgsExpressionNodeFunction * )
override
1114 if ( context && context->
hasVariable( u
"_mesh_vertex_index"_s ) && context->
hasVariable( u
"_native_mesh"_s ) )
1116 int vertexIndex = context->
variable( u
"_mesh_vertex_index"_s ).toInt();
1117 const QgsMesh nativeMesh = qvariant_cast<QgsMesh>( context->
variable( u
"_native_mesh"_s ) );
1126 bool isStatic(
const QgsExpressionNodeFunction *, QgsExpression *,
const QgsExpressionContext * )
const override {
return false; }
1129class CurrentVertexXValueExpressionFunction :
public QgsScopedExpressionFunction
1132 CurrentVertexXValueExpressionFunction()
1133 : QgsScopedExpressionFunction(
"$vertex_x", 0, u
"Meshes"_s )
1136 QgsScopedExpressionFunction *clone()
const override {
return new CurrentVertexXValueExpressionFunction(); }
1138 QVariant func(
const QVariantList &,
const QgsExpressionContext *context, QgsExpression *,
const QgsExpressionNodeFunction * )
override
1140 if ( context && context->
hasVariable( u
"_mesh_vertex_index"_s ) && context->
hasVariable( u
"_native_mesh"_s ) )
1142 int vertexIndex = context->
variable( u
"_mesh_vertex_index"_s ).toInt();
1143 const QgsMesh nativeMesh = qvariant_cast<QgsMesh>( context->
variable( u
"_native_mesh"_s ) );
1152 bool isStatic(
const QgsExpressionNodeFunction *, QgsExpression *,
const QgsExpressionContext * )
const override {
return false; }
1155class CurrentVertexYValueExpressionFunction :
public QgsScopedExpressionFunction
1158 CurrentVertexYValueExpressionFunction()
1159 : QgsScopedExpressionFunction(
"$vertex_y", 0, u
"Meshes"_s )
1162 QgsScopedExpressionFunction *clone()
const override {
return new CurrentVertexYValueExpressionFunction(); }
1164 QVariant func(
const QVariantList &,
const QgsExpressionContext *context, QgsExpression *,
const QgsExpressionNodeFunction * )
override
1166 if ( context && context->
hasVariable( u
"_mesh_vertex_index"_s ) && context->
hasVariable( u
"_native_mesh"_s ) )
1168 int vertexIndex = context->
variable( u
"_mesh_vertex_index"_s ).toInt();
1169 const QgsMesh nativeMesh = qvariant_cast<QgsMesh>( context->
variable( u
"_native_mesh"_s ) );
1178 bool isStatic(
const QgsExpressionNodeFunction *, QgsExpression *,
const QgsExpressionContext * )
const override {
return false; }
1181class CurrentVertexExpressionFunction :
public QgsScopedExpressionFunction
1184 CurrentVertexExpressionFunction()
1185 : QgsScopedExpressionFunction(
"$vertex_as_point", 0, u
"Meshes"_s )
1188 QgsScopedExpressionFunction *clone()
const override {
return new CurrentVertexExpressionFunction(); }
1190 QVariant func(
const QVariantList &,
const QgsExpressionContext *context, QgsExpression *,
const QgsExpressionNodeFunction * )
override
1192 if ( context && context->
hasVariable( u
"_mesh_vertex_index"_s ) && context->
hasVariable( u
"_native_mesh"_s ) )
1194 int vertexIndex = context->
variable( u
"_mesh_vertex_index"_s ).toInt();
1195 const QgsMesh nativeMesh = qvariant_cast<QgsMesh>( context->
variable( u
"_native_mesh"_s ) );
1198 return QVariant::fromValue( QgsGeometry(
new QgsPoint( vertex ) ) );
1204 bool isStatic(
const QgsExpressionNodeFunction *, QgsExpression *,
const QgsExpressionContext * )
const override {
return false; }
1207class CurrentVertexIndexExpressionFunction :
public QgsScopedExpressionFunction
1210 CurrentVertexIndexExpressionFunction()
1211 : QgsScopedExpressionFunction(
"$vertex_index", 0, u
"Meshes"_s )
1214 QgsScopedExpressionFunction *clone()
const override {
return new CurrentVertexIndexExpressionFunction(); }
1216 QVariant func(
const QVariantList &,
const QgsExpressionContext *context, QgsExpression *,
const QgsExpressionNodeFunction * )
override
1221 if ( !context->
hasVariable( u
"_mesh_vertex_index"_s ) )
1224 return context->
variable( u
"_mesh_vertex_index"_s );
1228 bool isStatic(
const QgsExpressionNodeFunction *, QgsExpression *,
const QgsExpressionContext * )
const override {
return false; }
1231class CurrentFaceAreaExpressionFunction :
public QgsScopedExpressionFunction
1234 CurrentFaceAreaExpressionFunction()
1235 : QgsScopedExpressionFunction(
"$face_area", 0, u
"Meshes"_s )
1238 QgsScopedExpressionFunction *clone()
const override {
return new CurrentFaceAreaExpressionFunction(); }
1240 QVariant func(
const QVariantList &,
const QgsExpressionContext *context, QgsExpression *parent,
const QgsExpressionNodeFunction * )
override
1242 if ( context && context->
hasVariable( u
"_mesh_face_index"_s ) && context->
hasVariable( u
"_native_mesh"_s ) )
1244 const int faceIndex = context->
variable( u
"_mesh_face_index"_s ).toInt();
1245 const QgsMesh nativeMesh = qvariant_cast<QgsMesh>( context->
variable( u
"_native_mesh"_s ) );
1247 if ( !face.isEmpty() )
1257 return QVariant( area );
1259 catch ( QgsCsException & )
1261 parent->
setEvalErrorString( QObject::tr(
"An error occurred while calculating area" ) );
1267 return QVariant( geom.
area() );
1275 bool isStatic(
const QgsExpressionNodeFunction *, QgsExpression *,
const QgsExpressionContext * )
const override {
return false; }
1278class CurrentFaceIndexExpressionFunction :
public QgsScopedExpressionFunction
1281 CurrentFaceIndexExpressionFunction()
1282 : QgsScopedExpressionFunction(
"$face_index", 0, u
"Meshes"_s )
1285 QgsScopedExpressionFunction *clone()
const override {
return new CurrentFaceIndexExpressionFunction(); }
1287 QVariant func(
const QVariantList &,
const QgsExpressionContext *context, QgsExpression *,
const QgsExpressionNodeFunction * )
override
1292 if ( !context->
hasVariable( u
"_mesh_face_index"_s ) )
1295 return context->
variable( u
"_mesh_face_index"_s ).toInt();
1298 bool isStatic(
const QgsExpressionNodeFunction *, QgsExpression *,
const QgsExpressionContext * )
const override {
return false; }
1304 auto scope = std::make_unique<QgsExpressionContextScope>();
1306 switch ( elementType )
1315 scope->addFunction(
"$vertex_as_point",
new CurrentVertexExpressionFunction );
1316 scope->addFunction(
"$vertex_x",
new CurrentVertexXValueExpressionFunction );
1317 scope->addFunction(
"$vertex_y",
new CurrentVertexYValueExpressionFunction );
1318 scope->addFunction(
"$vertex_z",
new CurrentVertexZValueExpressionFunction );
1319 scope->addFunction(
"$vertex_index",
new CurrentVertexIndexExpressionFunction );
1326 scope->addFunction(
"$face_area",
new CurrentFaceAreaExpressionFunction );
1327 scope->addFunction(
"$face_index",
new CurrentFaceIndexExpressionFunction );
1334 return scope.release();
1338QVariant LoadLayerFunction::func(
const QVariantList &,
const QgsExpressionContext *, QgsExpression *parent,
const QgsExpressionNodeFunction * )
1340 parent->
setEvalErrorString( QObject::tr(
"Invalid arguments for load_layer function" ) );
1344bool LoadLayerFunction::isStatic(
const QgsExpressionNodeFunction *node, QgsExpression *parent,
const QgsExpressionContext *context )
const
1354 parent->
setEvalErrorString( QObject::tr(
"load_layer cannot be used in this context" ) );
1358 QgsExpressionNode *uriNode = node->
args()->
at( 0 );
1359 QgsExpressionNode *providerNode = node->
args()->
at( 1 );
1360 if ( !uriNode->
isStatic( parent, context ) )
1362 parent->
setEvalErrorString( QObject::tr(
"load_layer requires a static value for the uri argument" ) );
1365 if ( !providerNode->
isStatic( parent, context ) )
1367 parent->
setEvalErrorString( QObject::tr(
"load_layer requires a static value for the provider argument" ) );
1371 const QString uri = uriNode->
eval( parent, context ).toString();
1372 if ( uri.isEmpty() )
1378 const QString providerKey = providerNode->
eval( parent, context ).toString();
1379 if ( providerKey.isEmpty() )
1381 parent->
setEvalErrorString( QObject::tr(
"Invalid provider argument for load_layer" ) );
1385 const QgsCoordinateTransformContext transformContext = context->
variable( u
"_project_transform_context"_s ).value<QgsCoordinateTransformContext>();
1388 auto loadLayer = [uri, providerKey, store, node, parent, &res, &transformContext] {
1392 parent->setEvalErrorString( QObject::tr(
"Invalid provider argument for load_layer" ) );
1398 parent->setEvalErrorString( QObject::tr(
"Cannot use %1 provider for load_layer" ).arg( providerKey ) );
1402 QgsMapLayerFactory::LayerOptions layerOptions( transformContext );
1403 layerOptions.loadAllStoredStyles =
false;
1404 layerOptions.loadDefaultStyle =
false;
1409 parent->setEvalErrorString( QObject::tr(
"Could not load_layer with uri: %1" ).arg( uri ) );
1415 parent->setEvalErrorString( QObject::tr(
"Could not load_layer with uri: %1" ).arg( uri ) );
1419 store->addMapLayer( layer );
1426 if ( QThread::currentThread() == store->thread() )
1429 QMetaObject::invokeMethod( store, std::move( loadLayer ), Qt::BlockingQueuedConnection );
1436QgsScopedExpressionFunction *LoadLayerFunction::clone()
const
1438 return new LoadLayerFunction();
static QString version()
Version string.
static QString releaseName()
Release name.
static int versionInt()
Version number used for comparing versions using the "Check QGIS Version" function.
@ Preferred
Preferred format, matching the most recent WKT ISO standard. Currently an alias to WKT2_2019,...
static void setCustomVariables(const QVariantMap &customVariables)
Custom expression variables for this application.
static QString osName()
Returns a string name of the operating system QGIS is running on.
static QString platform()
Returns the QGIS platform name, e.g., "desktop", "server", "qgis_process" or "external" (for external...
static QVariantMap customVariables()
Custom expression variables for this application.
static QString locale()
Returns the QGIS locale.
static void setCustomVariable(const QString &name, const QVariant &value)
Set a single custom expression variable.
static QString userFullName()
Returns the user's operating system login account full display name.
static QString userLoginName()
Returns the user's operating system login account name.
Represents a coordinate reference system (CRS).
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
QString toProj() const
Returns a Proj string representation of this CRS.
QString ellipsoidAcronym() const
Returns the ellipsoid acronym for the ellipsoid used by the CRS.
QString projectionAcronym() const
Returns the projection acronym for the projection used by the CRS.
QString toWkt(Qgis::CrsWktVariant variant=Qgis::CrsWktVariant::Wkt1Gdal, bool multiline=false, int indentationWidth=4) const
Returns a WKT representation of this CRS.
QgsProjOperation operation() const
Returns information about the PROJ operation associated with the coordinate reference system,...
double measureArea(const QgsGeometry &geometry) const
Measures the area of a geometry.
double convertAreaMeasurement(double area, Qgis::AreaUnit toUnits) const
Takes an area measurement calculated by this QgsDistanceArea object and converts it to a different ar...
QgsRange which stores a range of double values.
bool isInfinite() const
Returns true if the range consists of all possible values.
Single scope for storing variables and functions for use within a QgsExpressionContext.
void setFields(const QgsFields &fields)
Convenience function for setting a fields for the scope.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the scope.
void addFunction(const QString &name, QgsScopedExpressionFunction *function)
Adds a function to the scope.
void addVariable(const QgsExpressionContextScope::StaticVariable &variable)
Adds a variable into the context scope.
void setVariable(const QString &name, const QVariant &value, bool isStatic=false)
Convenience method for setting a variable in the context scope by name name and value.
static QgsExpressionContextScope * layoutItemScope(const QgsLayoutItem *item)
Creates a new scope which contains variables and functions relating to a QgsLayoutItem.
static void setLayoutMultiFrameVariable(QgsLayoutMultiFrame *frame, const QString &name, const QVariant &value)
Sets a layout multi frame context variable, with the given name and value.
static void setLayerVariable(QgsMapLayer *layer, const QString &name, const QVariant &value)
Sets a layer context variable.
static QgsExpressionContextScope * processingModelAlgorithmScope(const QgsProcessingModelAlgorithm *model, const QVariantMap ¶meters, QgsProcessingContext &context)
Creates a new scope which contains variables and functions relating to a processing model algorithm,...
static QgsExpressionContextScope * updateSymbolScope(const QgsSymbol *symbol, QgsExpressionContextScope *symbolScope=nullptr)
Updates a symbol scope related to a QgsSymbol to an expression context.
static void setProjectVariables(QgsProject *project, const QVariantMap &variables)
Sets all project context variables.
static QgsExpressionContextScope * layoutScope(const QgsLayout *layout)
Creates a new scope which contains variables and functions relating to a QgsLayout layout.
static QgsExpressionContext createFeatureBasedContext(const QgsFeature &feature, const QgsFields &fields)
Helper function for creating an expression context which contains just a feature and fields collectio...
static void removeProjectVariable(QgsProject *project, const QString &name)
Remove project context variable.
static void setLayerVariables(QgsMapLayer *layer, const QVariantMap &variables)
Sets all layer context variables.
static void setGlobalVariables(const QVariantMap &variables)
Sets all global context variables.
static void setLayoutItemVariables(QgsLayoutItem *item, const QVariantMap &variables)
Sets all layout item context variables for an item.
static void setLayoutMultiFrameVariables(QgsLayoutMultiFrame *frame, const QVariantMap &variables)
Sets all layout multiframe context variables for an frame.
static QgsExpressionContextScope * processingAlgorithmScope(const QgsProcessingAlgorithm *algorithm, const QVariantMap ¶meters, QgsProcessingContext &context)
Creates a new scope which contains variables and functions relating to a processing algorithm,...
static QgsExpressionContextScope * notificationScope(const QString &message=QString())
Creates a new scope which contains variables and functions relating to provider notifications.
static QgsExpressionContextScope * projectScope(const QgsProject *project)
Creates a new scope which contains variables and functions relating to a QGIS project.
static QgsExpressionContextScope * parentFormScope(const QgsFeature &formFeature=QgsFeature(), const QString &formMode=QString())
Creates a new scope which contains functions and variables from the current parent attribute form/tab...
static void setLayoutVariable(QgsLayout *layout, const QString &name, const QVariant &value)
Sets a layout context variable.
static QgsExpressionContextScope * formScope(const QgsFeature &formFeature=QgsFeature(), const QString &formMode=QString())
Creates a new scope which contains functions and variables from the current attribute form/table form...
static QgsExpressionContextScope * multiFrameScope(const QgsLayoutMultiFrame *frame)
Creates a new scope which contains variables and functions relating to a QgsLayoutMultiFrame.
static void setLayoutItemVariable(QgsLayoutItem *item, const QString &name, const QVariant &value)
Sets a layout item context variable, with the given name and value.
static QgsExpressionContextScope * mapToolCaptureScope(const QList< QgsPointLocator::Match > &matches)
Sets the expression context variables which are available for expressions triggered by a map tool cap...
static QgsExpressionContextScope * atlasScope(const QgsLayoutAtlas *atlas)
Creates a new scope which contains variables and functions relating to a QgsLayoutAtlas.
static void registerContextFunctions()
Registers all known core functions provided by QgsExpressionContextScope objects.
static QgsExpressionContextScope * mapLayerPositionScope(const QgsPointXY &position)
Sets the expression context variables which are available for expressions triggered by moving the mou...
static void setLayoutVariables(QgsLayout *layout, const QVariantMap &variables)
Sets all layout context variables.
static QgsExpressionContextScope * mapSettingsScope(const QgsMapSettings &mapSettings)
Creates a new scope which contains variables and functions relating to a QgsMapSettings object.
static void removeGlobalVariable(const QString &name)
Remove a global context variable.
static void setGlobalVariable(const QString &name, const QVariant &value)
Sets a global context variable.
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
static QgsExpressionContextScope * meshExpressionScope(QgsMesh::ElementType elementType)
Creates a new scope which contains functions relating to mesh layer element elementType.
static void setProjectVariable(QgsProject *project, const QString &name, const QVariant &value)
Sets a project context variable.
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QgsMapLayerStore * loadedLayerStore() const
Returns the destination layer store for any layers loaded during expression evaluation.
static const QString EXPR_SYMBOL_COLOR
Inbuilt variable name for symbol color variable.
bool hasVariable(const QString &name) const
Check whether a variable is specified by any scope within the context.
static const QString EXPR_SYMBOL_ANGLE
Inbuilt variable name for symbol angle variable.
QVariantMap variablesToMap() const
Returns a map of variable name to value representing all the expression variables contained by the co...
QVariant variable(const QString &name) const
Fetches a matching variable from the context.
An abstract base class for defining QgsExpression functions.
static bool allParamsStatic(const QgsExpressionNodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context)
This will return true if all the params for the provided function node are static within the constrai...
An expression node for expression functions.
QgsExpressionNode::NodeList * args() const
Returns a list of arguments specified for the function.
QgsExpressionNode * at(int i)
Gets the node at position i in the list.
int count() const
Returns the number of nodes in the list.
QVariant eval(QgsExpression *parent, const QgsExpressionContext *context)
Evaluate this node with the given context and parent.
virtual bool isStatic(QgsExpression *parent, const QgsExpressionContext *context) const =0
Returns true if this node can be evaluated for a static value.
Handles parsing and evaluation of expressions (formerly called "search strings").
static bool registerFunction(QgsExpressionFunction *function, bool transferOwnership=false)
Registers a function to the expression engine.
Qgis::AreaUnit areaUnits() const
Returns the desired areal units for calculations involving geomCalculator(), e.g.,...
void setEvalErrorString(const QString &str)
Sets evaluation error (used internally by evaluation functions).
QgsDistanceArea * geomCalculator()
Returns calculator used for distance and area calculations (used by $length, $area and $perimeter fun...
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
bool isValid() const
Returns the validity of this feature.
Container of fields for a vector layer.
A geometry is the spatial representation of a feature.
static QgsGeometry fromRect(const QgsRectangle &rect)
Creates a new geometry from a QgsRectangle.
static QgsGeometry fromPointXY(const QgsPointXY &point)
Creates a new geometry from a QgsPointXY object.
double area() const
Returns the planar, 2-dimensional area of the geometry.
A representation of the interval between two datetime values.
Used to render QgsLayout as an atlas, by iterating over the features from an associated vector layer.
QString nameForPage(int page) const
Returns the calculated name for a specified atlas page number.
QgsLayout * layout() override
Returns the layout associated with the iterator.
bool enabled() const
Returns whether the atlas generation is enabled.
QString currentFilename() const
Returns the current feature filename.
int count() const override
Returns the number of features to iterate over.
QgsVectorLayer * coverageLayer() const
Returns the coverage layer used for the atlas features.
int currentFeatureNumber() const
Returns the current feature number, where a value of 0 corresponds to the first feature.
Item representing the paper in a layout.
Base class for graphical items within a QgsLayout.
QgsLayoutSize sizeWithUnits() const
Returns the item's current size, including units.
int page() const
Returns the page the item is currently on, with the first page returning 0.
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
virtual QString uuid() const
Returns the item identification string.
QString id() const
Returns the item's ID name.
Abstract base class for layout items with the ability to distribute the content to several frames (Qg...
QVariant customProperty(const QString &key, const QVariant &defaultValue=QVariant()) const
Read a custom property from the object.
const QgsLayout * layout() const
Returns the layout the object is attached to.
void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for the object.
QPointF pagePositionToLayoutPosition(int page, const QgsLayoutPoint &position) const
Converts a position on a page to an absolute position in layout coordinates.
int pageCount() const
Returns the number of pages in the collection.
bool shouldExportPage(int page) const
Returns whether the specified page number should be included in exports of the layouts.
QgsLayoutItemPage * page(int pageNumber)
Returns a specific page (by pageNumber) from the collection.
Provides a method of storing points, consisting of an x and y coordinate, for use in QGIS layouts.
bool isPreviewRender() const
Returns true if the render current being conducted is a preview render, i.e.
double dpi() const
Returns the dpi for outputting the layout.
QgsFeature feature() const
Returns the current feature for evaluating the layout.
QgsVectorLayer * layer() const
Returns the vector layer associated with the layout's context.
QSizeF toQSizeF() const
Converts the layout size to a QSizeF.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for the layout.
QgsLayoutRenderContext & renderContext()
Returns a reference to the layout's render context, which stores information relating to the current ...
QgsLayoutPageCollection * pageCollection()
Returns a pointer to the layout's page collection, which stores and manages page items in the layout.
QVariant customProperty(const QString &key, const QVariant &defaultValue=QVariant()) const
Read a custom property from the layout.
QgsLayoutReportContext & reportContext()
Returns a reference to the layout's report context, which stores information relating to the current ...
static QgsMapLayer * createLayer(const QString &uri, const QString &name, Qgis::LayerType type, const LayerOptions &options, const QString &provider=QString())
Creates a map layer, given a uri, name, layer type and provider name.
Base class for all map layer types.
Q_INVOKABLE QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
QgsCoordinateReferenceSystem crs
Q_INVOKABLE void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for layer.
QgsProject * project() const
Returns the parent project if this map layer is added to a project.
QgsCoordinateReferenceSystem verticalCrs
Contains configuration for rendering maps.
Qgis::DistanceUnit mapUnits() const
Returns the units of the map's geographical coordinates - used for scale calculation.
QList< QgsMapLayer * > layers(bool expandGroupLayers=false) const
Returns the list of layers which will be rendered in the map.
double scale() const
Returns the calculated map scale.
QgsDoubleRange zRange() const
Returns the range of z-values which will be visible in the map.
long long currentFrame() const
Returns the current frame number of the map, for maps which are part of an animation.
double frameRate() const
Returns the frame rate of the map (in frames per second), for maps which are part of an animation.
QgsRectangle visibleExtent() const
Returns the actual extent derived from requested extent that takes output image size into account.
double rotation() const
Returns the rotation of the resulting map image, in degrees clockwise.
QgsCoordinateReferenceSystem destinationCrs() const
Returns the destination coordinate reference system for the map render.
A marker symbol type, for rendering Point and MultiPoint geometries.
double angle() const
Returns the marker angle for the whole symbol.
Interface for master layout type objects, such as print layouts and reports.
static QgsGeometry toGeometry(const QgsMeshFace &face, const QVector< QgsMeshVertex > &vertices)
Returns face as polygon geometry.
A collection of point cloud attributes.
QVector< QgsPointCloudAttribute > attributes() const
Returns all attributes.
Attribute for point cloud data pair of name and size in bytes.
@ UShort
Unsigned short int 2 bytes.
@ Short
Short int 2 bytes.
@ UChar
Unsigned char 1 byte.
@ UInt32
Unsigned int32 4 bytes.
@ UInt64
Unsigned int64 8 bytes.
Represents a map layer supporting display of point clouds.
bool isEmpty() const override
Returns true if the geometry is empty.
Abstract base class for processing algorithms.
Contains information about the context in which a processing algorithm is executed.
QgsProject * project() const
Returns the project in which the algorithm is being executed.
QString description() const
Description.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
static QgsProject * instance()
Returns the QgsProject singleton instance.
QgsExpressionContextScope * createExpressionContextScope() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
QString absoluteFilePath() const
Returns full absolute path to the project file if the project is stored in a file system - derived fr...
QVariantMap customVariables() const
A map of custom project variables.
void setCustomVariables(const QVariantMap &customVariables)
A map of custom project variables.
QgsProjectStorage * projectStorage() const
Returns pointer to project storage implementation that handles read/write of the project file.
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
QgsProviderMetadata * providerMetadata(const QString &providerKey) const
Returns metadata of the provider or nullptr if not found.
T lower() const
Returns the lower bound of the range.
T upper() const
Returns the upper bound of the range.
Expression function for use within a QgsExpressionContextScope.
QSet< QString > referencedColumns(const QgsExpressionNodeFunction *node) const override
Returns a set of field names which are required for this function.
virtual QgsScopedExpressionFunction * clone() const =0
Returns a clone of the function.
bool isStatic(const QgsExpressionNodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context) const override
Will be called during prepare to determine if the function is static.
bool usesGeometry(const QgsExpressionNodeFunction *node) const override
Does this function use a geometry object.
QVariant func(const QVariantList &values, const QgsExpressionContext *context, QgsExpression *parent, const QgsExpressionNodeFunction *node) override=0
Returns result of evaluating the function.
Abstract base class for all rendered symbols.
QColor color() const
Returns the symbol's color.
const QgsDateTimeRange & temporalRange() const
Returns the datetime range for the object.
bool isTemporal() const
Returns true if the object's temporal range is enabled, and the object will be filtered when renderin...
T begin() const
Returns the beginning of the range.
T end() const
Returns the upper bound of the range.
static Q_INVOKABLE QString toString(Qgis::DistanceUnit unit)
Returns a translated string representing a distance unit.
Represents a vector layer which manages a vector based dataset.
static double scaleToZoom(double mapScale, double z0Scale=559082264.0287178)
Finds zoom level given map scale denominator.
static int scaleToZoomLevel(double mapScale, int sourceMinZoom, int sourceMaxZoom, double z0Scale=559082264.0287178)
Finds the best fitting zoom level given a map scale denominator and allowed zoom level range.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into allowing algorithms to be written in pure substantial changes are required in order to port existing x Processing algorithms for QGIS x The most significant changes are outlined not GeoAlgorithm For algorithms which operate on features one by consider subclassing the QgsProcessingFeatureBasedAlgorithm class This class allows much of the boilerplate code for looping over features from a vector layer to be bypassed and instead requires implementation of a processFeature method Ensure that your algorithm(or algorithm 's parent class) implements the new pure virtual createInstance(self) call
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
#define Q_NOWARN_DEPRECATED_POP
#define Q_NOWARN_DEPRECATED_PUSH
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).
QPointer< QgsMapLayer > QgsWeakMapLayerPointer
Weak pointer for QgsMapLayer.
QVector< int > QgsMeshFace
List of vertex indexes.
QgsPoint QgsMeshVertex
xyz coords of vertex
Single variable definition for use within a QgsExpressionContextScope.
QVector< QgsMeshVertex > vertices
QgsMeshFace face(int index) const
Returns a face at the index.
ElementType
Defines type of mesh elements.
QgsMeshVertex vertex(int index) const
Returns a vertex at the index.