QGIS API Documentation  3.6.0-Noosa (5873452)
qgsexpressioncontextutils.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsexpressioncontextutils.h
3  ---------------------------
4  Date : April 2015
5  Copyright : (C) 2015 by Nyall Dawson
6  Email : nyall dot dawson at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 #ifndef QGSEXPRESSIONCONTEXTUTILS_H
16 #define QGSEXPRESSIONCONTEXTUTILS_H
17 
18 #include "qgis_core.h"
19 #include "qgis_sip.h"
20 #include "qgsfeature.h"
21 #include "qgspointlocator.h"
22 #include "qgsexpressioncontext.h"
23 #include <QString>
24 #include <QVariantMap>
25 
27 class QgsProject;
28 class QgsLayout;
29 class QgsSymbol;
30 class QgsLayoutAtlas;
31 class QgsLayoutItem;
33 class QgsProcessingModelAlgorithm;
35 
44 class CORE_EXPORT QgsExpressionContextUtils
45 {
46  public:
47 
53  static QgsExpressionContextScope *globalScope() SIP_FACTORY;
54 
61  static QgsExpressionContextScope *formScope( const QgsFeature &formFeature = QgsFeature( ), const QString &formMode = QString() ) SIP_FACTORY;
62 
72  static void setGlobalVariable( const QString &name, const QVariant &value );
73 
82  static void setGlobalVariables( const QVariantMap &variables );
83 
91  static void removeGlobalVariable( const QString &name );
92 
99  static QgsExpressionContextScope *projectScope( const QgsProject *project ) SIP_FACTORY;
100 
111  static void setProjectVariable( QgsProject *project, const QString &name, const QVariant &value );
112 
122  static void setProjectVariables( QgsProject *project, const QVariantMap &variables );
123 
132  static void removeProjectVariable( QgsProject *project, const QString &name );
133 
138  static QgsExpressionContextScope *layerScope( const QgsMapLayer *layer ) SIP_FACTORY;
139 
144  static QList<QgsExpressionContextScope *> globalProjectLayerScopes( const QgsMapLayer *layer ) SIP_FACTORY;
145 
155  static void setLayerVariable( QgsMapLayer *layer, const QString &name, const QVariant &value );
156 
165  static void setLayerVariables( QgsMapLayer *layer, const QVariantMap &variables );
166 
171  static QgsExpressionContextScope *mapSettingsScope( const QgsMapSettings &mapSettings ) SIP_FACTORY;
172 
179  static QgsExpressionContextScope *mapToolCaptureScope( const QList<QgsPointLocator::Match> &matches ) SIP_FACTORY;
180 
187  static QgsExpressionContextScope *updateSymbolScope( const QgsSymbol *symbol, QgsExpressionContextScope *symbolScope = nullptr );
188 
194  static QgsExpressionContextScope *layoutScope( const QgsLayout *layout ) SIP_FACTORY;
195 
206  static void setLayoutVariable( QgsLayout *layout, const QString &name, const QVariant &value );
207 
217  static void setLayoutVariables( QgsLayout *layout, const QVariantMap &variables );
218 
224  static QgsExpressionContextScope *atlasScope( QgsLayoutAtlas *atlas ) SIP_FACTORY;
225 
233  static QgsExpressionContextScope *layoutItemScope( const QgsLayoutItem *item ) SIP_FACTORY;
234 
243  static void setLayoutItemVariable( QgsLayoutItem *item, const QString &name, const QVariant &value );
244 
252  static void setLayoutItemVariables( QgsLayoutItem *item, const QVariantMap &variables );
253 
259  static QgsExpressionContext createFeatureBasedContext( const QgsFeature &feature, const QgsFields &fields );
260 
267  static QgsExpressionContextScope *processingAlgorithmScope( const QgsProcessingAlgorithm *algorithm, const QVariantMap &parameters, QgsProcessingContext &context ) SIP_FACTORY;
268 
275  static QgsExpressionContextScope *processingModelAlgorithmScope( const QgsProcessingModelAlgorithm *model, const QVariantMap &parameters, QgsProcessingContext &context ) SIP_FACTORY;
276 
281  static QgsExpressionContextScope *notificationScope( const QString &message = QString() ) SIP_FACTORY;
282 
286  static void registerContextFunctions();
287 
288  private:
289 
290  class GetLayerVisibility : public QgsScopedExpressionFunction
291  {
292  public:
293  GetLayerVisibility( const QList<QgsMapLayer *> &layers );
294  QVariant func( const QVariantList &values, const QgsExpressionContext *, QgsExpression *, const QgsExpressionNodeFunction * ) override;
295  QgsScopedExpressionFunction *clone() const override;
296 
297  private:
298 
299  const QList< QPointer< QgsMapLayer > > mLayers;
300 
301  };
302 
303  friend class QgsLayoutItemMap; // needs access to GetLayerVisibility
304 
305 };
306 
307 #endif // QGSEXPRESSIONCONTEXTUTILS_H
Class for parsing and evaluation of expressions (formerly called "search strings").
Base class for all map layer types.
Definition: qgsmaplayer.h:64
Base class for graphical items within a QgsLayout.
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:61
Container of fields for a vector layer.
Definition: qgsfields.h:42
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:55
Abstract base class for processing algorithms.
The QgsMapSettings class contains configuration for rendering of the map.
Layout graphical items for displaying a map.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Class used to render QgsLayout as an atlas, by iterating over the features from an associated vector ...
Reads and writes project states.
Definition: qgsproject.h:89
#define SIP_FACTORY
Definition: qgis_sip.h:69
Single scope for storing variables and functions for use within a QgsExpressionContext.
An expression node for expression functions.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:49
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
Contains utilities for working with QgsExpressionContext objects, including methods for creating scop...
Contains information about the context in which a processing algorithm is executed.
Expression function for use within a QgsExpressionContextScope.