QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
Loading...
Searching...
No Matches
qgsfieldmappingmodel.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsfieldmappingmodel.cpp - QgsFieldMappingModel
3
4 ---------------------
5 begin : 17.3.2020
6 copyright : (C) 2020 by Alessandro Pasotti
7 email : elpaso at itopen dot it
8 ***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16
20#include "qgsvariantutils.h"
21
23 const QgsFields &destinationFields,
24 const QMap<QString, QString> &expressions,
25 QObject *parent )
26 : QAbstractTableModel( parent )
27 , mSourceFields( sourceFields )
28 , mExpressionContextGenerator( new ExpressionContextGenerator( mSourceFields ) )
29{
30 setDestinationFields( destinationFields, expressions );
31}
32
33QVariant QgsFieldMappingModel::headerData( int section, Qt::Orientation orientation, int role ) const
34{
35 if ( role == Qt::DisplayRole )
36 {
37 switch ( orientation )
38 {
39 case Qt::Horizontal:
40 {
41 switch ( static_cast<ColumnDataIndex>( section ) )
42 {
44 {
45 return tr( "Source Expression" );
46 }
48 {
49 return tr( "Name" );
50 }
52 {
53 return tr( "Type" );
54 }
56 {
57 return tr( "Length" );
58 }
60 {
61 return tr( "Precision" );
62 }
64 {
65 return tr( "Constraints" );
66 }
68 {
69 return tr( "Alias" );
70 }
72 {
73 return tr( "Comment" );
74 }
75 }
76 break;
77 }
78 case Qt::Vertical:
79 {
80 return section;
81 }
82 }
83 }
84 return QVariant();
85}
86
88{
89 return mSourceFields;
90}
91
92int QgsFieldMappingModel::rowCount( const QModelIndex &parent ) const
93{
94 if ( parent.isValid() )
95 return 0;
96 return mMapping.count();
97}
98
99int QgsFieldMappingModel::columnCount( const QModelIndex &parent ) const
100{
101 if ( parent.isValid() )
102 return 0;
103 return 8;
104}
105
106QVariant QgsFieldMappingModel::data( const QModelIndex &index, int role ) const
107{
108 if ( index.isValid() )
109 {
110 const ColumnDataIndex col { static_cast<ColumnDataIndex>( index.column() ) };
111 const Field &f { mMapping.at( index.row() ) };
112
113 const QgsFieldConstraints::Constraints constraints { fieldConstraints( f.field ) };
114
115 switch ( role )
116 {
117 case Qt::DisplayRole:
118 case Qt::EditRole:
119 {
120 switch ( col )
121 {
123 {
124 return f.expression;
125 }
127 {
128 return f.field.displayNameWithAlias();
129 }
131 {
132 return f.field.typeName();
133 }
135 {
136 return f.field.length();
137 }
139 {
140 return f.field.precision();
141 }
143 {
144 return constraints != 0 ? tr( "Constraints active" ) : QString();
145 }
147 {
148 return f.field.alias();
149 }
151 {
152 return f.field.comment();
153 }
154 }
155 break;
156 }
157 case Qt::ToolTipRole:
158 {
160 constraints != 0 )
161 {
162 QStringList constraintDescription;
163 if ( constraints.testFlag( QgsFieldConstraints::Constraint::ConstraintUnique ) )
164 {
165 constraintDescription.push_back( tr( "Unique" ) );
166 }
167 if ( constraints.testFlag( QgsFieldConstraints::Constraint::ConstraintNotNull ) )
168 {
169 constraintDescription.push_back( tr( "Not null" ) );
170 }
171 if ( constraints.testFlag( QgsFieldConstraints::Constraint::ConstraintExpression ) )
172 {
173 constraintDescription.push_back( tr( "Expression" ) );
174 }
175 return constraintDescription.join( QLatin1String( "<br>" ) );
176 }
177 break;
178 }
179 case Qt::BackgroundRole:
180 {
181 if ( constraints != 0 )
182 {
183 return QBrush( QColor( 255, 224, 178 ) );
184 }
185 break;
186 }
187 }
188 }
189 return QVariant();
190}
191
192Qt::ItemFlags QgsFieldMappingModel::flags( const QModelIndex &index ) const
193{
194 if ( index.isValid() &&
195 index.column() != static_cast<int>( ColumnDataIndex::DestinationConstraints ) &&
196 ( index.column() == static_cast<int>( ColumnDataIndex::SourceExpression ) || destinationEditable() ) )
197 {
198 return Qt::ItemFlags( Qt::ItemIsSelectable |
199 Qt::ItemIsEditable |
200 Qt::ItemIsEnabled );
201 }
202 return Qt::ItemFlags();
203}
204
205bool QgsFieldMappingModel::setData( const QModelIndex &index, const QVariant &value, int role )
206{
207 if ( index.isValid() )
208 {
209 if ( role == Qt::EditRole )
210 {
211 Field &f = mMapping[index.row()];
212 switch ( static_cast<ColumnDataIndex>( index.column() ) )
213 {
215 {
216 const QgsExpression exp { value.toString() };
217 f.expression = exp;
218 break;
219 }
221 {
222 f.field.setName( value.toString() );
223 break;
224 }
226 {
227 setFieldTypeFromName( f.field, value.toString() );
228 break;
229 }
231 {
232 bool ok;
233 const int length { value.toInt( &ok ) };
234 if ( ok )
235 f.field.setLength( length );
236 break;
237 }
239 {
240 bool ok;
241 const int precision { value.toInt( &ok ) };
242 if ( ok )
244 break;
245 }
247 {
248 // Not editable: do nothing
249 break;
250 }
252 {
253 f.field.setAlias( value.toString() );
254 break;
255 }
257 {
258 f.field.setComment( value.toString() );
259 break;
260 }
261
262 }
263 emit dataChanged( index, index );
264 }
265 return true;
266 }
267 else
268 {
269 return false;
270 }
271}
272
273QgsFieldConstraints::Constraints QgsFieldMappingModel::fieldConstraints( const QgsField &field ) const
274{
275 QgsFieldConstraints::Constraints constraints;
276
277 const QgsFieldConstraints fieldConstraints { field.constraints() };
278
279 if ( fieldConstraints.constraints() & QgsFieldConstraints::ConstraintNotNull &&
281 constraints.setFlag( QgsFieldConstraints::ConstraintNotNull );
282
283 if ( fieldConstraints.constraints() & QgsFieldConstraints::ConstraintUnique &&
285 constraints.setFlag( QgsFieldConstraints::ConstraintUnique );
286
287 if ( fieldConstraints.constraints() & QgsFieldConstraints::ConstraintExpression &&
289 constraints.setFlag( QgsFieldConstraints::ConstraintExpression );
290
291 return constraints;
292}
293
294bool QgsFieldMappingModel::moveUpOrDown( const QModelIndex &index, bool up )
295{
296 if ( ! index.isValid() && index.model() == this )
297 return false;
298
299 // Always swap down
300 const int row { up ? index.row() - 1 : index.row() };
301 // Range checking
302 if ( row < 0 || row + 1 >= rowCount( QModelIndex() ) )
303 {
304 return false;
305 }
306 beginMoveRows( QModelIndex( ), row, row, QModelIndex(), row + 2 );
307 mMapping.swapItemsAt( row, row + 1 );
308 endMoveRows();
309 return true;
310}
311
312QString QgsFieldMappingModel::findExpressionForDestinationField( const QgsFieldMappingModel::Field &f, QStringList &excludedFieldNames )
313{
314 // Search for fields in the source
315 // 1. match by name
316 for ( const QgsField &sf : std::as_const( mSourceFields ) )
317 {
318 if ( sf.name() == f.field.name() )
319 {
320 excludedFieldNames.push_back( sf.name() );
321 return QgsExpression::quotedColumnRef( sf.name() );
322 }
323 }
324 // 2. match by type
325 for ( const QgsField &sf : std::as_const( mSourceFields ) )
326 {
327 if ( excludedFieldNames.contains( sf.name() ) || sf.type() != f.field.type() )
328 continue;
329 excludedFieldNames.push_back( sf.name() );
330 return QgsExpression::quotedColumnRef( sf.name() );
331 }
332 return QString();
333}
334
336{
337 mSourceFields = sourceFields;
338 if ( mExpressionContextGenerator )
339 mExpressionContextGenerator->setSourceFields( mSourceFields );
340 QStringList usedFields;
341 beginResetModel();
342 for ( const Field &f : std::as_const( mMapping ) )
343 {
344 if ( QgsExpression( f.expression ).isField() )
345 {
346 usedFields.push_back( f.expression.mid( 1, f.expression.length() - 2 ) );
347 }
348 }
349 for ( auto it = mMapping.begin(); it != mMapping.end(); ++it )
350 {
351 if ( it->expression.isEmpty() )
352 {
353 const QString expression { findExpressionForDestinationField( *it, usedFields ) };
354 if ( ! expression.isEmpty() )
355 it->expression = expression;
356 }
357 }
358 endResetModel();
359}
360
362{
363 return mExpressionContextGenerator.get();
364}
365
367{
368 mExpressionContextGenerator->setBaseExpressionContextGenerator( generator );
369}
370
372 const QMap<QString, QString> &expressions )
373{
374 beginResetModel();
375 mMapping.clear();
376 // Prepare the model data
377 QStringList usedFields;
378 for ( const QgsField &df : destinationFields )
379 {
380 Field f;
381 f.field = df;
382 f.field.setTypeName( qgsFieldToTypeName( df ) );
383 f.originalName = df.name();
384 if ( expressions.contains( f.field.name() ) )
385 {
386 f.expression = expressions.value( f.field.name() );
387 const QgsExpression exp { f.expression };
388 // if it's source field
389 if ( exp.isField() &&
390 mSourceFields.names().contains( qgis::setToList( exp.referencedColumns() ).first() ) )
391 {
392 usedFields.push_back( qgis::setToList( exp.referencedColumns() ).first() );
393 }
394 }
395 else
396 {
397 const QString expression { findExpressionForDestinationField( f, usedFields ) };
398 if ( ! expression.isEmpty() )
399 f.expression = expression;
400 }
401 mMapping.push_back( f );
402 }
403 endResetModel();
404}
405
407{
408 return mDestinationEditable;
409}
410
411void QgsFieldMappingModel::setDestinationEditable( bool destinationEditable )
412{
413 mDestinationEditable = destinationEditable;
414}
415
416const QMap<QVariant::Type, QString> QgsFieldMappingModel::dataTypes()
417{
418 static const QMap<QVariant::Type, QString> sDataTypes
419 {
420 { QVariant::Type::Int, QgsVariantUtils::typeToDisplayString( QVariant::Type::Int ) },
421 { QVariant::Type::LongLong, QgsVariantUtils::typeToDisplayString( QVariant::Type::LongLong ) },
422 { QVariant::Type::Double, QgsVariantUtils::typeToDisplayString( QVariant::Type::Double ) },
423 { QVariant::Type::String, QgsVariantUtils::typeToDisplayString( QVariant::Type::String ) },
424 { QVariant::Type::Date, QgsVariantUtils::typeToDisplayString( QVariant::Type::Date ) },
425 { QVariant::Type::Time, QgsVariantUtils::typeToDisplayString( QVariant::Type::Time ) },
426 { QVariant::Type::DateTime, QgsVariantUtils::typeToDisplayString( QVariant::Type::DateTime ) },
427 { QVariant::Type::Bool, QgsVariantUtils::typeToDisplayString( QVariant::Type::Bool ) },
428 { QVariant::Type::ByteArray, QgsVariantUtils::typeToDisplayString( QVariant::Type::ByteArray ) },
429 };
430 return sDataTypes;
431}
432
433const QList<QgsVectorDataProvider::NativeType> QgsFieldMappingModel::supportedDataTypes()
434{
435 static const QList<QgsVectorDataProvider::NativeType> sDataTypes =
436 QList<QgsVectorDataProvider::NativeType>() << QgsVectorDataProvider::NativeType( QgsVariantUtils::typeToDisplayString( QVariant::Type::Int ), QStringLiteral( "integer" ), QVariant::Int )
437 << QgsVectorDataProvider::NativeType( QgsVariantUtils::typeToDisplayString( QVariant::Type::LongLong ), QStringLiteral( "int8" ), QVariant::LongLong )
438 << QgsVectorDataProvider::NativeType( QgsVariantUtils::typeToDisplayString( QVariant::Type::Double ), QStringLiteral( "double precision" ), QVariant::Double )
439 << QgsVectorDataProvider::NativeType( QgsVariantUtils::typeToDisplayString( QVariant::Type::String ), QStringLiteral( "text" ), QVariant::String )
440 << QgsVectorDataProvider::NativeType( QgsVariantUtils::typeToDisplayString( QVariant::Type::Date ), QStringLiteral( "date" ), QVariant::Date )
441 << QgsVectorDataProvider::NativeType( QgsVariantUtils::typeToDisplayString( QVariant::Type::Time ), QStringLiteral( "time" ), QVariant::Time )
442 << QgsVectorDataProvider::NativeType( QgsVariantUtils::typeToDisplayString( QVariant::Type::DateTime ), QStringLiteral( "datetime" ), QVariant::DateTime )
443 << QgsVectorDataProvider::NativeType( QgsVariantUtils::typeToDisplayString( QVariant::Type::Bool ), QStringLiteral( "boolean" ), QVariant::Bool )
444 << QgsVectorDataProvider::NativeType( QgsVariantUtils::typeToDisplayString( QVariant::Type::ByteArray ), QStringLiteral( "binary" ), QVariant::ByteArray )
445 << QgsVectorDataProvider::NativeType( QgsVariantUtils::typeToDisplayString( QVariant::Type::StringList ), QStringLiteral( "stringlist" ), QVariant::StringList, 0, 0, 0, 0, QVariant::String )
446 << QgsVectorDataProvider::NativeType( QgsVariantUtils::typeToDisplayString( QVariant::Type::List, QVariant::Type::Int ), QStringLiteral( "integerlist" ), QVariant::List, 0, 0, 0, 0, QVariant::Int )
447 << QgsVectorDataProvider::NativeType( QgsVariantUtils::typeToDisplayString( QVariant::Type::List, QVariant::Type::Double ), QStringLiteral( "doublelist" ), QVariant::List, 0, 0, 0, 0, QVariant::Double )
448 << QgsVectorDataProvider::NativeType( QgsVariantUtils::typeToDisplayString( QVariant::Type::List, QVariant::Type::LongLong ), QStringLiteral( "integer64list" ), QVariant::List, 0, 0, 0, 0, QVariant::LongLong );
449 return sDataTypes;
450}
451
452const QString QgsFieldMappingModel::qgsFieldToTypeName( const QgsField &field )
453{
454 const QList<QgsVectorDataProvider::NativeType> types = supportedDataTypes();
455 for ( const auto &type : types )
456 {
457 if ( type.mType == field.type() && type.mSubType == field.subType() )
458 {
459 return type.mTypeName;
460 }
461 }
462 return QString();
463}
464
465void QgsFieldMappingModel::setFieldTypeFromName( QgsField &field, const QString &name )
466{
467 const QList<QgsVectorDataProvider::NativeType> types = supportedDataTypes();
468 for ( const auto &type : types )
469 {
470 if ( type.mTypeName == name )
471 {
472 field.setType( type.mType );
473 field.setTypeName( type.mTypeName );
474 field.setSubType( type.mSubType );
475 return;
476 }
477 }
478}
479
480QList<QgsFieldMappingModel::Field> QgsFieldMappingModel::mapping() const
481{
482 return mMapping;
483}
484
485QMap<QString, QgsProperty> QgsFieldMappingModel::fieldPropertyMap() const
486{
487 QMap< QString, QgsProperty > fieldMap;
488 for ( const QgsFieldMappingModel::Field &field : mMapping )
489 {
490 const QgsExpression exp( field.expression );
491 const bool isField = exp.isField();
492 fieldMap.insert( field.originalName, isField
493 ? QgsProperty::fromField( static_cast<const QgsExpressionNodeColumnRef *>( exp.rootNode() )->name() )
494 : QgsProperty::fromExpression( field.expression ) );
495 }
496 return fieldMap;
497}
498
499void QgsFieldMappingModel::setFieldPropertyMap( const QMap<QString, QgsProperty> &map )
500{
501 beginResetModel();
502 for ( int i = 0; i < mMapping.count(); ++i )
503 {
504 Field &f = mMapping[i];
505 if ( map.contains( f.field.name() ) )
506 {
507 const QgsProperty prop = map.value( f.field.name() );
508 switch ( prop.propertyType() )
509 {
512 break;
513
515 f.expression = prop.field();
516 break;
517
519 f.expression = prop.expressionString();
520 break;
521
523 f.expression.clear();
524 break;
525 }
526 }
527 else
528 {
529 f.expression.clear();
530 }
531 }
532 endResetModel();
533}
534
535void QgsFieldMappingModel::appendField( const QgsField &field, const QString &expression )
536{
537 const int lastRow { rowCount( QModelIndex( ) ) };
538 beginInsertRows( QModelIndex(), lastRow, lastRow );
539 Field f;
540 f.field = field;
541 f.field.setTypeName( qgsFieldToTypeName( field ) );
542 f.expression = expression;
543 f.originalName = field.name();
544 mMapping.push_back( f );
545 endInsertRows( );
546}
547
548bool QgsFieldMappingModel::removeField( const QModelIndex &index )
549{
550 if ( index.isValid() && index.model() == this && index.row() < rowCount( QModelIndex() ) )
551 {
552 beginRemoveRows( QModelIndex(), index.row(), index.row() );
553 mMapping.removeAt( index.row() );
554 endRemoveRows();
555 return true;
556 }
557 else
558 {
559 return false;
560 }
561}
562
563bool QgsFieldMappingModel::moveUp( const QModelIndex &index )
564{
565 return moveUpOrDown( index );
566}
567
568bool QgsFieldMappingModel::moveDown( const QModelIndex &index )
569{
570 return moveUpOrDown( index, false );
571}
572
573QgsFieldMappingModel::ExpressionContextGenerator::ExpressionContextGenerator( const QgsFields &sourceFields )
574 : mSourceFields( sourceFields )
575{
576}
577
578QgsExpressionContext QgsFieldMappingModel::ExpressionContextGenerator::createExpressionContext() const
579{
580 if ( mBaseGenerator )
581 {
582 QgsExpressionContext ctx = mBaseGenerator->createExpressionContext();
583 std::unique_ptr< QgsExpressionContextScope > fieldMappingScope = std::make_unique< QgsExpressionContextScope >( tr( "Field Mapping" ) );
584 fieldMappingScope->setFields( mSourceFields );
585 ctx.appendScope( fieldMappingScope.release() );
586 return ctx;
587 }
588 else
589 {
592 ctx.setFields( mSourceFields );
593 QgsFeature feature { mSourceFields };
594 feature.setValid( true );
595 ctx.setFeature( feature );
596 return ctx;
597 }
598}
599
600void QgsFieldMappingModel::ExpressionContextGenerator::setBaseExpressionContextGenerator( const QgsExpressionContextGenerator *generator )
601{
602 mBaseGenerator = generator;
603}
604
605void QgsFieldMappingModel::ExpressionContextGenerator::setSourceFields( const QgsFields &fields )
606{
607 mSourceFields = fields;
608}
Abstract interface for generating an expression context.
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
void setFields(const QgsFields &fields)
Convenience function for setting a fields for the context.
An expression node which takes it value from a feature's field.
QString name() const
The name of the column.
Class for parsing and evaluation of expressions (formerly called "search strings").
static QString quotedValue(const QVariant &value)
Returns a string representation of a literal value, including appropriate quotations where required.
bool isField() const
Checks whether an expression consists only of a single field reference.
static QString quotedColumnRef(QString name)
Returns a quoted column reference (in double quotes)
const QgsExpressionNode * rootNode() const
Returns the root node of the expression.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:56
void setValid(bool validity)
Sets the validity of the feature.
Stores information about constraints which may be present on a field.
@ ConstraintStrengthHard
Constraint must be honored before feature can be accepted.
@ ConstraintNotNull
Field may not be null.
@ ConstraintUnique
Field must have a unique value.
@ ConstraintExpression
Field has an expression constraint set. See constraintExpression().
void setDestinationEditable(bool editable)
Sets the destination fields editable state to editable.
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
ColumnDataIndex
The ColumnDataIndex enum represents the column index for the view.
@ DestinationPrecision
Destination field precision.
@ DestinationComment
Destination comment.
@ DestinationConstraints
Destination field constraints.
@ DestinationName
Destination field name.
@ DestinationType
Destination field type string.
@ DestinationLength
Destination field length.
Qt::ItemFlags flags(const QModelIndex &index) const override
static Q_DECL_DEPRECATED const QMap< QVariant::Type, QString > dataTypes()
Returns a static map of supported data types.
QgsFields sourceFields() const
Returns a list of source fields.
int columnCount(const QModelIndex &parent=QModelIndex()) const override
bool removeField(const QModelIndex &index)
Removes the field at index from the model, returns true on success.
void appendField(const QgsField &field, const QString &expression=QString())
Appends a new field to the model, with an optional expression.
QMap< QString, QgsProperty > fieldPropertyMap() const
Returns a map of destination field name to QgsProperty definition for field value,...
QList< QgsFieldMappingModel::Field > mapping() const
Returns a list of Field objects representing the current status of the model.
QgsFieldMappingModel(const QgsFields &sourceFields=QgsFields(), const QgsFields &destinationFields=QgsFields(), const QMap< QString, QString > &expressions=QMap< QString, QString >(), QObject *parent=nullptr)
Constructs a QgsFieldMappingModel from a set of sourceFields and destinationFields,...
bool moveDown(const QModelIndex &index)
Moves up the field at index.
bool moveUp(const QModelIndex &index)
Moves down the field at index.
int rowCount(const QModelIndex &parent=QModelIndex()) const override
QVariant data(const QModelIndex &index, int role) const override
void setBaseExpressionContextGenerator(const QgsExpressionContextGenerator *generator)
Sets the base expression context generator, which will generate the expression contexts for expressio...
static const QList< QgsVectorDataProvider::NativeType > supportedDataTypes()
Returns a static list of supported data types.
QgsExpressionContextGenerator * contextGenerator() const
Returns the context generator with the source fields.
void setDestinationFields(const QgsFields &destinationFields, const QMap< QString, QString > &expressions=QMap< QString, QString >())
Set destination fields to destinationFields, initial values for the expressions can be optionally spe...
void setSourceFields(const QgsFields &sourceFields)
Set source fields to sourceFields.
bool setData(const QModelIndex &index, const QVariant &value, int role) override
bool destinationEditable() const
Returns true if the destination fields are editable.
void setFieldPropertyMap(const QMap< QString, QgsProperty > &map)
Sets a map of destination field name to QgsProperty definition for field value.
Encapsulate a field in an attribute table or data source.
Definition qgsfield.h:53
void setAlias(const QString &alias)
Sets the alias for the field (the friendly displayed name of the field ).
Definition qgsfield.cpp:275
QString name
Definition qgsfield.h:62
void setPrecision(int precision)
Set the field precision.
Definition qgsfield.cpp:240
void setName(const QString &name)
Set the field name.
Definition qgsfield.cpp:216
void setComment(const QString &comment)
Set the field comment.
Definition qgsfield.cpp:245
void setLength(int len)
Set the field length.
Definition qgsfield.cpp:236
QVariant::Type type
Definition qgsfield.h:60
QVariant::Type subType() const
If the field is a collection, gets its element's type.
Definition qgsfield.cpp:145
void setSubType(QVariant::Type subType)
If the field is a collection, set its element's type.
Definition qgsfield.cpp:226
void setType(QVariant::Type type)
Set variant type.
Definition qgsfield.cpp:221
QgsFieldConstraints constraints
Definition qgsfield.h:65
void setTypeName(const QString &typeName)
Set the field type.
Definition qgsfield.cpp:231
Container of fields for a vector layer.
Definition qgsfields.h:45
QStringList names() const
Returns a list with field names.
A store for object properties.
@ ExpressionBasedProperty
Expression based property (QgsExpressionBasedProperty)
@ StaticProperty
Static property (QgsStaticProperty)
@ FieldBasedProperty
Field based property (QgsFieldBasedProperty)
@ InvalidProperty
Invalid (not set) property.
QString expressionString() const
Returns the expression used for the property value.
QString field() const
Returns the current field name the property references.
QVariant value(const QgsExpressionContext &context, const QVariant &defaultValue=QVariant(), bool *ok=nullptr) const
Calculates the current value of the property, including any transforms which are set for the property...
static QgsProperty fromExpression(const QString &expression, bool isActive=true)
Returns a new ExpressionBasedProperty created from the specified expression.
QVariant staticValue() const
Returns the current static value for the property.
Type propertyType() const
Returns the property type.
static QgsProperty fromField(const QString &fieldName, bool isActive=true)
Returns a new FieldBasedProperty created from the specified field name.
static QString typeToDisplayString(QVariant::Type type, QVariant::Type subType=QVariant::Type::Invalid)
Returns a user-friendly translated string representing a QVariant type.
int precision
The Field struct holds information about a mapped field.
QgsField field
The field in its current status (it might have been renamed)
QString expression
The expression for the mapped field from the source fields.
QString originalName
The original name of the field.