QGIS API Documentation
3.14.0-Pi (9f7028fd23)
|
Go to the documentation of this file.
22 #include "qgsprocessingmodelalgorithm.h"
39 for ( QVariantMap::const_iterator it = customVariables.constBegin(); it != customVariables.constEnd(); ++it )
71 if ( vars.remove( name ) )
90 QString
id = values.at( 0 ).toString();
98 return c.variablesToMap();
103 return new GetLayoutItemVariables( mLayout );
115 GetCurrentFormFieldValue( )
121 QString fieldName( values.at( 0 ).toString() );
122 const QgsFeature feat( context->
variable( QStringLiteral(
"current_feature" ) ).value<QgsFeature>() );
123 if ( fieldName.isEmpty() || ! feat.isValid( ) )
127 return feat.attribute( fieldName ) ;
132 return new GetCurrentFormFieldValue( );
145 GetCurrentParentFormFieldValue( )
151 QString fieldName( values.at( 0 ).toString() );
152 const QgsFeature feat( context->
variable( QStringLiteral(
"current_parent_feature" ) ).value<QgsFeature>() );
153 if ( fieldName.isEmpty() || ! feat.isValid( ) )
157 return feat.attribute( fieldName ) ;
162 return new GetCurrentParentFormFieldValue( );
176 GetProcessingParameterValue(
const QVariantMap ¶ms )
183 return mParams.value( values.at( 0 ).toString() );
188 return new GetProcessingParameterValue( mParams );
193 const QVariantMap mParams;
203 scope->
addFunction( QStringLiteral(
"current_value" ),
new GetCurrentFormFieldValue( ) );
205 scope->
setVariable( QStringLiteral(
"current_feature" ), formFeature,
true );
206 scope->
setVariable( QStringLiteral(
"form_mode" ), formMode,
true );
214 scope->
addFunction( QStringLiteral(
"current_parent_value" ),
new GetCurrentParentFormFieldValue( ) );
215 scope->
setVariable( QStringLiteral(
"current_parent_geometry" ), parentFormFeature.
geometry( ),
true );
216 scope->
setVariable( QStringLiteral(
"current_parent_feature" ), parentFormFeature,
true );
217 scope->
setVariable( QStringLiteral(
"parent_form_mode" ), parentFormMode,
true );
239 vars.insert( name, value );
260 if ( vars.remove( name ) )
272 const QStringList variableNames = layer->
customProperty( QStringLiteral(
"variableNames" ) ).toStringList();
273 const QStringList variableValues = layer->
customProperty( QStringLiteral(
"variableValues" ) ).toStringList();
276 for (
const QString &variableName : variableNames )
278 if ( varIndex >= variableValues.length() )
283 QVariant varValue = variableValues.at( varIndex );
285 scope->
setVariable( variableName, varValue,
true );
293 const QgsVectorLayer *vLayer = qobject_cast< const QgsVectorLayer * >( layer );
308 QList<QgsExpressionContextScope *> scopes;
327 QStringList variableNames = layer->
customProperty( QStringLiteral(
"variableNames" ) ).toStringList();
328 QStringList variableValues = layer->
customProperty( QStringLiteral(
"variableValues" ) ).toStringList();
330 variableNames << name;
331 variableValues << value.toString();
342 QStringList variableNames;
343 QStringList variableValues;
345 QVariantMap::const_iterator it = variables.constBegin();
346 for ( ; it != variables.constEnd(); ++it )
348 variableNames << it.key();
349 variableValues << it.value().toString();
399 QVariantList layersIds;
401 const QList<QgsMapLayer *> layersInMap = mapSettings.
layers();
402 layersIds.reserve( layersInMap.count() );
403 layers.reserve( layersInMap.count() );
406 layersIds << layer->id();
419 scope->
addFunction( QStringLiteral(
"is_layer_visible" ),
new GetLayerVisibility( mapSettings.
layers(), mapSettings.
scale() ) );
438 QVariantList matchList;
442 QVariantMap matchMap;
444 matchMap.insert( QStringLiteral(
"valid" ), match.isValid() );
445 matchMap.insert( QStringLiteral(
"layer" ), QVariant::fromValue<QgsWeakMapLayerPointer>(
QgsWeakMapLayerPointer( match.layer() ) ) );
446 matchMap.insert( QStringLiteral(
"feature_id" ), match.featureId() );
447 matchMap.insert( QStringLiteral(
"vertex_index" ), match.vertexIndex() );
448 matchMap.insert( QStringLiteral(
"distance" ), match.distance() );
450 matchList.append( matchMap );
480 return scope.release();
483 const QStringList variableNames = layout->
customProperty( QStringLiteral(
"variableNames" ) ).toStringList();
484 const QStringList variableValues = layout->
customProperty( QStringLiteral(
"variableValues" ) ).toStringList();
488 for (
const QString &variableName : variableNames )
490 if ( varIndex >= variableValues.length() )
495 QVariant varValue = variableValues.at( varIndex );
497 scope->setVariable( variableName, varValue );
514 scope->addFunction( QStringLiteral(
"item_variables" ),
new GetLayoutItemVariables( layout ) );
526 scope->setFeature( atlasFeature );
532 return scope.release();
541 QStringList variableNames = layout->
customProperty( QStringLiteral(
"variableNames" ) ).toStringList();
542 QStringList variableValues = layout->
customProperty( QStringLiteral(
"variableValues" ) ).toStringList();
544 variableNames << name;
545 variableValues << value.toString();
556 QStringList variableNames;
557 QStringList variableValues;
559 QVariantMap::const_iterator it = variables.constBegin();
560 for ( ; it != variables.constEnd(); ++it )
562 variableNames << it.key();
563 variableValues << it.value().toString();
616 const QStringList variableNames = item->
customProperty( QStringLiteral(
"variableNames" ) ).toStringList();
617 const QStringList variableValues = item->
customProperty( QStringLiteral(
"variableValues" ) ).toStringList();
620 for (
const QString &variableName : variableNames )
622 if ( varIndex >= variableValues.length() )
627 QVariant varValue = variableValues.at( varIndex );
662 QStringList variableNames = item->
customProperty( QStringLiteral(
"variableNames" ) ).toStringList();
663 QStringList variableValues = item->
customProperty( QStringLiteral(
"variableValues" ) ).toStringList();
665 variableNames << name;
666 variableValues << value.toString();
677 QStringList variableNames;
678 QStringList variableValues;
680 QVariantMap::const_iterator it = variables.constBegin();
681 for ( ; it != variables.constEnd(); ++it )
683 variableNames << it.key();
684 variableValues << it.value().toString();
698 const QStringList variableNames = frame->
customProperty( QStringLiteral(
"variableNames" ) ).toStringList();
699 const QStringList variableValues = frame->
customProperty( QStringLiteral(
"variableValues" ) ).toStringList();
702 for (
const QString &variableName : variableNames )
704 if ( varIndex >= variableValues.length() )
709 QVariant varValue = variableValues.at( varIndex );
723 QStringList variableNames = frame->
customProperty( QStringLiteral(
"variableNames" ) ).toStringList();
724 QStringList variableValues = frame->
customProperty( QStringLiteral(
"variableValues" ) ).toStringList();
726 variableNames << name;
727 variableValues << value.toString();
738 QStringList variableNames;
739 QStringList variableValues;
741 QVariantMap::const_iterator it = variables.constBegin();
742 for ( ; it != variables.constEnd(); ++it )
744 variableNames << it.key();
745 variableValues << it.value().toString();
766 scope->addFunction( QStringLiteral(
"parameter" ),
new GetProcessingParameterValue( parameters ) );
769 return scope.release();
774 return scope.release();
781 if ( !model->sourceFilePath().isEmpty() )
783 modelPath = model->sourceFilePath();
792 const QString modelFolder = !modelPath.isEmpty() ? QFileInfo( modelPath ).path() : QString();
799 const QVariantMap customVariables = model->variables();
800 for (
auto it = customVariables.constBegin(); it != customVariables.constEnd(); ++it )
805 return modelScope.release();
812 return scope.release();
828 return mUsesGeometry;
834 return mReferencedColumns;
846 QgsExpressionContextUtils::GetLayerVisibility::GetLayerVisibility(
const QList<QgsMapLayer *> &layers,
double scale )
848 , mLayers( _qgis_listRawToQPointer( layers ) )
851 for (
const auto &layer : mLayers )
853 if ( layer->hasScaleBasedVisibility() )
855 mScaleBasedVisibilityDetails[ layer ] = qMakePair( layer->minimumScale(), layer->maximumScale() );
860 QgsExpressionContextUtils::GetLayerVisibility::GetLayerVisibility()
866 if ( mLayers.isEmpty() )
871 bool isVisible =
false;
872 QgsMapLayer *layer = QgsExpressionUtils::getMapLayer( values.at( 0 ), parent );
873 if ( layer && mLayers.contains( layer ) )
876 if ( mScaleBasedVisibilityDetails.contains( layer ) && !
qgsDoubleNear( mScale, 0.0 ) )
878 if ( ( !
qgsDoubleNear( mScaleBasedVisibilityDetails[ layer ].first, 0.0 ) && mScale > mScaleBasedVisibilityDetails[ layer ].first ) ||
879 ( !
qgsDoubleNear( mScaleBasedVisibilityDetails[ layer ].second, 0.0 ) && mScale < mScaleBasedVisibilityDetails[ layer ].second ) )
891 GetLayerVisibility *func =
new GetLayerVisibility();
892 func->mLayers = mLayers;
893 func->mScale = mScale;
894 func->mScaleBasedVisibilityDetails = mScaleBasedVisibilityDetails;
static QgsGeometry fromPointXY(const QgsPointXY &point)
Creates a new geometry from a QgsPointXY object.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QVariant customProperty(const QString &key, const QVariant &defaultValue=QVariant()) const
Read a custom property from the object.
QgsCoordinateReferenceSystem crs
static QString osName()
Returns a string name of the operating system QGIS is running on.
QString id() const
Returns the item's ID name.
void addFunction(const QString &name, QgsScopedExpressionFunction *function)
Adds a function to the scope.
const QgsLayout * layout() const
Returns the layout the object is attached to.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the scope.
QColor color() const
Returns the symbol's color.
QVariantMap customVariables() const
A map of custom project variables.
QgsProjectStorage * projectStorage() const
Returns pointer to project storage implementation that handles read/write of the project file.
static QString version()
Version string.
QString description() const
Returns the descriptive name of the CRS, e.g., "WGS 84" or "GDA 94 / Vicgrid94".
Item representing the paper in a layout.
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 * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context.
QString projectionAcronym() const
Returns the projection acronym for the projection used by the CRS.
QgsProject * project() const
Returns the project in which the algorithm is being executed.
void addVariable(const QgsExpressionContextScope::StaticVariable &variable)
Adds a variable into the context scope.
static QgsExpressionContextScope * mapToolCaptureScope(const QList< QgsPointLocator::Match > &matches)
Sets the expression context variables which are available for expressions triggered by a map tool cap...
QgsLayoutRenderContext & renderContext()
Returns a reference to the layout's render context, which stores information relating to the current ...
Q_INVOKABLE void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for layer.
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
@ WKT_PREFERRED
Preferred format, matching the most recent WKT ISO standard. Currently an alias to WKT2_2019,...
bool isTemporal() const
Returns true if the object's temporal range is enabled, and the object will be filtered when renderin...
static QgsExpressionContextScope * notificationScope(const QString &message=QString())
Creates a new scope which contains variables and functions relating to provider notifications.
int count() const override
Returns the number of features to iterate over.
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 void setCustomVariables(const QVariantMap &customVariables)
Custom expression variables for this application.
static void registerContextFunctions()
Registers all known core functions provided by QgsExpressionContextScope objects.
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 void setLayerVariables(QgsMapLayer *layer, const QVariantMap &variables)
Sets all layer context variables.
const QgsDateTimeRange & temporalRange() const
Returns the datetime range for the object.
static QgsExpressionContextScope * mapSettingsScope(const QgsMapSettings &mapSettings)
Creates a new scope which contains variables and functions relating to a QgsMapSettings object.
void setCustomVariables(const QVariantMap &customVariables)
A map of custom project variables.
static QgsProject * instance()
Returns the QgsProject singleton instance.
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
static QgsExpressionContextScope * layoutScope(const QgsLayout *layout)
Creates a new scope which contains variables and functions relating to a QgsLayout layout.
static QgsExpressionContextScope * layoutItemScope(const QgsLayoutItem *item)
Creates a new scope which contains variables and functions relating to a QgsLayoutItem.
int page() const
Returns the page the item is currently on, with the first page returning 0.
static QgsExpressionContextScope * multiFrameScope(const QgsLayoutMultiFrame *frame)
Creates a new scope which contains variables and functions relating to a QgsLayoutMultiFrame.
void setFields(const QgsFields &fields)
Convenience function for setting a fields for the scope.
static void setLayerVariable(QgsMapLayer *layer, const QString &name, const QVariant &value)
Sets a layer context variable.
double angle() const
Returns the marker angle for the whole symbol.
static void removeProjectVariable(QgsProject *project, const QString &name)
Remove project context variable.
static const QString EXPR_SYMBOL_COLOR
Inbuilt variable name for symbol color variable.
QVariant variable(const QString &name) const
Fetches a matching variable from the context.
QgsLayoutPageCollection * pageCollection()
Returns a pointer to the layout's page collection, which stores and manages page items in the layout.
QgsLayout * layout() override
Returns the layout associated with the iterator.
QgsLayoutSize sizeWithUnits() const
Returns the item's current size, including units.
static QgsGeometry fromRect(const QgsRectangle &rect)
Creates a new geometry from a QgsRectangle.
static QString platform()
Returns the QGIS platform name, e.g., "desktop" or "server".
static const QString EXPR_SYMBOL_ANGLE
Inbuilt variable name for symbol angle variable.
static QString locale()
Returns the QGIS locale.
QgsFields fields() const FINAL
Returns the list of fields of this layer.
static QgsExpressionContextScope * projectScope(const QgsProject *project)
Creates a new scope which contains variables and functions relating to a QGIS project.
static void setLayoutVariable(QgsLayout *layout, const QString &name, const QVariant &value)
Sets a layout context variable.
double rotation() const
Returns the rotation of the resulting map image, in degrees clockwise.
QString id() const
Returns the unique ID for the algorithm, which is a combination of the algorithm provider's ID and th...
QSizeF toQSizeF() const
Converts the layout size to a QSizeF.
QVariant customProperty(const QString &key, const QVariant &defaultValue=QVariant()) const
Read a custom property from the layout.
bool enabled() const
Returns whether the atlas generation is enabled.
static void setLayoutMultiFrameVariables(QgsLayoutMultiFrame *frame, const QVariantMap &variables)
Sets all layout multiframe context variables for an frame.
bool isValid() const
Returns the validity of this feature.
static Q_INVOKABLE QString toString(QgsUnitTypes::DistanceUnit unit)
Returns a translated string representing a distance unit.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
QgsUnitTypes::DistanceUnit mapUnits() const
Gets units of map's geographical coordinates - used for scale calculation.
QgsFeature feature() const
Returns the current feature for evaluating the layout.
QgsVectorLayer * coverageLayer() const
Returns the coverage layer used for the atlas features.
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...
QString authid() const
Returns the authority identifier for the CRS.
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,...
QgsLayoutReportContext & reportContext()
Returns a reference to the layout's report context, which stores information relating to the current ...
static void setGlobalVariable(const QString &name, const QVariant &value)
Sets a global context variable.
QString toWkt(WktVariant variant=WKT1_GDAL, bool multiline=false, int indentationWidth=4) const
Returns a WKT representation of this CRS.
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 * 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 void setLayoutItemVariables(QgsLayoutItem *item, const QVariantMap &variables)
Sets all layout item context variables for an item.
QSet< QString > referencedColumns(const QgsExpressionNodeFunction *node) const override
Returns a set of field names which are required for this function.
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
QgsLayoutItemPage * page(int pageNumber)
Returns a specific page (by pageNumber) from the collection.
static void setCustomVariable(const QString &name, const QVariant &value)
Set a single custom expression variable.
QPointer< QgsMapLayer > QgsWeakMapLayerPointer
Weak pointer for QgsMapLayer.
double scale() const
Returns the calculated map scale.
Base class for graphical items within a QgsLayout.
QString toProj() const
Returns a Proj string representation of this CRS.
An expression node for expression functions.
void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for the object.
Single scope for storing variables and functions for use within a QgsExpressionContext....
static void setGlobalVariables(const QVariantMap &variables)
Sets all global context variables.
int currentFeatureNumber() const
Returns the current feature number, where a value of 0 corresponds to the first feature.
QString absoluteFilePath() const
Returns full absolute path to the project file if the project is stored in a file system - derived fr...
QgsCoordinateReferenceSystem destinationCrs() const
returns CRS of destination coordinate reference system
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 QString userLoginName()
Returns the user's operating system login account name.
virtual QString uuid() const
Returns the item identification string.
Q_INVOKABLE QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
static QgsExpressionContextScope * updateSymbolScope(const QgsSymbol *symbol, QgsExpressionContextScope *symbolScope=nullptr)
Updates a symbol scope related to a QgsSymbol to an expression context.
QgsPointXY center() const
Returns the center point of the rectangle.
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
QString currentFilename() const
Returns the current feature filename.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
virtual QgsScopedExpressionFunction * clone() const =0
Returns a clone of the function.
double height() const
Returns the height of the rectangle.
static void removeGlobalVariable(const QString &name)
Remove a global context variable.
QgsExpressionContextScope * createExpressionContextScope() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
bool isStatic(const QgsExpressionNodeFunction *node, QgsExpression *parent, const QgsExpressionContext *context) const override
Will be called during prepare to determine if the function is static.
static QgsExpressionContextScope * atlasScope(const QgsLayoutAtlas *atlas)
Creates a new scope which contains variables and functions relating to a QgsLayoutAtlas.
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...
static QString releaseName()
Release name.
QList< QgsMapLayer * > layers() const
Gets list of layers for map rendering The layers are stored in the reverse order of how they are rend...
static QVariantMap customVariables()
Custom expression variables for this application.
static bool registerFunction(QgsExpressionFunction *function, bool transferOwnership=false)
Registers a function to the expression engine.
double dpi() const
Returns the dpi for outputting the layout.
QString ellipsoidAcronym() const
Returns the ellipsoid acronym for the ellipsoid used by the CRS.
Interface for master layout type objects, such as print layouts and reports.
void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for the layout.
bool usesGeometry(const QgsExpressionNodeFunction *node) const override
Does this function use a geometry object.
Single variable definition for use within a QgsExpressionContextScope.
int pageCount() const
Returns the number of pages in the collection.
QgsRectangle visibleExtent() const
Returns the actual extent derived from requested extent that takes takes output image size into accou...
static void setLayoutMultiFrameVariable(QgsLayoutMultiFrame *frame, const QString &name, const QVariant &value)
Sets a layout multi frame context variable, with the given name and value.
Expression function for use within a QgsExpressionContextScope. This differs from a standard QgsExpre...
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
static int versionInt()
Version number used for comparing versions using the "Check QGIS Version" function.
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
QVariant func(const QVariantList &values, const QgsExpressionContext *context, QgsExpression *parent, const QgsExpressionNodeFunction *node) override=0
Returns result of evaluating the function.
double width() const
Returns the width of the rectangle.
QgsVectorLayer * layer() const
Returns the vector layer associated with the layout's context.
static void setProjectVariables(QgsProject *project, const QVariantMap &variables)
Sets all project context variables.
static void setLayoutVariables(QgsLayout *layout, const QVariantMap &variables)
Sets all layout context variables.
static QString userFullName()
Returns the user's operating system login account full display name.
QString nameForPage(int page) const
Returns the calculated name for a specified atlas page number.