30 mExpressions.removeAt( index );
35 mExpressions[index].field.setName( name );
45 QDomElement expressionFieldsElem = document.createElement( QStringLiteral(
"expressionfields" ) );
46 layerNode.appendChild( expressionFieldsElem );
48 const auto constMExpressions = mExpressions;
51 QDomElement fldElem = document.createElement( QStringLiteral(
"field" ) );
53 fldElem.setAttribute( QStringLiteral(
"expression" ), fld.cachedExpression.expression() );
54 fldElem.setAttribute( QStringLiteral(
"name" ), fld.field.name() );
55 fldElem.setAttribute( QStringLiteral(
"precision" ), fld.field.precision() );
56 fldElem.setAttribute( QStringLiteral(
"comment" ), fld.field.comment() );
57 fldElem.setAttribute( QStringLiteral(
"length" ), fld.field.length() );
58 fldElem.setAttribute( QStringLiteral(
"type" ), fld.field.type() );
59 fldElem.setAttribute( QStringLiteral(
"subType" ), fld.field.subType() );
60 fldElem.setAttribute( QStringLiteral(
"typeName" ), fld.field.typeName() );
62 expressionFieldsElem.appendChild( fldElem );
70 const QDomElement expressionFieldsElem = layerNode.firstChildElement( QStringLiteral(
"expressionfields" ) );
72 if ( !expressionFieldsElem.isNull() )
74 QDomNodeList fields = expressionFieldsElem.elementsByTagName( QStringLiteral(
"field" ) );
76 for (
int i = 0; i < fields.size(); ++i )
78 QDomElement field = fields.at( i ).toElement();
79 QString exp = field.attribute( QStringLiteral(
"expression" ) );
80 QString name = field.attribute( QStringLiteral(
"name" ) );
81 QString comment = field.attribute( QStringLiteral(
"comment" ) );
82 int precision = field.attribute( QStringLiteral(
"precision" ) ).toInt();
83 int length = field.attribute( QStringLiteral(
"length" ) ).toInt();
84 QVariant::Type type =
static_cast< QVariant::Type
>( field.attribute( QStringLiteral(
"type" ) ).toInt() );
85 QVariant::Type subType =
static_cast< QVariant::Type
>( field.attribute( QStringLiteral(
"subType" ), QStringLiteral(
"0" ) ).toInt() );
86 QString
typeName = field.attribute( QStringLiteral(
"typeName" ) );
88 mExpressions.append(
ExpressionField( exp,
QgsField( name, type, typeName, length, precision, comment, subType ) ) );
96 const auto constMExpressions = mExpressions;
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)
Appends an expression field. The field must have unique name, otherwise it is rejected (returns false...
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.
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.