24using namespace Qt::StringLiterals;
33 mExpressions.removeAt( index );
38 mExpressions[index].field.setName( name );
48 QDomElement expressionFieldsElem = document.createElement( u
"expressionfields"_s );
49 layerNode.appendChild( expressionFieldsElem );
51 const auto constMExpressions = mExpressions;
54 QDomElement fldElem = document.createElement( u
"field"_s );
56 fldElem.setAttribute( u
"expression"_s, fld.cachedExpression.expression() );
57 fldElem.setAttribute( u
"name"_s, fld.field.name() );
58 fldElem.setAttribute( u
"precision"_s, fld.field.precision() );
59 fldElem.setAttribute( u
"comment"_s, fld.field.comment() );
60 fldElem.setAttribute( u
"length"_s, fld.field.length() );
61 fldElem.setAttribute( u
"type"_s, fld.field.type() );
62 fldElem.setAttribute( u
"subType"_s, fld.field.subType() );
63 fldElem.setAttribute( u
"typeName"_s, fld.field.typeName() );
65 expressionFieldsElem.appendChild( fldElem );
73 const QDomElement expressionFieldsElem = layerNode.firstChildElement( u
"expressionfields"_s );
75 if ( !expressionFieldsElem.isNull() )
77 const QDomNodeList fields = expressionFieldsElem.elementsByTagName( u
"field"_s );
79 for (
int i = 0; i < fields.size(); ++i )
81 const QDomElement field = fields.at( i ).toElement();
82 const QString exp = field.attribute( u
"expression"_s );
83 const QString name = field.attribute( u
"name"_s );
84 const QString comment = field.attribute( u
"comment"_s );
85 const int precision = field.attribute( u
"precision"_s ).toInt();
86 const int length = field.attribute( u
"length"_s ).toInt();
87 const QMetaType::Type type =
static_cast< QMetaType::Type
>( field.attribute( u
"type"_s ).toInt() );
88 const QMetaType::Type subType =
static_cast< QMetaType::Type
>( field.attribute( u
"subType"_s, u
"0"_s ).toInt() );
89 const QString typeName = field.attribute( u
"typeName"_s );
91 mExpressions.append(
ExpressionField( exp,
QgsField( name, type, typeName, length, precision, comment, subType ) ) );
99 const auto constMExpressions = mExpressions;
void removeExpression(int index)
Remove an expression from the buffer.
void writeXml(QDomNode &layer_node, QDomDocument &document) const
Saves expressions to xml under the layer node.
void readXml(const QDomNode &layer_node)
Reads expressions from project file.
void updateFields(QgsFields &flds) const
Adds fields with the expressions buffered in this object to a QgsFields object.
void addExpression(const QString &exp, const QgsField &fld)
Add an expression to the buffer.
void updateExpression(int index, const QString &exp)
Changes the expression at a given index.
void renameExpression(int index, const QString &name)
Renames an expression field at a given index.
Handles parsing and evaluation of expressions (formerly called "search strings").
Encapsulate a field in an attribute table or data source.
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...