26 const QString& field )
28 , mUseExpression( useexpr )
29 , mExpressionString( expr )
33 mExpressionPrepared =
false;
37 : mActive( bool( expression ) )
38 , mUseExpression( expression && expression->rootNode() && !dynamic_cast<const
QgsExpression::NodeColumnRef*>( expression->rootNode() ) )
39 , mExpressionString( mUseExpression ? expression->expression() :
"" )
40 , mField( !mUseExpression ? ( expression ? expression->expression() :
"" ) :
"" )
43 mExpressionPrepared =
false;
48 mExpressionParams.clear();
54 return ( !mActive && !mUseExpression && mExpressionString.isEmpty() && mField.isEmpty() );
59 mExpressionString = expr;
60 mExpressionPrepared =
false;
65 if ( !mUseExpression || mExpressionString.isEmpty() )
78 QVariant scaleV = mExpressionParams.value(
"scale" );
79 if ( scaleV.isValid() )
82 double scale = scaleV.toDouble( &ok );
106 mExpressionPrepared =
true;
114 if ( !mExprRefColmuns.isEmpty() )
116 return mExprRefColmuns;
119 if ( mUseExpression )
121 if ( !mExpression || !mExpressionPrepared )
126 else if ( !mField.isEmpty() )
128 mExprRefColmuns << mField;
131 return mExprRefColmuns;
136 mExpressionParams.insert( key, param );
141 QMap< QString, QString > map;
142 map.insert(
"active", ( mActive ?
"1" :
"0" ) );
143 map.insert(
"useexpr", ( mUseExpression ?
"1" :
"0" ) );
144 map.insert(
"expression", mExpressionString );
145 map.insert(
"field", mField );
152 QDomElement element = document.createElement( elementName );
153 element.setAttribute(
"active", mActive ?
"true" :
"false" );
154 element.setAttribute(
"useExpr", mUseExpression ?
"true" :
"false" );
155 element.setAttribute(
"expr", mExpressionString );
156 element.setAttribute(
"field", mField );
162 if ( element.isNull() )
167 mActive = element.attribute(
"active" ).compare(
"true", Qt::CaseInsensitive ) == 0;
168 mUseExpression = element.attribute(
"useExpr" ).compare(
"true", Qt::CaseInsensitive ) == 0;
169 mField = element.attribute(
"field" );
182 return !( *
this == other );
Class for parsing and evaluation of expressions (formerly called "search strings").
bool hasEvalError() const
Returns true if an error occurred when evaluating last input.
bool hasParserError() const
Returns true if an error occurred when parsing the input expression.
QStringList referencedColumns() const
Get list of columns referenced by the expression.
A container class for data source field mapping or expression.
bool operator!=(const QgsDataDefined &other) const
QgsExpression * expression()
bool prepare(const QgsFields &fields)
Get the expression ready for evaluation - find out column indexes.
void insertExpressionParam(QString key, QVariant param)
Container of fields for a vector layer.
QString expressionString() const
bool setFromXmlElement(const QDomElement &element)
Sets the properties of the data defined container from an XML element.
QMap< QString, QString > toMap()
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 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)
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
void setScale(double scale)
Represents a vector layer which manages a vector based data sets.
QString parserErrorString() const
Returns parser error.
QString evalErrorString() const
Returns evaluation error.
void setExpressionString(const QString &expr)
QStringList referencedColumns(QgsVectorLayer *layer)