30 mExpressions.removeAt( index );
35 mExpressions[index].field.setName( name );
45 QDomElement expressionFieldsElem = document.createElement( QStringLiteral(
"expressionfields" ) );
46 layerNode.appendChild( expressionFieldsElem );
50 QDomElement fldElem = document.createElement( QStringLiteral(
"field" ) );
53 fldElem.setAttribute( QStringLiteral(
"name" ), fld.
field.
name() );
54 fldElem.setAttribute( QStringLiteral(
"precision" ), fld.
field.
precision() );
55 fldElem.setAttribute( QStringLiteral(
"comment" ), fld.
field.
comment() );
56 fldElem.setAttribute( QStringLiteral(
"length" ), fld.
field.
length() );
57 fldElem.setAttribute( QStringLiteral(
"type" ), fld.
field.
type() );
58 fldElem.setAttribute( QStringLiteral(
"subType" ), fld.
field.
subType() );
59 fldElem.setAttribute( QStringLiteral(
"typeName" ), fld.
field.
typeName() );
61 expressionFieldsElem.appendChild( fldElem );
69 const QDomElement expressionFieldsElem = layerNode.firstChildElement( QStringLiteral(
"expressionfields" ) );
71 if ( !expressionFieldsElem.isNull() )
73 QDomNodeList fields = expressionFieldsElem.elementsByTagName( QStringLiteral(
"field" ) );
75 for (
int i = 0; i < fields.size(); ++i )
77 QDomElement field = fields.at( i ).toElement();
78 QString exp = field.attribute( QStringLiteral(
"expression" ) );
79 QString name = field.attribute( QStringLiteral(
"name" ) );
80 QString comment = field.attribute( QStringLiteral(
"comment" ) );
81 int precision = field.attribute( QStringLiteral(
"precision" ) ).toInt();
82 int length = field.attribute( QStringLiteral(
"length" ) ).toInt();
83 QVariant::Type type =
static_cast< QVariant::Type
>( field.attribute( QStringLiteral(
"type" ) ).toInt() );
84 QVariant::Type subType =
static_cast< QVariant::Type
>( field.attribute( QStringLiteral(
"subType" ), QStringLiteral(
"0" ) ).toInt() );
85 QString typeName = field.attribute( QStringLiteral(
"typeName" ) );
87 mExpressions.append(
ExpressionField( exp,
QgsField( name, type, typeName, length, precision, comment, subType ) ) );
Class for parsing and evaluation of expressions (formerly called "search strings").
void renameExpression(int index, const QString &name)
Renames an expression field at a given index.
void addExpression(const QString &exp, const QgsField &fld)
Add an expression to the buffer.
Container of fields for a vector layer.
bool appendExpressionField(const QgsField &field, int originIndex)
Append an expression field. The field must have unique name, otherwise it is rejected (returns false)...
QString typeName() const
Gets the field type.
void writeXml(QDomNode &layer_node, QDomDocument &document) const
Saves expressions to xml under the layer node.
Encapsulate a field in an attribute table or data source.
void updateFields(QgsFields &flds)
Adds fields with the expressions buffered in this object to a QgsFields object.
QString expression() const
Returns the original, unmodified expression string.
void updateExpression(int index, const QString &exp)
Changes the expression at a given index.
void readXml(const QDomNode &layer_node)
Reads expressions from project file.
void removeExpression(int index)
Remove an expression from the buffer.
QgsExpression cachedExpression
QVariant::Type subType() const
If the field is a collection, gets its element's type.