47 : mName( other.mName )
48 , mVariables( other.mVariables )
50 Q_FOREACH (
const QString& key, other.mFunctions.
keys() )
52 mFunctions.
insert( key, other.mFunctions.
value( key )->clone() );
59 mVariables = other.mVariables;
61 qDeleteAll( mFunctions );
63 Q_FOREACH (
const QString& key, other.mFunctions.
keys() )
65 mFunctions.
insert( key, other.mFunctions.
value( key )->clone() );
73 qDeleteAll( mFunctions );
78 if ( mVariables.contains( name ) )
81 existing.
value = value;
92 mVariables.insert( variable.
name, variable );
97 return mVariables.remove( name ) > 0;
102 return mVariables.contains( name );
116 bool QgsExpressionContextScope::variableNameSort(
const QString& a,
const QString& b )
123 class QgsExpressionContextVariableCompare
132 bool aReadOnly = mScope.isReadOnly( a );
133 bool bReadOnly = mScope.isReadOnly( b );
134 if ( aReadOnly != bReadOnly )
155 QgsExpressionContextVariableCompare cmp( *
this );
156 qSort( filtered.
begin(), filtered.
end(), cmp );
163 return hasVariable( name ) ? mVariables.value( name ).readOnly :
false;
173 return mFunctions.
contains( name ) ? mFunctions.
value( name ) : 0;
178 return mFunctions.
keys();
183 mFunctions.
insert( name,
function );
207 mHighlightedVariables = other.mHighlightedVariables;
212 qDeleteAll( mStack );
218 mHighlightedVariables = other.mHighlightedVariables;
224 qDeleteAll( mStack );
246 return mHighlightedVariables.
contains( name );
261 if (( *it )->hasVariable( name ) )
271 while ( it != mStack.
begin() )
274 if (( *it )->hasVariable( name ) )
282 if ( index < 0 || index >= mStack.
count() )
285 return mStack[
index];
290 if ( mStack.
count() < 1 )
293 return mStack.
last();
301 return mStack.
indexOf( scope );
311 return names.
toSet().toList();
357 result = result.
toSet().toList();
369 if (( *it )->hasFunction( name ) )
370 return ( *it )->function( name );
377 return mStack.
count();
396 mStack.
last()->setFeature( feature );
409 mStack.
last()->setFields( fields );
442 int variableIndex = 0;
444 it != customVariableVariants.
constEnd(); ++it )
446 if ( variableIndex >= customVariableNames.
length() )
452 QString name = customVariableNames.
at( variableIndex ).toString();
475 customVariableVariants << value;
476 customVariableNames << name;
478 settings.
setValue(
QString(
"/variables/names" ), customVariableNames );
479 settings.
setValue(
QString(
"/variables/values" ), customVariableVariants );
489 Q_FOREACH (
const QString& variable, variables.
keys() )
491 customVariableNames << variable;
492 customVariableVariants << variables.
value( variable );
495 settings.
setValue(
QString(
"/variables/names" ), customVariableNames );
496 settings.
setValue(
QString(
"/variables/values" ), customVariableVariants );
512 it != colorStrings.
end(); ++it )
516 if ( colorLabels.
length() > colorIndex )
518 label = colorLabels.
at( colorIndex );
529 if ( mColors.
contains( colorName ) )
531 return QString(
"%1,%2,%3" ).
arg( mColors.
value( colorName ).red() ).arg( mColors.
value( colorName ).green() ).arg( mColors.
value( colorName ).blue() );
559 Q_FOREACH (
const QString& variableName, variableNames )
561 if ( varIndex >= variableValues.
length() )
566 QString varValueString = variableValues.
at( varIndex );
568 scope->
setVariable( variableName, varValueString );
589 variableNames << name;
592 project->
writeEntry(
"Variables",
"/variableNames", variableNames );
593 project->
writeEntry(
"Variables",
"/variableValues", variableValues );
604 Q_FOREACH (
const QString& variable, variables.
keys() )
606 variableNames << variable;
607 variableValues << variables.
value( variable );
610 project->
writeEntry(
"Variables",
"/variableNames", variableNames );
611 project->
writeEntry(
"Variables",
"/variableValues", variableValues );
626 Q_FOREACH (
const QString& variableName, variableNames )
628 if ( varIndex >= variableValues.
length() )
633 QVariant varValue = variableValues.
at( varIndex );
663 variableNames << name;
678 Q_FOREACH (
const QString& variable, variables.
keys() )
680 variableNames << variable;
681 variableValues << variables.
value( variable );
711 Q_FOREACH (
const QString& variableName, variableNames )
713 if ( varIndex >= variableValues.
length() )
718 QVariant varValue = variableValues.
at( varIndex );
741 variableNames << name;
756 Q_FOREACH (
const QString& variable, variables.
keys() )
758 variableNames << variable;
759 variableValues << variables.
value( variable );
814 Q_FOREACH (
const QString& variableName, variableNames )
816 if ( varIndex >= variableValues.
length() )
821 QVariant varValue = variableValues.
at( varIndex );
843 variableNames << name;
858 Q_FOREACH (
const QString& variable, variables.
keys() )
860 variableNames << variable;
861 variableValues << variables.
value( variable );
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
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.
int localeAwareCompare(const QString &other) const
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 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.
bool contains(const QString &str, Qt::CaseSensitivity cs) const
bool enabled() const
Returns whether the atlas generation is enabled.
Container of fields for a vector layer.
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.
virtual QVariant func(const QVariantList &values, const QgsExpressionContext *, QgsExpression *) override
Returns result of evaluating the function.
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.
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.
int indexOf(const T &value, int from) const
const QString & name() const
Get the display name of the layer.
QList< Key > keys() const
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.
int count(const T &value) const
void append(const T &value)
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.
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.
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.
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
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.
QList< Key > keys() const
static void setLayerVariable(QgsMapLayer *layer, const QString &name, const QVariant &value)
Sets a layer context variable.
const T value(const Key &key) const
static const char * QGIS_RELEASE_NAME
QVariant fromValue(const T &value)
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
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
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.
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...
const QString & currentFilename() const
Returns the current filename.
static QColor decodeColor(const QString &str)
bool contains(const Key &key) const
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.
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
const_iterator constEnd() const
QgsScopedExpressionFunction * clone() const override
Returns a clone of the function.
const_iterator constBegin() const
QFileInfo fileInfo() const
Returns QFileInfo object for the project's associated file.
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.
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 const int QGIS_VERSION_INT
Expression function for use within a QgsExpressionContextScope.
QString name
Variable name.
QStringList readListEntry(const QString &scope, const QString &key, const QStringList &def=QStringList(), bool *ok=0) const
Key value accessors.
QStringList variableNames() const
Returns a list of variable names contained within the scope.
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)