QGIS API Documentation  2.99.0-Master (8ec3eaf)
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...
 
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...
 
bool isActive () const
 
bool operator!= (const QgsDataDefined &other) const
 
QgsDataDefinedoperator= (QgsDataDefined const &rhs)
 Assignment operator. More...
 
bool operator== (const QgsDataDefined &other) const
 
bool prepareExpression (const QgsExpressionContext &context=QgsExpressionContext())
 Prepares the expression using an expression context. More...
 
QSet< QString > referencedColumns (const QgsExpressionContext &context=QgsExpressionContext())
 Returns the columns referenced by the QgsDataDefined. More...
 
void setActive (bool active)
 
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 36 of file qgsdatadefined.h.

Constructor & Destructor Documentation

§ QgsDataDefined() [1/4]

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() [2/4]

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() [3/4]

QgsDataDefined::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.

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

Definition at line 70 of file qgsdatadefined.cpp.

§ QgsDataDefined() [4/4]

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::~QgsDataDefined ( )
virtual

Definition at line 82 of file qgsdatadefined.cpp.

Member Function Documentation

§ expression()

QgsExpression * QgsDataDefined::expression ( )

Definition at line 181 of file qgsdatadefined.cpp.

§ expressionIsPrepared()

bool QgsDataDefined::expressionIsPrepared ( ) const

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

Returns
true if expression is prepared

Definition at line 176 of file qgsdatadefined.cpp.

§ expressionOrField()

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.

§ expressionString()

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.

§ field()

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 213 of file qgsdatadefined.cpp.

§ fromMap()

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.

§ hasDefaultValues()

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.

§ isActive()

bool QgsDataDefined::isActive ( ) const

Definition at line 92 of file qgsdatadefined.cpp.

§ operator!=()

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

Definition at line 278 of file qgsdatadefined.cpp.

§ operator=()

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 283 of file qgsdatadefined.cpp.

§ operator==()

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

Definition at line 273 of file qgsdatadefined.cpp.

§ prepareExpression()

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 145 of file qgsdatadefined.cpp.

§ referencedColumns()

QSet< QString > 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 190 of file qgsdatadefined.cpp.

§ setActive()

void QgsDataDefined::setActive ( bool  active)

Definition at line 97 of file qgsdatadefined.cpp.

§ setExpressionString()

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.

§ setField()

void QgsDataDefined::setField ( const QString &  field)

Set the field name which this QgsDataDefined represents.

Will set useExpression to false.

Parameters
field

Definition at line 218 of file qgsdatadefined.cpp.

§ setFromXmlElement()

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 256 of file qgsdatadefined.cpp.

§ setUseExpression()

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.

§ toMap()

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 229 of file qgsdatadefined.cpp.

§ toXmlElement()

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 246 of file qgsdatadefined.cpp.

§ useExpression()

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: