QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
qgsexpressioncontextutils.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsexpressioncontextutils.cpp
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 
17 #include "qgsapplication.h"
18 #include "qgsvectorlayer.h"
19 #include "qgsproject.h"
20 #include "qgsexpression.h"
21 #include "qgsprocessingcontext.h"
22 #include "qgsprocessingmodelalgorithm.h"
23 #include "qgsprocessingalgorithm.h"
24 #include "qgsmapsettings.h"
25 #include "qgssymbollayerutils.h"
26 #include "qgslayout.h"
27 #include "qgslayoutitem.h"
28 #include "qgsexpressionutils.h"
30 #include "qgslayoutatlas.h"
31 #include "qgslayoutmultiframe.h"
32 
34 {
35  QgsExpressionContextScope *scope = new QgsExpressionContextScope( QObject::tr( "Global" ) );
36 
37  QVariantMap customVariables = QgsApplication::customVariables();
38 
39  for ( QVariantMap::const_iterator it = customVariables.constBegin(); it != customVariables.constEnd(); ++it )
40  {
41  scope->setVariable( it.key(), it.value(), true );
42  }
43 
44  //add some extra global variables
45  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "qgis_version" ), Qgis::QGIS_VERSION, true, true ) );
46  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "qgis_version_no" ), Qgis::QGIS_VERSION_INT, true, true ) );
47  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "qgis_short_version" ), QStringLiteral( "%1.%2" ).arg( Qgis::QGIS_VERSION_INT / 10000 ).arg( Qgis::QGIS_VERSION_INT / 100 % 100 ), true, true ) );
48  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "qgis_release_name" ), Qgis::QGIS_RELEASE_NAME, true, true ) );
49  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "qgis_platform" ), QgsApplication::platform(), true, true ) );
50  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "qgis_os_name" ), QgsApplication::osName(), true, true ) );
51  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "qgis_locale" ), QgsApplication::locale(), true, true ) );
52  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "user_account_name" ), QgsApplication::userLoginName(), true, true ) );
53  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "user_full_name" ), QgsApplication::userFullName(), true, true ) );
54 
55  return scope;
56 }
57 
58 void QgsExpressionContextUtils::setGlobalVariable( const QString &name, const QVariant &value )
59 {
60  QgsApplication::setCustomVariable( name, value );
61 }
62 
63 void QgsExpressionContextUtils::setGlobalVariables( const QVariantMap &variables )
64 {
66 }
67 
69 {
70  QVariantMap vars = QgsApplication::customVariables();
71  if ( vars.remove( name ) )
73 }
74 
76 
77 class GetLayoutItemVariables : public QgsScopedExpressionFunction
78 {
79  public:
80  GetLayoutItemVariables( const QgsLayout *c )
81  : QgsScopedExpressionFunction( QStringLiteral( "item_variables" ), QgsExpressionFunction::ParameterList() << QgsExpressionFunction::Parameter( QStringLiteral( "id" ) ), QStringLiteral( "Layout" ) )
82  , mLayout( c )
83  {}
84 
85  QVariant func( const QVariantList &values, const QgsExpressionContext *, QgsExpression *, const QgsExpressionNodeFunction * ) override
86  {
87  if ( !mLayout )
88  return QVariant();
89 
90  QString id = values.at( 0 ).toString();
91 
92  const QgsLayoutItem *item = mLayout->itemById( id );
93  if ( !item )
94  return QVariant();
95 
97 
98  return c.variablesToMap();
99  }
100 
101  QgsScopedExpressionFunction *clone() const override
102  {
103  return new GetLayoutItemVariables( mLayout );
104  }
105 
106  private:
107 
108  const QgsLayout *mLayout = nullptr;
109 
110 };
111 
112 class GetCurrentFormFieldValue : public QgsScopedExpressionFunction
113 {
114  public:
115  GetCurrentFormFieldValue( )
116  : QgsScopedExpressionFunction( QStringLiteral( "current_value" ), QgsExpressionFunction::ParameterList() << QStringLiteral( "field_name" ), QStringLiteral( "Form" ) )
117  {}
118 
119  QVariant func( const QVariantList &values, const QgsExpressionContext *context, QgsExpression *, const QgsExpressionNodeFunction * ) override
120  {
121  QString fieldName( values.at( 0 ).toString() );
122  const QgsFeature feat( context->variable( QStringLiteral( "current_feature" ) ).value<QgsFeature>() );
123  if ( fieldName.isEmpty() || ! feat.isValid( ) )
124  {
125  return QVariant();
126  }
127  return feat.attribute( fieldName ) ;
128  }
129 
130  QgsScopedExpressionFunction *clone() const override
131  {
132  return new GetCurrentFormFieldValue( );
133  }
134 
135 };
136 
137 
138 class GetProcessingParameterValue : public QgsScopedExpressionFunction
139 {
140  public:
141  GetProcessingParameterValue( const QVariantMap &params )
142  : QgsScopedExpressionFunction( QStringLiteral( "parameter" ), QgsExpressionFunction::ParameterList() << QgsExpressionFunction::Parameter( QStringLiteral( "name" ) ), QStringLiteral( "Processing" ) )
143  , mParams( params )
144  {}
145 
146  QVariant func( const QVariantList &values, const QgsExpressionContext *, QgsExpression *, const QgsExpressionNodeFunction * ) override
147  {
148  return mParams.value( values.at( 0 ).toString() );
149  }
150 
151  QgsScopedExpressionFunction *clone() const override
152  {
153  return new GetProcessingParameterValue( mParams );
154  }
155 
156  private:
157 
158  const QVariantMap mParams;
159 
160 };
161 
163 
164 
165 QgsExpressionContextScope *QgsExpressionContextUtils::formScope( const QgsFeature &formFeature, const QString &formMode )
166 {
167  QgsExpressionContextScope *scope = new QgsExpressionContextScope( QObject::tr( "Form" ) );
168  scope->addFunction( QStringLiteral( "current_value" ), new GetCurrentFormFieldValue( ) );
169  scope->setVariable( QStringLiteral( "current_geometry" ), formFeature.geometry( ), true );
170  scope->setVariable( QStringLiteral( "current_feature" ), formFeature, true );
171  scope->setVariable( QStringLiteral( "form_mode" ), formMode, true );
172  return scope;
173 }
174 
176 {
177  if ( !project )
178  {
179  QgsExpressionContextScope *scope = new QgsExpressionContextScope( QObject::tr( "Project" ) );
180  return scope;
181  }
182  else
183  return project->createExpressionContextScope();
184 }
185 
186 void QgsExpressionContextUtils::setProjectVariable( QgsProject *project, const QString &name, const QVariant &value )
187 {
188  if ( !project )
189  return;
190 
191  QVariantMap vars = project->customVariables();
192 
193  vars.insert( name, value );
194 
195  project->setCustomVariables( vars );
196 }
197 
198 void QgsExpressionContextUtils::setProjectVariables( QgsProject *project, const QVariantMap &variables )
199 {
200  if ( !project )
201  return;
202 
203  project->setCustomVariables( variables );
204 }
205 
207 {
208  if ( !project )
209  {
210  return;
211  }
212 
213  QVariantMap vars = project->customVariables();
214  if ( vars.remove( name ) )
215  project->setCustomVariables( vars );
216 }
217 
219 {
220  QgsExpressionContextScope *scope = new QgsExpressionContextScope( QObject::tr( "Layer" ) );
221 
222  if ( !layer )
223  return scope;
224 
225  //add variables defined in layer properties
226  const QStringList variableNames = layer->customProperty( QStringLiteral( "variableNames" ) ).toStringList();
227  const QStringList variableValues = layer->customProperty( QStringLiteral( "variableValues" ) ).toStringList();
228 
229  int varIndex = 0;
230  for ( const QString &variableName : variableNames )
231  {
232  if ( varIndex >= variableValues.length() )
233  {
234  break;
235  }
236 
237  QVariant varValue = variableValues.at( varIndex );
238  varIndex++;
239  scope->setVariable( variableName, varValue, true );
240  }
241 
242  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "layer_name" ), layer->name(), true, true ) );
243  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "layer_id" ), layer->id(), true, true ) );
244  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "_layer_crs" ), QVariant::fromValue<QgsCoordinateReferenceSystem>( layer->crs() ), true, true ) );
245  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "layer" ), QVariant::fromValue<QgsWeakMapLayerPointer >( QgsWeakMapLayerPointer( const_cast<QgsMapLayer *>( layer ) ) ), true, true ) );
246 
247  const QgsVectorLayer *vLayer = qobject_cast< const QgsVectorLayer * >( layer );
248  if ( vLayer )
249  {
250  scope->setFields( vLayer->fields() );
251  }
252 
253  //TODO - add functions. Possibilities include:
254  //is_selected
255  //field summary stats
256 
257  return scope;
258 }
259 
260 QList<QgsExpressionContextScope *> QgsExpressionContextUtils::globalProjectLayerScopes( const QgsMapLayer *layer )
261 {
262  QList<QgsExpressionContextScope *> scopes;
263  scopes << globalScope();
264 
265  QgsProject *project = QgsProject::instance(); // TODO: use project associated with layer
266  if ( project )
267  scopes << projectScope( project );
268 
269  if ( layer )
270  scopes << layerScope( layer );
271  return scopes;
272 }
273 
274 
275 void QgsExpressionContextUtils::setLayerVariable( QgsMapLayer *layer, const QString &name, const QVariant &value )
276 {
277  if ( !layer )
278  return;
279 
280  //write variable to layer
281  QStringList variableNames = layer->customProperty( QStringLiteral( "variableNames" ) ).toStringList();
282  QStringList variableValues = layer->customProperty( QStringLiteral( "variableValues" ) ).toStringList();
283 
284  variableNames << name;
285  variableValues << value.toString();
286 
287  layer->setCustomProperty( QStringLiteral( "variableNames" ), variableNames );
288  layer->setCustomProperty( QStringLiteral( "variableValues" ), variableValues );
289 }
290 
291 void QgsExpressionContextUtils::setLayerVariables( QgsMapLayer *layer, const QVariantMap &variables )
292 {
293  if ( !layer )
294  return;
295 
296  QStringList variableNames;
297  QStringList variableValues;
298 
299  QVariantMap::const_iterator it = variables.constBegin();
300  for ( ; it != variables.constEnd(); ++it )
301  {
302  variableNames << it.key();
303  variableValues << it.value().toString();
304  }
305 
306  layer->setCustomProperty( QStringLiteral( "variableNames" ), variableNames );
307  layer->setCustomProperty( QStringLiteral( "variableValues" ), variableValues );
308 }
309 
311 {
312  // IMPORTANT: ANY CHANGES HERE ALSO NEED TO BE MADE TO QgsLayoutItemMap::createExpressionContext()
313  // (rationale is described in QgsLayoutItemMap::createExpressionContext() )
314 
315  // and because people don't read that ^^, I'm going to blast it all over this function
316 
317  QgsExpressionContextScope *scope = new QgsExpressionContextScope( QObject::tr( "Map Settings" ) );
318 
319  //add known map settings context variables
320  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_id" ), "canvas", true ) );
321  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_rotation" ), mapSettings.rotation(), true ) );
322  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_scale" ), mapSettings.scale(), true ) );
323 
324  // IMPORTANT: ANY CHANGES HERE ALSO NEED TO BE MADE TO QgsLayoutItemMap::createExpressionContext()
325  // (rationale is described in QgsLayoutItemMap::createExpressionContext() )
326 
327  QgsGeometry extent = QgsGeometry::fromRect( mapSettings.visibleExtent() );
328  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_extent" ), QVariant::fromValue( extent ), true ) );
329  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_extent_width" ), mapSettings.visibleExtent().width(), true ) );
330  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_extent_height" ), mapSettings.visibleExtent().height(), true ) );
331 
332  // IMPORTANT: ANY CHANGES HERE ALSO NEED TO BE MADE TO QgsLayoutItemMap::createExpressionContext()
333  // (rationale is described in QgsLayoutItemMap::createExpressionContext() )
334 
335  QgsGeometry centerPoint = QgsGeometry::fromPointXY( mapSettings.visibleExtent().center() );
336  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_extent_center" ), QVariant::fromValue( centerPoint ), true ) );
337 
338  // IMPORTANT: ANY CHANGES HERE ALSO NEED TO BE MADE TO QgsLayoutItemMap::createExpressionContext()
339  // (rationale is described in QgsLayoutItemMap::createExpressionContext() )
340 
341  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_crs" ), mapSettings.destinationCrs().authid(), true ) );
342  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_crs_definition" ), mapSettings.destinationCrs().toProj4(), true ) );
343  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_units" ), QgsUnitTypes::toString( mapSettings.mapUnits() ), true ) );
344  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_crs_description" ), mapSettings.destinationCrs().description(), true ) );
345  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_crs_acronym" ), mapSettings.destinationCrs().projectionAcronym(), true ) );
346  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_crs_ellipsoid" ), mapSettings.destinationCrs().ellipsoidAcronym(), true ) );
347  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_crs_proj4" ), mapSettings.destinationCrs().toProj4(), true ) );
348  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_crs_wkt" ), mapSettings.destinationCrs().toWkt(), true ) );
349 
350  // IMPORTANT: ANY CHANGES HERE ALSO NEED TO BE MADE TO QgsLayoutItemMap::createExpressionContext()
351  // (rationale is described in QgsLayoutItemMap::createExpressionContext() )
352 
353  QVariantList layersIds;
354  QVariantList layers;
355  const QList<QgsMapLayer *> layersInMap = mapSettings.layers();
356  layersIds.reserve( layersInMap.count() );
357  layers.reserve( layersInMap.count() );
358  for ( QgsMapLayer *layer : layersInMap )
359  {
360  layersIds << layer->id();
361  layers << QVariant::fromValue<QgsWeakMapLayerPointer>( QgsWeakMapLayerPointer( layer ) );
362  }
363 
364  // IMPORTANT: ANY CHANGES HERE ALSO NEED TO BE MADE TO QgsLayoutItemMap::createExpressionContext()
365  // (rationale is described in QgsLayoutItemMap::createExpressionContext() )
366 
367  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_layer_ids" ), layersIds, true ) );
368  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_layers" ), layers, true ) );
369 
370  // IMPORTANT: ANY CHANGES HERE ALSO NEED TO BE MADE TO QgsLayoutItemMap::createExpressionContext()
371  // (rationale is described in QgsLayoutItemMap::createExpressionContext() )
372 
373  scope->addFunction( QStringLiteral( "is_layer_visible" ), new GetLayerVisibility( mapSettings.layers(), mapSettings.scale() ) );
374 
375  // IMPORTANT: ANY CHANGES HERE ALSO NEED TO BE MADE TO QgsLayoutItemMap::createExpressionContext()
376  // (rationale is described in QgsLayoutItemMap::createExpressionContext() )
377 
378  return scope;
379 }
380 
381 QgsExpressionContextScope *QgsExpressionContextUtils::mapToolCaptureScope( const QList<QgsPointLocator::Match> &matches )
382 {
383  QgsExpressionContextScope *scope = new QgsExpressionContextScope( QObject::tr( "Map Tool Capture" ) );
384 
385  QVariantList matchList;
386 
387  for ( const QgsPointLocator::Match &match : matches )
388  {
389  QVariantMap matchMap;
390 
391  matchMap.insert( QStringLiteral( "valid" ), match.isValid() );
392  matchMap.insert( QStringLiteral( "layer" ), QVariant::fromValue<QgsWeakMapLayerPointer>( QgsWeakMapLayerPointer( match.layer() ) ) );
393  matchMap.insert( QStringLiteral( "feature_id" ), match.featureId() );
394  matchMap.insert( QStringLiteral( "vertex_index" ), match.vertexIndex() );
395  matchMap.insert( QStringLiteral( "distance" ), match.distance() );
396 
397  matchList.append( matchMap );
398  }
399 
400  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "snapping_results" ), matchList ) );
401 
402  return scope;
403 }
404 
406 {
407  if ( !symbolScope )
408  return nullptr;
409 
410  symbolScope->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_SYMBOL_COLOR, symbol ? symbol->color() : QColor(), true ) );
411 
412  double angle = 0.0;
413  const QgsMarkerSymbol *markerSymbol = dynamic_cast< const QgsMarkerSymbol * >( symbol );
414  if ( markerSymbol )
415  {
416  angle = markerSymbol->angle();
417  }
419 
420  return symbolScope;
421 }
422 
424 {
425  std::unique_ptr< QgsExpressionContextScope > scope( new QgsExpressionContextScope( QObject::tr( "Layout" ) ) );
426  if ( !layout )
427  return scope.release();
428 
429  //add variables defined in layout properties
430  const QStringList variableNames = layout->customProperty( QStringLiteral( "variableNames" ) ).toStringList();
431  const QStringList variableValues = layout->customProperty( QStringLiteral( "variableValues" ) ).toStringList();
432 
433  int varIndex = 0;
434 
435  for ( const QString &variableName : variableNames )
436  {
437  if ( varIndex >= variableValues.length() )
438  {
439  break;
440  }
441 
442  QVariant varValue = variableValues.at( varIndex );
443  varIndex++;
444  scope->setVariable( variableName, varValue );
445  }
446 
447  //add known layout context variables
448  if ( const QgsMasterLayoutInterface *l = dynamic_cast< const QgsMasterLayoutInterface * >( layout ) )
449  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "layout_name" ), l->name(), true ) );
450 
451  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "layout_numpages" ), layout->pageCollection()->pageCount(), true ) );
452  if ( layout->pageCollection()->pageCount() > 0 )
453  {
454  // just take first page size
455  QSizeF s = layout->pageCollection()->page( 0 )->sizeWithUnits().toQSizeF();
456  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "layout_pageheight" ), s.height(), true ) );
457  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "layout_pagewidth" ), s.width(), true ) );
458  }
459  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "layout_dpi" ), layout->renderContext().dpi(), true ) );
460 
461  scope->addFunction( QStringLiteral( "item_variables" ), new GetLayoutItemVariables( layout ) );
462 
463  if ( layout->reportContext().layer() )
464  {
465  scope->setFields( layout->reportContext().layer()->fields() );
466  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "atlas_layerid" ), layout->reportContext().layer()->id(), true ) );
467  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "atlas_layername" ), layout->reportContext().layer()->name(), true ) );
468  }
469 
470  if ( layout->reportContext().feature().isValid() )
471  {
472  QgsFeature atlasFeature = layout->reportContext().feature();
473  scope->setFeature( atlasFeature );
474  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "atlas_feature" ), QVariant::fromValue( atlasFeature ), true ) );
475  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "atlas_featureid" ), atlasFeature.id(), true ) );
476  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "atlas_geometry" ), QVariant::fromValue( atlasFeature.geometry() ), true ) );
477  }
478 
479  return scope.release();
480 }
481 
482 void QgsExpressionContextUtils::setLayoutVariable( QgsLayout *layout, const QString &name, const QVariant &value )
483 {
484  if ( !layout )
485  return;
486 
487  //write variable to layout
488  QStringList variableNames = layout->customProperty( QStringLiteral( "variableNames" ) ).toStringList();
489  QStringList variableValues = layout->customProperty( QStringLiteral( "variableValues" ) ).toStringList();
490 
491  variableNames << name;
492  variableValues << value.toString();
493 
494  layout->setCustomProperty( QStringLiteral( "variableNames" ), variableNames );
495  layout->setCustomProperty( QStringLiteral( "variableValues" ), variableValues );
496 }
497 
498 void QgsExpressionContextUtils::setLayoutVariables( QgsLayout *layout, const QVariantMap &variables )
499 {
500  if ( !layout )
501  return;
502 
503  QStringList variableNames;
504  QStringList variableValues;
505 
506  QVariantMap::const_iterator it = variables.constBegin();
507  for ( ; it != variables.constEnd(); ++it )
508  {
509  variableNames << it.key();
510  variableValues << it.value().toString();
511  }
512 
513  layout->setCustomProperty( QStringLiteral( "variableNames" ), variableNames );
514  layout->setCustomProperty( QStringLiteral( "variableValues" ), variableValues );
515 }
516 
518 {
519  QgsExpressionContextScope *scope = new QgsExpressionContextScope( QObject::tr( "Atlas" ) );
520  if ( !atlas )
521  {
522  //add some dummy atlas variables. This is done so that as in certain contexts we want to show
523  //users that these variables are available even if they have no current value
524  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "atlas_pagename" ), QString(), true ) );
525  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "atlas_feature" ), QVariant::fromValue( QgsFeature() ), true ) );
526  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "atlas_featureid" ), 0, true ) );
527  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "atlas_geometry" ), QVariant::fromValue( QgsGeometry() ), true ) );
528  return scope;
529  }
530 
531  //add known atlas variables
532  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "atlas_totalfeatures" ), atlas->count(), true ) );
533  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "atlas_featurenumber" ), atlas->currentFeatureNumber() + 1, true ) );
534  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "atlas_filename" ), atlas->currentFilename(), true ) );
535  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "atlas_pagename" ), atlas->nameForPage( atlas->currentFeatureNumber() ), true ) );
536 
537  if ( atlas->enabled() && atlas->coverageLayer() )
538  {
539  scope->setFields( atlas->coverageLayer()->fields() );
540  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "atlas_layerid" ), atlas->coverageLayer()->id(), true ) );
541  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "atlas_layername" ), atlas->coverageLayer()->name(), true ) );
542  }
543 
544  if ( atlas->enabled() )
545  {
546  QgsFeature atlasFeature = atlas->layout()->reportContext().feature();
547  scope->setFeature( atlasFeature );
548  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "atlas_feature" ), QVariant::fromValue( atlasFeature ), true ) );
549  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "atlas_featureid" ), atlasFeature.id(), true ) );
550  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "atlas_geometry" ), QVariant::fromValue( atlasFeature.geometry() ), true ) );
551  }
552 
553  return scope;
554 }
555 
557 {
558  QgsExpressionContextScope *scope = new QgsExpressionContextScope( QObject::tr( "Layout Item" ) );
559  if ( !item )
560  return scope;
561 
562  //add variables defined in layout item properties
563  const QStringList variableNames = item->customProperty( QStringLiteral( "variableNames" ) ).toStringList();
564  const QStringList variableValues = item->customProperty( QStringLiteral( "variableValues" ) ).toStringList();
565 
566  int varIndex = 0;
567  for ( const QString &variableName : variableNames )
568  {
569  if ( varIndex >= variableValues.length() )
570  {
571  break;
572  }
573 
574  QVariant varValue = variableValues.at( varIndex );
575  varIndex++;
576  scope->setVariable( variableName, varValue );
577  }
578 
579  //add known layout item context variables
580  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "item_id" ), item->id(), true ) );
581  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "item_uuid" ), item->uuid(), true ) );
582  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "layout_page" ), item->page() + 1, true ) );
583 
584  if ( item->layout() )
585  {
586  const QgsLayoutItemPage *page = item->layout()->pageCollection()->page( item->page() );
587  if ( page )
588  {
589  const QSizeF s = page->sizeWithUnits().toQSizeF();
590  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "layout_pageheight" ), s.height(), true ) );
591  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "layout_pagewidth" ), s.width(), true ) );
592  }
593  else
594  {
595  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "layout_pageheight" ), QVariant(), true ) );
596  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "layout_pagewidth" ), QVariant(), true ) );
597  }
598  }
599 
600  return scope;
601 }
602 
603 void QgsExpressionContextUtils::setLayoutItemVariable( QgsLayoutItem *item, const QString &name, const QVariant &value )
604 {
605  if ( !item )
606  return;
607 
608  //write variable to layout item
609  QStringList variableNames = item->customProperty( QStringLiteral( "variableNames" ) ).toStringList();
610  QStringList variableValues = item->customProperty( QStringLiteral( "variableValues" ) ).toStringList();
611 
612  variableNames << name;
613  variableValues << value.toString();
614 
615  item->setCustomProperty( QStringLiteral( "variableNames" ), variableNames );
616  item->setCustomProperty( QStringLiteral( "variableValues" ), variableValues );
617 }
618 
619 void QgsExpressionContextUtils::setLayoutItemVariables( QgsLayoutItem *item, const QVariantMap &variables )
620 {
621  if ( !item )
622  return;
623 
624  QStringList variableNames;
625  QStringList variableValues;
626 
627  QVariantMap::const_iterator it = variables.constBegin();
628  for ( ; it != variables.constEnd(); ++it )
629  {
630  variableNames << it.key();
631  variableValues << it.value().toString();
632  }
633 
634  item->setCustomProperty( QStringLiteral( "variableNames" ), variableNames );
635  item->setCustomProperty( QStringLiteral( "variableValues" ), variableValues );
636 }
637 
639 {
640  QgsExpressionContextScope *scope = new QgsExpressionContextScope( QObject::tr( "Multiframe Item" ) );
641  if ( !frame )
642  return scope;
643 
644  //add variables defined in layout item properties
645  const QStringList variableNames = frame->customProperty( QStringLiteral( "variableNames" ) ).toStringList();
646  const QStringList variableValues = frame->customProperty( QStringLiteral( "variableValues" ) ).toStringList();
647 
648  int varIndex = 0;
649  for ( const QString &variableName : variableNames )
650  {
651  if ( varIndex >= variableValues.length() )
652  {
653  break;
654  }
655 
656  QVariant varValue = variableValues.at( varIndex );
657  varIndex++;
658  scope->setVariable( variableName, varValue );
659  }
660 
661  return scope;
662 }
663 
664 void QgsExpressionContextUtils::setLayoutMultiFrameVariable( QgsLayoutMultiFrame *frame, const QString &name, const QVariant &value )
665 {
666  if ( !frame )
667  return;
668 
669  //write variable to layout multiframe
670  QStringList variableNames = frame->customProperty( QStringLiteral( "variableNames" ) ).toStringList();
671  QStringList variableValues = frame->customProperty( QStringLiteral( "variableValues" ) ).toStringList();
672 
673  variableNames << name;
674  variableValues << value.toString();
675 
676  frame->setCustomProperty( QStringLiteral( "variableNames" ), variableNames );
677  frame->setCustomProperty( QStringLiteral( "variableValues" ), variableValues );
678 }
679 
681 {
682  if ( !frame )
683  return;
684 
685  QStringList variableNames;
686  QStringList variableValues;
687 
688  QVariantMap::const_iterator it = variables.constBegin();
689  for ( ; it != variables.constEnd(); ++it )
690  {
691  variableNames << it.key();
692  variableValues << it.value().toString();
693  }
694 
695  frame->setCustomProperty( QStringLiteral( "variableNames" ), variableNames );
696  frame->setCustomProperty( QStringLiteral( "variableValues" ), variableValues );
697 }
698 
700 {
702  scope->setFeature( feature );
703  scope->setFields( fields );
704  return QgsExpressionContext() << scope;
705 }
706 
708 {
709  // set aside for future use
710  Q_UNUSED( context )
711 
712  std::unique_ptr< QgsExpressionContextScope > scope( new QgsExpressionContextScope( QObject::tr( "Algorithm" ) ) );
713  scope->addFunction( QStringLiteral( "parameter" ), new GetProcessingParameterValue( parameters ) );
714 
715  if ( !algorithm )
716  return scope.release();
717 
718  //add standard algorithm variables
719  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "algorithm_id" ), algorithm->id(), true ) );
720 
721  return scope.release();
722 }
723 
724 QgsExpressionContextScope *QgsExpressionContextUtils::processingModelAlgorithmScope( const QgsProcessingModelAlgorithm *model, const QVariantMap &, QgsProcessingContext &context )
725 {
726  std::unique_ptr< QgsExpressionContextScope > modelScope( new QgsExpressionContextScope( QObject::tr( "Model" ) ) );
727  QString modelPath;
728  if ( !model->sourceFilePath().isEmpty() )
729  {
730  modelPath = model->sourceFilePath();
731  }
732  else if ( context.project() )
733  {
734  // fallback to project path -- the model may be embedded in a project, OR an unsaved model. In either case the
735  // project path is a logical value to fall back to
736  modelPath = context.project()->projectStorage() ? context.project()->fileName() : context.project()->absoluteFilePath();
737  }
738 
739  const QString modelFolder = !modelPath.isEmpty() ? QFileInfo( modelPath ).path() : QString();
740  modelScope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "model_path" ), QDir::toNativeSeparators( modelPath ), true ) );
741  modelScope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "model_folder" ), QDir::toNativeSeparators( modelFolder ), true, true ) );
742  modelScope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "model_name" ), model->displayName(), true ) );
743  modelScope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "model_group" ), model->group(), true ) );
744 
745  // custom variables
746  const QVariantMap customVariables = model->variables();
747  for ( auto it = customVariables.constBegin(); it != customVariables.constEnd(); ++it )
748  {
749  modelScope->addVariable( QgsExpressionContextScope::StaticVariable( it.key(), it.value(), true ) );
750  }
751 
752  return modelScope.release();
753 }
754 
756 {
757  std::unique_ptr< QgsExpressionContextScope > scope( new QgsExpressionContextScope() );
758  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "notification_message" ), message, true ) );
759  return scope.release();
760 }
761 
763 {
764  QgsExpression::registerFunction( new GetNamedProjectColor( nullptr ) );
765  QgsExpression::registerFunction( new GetLayoutItemVariables( nullptr ) );
766  QgsExpression::registerFunction( new GetLayerVisibility( QList<QgsMapLayer *>(), 0.0 ) );
767  QgsExpression::registerFunction( new GetProcessingParameterValue( QVariantMap() ) );
768  QgsExpression::registerFunction( new GetCurrentFormFieldValue( ) );
769 }
770 
772 {
773  Q_UNUSED( node )
774  return mUsesGeometry;
775 }
776 
778 {
779  Q_UNUSED( node )
780  return mReferencedColumns;
781 }
782 
784 {
785  return allParamsStatic( node, parent, context );
786 }
787 
788 //
789 // GetLayerVisibility
790 //
791 
792 QgsExpressionContextUtils::GetLayerVisibility::GetLayerVisibility( const QList<QgsMapLayer *> &layers, double scale )
793  : QgsScopedExpressionFunction( QStringLiteral( "is_layer_visible" ), QgsExpressionFunction::ParameterList() << QgsExpressionFunction::Parameter( QStringLiteral( "id" ) ), QStringLiteral( "General" ) )
794  , mLayers( _qgis_listRawToQPointer( layers ) )
795  , mScale( scale )
796 {
797  for ( const auto layer : mLayers )
798  {
799  if ( layer->hasScaleBasedVisibility() )
800  {
801  mScaleBasedVisibilityDetails[ layer ] = qMakePair( layer->minimumScale(), layer->maximumScale() );
802  }
803  }
804 }
805 
806 QgsExpressionContextUtils::GetLayerVisibility::GetLayerVisibility()
807  : QgsScopedExpressionFunction( QStringLiteral( "is_layer_visible" ), QgsExpressionFunction::ParameterList() << QgsExpressionFunction::Parameter( QStringLiteral( "id" ) ), QStringLiteral( "General" ) )
808 {}
809 
810 QVariant QgsExpressionContextUtils::GetLayerVisibility::func( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent, const QgsExpressionNodeFunction * )
811 {
812  if ( mLayers.isEmpty() )
813  {
814  return false;
815  }
816 
817  bool isVisible = false;
818  QgsMapLayer *layer = QgsExpressionUtils::getMapLayer( values.at( 0 ), parent );
819  if ( layer && mLayers.contains( layer ) )
820  {
821  isVisible = true;
822  if ( mScaleBasedVisibilityDetails.contains( layer ) && !qgsDoubleNear( mScale, 0.0 ) )
823  {
824  if ( ( !qgsDoubleNear( mScaleBasedVisibilityDetails[ layer ].first, 0.0 ) && mScale > mScaleBasedVisibilityDetails[ layer ].first ) ||
825  ( !qgsDoubleNear( mScaleBasedVisibilityDetails[ layer ].second, 0.0 ) && mScale < mScaleBasedVisibilityDetails[ layer ].second ) )
826  {
827  isVisible = false;
828  }
829  }
830  }
831 
832  return isVisible;
833 }
834 
835 QgsScopedExpressionFunction *QgsExpressionContextUtils::GetLayerVisibility::clone() const
836 {
837  GetLayerVisibility *func = new GetLayerVisibility();
838  func->mLayers = mLayers;
839  func->mScale = mScale;
840  func->mScaleBasedVisibilityDetails = mScaleBasedVisibilityDetails;
841  return func;
842 }
bool isValid() const
Returns the validity of this feature.
Definition: qgsfeature.cpp:183
Class for parsing and evaluation of expressions (formerly called "search strings").
static QString locale()
Returns the QGIS locale.
QgsFeatureId id
Definition: qgsfeature.h:64
static QgsExpressionContextScope * updateSymbolScope(const QgsSymbol *symbol, QgsExpressionContextScope *symbolScope=nullptr)
Updates a symbol scope related to a QgsSymbol to an expression context.
static QgsExpressionContextScope * processingAlgorithmScope(const QgsProcessingAlgorithm *algorithm, const QVariantMap &parameters, QgsProcessingContext &context)
Creates a new scope which contains variables and functions relating to a processing algorithm...
static void setLayoutItemVariable(QgsLayoutItem *item, const QString &name, const QVariant &value)
Sets a layout item context variable, with the given name and value.
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
Single variable definition for use within a QgsExpressionContextScope.
static void setGlobalVariable(const QString &name, const QVariant &value)
Sets a global context variable.
Base class for all map layer types.
Definition: qgsmaplayer.h:79
static void setLayoutItemVariables(QgsLayoutItem *item, const QVariantMap &variables)
Sets all layout item context variables for an item.
static const QString QGIS_VERSION
Version string.
Definition: qgis.h:52
static void setLayerVariables(QgsMapLayer *layer, const QVariantMap &variables)
Sets all layer context variables.
QString id() const
Returns the unique ID for the algorithm, which is a combination of the algorithm provider&#39;s ID and th...
Base class for graphical items within a QgsLayout.
static Q_INVOKABLE QString toString(QgsUnitTypes::DistanceUnit unit)
Returns a translated string representing a distance unit.
static void setLayoutVariable(QgsLayout *layout, const QString &name, const QVariant &value)
Sets a layout context variable.
static void setCustomVariables(const QVariantMap &customVariables)
Custom expression variables for this application.
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:61
double rotation() const
Returns the rotation of the resulting map image, in degrees clockwise.
QVariant customProperty(const QString &key, const QVariant &defaultValue=QVariant()) const
Read a custom property from the layout.
Definition: qgslayout.cpp:414
void addFunction(const QString &name, QgsScopedExpressionFunction *function)
Adds a function to the scope.
static void removeProjectVariable(QgsProject *project, const QString &name)
Remove project context variable.
static QgsExpressionContext createFeatureBasedContext(const QgsFeature &feature, const QgsFields &fields)
Helper function for creating an expression context which contains just a feature and fields collectio...
int count() const override
Returns the number of features to iterate over.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition: qgis.h:280
QgsLayoutSize sizeWithUnits() const
Returns the item&#39;s current size, including units.
void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for layer.
void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for the object.
QVariant customProperty(const QString &key, const QVariant &defaultValue=QVariant()) const
Read a custom property from the object.
QString toProj4() const
Returns a Proj4 string representation of this CRS.
Container of fields for a vector layer.
Definition: qgsfields.h:42
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:122
static QVariantMap customVariables()
Custom expression variables for this application.
void setFields(const QgsFields &fields)
Convenience function for setting a fields for the 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...
static QgsExpressionContextScope * projectScope(const QgsProject *project)
Creates a new scope which contains variables and functions relating to a QGIS project.
QList< QgsMapLayer * > layers() const
Gets list of layers for map rendering The layers are stored in the reverse order of how they are rend...
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:55
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 feat...
bool usesGeometry(const QgsExpressionNodeFunction *node) const override
Does this function use a geometry object.
static void setLayoutVariables(QgsLayout *layout, const QVariantMap &variables)
Sets all layout context variables.
QPointer< QgsMapLayer > QgsWeakMapLayerPointer
Weak pointer for QgsMapLayer.
Definition: qgsmaplayer.h:1632
static const int QGIS_VERSION_INT
Version number used for comparing versions using the "Check QGIS Version" function.
Definition: qgis.h:54
static QgsExpressionContextScope * atlasScope(const QgsLayoutAtlas *atlas)
Creates a new scope which contains variables and functions relating to a QgsLayoutAtlas.
Abstract base class for processing algorithms.
QList< QgsExpressionFunction::Parameter > ParameterList
List of parameters, used for function definition.
QgsLayoutRenderContext & renderContext()
Returns a reference to the layout&#39;s render context, which stores information relating to the current ...
Definition: qgslayout.cpp:358
QgsRectangle visibleExtent() const
Returns the actual extent derived from requested extent that takes takes output image size into accou...
QVariant variable(const QString &name) const
Fetches a matching variable from the context.
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)
Definition: MathUtils.cpp:786
void addVariable(const QgsExpressionContextScope::StaticVariable &variable)
Adds a variable into the context scope.
A marker symbol type, for rendering Point and MultiPoint geometries.
Definition: qgssymbol.h:860
static QString userFullName()
Returns the user&#39;s operating system login account full display name.
QgsProject * project() const
Returns the project in which the algorithm is being executed.
QgsCoordinateReferenceSystem destinationCrs() const
returns CRS of destination coordinate reference system
Abstract base class for layout items with the ability to distribute the content to several frames (Qg...
QgsUnitTypes::DistanceUnit mapUnits() const
Gets units of map&#39;s geographical coordinates - used for scale calculation.
QgsLayout * layout() override
Returns the layout associated with the iterator.
The QgsMapSettings class contains configuration for rendering of the map.
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.
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
QSizeF toQSizeF() const
Converts the layout size to a QSizeF.
static QgsExpressionContextScope * layoutItemScope(const QgsLayoutItem *item)
Creates a new scope which contains variables and functions relating to a QgsLayoutItem.
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 QgsGeometry fromRect(const QgsRectangle &rect)
Creates a new geometry from a QgsRectangle.
static QgsExpressionContextScope * multiFrameScope(const QgsLayoutMultiFrame *frame)
Creates a new scope which contains variables and functions relating to a QgsLayoutMultiFrame.
QgsVectorLayer * layer() const
Returns the vector layer associated with the layout&#39;s context.
static const QString EXPR_SYMBOL_ANGLE
Inbuilt variable name for symbol angle variable.
QString ellipsoidAcronym() const
Returns the ellipsoid acronym for the ellipsoid used by the CRS.
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context...
QString id() const
Returns the layer&#39;s unique ID, which is used to access this layer from QgsProject.
const QgsLayout * layout() const
Returns the layout the object is attached to.
static void setLayoutMultiFrameVariable(QgsLayoutMultiFrame *frame, const QString &name, const QVariant &value)
Sets a layout multi frame context variable, with the given name and value.
QgsLayoutItemPage * page(int pageNumber)
Returns a specific page (by pageNumber) from the collection.
QgsFields fields() const FINAL
Returns the list of fields of this layer.
QgsLayoutPageCollection * pageCollection()
Returns a pointer to the layout&#39;s page collection, which stores and manages page items in the layout...
Definition: qgslayout.cpp:458
static void setProjectVariables(QgsProject *project, const QVariantMap &variables)
Sets all project context variables.
double scale() const
Returns the calculated map scale.
double dpi() const
Returns the dpi for outputting the layout.
double width() const
Returns the width of the rectangle.
Definition: qgsrectangle.h:202
static QgsExpressionContextScope * notificationScope(const QString &message=QString())
Creates a new scope which contains variables and functions relating to provider notifications.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
static void removeGlobalVariable(const QString &name)
Remove a global context variable.
QVariantMap variablesToMap() const
Returns a map of variable name to value representing all the expression variables contained by the co...
Class used to render QgsLayout as an atlas, by iterating over the features from an associated vector ...
static const QString EXPR_SYMBOL_COLOR
Inbuilt variable name for symbol color variable.
QString description() const
Returns the descriptive name of the CRS, e.g., "WGS 84" or "GDA 94 / Vicgrid94".
static bool registerFunction(QgsExpressionFunction *function, bool transferOwnership=false)
Registers a function to the expression engine.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts, annotations, canvases, etc.
Definition: qgsproject.h:89
QgsExpressionContextScope * createExpressionContextScope() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
static void setCustomVariable(const QString &name, const QVariant &value)
Set a single custom expression variable.
QColor color() const
Returns the symbol&#39;s color.
Definition: qgssymbol.cpp:484
QString currentFilename() const
Returns the current feature filename.
int page() const
Returns the page the item is currently on, with the first page returning 0.
QString id() const
Returns the item&#39;s ID name.
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer&#39;s project and layer.
Single scope for storing variables and functions for use within a QgsExpressionContext.
An expression node for expression functions.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the scope.
void setCustomVariables(const QVariantMap &customVariables)
A map of custom project variables.
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
QgsProjectStorage * projectStorage() const
Returns pointer to project storage implementation that handles read/write of the project file...
Definition: qgsproject.cpp:600
static void setLayerVariable(QgsMapLayer *layer, const QString &name, const QVariant &value)
Sets a layer context variable.
static QString userLoginName()
Returns the user&#39;s operating system login account name.
static QString osName()
Returns a string name of the operating system QGIS is running on.
int pageCount() const
Returns the number of pages in the collection.
int currentFeatureNumber() const
Returns the current feature number, where a value of 0 corresponds to the first feature.
QString projectionAcronym() const
Returns the projection acronym for the projection used by the CRS.
QgsLayoutReportContext & reportContext()
Returns a reference to the layout&#39;s report context, which stores information relating to the current ...
Definition: qgslayout.cpp:368
static void setProjectVariable(QgsProject *project, const QString &name, const QVariant &value)
Sets a project context variable.
static QgsExpressionContextScope * processingModelAlgorithmScope(const QgsProcessingModelAlgorithm *model, const QVariantMap &parameters, QgsProcessingContext &context)
Creates a new scope which contains variables and functions relating to a processing model algorithm...
static void registerContextFunctions()
Registers all known core functions provided by QgsExpressionContextScope objects. ...
static QgsExpressionContextScope * mapSettingsScope(const QgsMapSettings &mapSettings)
Creates a new scope which contains variables and functions relating to a QgsMapSettings object...
static const QString QGIS_RELEASE_NAME
Release name.
Definition: qgis.h:56
static QgsExpressionContextScope * layoutScope(const QgsLayout *layout)
Creates a new scope which contains variables and functions relating to a QgsLayout layout...
static void setLayoutMultiFrameVariables(QgsLayoutMultiFrame *frame, const QVariantMap &variables)
Sets all layout multiframe context variables for an frame.
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:442
virtual QString uuid() const
Returns the item identification string.
QString nameForPage(int page) const
Returns the calculated name for a specified atlas page number.
static QString platform()
Returns the QGIS platform name, e.g., "desktop" or "server".
void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for the layout.
Definition: qgslayout.cpp:406
bool enabled() const
Returns whether the atlas generation is enabled.
QgsVectorLayer * coverageLayer() const
Returns the coverage layer used for the atlas features.
QgsFeature feature() const
Returns the current feature for evaluating the layout.
QString name
Definition: qgsmaplayer.h:83
Represents a single parameter passed to a function.
QgsGeometry geometry
Definition: qgsfeature.h:67
QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
QgsPointXY center() const
Returns the center point of the rectangle.
Definition: qgsrectangle.h:230
QVariantMap customVariables() const
A map of custom project variables.
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
Interface for master layout type objects, such as print layouts and reports.
QString absoluteFilePath() const
Returns full absolute path to the project file if the project is stored in a file system - derived fr...
Definition: qgsproject.cpp:630
Represents a vector layer which manages a vector based data sets.
Contains information about the context in which a processing algorithm is executed.
QString fileName
Definition: qgsproject.h:93
static void setGlobalVariables(const QVariantMap &variables)
Sets all global context variables.
Expression function for use within a QgsExpressionContextScope.
double angle() const
Returns the marker angle for the whole symbol.
Definition: qgssymbol.cpp:1284
static QgsGeometry fromPointXY(const QgsPointXY &point)
Creates a new geometry from a QgsPointXY object.
QString authid() const
Returns the authority identifier for the CRS.
QgsCoordinateReferenceSystem crs
Definition: qgsmaplayer.h:86
QSet< QString > referencedColumns(const QgsExpressionNodeFunction *node) const override
Returns a set of field names which are required for this function.
QString toWkt(WktVariant variant=WKT1_GDAL, bool multiline=false, int indentationWidth=4) const
Returns a WKT representation of this CRS.
double height() const
Returns the height of the rectangle.
Definition: qgsrectangle.h:209
Item representing the paper in a layout.