QGIS API Documentation  2.11.0-Master
Public Member Functions | Static Public Member Functions | List of all members
QgsDataDefined Class Reference

A container class for data source field mapping or expression. More...

#include <qgsdatadefined.h>

Public Member Functions

 QgsDataDefined (bool active=false, bool useexpr=false, const QString &expr=QString(), const QString &field=QString())
 Construct a new data defined object. More...
 
 QgsDataDefined (const QgsExpression *expression)
 Construct a new data defined object, analysing the expression to determine if it's a simple field reference or an expression. More...
 
 QgsDataDefined (const QString &string)
 Construct a new data defined object, analysing the string to determine if it's a simple field reference or an expression. More...
 
 QgsDataDefined (const QgsDataDefined &other)
 Copy constructor. More...
 
virtual ~QgsDataDefined ()
 
QgsExpressionexpression ()
 
bool expressionIsPrepared () const
 Returns whether the data defined object's expression is prepared. More...
 
QString expressionOrField () const
 Returns an expression which represents a single field if useExpression returns false, otherwise returns the current expression string. More...
 
QMap< QString, QVariantexpressionParams () const
 
QString expressionString () const
 Returns the expression string of this QgsDataDefined. More...
 
QString field () const
 Get the field which this QgsDataDefined represents. More...
 
bool hasDefaultValues () const
 Returns whether the data defined container is set to all the default values, ie, disabled, with empty expression and no assigned field. More...
 
void insertExpressionParam (QString key, QVariant param)
 
bool isActive () const
 
bool operator!= (const QgsDataDefined &other) const
 
QgsDataDefinedoperator= (QgsDataDefined const &rhs)
 Assignment operator. More...
 
bool operator== (const QgsDataDefined &other) const
 
Q_DECL_DEPRECATED bool prepareExpression (QgsVectorLayer *layer)
 Prepares the expression using a vector layer. More...
 
Q_DECL_DEPRECATED bool prepareExpression (const QgsFields &fields)
 Prepares the expression using a fields collection. More...
 
bool prepareExpression (const QgsExpressionContext &context=QgsExpressionContext())
 Prepares the expression using an expression context. More...
 
Q_DECL_DEPRECATED QStringList referencedColumns (QgsVectorLayer *layer)
 Returns the columns referenced by the QgsDataDefined. More...
 
Q_DECL_DEPRECATED QStringList referencedColumns (const QgsFields &fields)
 Returns the columns referenced by the QgsDataDefined. More...
 
QStringList referencedColumns (const QgsExpressionContext &context=QgsExpressionContext())
 Returns the columns referenced by the QgsDataDefined. More...
 
void setActive (bool active)
 
void setExpressionParams (QMap< QString, QVariant > params)
 
void setExpressionString (const QString &expr)
 Sets the expression for this QgsDataDefined. More...
 
void setField (const QString &field)
 Set the field name which this QgsDataDefined represents. More...
 
bool setFromXmlElement (const QDomElement &element)
 Sets the properties of the data defined container from an XML element. More...
 
void setUseExpression (bool use)
 Controls if the field or the expression part is active. More...
 
QgsStringMap toMap (const QString &baseName=QString()) const
 Encodes the QgsDataDefined into a string map. More...
 
QDomElement toXmlElement (QDomDocument &document, const QString &elementName) const
 Returns a DOM element containing the properties of the data defined container. More...
 
bool useExpression () const
 Returns if the field or the expression part is active. More...
 

Static Public Member Functions

static QgsDataDefinedfromMap (const QgsStringMap &map, const QString &baseName=QString())
 Creates a QgsDataDefined from a decoded QgsStringMap. More...
 

Detailed Description

A container class for data source field mapping or expression.

Note
QgsDataDefined objects are implicitly shared.

Definition at line 37 of file qgsdatadefined.h.

Constructor & Destructor Documentation

QgsDataDefined::QgsDataDefined ( bool  active = false,
bool  useexpr = false,
const QString expr = QString(),
const QString field = QString() 
)

Construct a new data defined object.

Parameters
activeWhether the current data defined is active
useexprWhether to use expression instead of field
exprExpression string
fieldField name string

Definition at line 24 of file qgsdatadefined.cpp.

QgsDataDefined::QgsDataDefined ( const QgsExpression expression)
explicit

Construct a new data defined object, analysing the expression to determine if it's a simple field reference or an expression.

Parameters
expressioncan be null

Definition at line 32 of file qgsdatadefined.cpp.

QgsDataDefined::QgsDataDefined ( const QString string)
explicit

Construct a new data defined object, analysing the string to determine if it's a simple field reference or an expression.

Parameters
stringfield reference or an expression, can be empty
Note
added in QGIS 2.9

Definition at line 70 of file qgsdatadefined.cpp.

QgsDataDefined::QgsDataDefined ( const QgsDataDefined other)

Copy constructor.

Note that copies of data defined objects with expressions will not be prepared.

Definition at line 42 of file qgsdatadefined.cpp.

QgsDataDefined::~QgsDataDefined ( )
virtual

Definition at line 82 of file qgsdatadefined.cpp.

Member Function Documentation

QgsExpression * QgsDataDefined::expression ( )

Definition at line 223 of file qgsdatadefined.cpp.

bool QgsDataDefined::expressionIsPrepared ( ) const

Returns whether the data defined object's expression is prepared.

Returns
true if expression is prepared

Definition at line 218 of file qgsdatadefined.cpp.

QString QgsDataDefined::expressionOrField ( ) const

Returns an expression which represents a single field if useExpression returns false, otherwise returns the current expression string.

Returns
An expression
Note
added in 2.12

Definition at line 140 of file qgsdatadefined.cpp.

QMap< QString, QVariant > QgsDataDefined::expressionParams ( ) const
Note
not available in python bindings

Definition at line 145 of file qgsdatadefined.cpp.

QString QgsDataDefined::expressionString ( ) const

Returns the expression string of this QgsDataDefined.

Returns
An expression
See also
field()
expressionOrField()

Definition at line 122 of file qgsdatadefined.cpp.

QString QgsDataDefined::field ( ) const

Get the field which this QgsDataDefined represents.

Be aware that this may return a field name which may not be active if useExpression is true.

Returns
A fieldname
See also
expressionOrField()

Definition at line 273 of file qgsdatadefined.cpp.

QgsDataDefined * QgsDataDefined::fromMap ( const QgsStringMap map,
const QString baseName = QString() 
)
static

Creates a QgsDataDefined from a decoded QgsStringMap.

Parameters
mapstring map encoding of QgsDataDefined
baseNamebase name for values in the string map
Returns
new QgsDataDefined if string map was successfully interpreted
See also
toMap
Note
added in QGIS 2.9

Definition at line 48 of file qgsdatadefined.cpp.

bool QgsDataDefined::hasDefaultValues ( ) const

Returns whether the data defined container is set to all the default values, ie, disabled, with empty expression and no assigned field.

Returns
true if data defined container is set to default values
Note
added in QGIS 2.7

Definition at line 87 of file qgsdatadefined.cpp.

void QgsDataDefined::insertExpressionParam ( QString  key,
QVariant  param 
)

Definition at line 289 of file qgsdatadefined.cpp.

bool QgsDataDefined::isActive ( ) const

Definition at line 92 of file qgsdatadefined.cpp.

bool QgsDataDefined::operator!= ( const QgsDataDefined other) const

Definition at line 342 of file qgsdatadefined.cpp.

QgsDataDefined & QgsDataDefined::operator= ( QgsDataDefined const &  rhs)

Assignment operator.

Note that after assignment the data defined object's expression will not be prepared.

Definition at line 347 of file qgsdatadefined.cpp.

bool QgsDataDefined::operator== ( const QgsDataDefined other) const

Definition at line 337 of file qgsdatadefined.cpp.

bool QgsDataDefined::prepareExpression ( QgsVectorLayer layer)

Prepares the expression using a vector layer.

Parameters
layervector layer
Returns
true if expression was successfully prepared

Definition at line 156 of file qgsdatadefined.cpp.

bool QgsDataDefined::prepareExpression ( const QgsFields fields)

Prepares the expression using a fields collection.

Parameters
fields
Returns
true if expression was successfully prepared
Note
added in QGIS 2.9

Definition at line 170 of file qgsdatadefined.cpp.

bool QgsDataDefined::prepareExpression ( const QgsExpressionContext context = QgsExpressionContext())

Prepares the expression using an expression context.

Parameters
contextexpression context
Returns
true if expression was successfully prepared
Note
added in QGIS 2.12

Definition at line 175 of file qgsdatadefined.cpp.

QStringList QgsDataDefined::referencedColumns ( QgsVectorLayer layer)

Returns the columns referenced by the QgsDataDefined.

Parameters
layervector layer, used for preparing the expression if required

Definition at line 232 of file qgsdatadefined.cpp.

QStringList QgsDataDefined::referencedColumns ( const QgsFields fields)

Returns the columns referenced by the QgsDataDefined.

Parameters
fieldsvector layer, used for preparing the expression if required
Note
added in QGIS 2.9

Definition at line 245 of file qgsdatadefined.cpp.

QStringList QgsDataDefined::referencedColumns ( const QgsExpressionContext context = QgsExpressionContext())

Returns the columns referenced by the QgsDataDefined.

Parameters
contextexpression context, used for preparing the expression if required
Note
added in QGIS 2.12

Definition at line 250 of file qgsdatadefined.cpp.

void QgsDataDefined::setActive ( bool  active)

Definition at line 97 of file qgsdatadefined.cpp.

void QgsDataDefined::setExpressionParams ( QMap< QString, QVariant params)
Note
not available in python bindings

Definition at line 150 of file qgsdatadefined.cpp.

void QgsDataDefined::setExpressionString ( const QString expr)

Sets the expression for this QgsDataDefined.

Will also set useExpression to true.

Parameters
exprThe expression to set
See also
setField

Definition at line 127 of file qgsdatadefined.cpp.

void QgsDataDefined::setField ( const QString field)

Set the field name which this QgsDataDefined represents.

Will set useExpression to false.

Parameters
field

Definition at line 278 of file qgsdatadefined.cpp.

bool QgsDataDefined::setFromXmlElement ( const QDomElement element)

Sets the properties of the data defined container from an XML element.

Calling this will overwrite all the current properties of the container.

Parameters
elementDOM element
Returns
true if properties were successfully read from element
Note
added in QGIS 2.7
See also
toXmlElement

Definition at line 322 of file qgsdatadefined.cpp.

void QgsDataDefined::setUseExpression ( bool  use)

Controls if the field or the expression part is active.

For QGIS<=2.10 it is mandatory to call this after setExpressionString or setField.

Parameters
useTrue if it should be set to expression mode.

Definition at line 111 of file qgsdatadefined.cpp.

QgsStringMap QgsDataDefined::toMap ( const QString baseName = QString()) const

Encodes the QgsDataDefined into a string map.

Parameters
baseNameoptional base name for values in the string map. Can be used to differentiate multiple QgsDataDefineds encoded in the same string map.
See also
fromMap

Definition at line 295 of file qgsdatadefined.cpp.

QDomElement QgsDataDefined::toXmlElement ( QDomDocument document,
const QString elementName 
) const

Returns a DOM element containing the properties of the data defined container.

Parameters
documentDOM document
elementNamename for DOM element
Returns
DOM element corresponding to data defined container
Note
added in QGIS 2.7
See also
setFromXmlElement

Definition at line 312 of file qgsdatadefined.cpp.

bool QgsDataDefined::useExpression ( ) const

Returns if the field or the expression part is active.

Returns
True if it is in expression mode.

Definition at line 106 of file qgsdatadefined.cpp.


The documentation for this class was generated from the following files: