54 : mName( other.mName )
55 , mVariables( other.mVariables )
58 for ( ; it != other.mFunctions.
constEnd(); ++it )
67 mVariables = other.mVariables;
69 qDeleteAll( mFunctions );
72 for ( ; it != other.mFunctions.
constEnd(); ++it )
82 qDeleteAll( mFunctions );
87 if ( mVariables.contains( name ) )
90 existing.
value = value;
101 mVariables.insert( variable.
name, variable );
106 return mVariables.remove( name ) > 0;
111 return mVariables.contains( name );
125 bool QgsExpressionContextScope::variableNameSort(
const QString& a,
const QString& b )
131 class QgsExpressionContextVariableCompare
140 bool aReadOnly = mScope.isReadOnly( a );
141 bool bReadOnly = mScope.isReadOnly( b );
142 if ( aReadOnly != bReadOnly )
163 QgsExpressionContextVariableCompare cmp( *
this );
164 qSort( filtered.
begin(), filtered.
end(), cmp );
171 return hasVariable( name ) ? mVariables.value( name ).readOnly :
false;
176 return mFunctions.contains( name );
181 return mFunctions.contains( name ) ? mFunctions.value( name ) :
nullptr;
186 return mFunctions.keys();
191 mFunctions.insert( name,
function );
215 mHighlightedVariables = other.mHighlightedVariables;
216 mCachedValues = other.mCachedValues;
221 qDeleteAll( mStack );
227 mHighlightedVariables = other.mHighlightedVariables;
228 mCachedValues = other.mCachedValues;
234 qDeleteAll( mStack );
256 return mHighlightedVariables.contains( name );
268 while ( it != mStack.constBegin() )
271 if (( *it )->hasVariable( name ) )
281 while ( it != mStack.constBegin() )
284 if (( *it )->hasVariable( name ) )
292 if ( index < 0 || index >= mStack.count() )
295 return mStack.at( index );
300 if ( mStack.count() < 1 )
303 return mStack.last();
311 return mStack.indexOf( scope );
319 if ( scope->
name() == scopeName )
334 return names.
toSet().toList();
380 result = result.
toSet().toList();
389 while ( it != mStack.constBegin() )
392 if (( *it )->hasFunction( name ) )
393 return ( *it )->function( name );
400 return mStack.count();
405 mStack.append( scope );
410 if ( !mStack.isEmpty() )
411 return mStack.takeLast();
418 mStack.append( scope );
424 if ( mStack.isEmpty() )
427 mStack.last()->setFeature( feature );
437 if ( mStack.isEmpty() )
440 mStack.last()->setFields( fields );
450 if ( mStack.isEmpty() )
459 mCachedValues.insert( key, value );
464 return mCachedValues.contains( key );
474 mCachedValues.clear();
494 int variableIndex = 0;
496 it != customVariableVariants.
constEnd(); ++it )
498 if ( variableIndex >= customVariableNames.
length() )
504 QString name = customVariableNames.
at( variableIndex ).toString();
531 customVariableVariants << value;
532 customVariableNames <<
name;
534 settings.
setValue(
QString(
"/variables/names" ), customVariableNames );
535 settings.
setValue(
QString(
"/variables/values" ), customVariableVariants );
546 for ( ; it != variables.
constEnd(); ++it )
548 customVariableNames << it.
key();
549 customVariableVariants << it.
value();
552 settings.
setValue(
QString(
"/variables/names" ), customVariableNames );
553 settings.
setValue(
QString(
"/variables/values" ), customVariableVariants );
561 GetNamedProjectColor()
571 it != colorStrings.
end(); ++it )
575 if ( colorLabels.
length() > colorIndex )
577 label = colorLabels.
at( colorIndex );
580 mColors.insert( label.
toLower(), color );
588 if ( mColors.contains( colorName ) )
590 return QString(
"%1,%2,%3" ).
arg( mColors.value( colorName ).red() ).arg( mColors.value( colorName ).green() ).arg( mColors.value( colorName ).blue() );
598 return new GetNamedProjectColor();
620 Q_FOREACH (
const QString& variableName, variableNames )
622 if ( varIndex >= variableValues.
length() )
627 QString varValueString = variableValues.
at( varIndex );
629 scope->
setVariable( variableName, varValueString );
638 scope->
addFunction(
"project_color",
new GetNamedProjectColor() );
650 variableNames <<
name;
653 project->
writeEntry(
"Variables",
"/variableNames", variableNames );
654 project->
writeEntry(
"Variables",
"/variableValues", variableValues );
666 for ( ; it != variables.
constEnd(); ++it )
668 variableNames << it.
key();
669 variableValues << it.
value();
672 project->
writeEntry(
"Variables",
"/variableNames", variableNames );
673 project->
writeEntry(
"Variables",
"/variableValues", variableValues );
688 Q_FOREACH (
const QString& variableName, variableNames )
690 if ( varIndex >= variableValues.
length() )
695 QVariant varValue = variableValues.
at( varIndex );
725 variableNames <<
name;
741 for ( ; it != variables.
constEnd(); ++it )
743 variableNames << it.
key();
744 variableValues << it.
value();
782 angle = markerSymbol->
angle();
800 Q_FOREACH (
const QString& variableName, variableNames )
802 if ( varIndex >= variableValues.
length() )
807 QVariant varValue = variableValues.
at( varIndex );
830 variableNames <<
name;
846 for ( ; it != variables.
constEnd(); ++it )
848 variableNames << it.
key();
849 variableValues << it.
value();
904 Q_FOREACH (
const QString& variableName, variableNames )
906 if ( varIndex >= variableValues.
length() )
911 QVariant varValue = variableValues.
at( varIndex );
933 variableNames <<
name;
949 for ( ; it != variables.
constEnd(); ++it )
951 variableNames << it.
key();
952 variableValues << it.
value();
bool hasVariable(const QString &name) const
Tests whether a variable with the specified name exists in the scope.
static const QString EXPR_ORIGINAL_VALUE
Inbuilt variable name for value original value variable.
Class for parsing and evaluation of expressions (formerly called "search strings").
QVariant cachedValue(const QString &key) const
Returns the matching cached value, if set.
Single variable definition for use within a QgsExpressionContextScope.
QVariant customProperty(const QString &key, const QVariant &defaultValue=QVariant()) const
Read a custom property from the object.
static void setGlobalVariable(const QString &name, const QVariant &value)
Sets a global context variable.
Base class for all map layer types.
QString toNativeSeparators(const QString &pathName)
void setCachedValue(const QString &key, const QVariant &value) const
Sets a value to cache within the expression context.
QgsPoint center() const
Center point of the rectangle.
QgsExpression::Function * function(const QString &name) const
Retrieves a function from the scope.
double angle() const
Returns the marker angle for the whole symbol.
iterator insert(const Key &key, const T &value)
QgsExpressionContextScope * scope(int index)
Returns the scope at the specified index within the context.
bool isReadOnly(const QString &name) const
Returns whether a variable is read only, and should not be modifiable by users.
static void setGlobalVariables(const QgsStringMap &variables)
Sets all global context variables.
static const QString EXPR_GEOMETRY_POINT_COUNT
Inbuilt variable name for point count variable.
QStringList filteredVariableNames() const
Returns a filtered list of variables names set by all scopes in the context.
int localeAwareCompare(const QString &other) const
QgsExpressionContext & operator=(const QgsExpressionContext &other)
double rotation() const
Return the rotation of the resulting map image Units are clockwise degrees.
bool hasFunction(const QString &name) const
Checks whether a specified function is contained in the context.
static QgsExpressionContextScope * atlasScope(const QgsAtlasComposition *atlas)
Creates a new scope which contains variables and functions relating to a QgsAtlasComposition.
void addFunction(const QString &name, QgsScopedExpressionFunction *function)
Adds a function to the scope.
A abstract base class for defining QgsExpression functions.
QgsExpressionContextScope(const QString &name=QString())
Constructor for QgsExpressionContextScope.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
static void setLayerVariables(QgsMapLayer *layer, const QgsStringMap &variables)
Sets all layer context variables.
QgsExpressionContextScope * activeScopeForVariable(const QString &name)
Returns the currently active scope from the context for a specified variable name.
QList< QVariant > toList() const
static QgsExpressionContext createFeatureBasedContext(const QgsFeature &feature, const QgsFields &fields)
Helper function for creating an expression context which contains just a feature and fields collectio...
QStringList variableNames() const
Returns a list of variable names contained within the scope.
bool hasCachedValue(const QString &key) const
Returns true if the expression context contains a cached value with a matching key.
int printResolution() const
const_iterator constBegin() const
const T & at(int i) const
void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for layer.
QString currentPageName() const
Returns the name of the page for the current atlas feature.
A item that forms part of a map composition.
QVariant customProperty(const QString &key, const QVariant &defaultValue=QVariant()) const
Read a custom property from the composition.
bool isReadOnly(const QString &name) const
Tests whether the specified variable is read only and should not be editable by users.
QString currentFilename() const
Returns the current filename.
int numPages() const
Returns the number of pages in the composition.
Container of fields for a vector layer.
bool hasVariable(const QString &name) const
Check whether a variable is specified by any scope within the context.
A geometry is the spatial representation of a feature.
int numFeatures() const
Returns the number of features in the coverage layer.
void setFields(const QgsFields &fields)
Convenience function for setting a fields for the scope.
const QgsGeometry * constGeometry() const
Gets a const pointer to the geometry object associated with this feature.
QgsFields fields() const
Convenience function for retrieving the fields for the context, if set.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
QgsExpressionContextScope & operator=(const QgsExpressionContextScope &other)
QString tr(const char *sourceText, const char *disambiguation, int n)
QgsRectangle visibleExtent() const
Return the actual extent derived from requested extent that takes takes output image size into accoun...
void setVariable(const QString &name, const QVariant &value)
Convenience method for setting a variable in the context scope by name and value. ...
QVariant variable(const QString &name) const
Fetches a matching variable from the context.
void addVariable(const QgsExpressionContextScope::StaticVariable &variable)
Adds a variable into the context scope.
QgsExpressionContext & operator<<(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
static QString userFullName()
Returns the user's operating system login account full display name.
static void setCompositionVariables(QgsComposition *composition, const QgsStringMap &variables)
Sets all composition context variables.
QgsFields fields() const
Returns the list of fields of this layer.
void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for the composition.
The QgsMapSettings class contains configuration for rendering of the map.
void setValue(const QString &key, const QVariant &value)
~QgsExpressionContextScope()
int page() const
Gets the page the item is currently on.
bool writeEntry(const QString &scope, const QString &key, bool value)
bool removeVariable(const QString &name)
Removes a variable from the context scope, if found.
QgsExpressionContextScope * lastScope()
Returns the last scope added to the context.
bool hasFunction(const QString &name) const
Tests whether a function with the specified name exists in the scope.
static const QString EXPR_SYMBOL_ANGLE
Inbuilt variable name for symbol angle variable.
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context...
QString id() const
Get this layer's unique ID, this ID is used to access this layer from map layer registry.
const_iterator constEnd() const
int scopeCount() const
Returns the number of scopes contained in the context.
bool isHighlightedVariable(const QString &name) const
Returns true if the specified variable name is intended to be highlighted to the user.
Q_DECL_DEPRECATED void title(const QString &title)
Every project has an associated title string.
double scale() const
Return the calculated scale of the map.
double width() const
Width of the rectangle.
bool contains(const QString &key) const
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
static bool registerFunction(Function *function, bool transferOwnership=false)
Registers a function to the expression engine.
const_iterator constEnd() const
QVariant variable(const QString &name) const
Retrieves a variable's value from the scope.
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
static void setComposerItemVariable(QgsComposerItem *composerItem, const QString &name, const QVariant &value)
Sets a composer item context variable.
static const QString EXPR_SYMBOL_COLOR
Inbuilt variable name for symbol color variable.
QStringList readListEntry(const QString &scope, const QString &key, const QStringList &def=QStringList(), bool *ok=nullptr) const
Key value accessors.
Reads and writes project states.
QString uuid() const
Get item identification name.
static void setCompositionVariable(QgsComposition *composition, const QString &name, const QVariant &value)
Sets a composition context variable.
static const QString EXPR_FIELDS
Inbuilt variable name for fields storage.
QStringList variableNames() const
Returns a list of variables names set by all scopes in the context.
Single scope for storing variables and functions for use within a QgsExpressionContext.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the scope.
static QgsExpressionContextScope * composerItemScope(const QgsComposerItem *composerItem)
Creates a new scope which contains variables and functions relating to a QgsComposerItem.
QStringList functionNames() const
Retrieves a list of names of functions contained in the scope.
static QString QGIS_VERSION
Graphics scene for map printing.
void setFields(const QgsFields &fields)
Convenience function for setting a fields for the context.
static void setLayerVariable(QgsMapLayer *layer, const QString &name, const QVariant &value)
Sets a layer context variable.
static QgsGeometry * fromPoint(const QgsPoint &point)
Creates a new geometry from a QgsPoint object.
static QString userLoginName()
Returns the user's operating system login account name.
int currentFeatureNumber() const
Returns the current feature number, where a value of 0 corresponds to the first feature.
double ANALYSIS_EXPORT angle(Point3D *p1, Point3D *p2, Point3D *p3, Point3D *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
QgsFeatureId id() const
Get the feature ID for this feature.
static QString osName()
Returns a string name of the operating system QGIS is running on.
QVariant fromValue(const T &value)
const Key key(const T &value) const
static void setComposerItemVariables(QgsComposerItem *composerItem, const QgsStringMap &variables)
Sets all composition context variables.
QgsExpression::Function * function(const QString &name) const
Fetches a matching function from the context.
static void registerContextFunctions()
Registers all known core functions provided by QgsExpressionContextScope objects. ...
QVariant value(const QString &key, const QVariant &defaultValue) const
const_iterator constBegin() const
QFileInfo fileInfo() const
Returns QFileInfo object for the project's associated file.
static QgsExpressionContextScope * mapSettingsScope(const QgsMapSettings &mapSettings)
Creates a new scope which contains variables and functions relating to a QgsMapSettings object...
QStringList functionNames() const
Retrieves a list of function names contained in the context.
QStringList toStringList() const
static const QString EXPR_FEATURE
Inbuilt variable name for feature storage.
void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for the object.
void clearCachedValues() const
Clears all cached values from the context.
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
const QChar at(int position) const
static QgsProject * instance()
Returns the QgsProject singleton instance.
static QString platform()
Returns the QGIS platform name, eg "desktop" or "server".
QgsFeature feature() const
Convenience function for retrieving the feature for the context, if set.
static const QString EXPR_GEOMETRY_POINT_NUM
Inbuilt variable name for point number variable.
Class used to render an Atlas, iterating over geometry features.
double paperHeight() const
Height of paper item.
QgsVectorLayer * coverageLayer() const
Returns the coverage layer used for the atlas features.
void setHighlightedVariables(const QStringList &variableNames)
Sets the list of variable names within the context intended to be highlighted to the user...
static QColor decodeColor(const QString &str)
QString name
Read property of QString layerName.
double paperWidth() const
Width of paper item.
QgsFeature feature() const
Returns the current atlas feature.
QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
static void setProjectVariable(const QString &name, const QVariant &value)
Sets a project context variable.
static QgsExpressionContextScope * projectScope()
Creates a new scope which contains variables and functions relating to the current QGIS project...
QString name() const
Returns the friendly display name of the context scope.
QgsExpressionContextScope * popScope()
Removes the last scope from the expression context and return it.
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
const_iterator constEnd() const
const_iterator constBegin() const
static const QString EXPR_GEOMETRY_PART_NUM
Inbuilt variable name for geometry part number variable.
Represents a vector layer which manages a vector based data sets.
int indexOfScope(QgsExpressionContextScope *scope) const
Returns the index of the specified scope if it exists within the context.
static const QString EXPR_GEOMETRY_PART_COUNT
Inbuilt variable name for geometry part count variable.
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for the context.
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
static QgsExpressionContextScope * updateSymbolScope(const QgsSymbolV2 *symbol, QgsExpressionContextScope *symbolScope=nullptr)
Updates a symbol scope related to a QgsSymbolV2 to an expression context.
static QString QGIS_RELEASE_NAME
QStringList filteredVariableNames() const
Returns a fitlered and sorted list of variable names contained within the scope.
static const int QGIS_VERSION_INT
QString id() const
Get item's id (which is not necessarly unique)
Expression function for use within a QgsExpressionContextScope.
bool enabled() const
Returns whether the atlas generation is enabled.
QString name
Variable name.
double height() const
Height of the rectangle.
const T value(const Key &key) const
static void setProjectVariables(const QgsStringMap &variables)
Sets all project context variables.
QVariant value
Variable value.
static QgsExpressionContextScope * compositionScope(const QgsComposition *composition)
Creates a new scope which contains variables and functions relating to a QgsComposition.