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 );
267 if (( *it )->hasVariable( name ) )
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 );
317 return names.
toSet().toList();
363 result = result.
toSet().toList();
375 if (( *it )->hasFunction( name ) )
376 return ( *it )->function( name );
383 return mStack.count();
388 mStack.append( scope );
393 if ( !mStack.isEmpty() )
394 return mStack.takeLast();
401 mStack.append( scope );
407 if ( mStack.isEmpty() )
410 mStack.last()->setFeature( feature );
420 if ( mStack.isEmpty() )
423 mStack.last()->setFields( fields );
433 if ( mStack.isEmpty() )
457 int variableIndex = 0;
459 it != customVariableVariants.
constEnd(); ++it )
461 if ( variableIndex >= customVariableNames.
length() )
467 QString name = customVariableNames.
at( variableIndex ).toString();
494 customVariableVariants << value;
495 customVariableNames <<
name;
497 settings.
setValue(
QString(
"/variables/names" ), customVariableNames );
498 settings.
setValue(
QString(
"/variables/values" ), customVariableVariants );
509 for ( ; it != variables.
constEnd(); ++it )
511 customVariableNames << it.
key();
512 customVariableVariants << it.
value();
515 settings.
setValue(
QString(
"/variables/names" ), customVariableNames );
516 settings.
setValue(
QString(
"/variables/values" ), customVariableVariants );
524 GetNamedProjectColor()
534 it != colorStrings.
end(); ++it )
538 if ( colorLabels.
length() > colorIndex )
540 label = colorLabels.
at( colorIndex );
543 mColors.insert( label.
toLower(), color );
551 if ( mColors.contains( colorName ) )
553 return QString(
"%1,%2,%3" ).
arg( mColors.value( colorName ).red() ).arg( mColors.value( colorName ).green() ).arg( mColors.value( colorName ).blue() );
561 return new GetNamedProjectColor();
583 Q_FOREACH (
const QString& variableName, variableNames )
585 if ( varIndex >= variableValues.
length() )
590 QString varValueString = variableValues.
at( varIndex );
592 scope->
setVariable( variableName, varValueString );
601 scope->
addFunction(
"project_color",
new GetNamedProjectColor() );
613 variableNames <<
name;
616 project->
writeEntry(
"Variables",
"/variableNames", variableNames );
617 project->
writeEntry(
"Variables",
"/variableValues", variableValues );
629 for ( ; it != variables.
constEnd(); ++it )
631 variableNames << it.
key();
632 variableValues << it.
value();
635 project->
writeEntry(
"Variables",
"/variableNames", variableNames );
636 project->
writeEntry(
"Variables",
"/variableValues", variableValues );
651 Q_FOREACH (
const QString& variableName, variableNames )
653 if ( varIndex >= variableValues.
length() )
658 QVariant varValue = variableValues.
at( varIndex );
688 variableNames <<
name;
704 for ( ; it != variables.
constEnd(); ++it )
706 variableNames << it.
key();
707 variableValues << it.
value();
742 angle = markerSymbol->
angle();
760 Q_FOREACH (
const QString& variableName, variableNames )
762 if ( varIndex >= variableValues.
length() )
767 QVariant varValue = variableValues.
at( varIndex );
790 variableNames <<
name;
806 for ( ; it != variables.
constEnd(); ++it )
808 variableNames << it.
key();
809 variableValues << it.
value();
864 Q_FOREACH (
const QString& variableName, variableNames )
866 if ( varIndex >= variableValues.
length() )
871 QVariant varValue = variableValues.
at( varIndex );
893 variableNames <<
name;
909 for ( ; it != variables.
constEnd(); ++it )
911 variableNames << it.
key();
912 variableValues << it.
value();
QgsFeatureId id() const
Get the feature ID for this feature.
static const char * QGIS_VERSION
QgsExpression::Function * function(const QString &name) const
Retrieves a function from 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").
bool isHighlightedVariable(const QString &name) const
Returns true if the specified variable name is intended to be highlighted to the user.
Single variable definition for use within a QgsExpressionContextScope.
static void setGlobalVariable(const QString &name, const QVariant &value)
Sets a global context variable.
bool hasFunction(const QString &name) const
Checks whether a specified function is contained in the context.
Base class for all map layer types.
double paperWidth() const
Width of paper item.
iterator insert(const Key &key, const T &value)
QgsExpressionContextScope * scope(int index)
Returns the scope at the specified index within the context.
static void setGlobalVariables(const QgsStringMap &variables)
Sets all global context variables.
double scale() const
Return the calculated scale of the map.
const Key key(const T &value) const
int localeAwareCompare(const QString &other) const
QString name() const
Get the display name of the layer.
bool hasVariable(const QString &name) const
Check whether a variable is specified by any scope within the context.
QgsExpressionContext & operator=(const QgsExpressionContext &other)
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.
QgsFields fields() const
Returns the list of fields of this layer.
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...
int scopeCount() const
Returns the number of scopes contained in the context.
const_iterator constBegin() const
const T & at(int i) const
void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for layer.
A item that forms part of a map composition.
QgsRectangle visibleExtent() const
Return the actual extent derived from requested extent that takes takes output image size into accoun...
bool enabled() const
Returns whether the atlas generation is enabled.
Container of fields for a vector layer.
QStringList readListEntry(const QString &scope, const QString &key, const QStringList &def=QStringList(), bool *ok=nullptr) const
Key value accessors.
A geometry is the spatial representation of a feature.
bool hasVariable(const QString &name) const
Tests whether a variable with the specified name exists in the scope.
QgsFeature feature() const
Returns the current atlas feature.
void setFields(const QgsFields &fields)
Convenience function for setting a fields for the scope.
double rotation() const
Return the rotation of the resulting map image Units are clockwise degrees.
QVariant customProperty(const QString &key, const QVariant &defaultValue=QVariant()) const
Read a custom property from the composition.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
QgsExpressionContextScope & operator=(const QgsExpressionContextScope &other)
QString currentPageName() const
Returns the name of the page for the current atlas feature.
int indexOfScope(QgsExpressionContextScope *scope) const
Returns the index of the specified scope if it exists within the context.
QVariant customProperty(const QString &key, const QVariant &defaultValue=QVariant()) const
Read a custom property from the object.
QString tr(const char *sourceText, const char *disambiguation, int n)
int numPages() const
Returns the number of pages in the composition.
void setVariable(const QString &name, const QVariant &value)
Convenience method for setting a variable in the context scope by name and value. ...
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.
QVariant variable(const QString &name) const
Fetches a matching variable from the context.
static void setCompositionVariables(QgsComposition *composition, const QgsStringMap &variables)
Sets all composition context variables.
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.
QString name() const
Returns the friendly display name of the context scope.
void setValue(const QString &key, const QVariant &value)
~QgsExpressionContextScope()
QString uuid() const
Get item identification name.
bool hasFunction(const QString &name) const
Tests whether a function with the specified name exists in the scope.
bool writeEntry(const QString &scope, const QString &key, bool value)
QStringList variableNames() const
Returns a list of variables names set by all scopes in the context.
bool removeVariable(const QString &name)
Removes a variable from the context scope, if found.
QgsExpressionContextScope * lastScope()
Returns the last scope added to the context.
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...
QStringList filteredVariableNames() const
Returns a fitlered and sorted list of variable names contained within the scope.
const_iterator constEnd() const
int printResolution() const
Q_DECL_DEPRECATED void title(const QString &title)
Every project has an associated title string.
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
QgsFields fields() const
Convenience function for retrieving the fields for the context, if set.
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.
bool isReadOnly(const QString &name) const
Returns whether a variable is read only, and should not be modifiable by users.
int numFeatures() const
Returns the number of features in the coverage layer.
QgsFeature feature() const
Convenience function for retrieving the feature for the context, if set.
QString id() const
Get this layer's unique ID, this ID is used to access this layer from map layer registry.
Reads and writes project states.
static void setCompositionVariable(QgsComposition *composition, const QString &name, const QVariant &value)
Sets a composition context variable.
QStringList functionNames() const
Retrieves a list of function names contained in the context.
static const QString EXPR_FIELDS
Inbuilt variable name for fields storage.
QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
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.
QVariant variable(const QString &name) const
Retrieves a variable's value from the scope.
static QgsExpressionContextScope * composerItemScope(const QgsComposerItem *composerItem)
Creates a new scope which contains variables and functions relating to a QgsComposerItem.
Graphics scene for map printing.
void setFields(const QgsFields &fields)
Convenience function for setting a fields for the context.
QString currentFilename() const
Returns the current filename.
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.
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)
const T value(const Key &key) const
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.
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
static QgsExpressionContextScope * mapSettingsScope(const QgsMapSettings &mapSettings)
Creates a new scope which contains variables and functions relating to a QgsMapSettings object...
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.
QStringList filteredVariableNames() const
Returns a filtered list of variables names set by all scopes in the context.
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
const QgsGeometry * constGeometry() const
Gets a const pointer to the geometry object associated with this feature.
double paperHeight() const
Height of paper item.
QgsRectangle extent() const
Return geographical coordinates of the rectangle that should be rendered.
static QString platform()
Returns the QGIS platform name, eg "desktop" or "server".
int page() const
Gets the page the item is currently on.
QStringList functionNames() const
Retrieves a list of names of functions contained in the scope.
Class used to render an Atlas, iterating over geometry 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)
QgsVectorLayer * coverageLayer() const
Returns the coverage layer used for the atlas features.
static void setProjectVariable(const QString &name, const QVariant &value)
Sets a project context variable.
int currentFeatureNumber() const
Returns the current feature number, where a value of 0 corresponds to the first feature.
static QgsExpressionContextScope * projectScope()
Creates a new scope which contains variables and functions relating to the current QGIS project...
QgsExpression::Function * function(const QString &name) const
Fetches a matching function from the context.
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
QFileInfo fileInfo() const
Returns QFileInfo object for the project's associated file.
double width() const
Width of the rectangle.
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.
bool isReadOnly(const QString &name) const
Tests whether the specified variable is read only and should not be editable by users.
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.
QgsPoint center() const
Center point of the rectangle.
static const int QGIS_VERSION_INT
Expression function for use within a QgsExpressionContextScope.
QString name
Variable name.
QStringList variableNames() const
Returns a list of variable names contained within the scope.
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.
QString id() const
Get item's id (which is not necessarly unique)