29 d =
new QgsDataDefinedPrivate( active, useexpr, expr, field );
34 bool active = bool( expression );
36 d =
new QgsDataDefinedPrivate( active,
67 return new QgsDataDefined( active, useExpression, expression, field );
76 d =
new QgsDataDefinedPrivate( active,
89 return ( !d->active && !d->useExpression && d->expressionString.isEmpty() && d->field.isEmpty() );
99 if ( active == d->active )
108 return d->useExpression;
113 if ( use == d->useExpression )
117 d->useExpression = use;
118 d->expressionPrepared =
false;
119 d->exprRefColumns.clear();
124 return d->expressionString;
129 if ( expr == d->expressionString )
134 d->useExpression =
true;
135 d->expressionString = expr;
136 d->expressionPrepared =
false;
137 d->exprRefColumns.clear();
142 return d->useExpression ? d->expressionString :
QString(
"\"%1\"" ).
arg( d->field );
147 return d->expressionParams;
153 d->expressionParams = params;
177 if ( !d->useExpression || d->expressionString.isEmpty() )
183 delete d->expression;
185 if ( d->expression->hasParserError() )
187 QgsDebugMsg(
"Parser error:" + d->expression->parserErrorString() );
192 QVariant scaleV = d->expressionParams.value(
"scale" );
196 double scale = scaleV.
toDouble( &ok );
199 d->expression->setScale( scale );
203 d->expression->prepare( &context );
204 d->exprRefColumns = d->expression->referencedColumns();
206 if ( d->expression->hasEvalError() )
208 d->expressionPrepared =
false;
209 QgsDebugMsg(
"Prepare error:" + d->expression->evalErrorString() );
213 d->expressionPrepared =
true;
220 return d->expressionPrepared;
229 return d->expression;
252 if ( !d->exprRefColumns.isEmpty() )
254 return d->exprRefColumns;
258 if ( d->useExpression )
260 if ( !d->expression || !d->expressionPrepared )
265 else if ( !d->field.isEmpty() )
267 d->exprRefColumns << d->field;
270 return d->exprRefColumns;
280 if ( field == d->field )
284 d->useExpression =
false;
286 d->exprRefColumns.clear();
292 d->expressionParams.insert( key, param );
304 map.
insert(
QString(
"%1active" ).arg( prefix ), ( d->active ?
"1" :
"0" ) );
305 map.
insert(
QString(
"%1useexpr" ).arg( prefix ), ( d->useExpression ?
"1" :
"0" ) );
306 map.
insert(
QString(
"%1expression" ).arg( prefix ), d->expressionString );
315 element.
setAttribute(
"active", d->active ?
"true" :
"false" );
316 element.
setAttribute(
"useExpr", d->useExpression ?
"true" :
"false" );
330 d->active = element.
attribute(
"active" ).
compare(
"true", Qt::CaseInsensitive ) == 0;
331 d->useExpression = element.
attribute(
"useExpr" ).
compare(
"true", Qt::CaseInsensitive ) == 0;
339 return *( other.d ) == *d;
344 return !( *
this == other );
Class for parsing and evaluation of expressions (formerly called "search strings").
void setExpressionParams(const QMap< QString, QVariant > ¶ms)
void setActive(bool active)
QgsDataDefined & operator=(QgsDataDefined const &rhs)
Assignment operator.
QString & append(QChar ch)
A container class for data source field mapping or expression.
bool contains(const Key &key) const
QgsStringMap toMap(const QString &baseName=QString()) const
Encodes the QgsDataDefined into a string map.
bool operator!=(const QgsDataDefined &other) const
const QString expression() const
Alias for dump()
QString attribute(const QString &name, const QString &defValue) const
QString field() const
Get the field which this QgsDataDefined represents.
QgsFields fields() const
Returns the list of fields of this layer.
static QgsExpressionContext createFeatureBasedContext(const QgsFeature &feature, const QgsFields &fields)
Helper function for creating an expression context which contains just a feature and fields collectio...
virtual QString dump() const =0
Abstract virtual dump method.
QgsExpression * expression()
Container of fields for a vector layer.
QMap< QString, QVariant > expressionParams() const
QString expressionString() const
Returns the expression string of this QgsDataDefined.
static QgsDataDefined * fromMap(const QgsStringMap &map, const QString &baseName=QString())
Creates a QgsDataDefined from a decoded QgsStringMap.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
QString expressionOrField() const
Returns an expression which represents a single field if useExpression returns false, otherwise returns the current expression string.
void setUseExpression(bool use)
Controls if the field or the expression part is active.
bool setFromXmlElement(const QDomElement &element)
Sets the properties of the data defined container from an XML element.
void setAttribute(const QString &name, const QString &value)
void setField(const QString &field)
Set the field name which this QgsDataDefined represents.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
const Node * rootNode() const
Returns root node of the expression. Root node is null is parsing has failed.
QDomElement toXmlElement(QDomDocument &document, const QString &elementName) const
Returns a DOM element containing the properties of the data defined container.
bool operator==(const QgsDataDefined &other) const
bool isField() const
Checks whether an expression consists only of a single field reference.
bool useExpression() const
Returns if the field or the expression part is active.
QgsDataDefined(bool active=false, bool useexpr=false, const QString &expr=QString(), const QString &field=QString())
Construct a new data defined object.
Q_DECL_DEPRECATED bool prepareExpression(QgsVectorLayer *layer)
Prepares the expression using a vector layer.
bool expressionIsPrepared() const
Returns whether the data defined object's expression is prepared.
void insertExpressionParam(const QString &key, const QVariant ¶m)
double toDouble(bool *ok) const
iterator insert(const Key &key, const T &value)
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.
QDomElement createElement(const QString &tagName)
Represents a vector layer which manages a vector based data sets.
int compare(const QString &other) const
virtual ~QgsDataDefined()
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
void setExpressionString(const QString &expr)
Sets the expression for this QgsDataDefined.
Q_DECL_DEPRECATED QStringList referencedColumns(QgsVectorLayer *layer)
Returns the columns referenced by the QgsDataDefined.
const T value(const Key &key) const