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->exprRefColumns.clear();
123 return d->expressionString;
128 if ( expr == d->expressionString )
133 d->expressionString = expr;
134 d->expressionPrepared =
false;
135 d->exprRefColumns.clear();
140 return d->expressionParams;
146 d->expressionParams = params;
165 if ( !d->useExpression || d->expressionString.isEmpty() )
171 delete d->expression;
173 if ( d->expression->hasParserError() )
175 QgsDebugMsg(
"Parser error:" + d->expression->parserErrorString() );
180 QVariant scaleV = d->expressionParams.value(
"scale" );
184 double scale = scaleV.
toDouble( &ok );
187 d->expression->setScale( scale );
191 d->expression->prepare( fields );
192 d->exprRefColumns = d->expression->referencedColumns();
194 if ( d->expression->hasEvalError() )
196 d->expressionPrepared =
false;
197 QgsDebugMsg(
"Prepare error:" + d->expression->evalErrorString() );
201 d->expressionPrepared =
true;
208 return d->expressionPrepared;
217 return d->expression;
234 if ( !d->exprRefColumns.isEmpty() )
236 return d->exprRefColumns;
240 if ( d->useExpression )
242 if ( !d->expression || !d->expressionPrepared )
247 else if ( !d->field.isEmpty() )
249 d->exprRefColumns << d->field;
252 return d->exprRefColumns;
262 if ( field == d->field )
267 d->exprRefColumns.clear();
273 d->expressionParams.insert( key, param );
285 map.
insert(
QString(
"%1active" ).arg( prefix ), ( d->active ?
"1" :
"0" ) );
286 map.
insert(
QString(
"%1useexpr" ).arg( prefix ), ( d->useExpression ?
"1" :
"0" ) );
287 map.
insert(
QString(
"%1expression" ).arg( prefix ), d->expressionString );
296 element.
setAttribute(
"active", d->active ?
"true" :
"false" );
297 element.
setAttribute(
"useExpr", d->useExpression ?
"true" :
"false" );
311 d->active = element.
attribute(
"active" ).
compare(
"true", Qt::CaseInsensitive ) == 0;
312 d->useExpression = element.
attribute(
"useExpr" ).
compare(
"true", Qt::CaseInsensitive ) == 0;
320 return *( other.d ) == *d;
325 return !( *
this == other );
Class for parsing and evaluation of expressions (formerly called "search strings").
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
virtual QString dump() const =0
void insertExpressionParam(QString key, QVariant param)
QgsExpression * expression()
Container of fields for a vector layer.
QMap< QString, QVariant > expressionParams() const
QString expressionString() const
static QgsDataDefined * fromMap(const QgsStringMap &map, const QString &baseName=QString())
Creates a QgsDataDefined from a decoded QgsStringMap.
void setUseExpression(bool use)
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)
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.
void setExpressionParams(QMap< QString, QVariant > params)
bool operator==(const QgsDataDefined &other) const
bool isField() const
Checks whether an expression consists only of a single field reference.
bool useExpression() const
QgsDataDefined(bool active=false, bool useexpr=false, const QString &expr=QString(), const QString &field=QString())
Construct a new data defined object.
bool prepareExpression(QgsVectorLayer *layer)
Prepares the expression using a vector layer.
bool expressionIsPrepared() const
Returns whether the data defined object's expression is prepared.
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.
const QgsFields & pendingFields() const
returns field list in the to-be-committed state
QDomElement createElement(const QString &tagName)
Represents a vector layer which manages a vector based data sets.
int compare(const QString &other) const
virtual ~QgsDataDefined()
void setExpressionString(const QString &expr)
QStringList referencedColumns(QgsVectorLayer *layer)
Returns the columns referenced by the QgsDataDefined.
const T value(const Key &key) const