52 : mName( other.mName )
53 , mVariables( other.mVariables )
56 for ( ; it != other.mFunctions.
constEnd(); ++it )
65 mVariables = other.mVariables;
67 qDeleteAll( mFunctions );
70 for ( ; it != other.mFunctions.
constEnd(); ++it )
80 qDeleteAll( mFunctions );
85 if ( mVariables.contains( name ) )
88 existing.
value = value;
99 mVariables.insert( variable.
name, variable );
104 return mVariables.remove( name ) > 0;
109 return mVariables.contains( name );
123 bool QgsExpressionContextScope::variableNameSort(
const QString& a,
const QString& b )
129 class QgsExpressionContextVariableCompare
138 bool aReadOnly = mScope.isReadOnly( a );
139 bool bReadOnly = mScope.isReadOnly( b );
140 if ( aReadOnly != bReadOnly )
161 QgsExpressionContextVariableCompare cmp( *
this );
162 qSort( filtered.
begin(), filtered.
end(), cmp );
169 return hasVariable( name ) ? mVariables.value( name ).readOnly :
false;
174 return mFunctions.contains( name );
179 return mFunctions.contains( name ) ? mFunctions.value( name ) :
nullptr;
184 return mFunctions.keys();
189 mFunctions.insert( name,
function );
213 mHighlightedVariables = other.mHighlightedVariables;
218 qDeleteAll( mStack );
224 mHighlightedVariables = other.mHighlightedVariables;
230 qDeleteAll( mStack );
252 return mHighlightedVariables.contains( name );
264 while ( it != mStack.constBegin() )
267 if (( *it )->hasVariable( name ) )
277 while ( it != mStack.constBegin() )
280 if (( *it )->hasVariable( name ) )
288 if ( index < 0 || index >= mStack.count() )
291 return mStack.at( index );
296 if ( mStack.count() < 1 )
299 return mStack.last();
307 return mStack.indexOf( scope );
315 if ( scope->
name() == scopeName )
330 return names.
toSet().toList();
376 result = result.
toSet().toList();
385 while ( it != mStack.constBegin() )
388 if (( *it )->hasFunction( name ) )
389 return ( *it )->function( name );
396 return mStack.count();
401 mStack.append( scope );
406 if ( !mStack.isEmpty() )
407 return mStack.takeLast();
414 mStack.append( scope );
420 if ( mStack.isEmpty() )
423 mStack.last()->setFeature( feature );
433 if ( mStack.isEmpty() )
436 mStack.last()->setFields( fields );
446 if ( mStack.isEmpty() )
470 int variableIndex = 0;
472 it != customVariableVariants.
constEnd(); ++it )
474 if ( variableIndex >= customVariableNames.
length() )
480 QString name = customVariableNames.
at( variableIndex ).toString();
507 customVariableVariants << value;
508 customVariableNames <<
name;
510 settings.
setValue(
QString(
"/variables/names" ), customVariableNames );
511 settings.
setValue(
QString(
"/variables/values" ), customVariableVariants );
522 for ( ; it != variables.
constEnd(); ++it )
524 customVariableNames << it.
key();
525 customVariableVariants << it.
value();
528 settings.
setValue(
QString(
"/variables/names" ), customVariableNames );
529 settings.
setValue(
QString(
"/variables/values" ), customVariableVariants );
537 GetNamedProjectColor()
547 it != colorStrings.
end(); ++it )
551 if ( colorLabels.
length() > colorIndex )
553 label = colorLabels.
at( colorIndex );
556 mColors.insert( label.
toLower(), color );
564 if ( mColors.contains( colorName ) )
566 return QString(
"%1,%2,%3" ).
arg( mColors.value( colorName ).red() ).arg( mColors.value( colorName ).green() ).arg( mColors.value( colorName ).blue() );
574 return new GetNamedProjectColor();
596 Q_FOREACH (
const QString& variableName, variableNames )
598 if ( varIndex >= variableValues.
length() )
603 QString varValueString = variableValues.
at( varIndex );
605 scope->
setVariable( variableName, varValueString );
614 scope->
addFunction(
"project_color",
new GetNamedProjectColor() );
626 variableNames <<
name;
629 project->
writeEntry(
"Variables",
"/variableNames", variableNames );
630 project->
writeEntry(
"Variables",
"/variableValues", variableValues );
642 for ( ; it != variables.
constEnd(); ++it )
644 variableNames << it.
key();
645 variableValues << it.
value();
648 project->
writeEntry(
"Variables",
"/variableNames", variableNames );
649 project->
writeEntry(
"Variables",
"/variableValues", variableValues );
664 Q_FOREACH (
const QString& variableName, variableNames )
666 if ( varIndex >= variableValues.
length() )
671 QVariant varValue = variableValues.
at( varIndex );
701 variableNames <<
name;
717 for ( ; it != variables.
constEnd(); ++it )
719 variableNames << it.
key();
720 variableValues << it.
value();
758 angle = markerSymbol->
angle();
776 Q_FOREACH (
const QString& variableName, variableNames )
778 if ( varIndex >= variableValues.
length() )
783 QVariant varValue = variableValues.
at( varIndex );
806 variableNames <<
name;
822 for ( ; it != variables.
constEnd(); ++it )
824 variableNames << it.
key();
825 variableValues << it.
value();
880 Q_FOREACH (
const QString& variableName, variableNames )
882 if ( varIndex >= variableValues.
length() )
887 QVariant varValue = variableValues.
at( varIndex );
909 variableNames <<
name;
925 for ( ; it != variables.
constEnd(); ++it )
927 variableNames << it.
key();
928 variableValues << it.
value();
static const char * QGIS_VERSION
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").
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.
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.
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.
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.
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 const char * QGIS_RELEASE_NAME
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
QString name() const
Get the display name of the layer.
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 appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
const QChar at(int position) const
static QgsProject * instance()
access to canonical QgsProject 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.
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)
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.
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.