QGIS API Documentation  3.24.2-Tisler (13c1a02865)
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 
17 #include "qgsfieldmappingmodel.h"
19 #include "qgsexpressionnodeimpl.h"
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 
33 QVariant 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  }
67  }
68  break;
69  }
70  case Qt::Vertical:
71  {
72  return section;
73  }
74  }
75  }
76  return QVariant();
77 }
78 
80 {
81  return mSourceFields;
82 }
83 
84 int QgsFieldMappingModel::rowCount( const QModelIndex &parent ) const
85 {
86  if ( parent.isValid() )
87  return 0;
88  return mMapping.count();
89 }
90 
91 int QgsFieldMappingModel::columnCount( const QModelIndex &parent ) const
92 {
93  if ( parent.isValid() )
94  return 0;
95  return 6;
96 }
97 
98 QVariant QgsFieldMappingModel::data( const QModelIndex &index, int role ) const
99 {
100  if ( index.isValid() )
101  {
102  const ColumnDataIndex col { static_cast<ColumnDataIndex>( index.column() ) };
103  const Field &f { mMapping.at( index.row() ) };
104 
105  const QgsFieldConstraints::Constraints constraints { fieldConstraints( f.field ) };
106 
107  switch ( role )
108  {
109  case Qt::DisplayRole:
110  case Qt::EditRole:
111  {
112  switch ( col )
113  {
115  {
116  return f.expression;
117  }
119  {
120  return f.field.displayName();
121  }
123  {
124  return f.field.typeName();
125  }
127  {
128  return f.field.length();
129  }
131  {
132  return f.field.precision();
133  }
135  {
136  return constraints != 0 ? tr( "Constraints active" ) : QString();
137  }
138  }
139  break;
140  }
141  case Qt::ToolTipRole:
142  {
144  constraints != 0 )
145  {
146  QStringList constraintDescription;
147  if ( constraints.testFlag( QgsFieldConstraints::Constraint::ConstraintUnique ) )
148  {
149  constraintDescription.push_back( tr( "Unique" ) );
150  }
151  if ( constraints.testFlag( QgsFieldConstraints::Constraint::ConstraintNotNull ) )
152  {
153  constraintDescription.push_back( tr( "Not null" ) );
154  }
155  if ( constraints.testFlag( QgsFieldConstraints::Constraint::ConstraintExpression ) )
156  {
157  constraintDescription.push_back( tr( "Expression" ) );
158  }
159  return constraintDescription.join( QLatin1String( "<br>" ) );
160  }
161  break;
162  }
163  case Qt::BackgroundRole:
164  {
165  if ( constraints != 0 )
166  {
167  return QBrush( QColor( 255, 224, 178 ) );
168  }
169  break;
170  }
171  }
172  }
173  return QVariant();
174 }
175 
176 Qt::ItemFlags QgsFieldMappingModel::flags( const QModelIndex &index ) const
177 {
178  if ( index.isValid() &&
179  index.column() != static_cast<int>( ColumnDataIndex::DestinationConstraints ) &&
180  ( index.column() == static_cast<int>( ColumnDataIndex::SourceExpression ) || destinationEditable() ) )
181  {
182  return Qt::ItemFlags( Qt::ItemIsSelectable |
183  Qt::ItemIsEditable |
184  Qt::ItemIsEnabled );
185  }
186  return Qt::ItemFlags();
187 }
188 
189 bool QgsFieldMappingModel::setData( const QModelIndex &index, const QVariant &value, int role )
190 {
191  if ( index.isValid() )
192  {
193  if ( role == Qt::EditRole )
194  {
195  Field &f = mMapping[index.row()];
196  switch ( static_cast<ColumnDataIndex>( index.column() ) )
197  {
199  {
200  const QgsExpression exp { value.toString() };
201  f.expression = exp;
202  break;
203  }
205  {
206  f.field.setName( value.toString() );
207  break;
208  }
210  {
211  setFieldTypeFromName( f.field, value.toString() );
212  break;
213  }
215  {
216  bool ok;
217  const int length { value.toInt( &ok ) };
218  if ( ok )
219  f.field.setLength( length );
220  break;
221  }
223  {
224  bool ok;
225  const int precision { value.toInt( &ok ) };
226  if ( ok )
228  break;
229  }
231  {
232  // Not editable: do nothing
233  }
234  }
235  emit dataChanged( index, index );
236  }
237  return true;
238  }
239  else
240  {
241  return false;
242  }
243 }
244 
245 QgsFieldConstraints::Constraints QgsFieldMappingModel::fieldConstraints( const QgsField &field ) const
246 {
247  QgsFieldConstraints::Constraints constraints;
248 
249  const QgsFieldConstraints fieldConstraints { field.constraints() };
250 
251  if ( fieldConstraints.constraints() & QgsFieldConstraints::ConstraintNotNull &&
253  constraints.setFlag( QgsFieldConstraints::ConstraintNotNull );
254 
255  if ( fieldConstraints.constraints() & QgsFieldConstraints::ConstraintUnique &&
257  constraints.setFlag( QgsFieldConstraints::ConstraintUnique );
258 
259  if ( fieldConstraints.constraints() & QgsFieldConstraints::ConstraintExpression &&
261  constraints.setFlag( QgsFieldConstraints::ConstraintExpression );
262 
263  return constraints;
264 }
265 
266 bool QgsFieldMappingModel::moveUpOrDown( const QModelIndex &index, bool up )
267 {
268  if ( ! index.isValid() && index.model() == this )
269  return false;
270 
271  // Always swap down
272  const int row { up ? index.row() - 1 : index.row() };
273  // Range checking
274  if ( row < 0 || row + 1 >= rowCount( QModelIndex() ) )
275  {
276  return false;
277  }
278  beginMoveRows( QModelIndex( ), row, row, QModelIndex(), row + 2 );
279 #if QT_VERSION < QT_VERSION_CHECK(5, 13, 0)
280  mMapping.swap( row, row + 1 );
281 #else
282  mMapping.swapItemsAt( row, row + 1 );
283 #endif
284  endMoveRows();
285  return true;
286 }
287 
288 QString QgsFieldMappingModel::findExpressionForDestinationField( const QgsFieldMappingModel::Field &f, QStringList &excludedFieldNames )
289 {
290  // Search for fields in the source
291  // 1. match by name
292  for ( const QgsField &sf : std::as_const( mSourceFields ) )
293  {
294  if ( sf.name() == f.field.name() )
295  {
296  excludedFieldNames.push_back( sf.name() );
297  return QgsExpression::quotedColumnRef( sf.name() );
298  }
299  }
300  // 2. match by type
301  for ( const QgsField &sf : std::as_const( mSourceFields ) )
302  {
303  if ( excludedFieldNames.contains( sf.name() ) || sf.type() != f.field.type() )
304  continue;
305  excludedFieldNames.push_back( sf.name() );
306  return QgsExpression::quotedColumnRef( sf.name() );
307  }
308  return QString();
309 }
310 
312 {
313  mSourceFields = sourceFields;
314  if ( mExpressionContextGenerator )
315  mExpressionContextGenerator->setSourceFields( mSourceFields );
316  QStringList usedFields;
317  beginResetModel();
318  for ( const Field &f : std::as_const( mMapping ) )
319  {
320  if ( QgsExpression( f.expression ).isField() )
321  {
322  usedFields.push_back( f.expression.mid( 1, f.expression.length() - 2 ) );
323  }
324  }
325  for ( auto it = mMapping.begin(); it != mMapping.end(); ++it )
326  {
327  if ( it->expression.isEmpty() )
328  {
329  const QString expression { findExpressionForDestinationField( *it, usedFields ) };
330  if ( ! expression.isEmpty() )
331  it->expression = expression;
332  }
333  }
334  endResetModel();
335 }
336 
338 {
339  return mExpressionContextGenerator.get();
340 }
341 
343 {
344  mExpressionContextGenerator->setBaseExpressionContextGenerator( generator );
345 }
346 
348  const QMap<QString, QString> &expressions )
349 {
350  beginResetModel();
351  mMapping.clear();
352  // Prepare the model data
353  QStringList usedFields;
354  for ( const QgsField &df : destinationFields )
355  {
356  Field f;
357  f.field = df;
358  f.field.setTypeName( qgsFieldToTypeName( df ) );
359  f.originalName = df.name();
360  if ( expressions.contains( f.field.name() ) )
361  {
362  f.expression = expressions.value( f.field.name() );
363  const QgsExpression exp { f.expression };
364  // if it's source field
365  if ( exp.isField() &&
366  mSourceFields.names().contains( qgis::setToList( exp.referencedColumns() ).first() ) )
367  {
368  usedFields.push_back( qgis::setToList( exp.referencedColumns() ).first() );
369  }
370  }
371  else
372  {
373  const QString expression { findExpressionForDestinationField( f, usedFields ) };
374  if ( ! expression.isEmpty() )
375  f.expression = expression;
376  }
377  mMapping.push_back( f );
378  }
379  endResetModel();
380 }
381 
383 {
384  return mDestinationEditable;
385 }
386 
387 void QgsFieldMappingModel::setDestinationEditable( bool destinationEditable )
388 {
389  mDestinationEditable = destinationEditable;
390 }
391 
392 const QMap<QVariant::Type, QString> QgsFieldMappingModel::dataTypes()
393 {
394  static const QMap<QVariant::Type, QString> sDataTypes
395  {
396  { QVariant::Type::Int, QgsVariantUtils::typeToDisplayString( QVariant::Type::Int ) },
397  { QVariant::Type::LongLong, QgsVariantUtils::typeToDisplayString( QVariant::Type::LongLong ) },
398  { QVariant::Type::Double, QgsVariantUtils::typeToDisplayString( QVariant::Type::Double ) },
399  { QVariant::Type::String, QgsVariantUtils::typeToDisplayString( QVariant::Type::String ) },
400  { QVariant::Type::Date, QgsVariantUtils::typeToDisplayString( QVariant::Type::Date ) },
401  { QVariant::Type::Time, QgsVariantUtils::typeToDisplayString( QVariant::Type::Time ) },
402  { QVariant::Type::DateTime, QgsVariantUtils::typeToDisplayString( QVariant::Type::DateTime ) },
403  { QVariant::Type::Bool, QgsVariantUtils::typeToDisplayString( QVariant::Type::Bool ) },
404  { QVariant::Type::ByteArray, QgsVariantUtils::typeToDisplayString( QVariant::Type::ByteArray ) },
405  };
406  return sDataTypes;
407 }
408 
409 const QList<QgsVectorDataProvider::NativeType> QgsFieldMappingModel::supportedDataTypes()
410 {
411  static const QList<QgsVectorDataProvider::NativeType> sDataTypes =
412  QList<QgsVectorDataProvider::NativeType>() << QgsVectorDataProvider::NativeType( QgsVariantUtils::typeToDisplayString( QVariant::Type::Int ), QStringLiteral( "integer" ), QVariant::Int )
413  << QgsVectorDataProvider::NativeType( QgsVariantUtils::typeToDisplayString( QVariant::Type::LongLong ), QStringLiteral( "int8" ), QVariant::LongLong )
414  << QgsVectorDataProvider::NativeType( QgsVariantUtils::typeToDisplayString( QVariant::Type::Double ), QStringLiteral( "double precision" ), QVariant::Double )
415  << QgsVectorDataProvider::NativeType( QgsVariantUtils::typeToDisplayString( QVariant::Type::String ), QStringLiteral( "text" ), QVariant::String )
416  << QgsVectorDataProvider::NativeType( QgsVariantUtils::typeToDisplayString( QVariant::Type::Date ), QStringLiteral( "date" ), QVariant::Date )
417  << QgsVectorDataProvider::NativeType( QgsVariantUtils::typeToDisplayString( QVariant::Type::Time ), QStringLiteral( "time" ), QVariant::Time )
418  << QgsVectorDataProvider::NativeType( QgsVariantUtils::typeToDisplayString( QVariant::Type::DateTime ), QStringLiteral( "datetime" ), QVariant::DateTime )
419  << QgsVectorDataProvider::NativeType( QgsVariantUtils::typeToDisplayString( QVariant::Type::Bool ), QStringLiteral( "boolean" ), QVariant::Bool )
420  << QgsVectorDataProvider::NativeType( QgsVariantUtils::typeToDisplayString( QVariant::Type::ByteArray ), QStringLiteral( "binary" ), QVariant::ByteArray )
421  << QgsVectorDataProvider::NativeType( QgsVariantUtils::typeToDisplayString( QVariant::Type::StringList ), QStringLiteral( "stringlist" ), QVariant::StringList, 0, 0, 0, 0, QVariant::String )
422  << QgsVectorDataProvider::NativeType( QgsVariantUtils::typeToDisplayString( QVariant::Type::List, QVariant::Type::Int ), QStringLiteral( "integerlist" ), QVariant::List, 0, 0, 0, 0, QVariant::Int )
423  << QgsVectorDataProvider::NativeType( QgsVariantUtils::typeToDisplayString( QVariant::Type::List, QVariant::Type::Double ), QStringLiteral( "doublelist" ), QVariant::List, 0, 0, 0, 0, QVariant::Double )
424  << QgsVectorDataProvider::NativeType( QgsVariantUtils::typeToDisplayString( QVariant::Type::List, QVariant::Type::LongLong ), QStringLiteral( "integer64list" ), QVariant::List, 0, 0, 0, 0, QVariant::LongLong );
425  return sDataTypes;
426 }
427 
428 const QString QgsFieldMappingModel::qgsFieldToTypeName( const QgsField &field )
429 {
430  const QList<QgsVectorDataProvider::NativeType> types = supportedDataTypes();
431  for ( const auto &type : types )
432  {
433  if ( type.mType == field.type() && type.mSubType == field.subType() )
434  {
435  return type.mTypeName;
436  }
437  }
438  return QString();
439 }
440 
441 void QgsFieldMappingModel::setFieldTypeFromName( QgsField &field, const QString &name )
442 {
443  const QList<QgsVectorDataProvider::NativeType> types = supportedDataTypes();
444  for ( const auto &type : types )
445  {
446  if ( type.mTypeName == name )
447  {
448  field.setType( type.mType );
449  field.setTypeName( type.mTypeName );
450  field.setSubType( type.mSubType );
451  return;
452  }
453  }
454 }
455 
456 QList<QgsFieldMappingModel::Field> QgsFieldMappingModel::mapping() const
457 {
458  return mMapping;
459 }
460 
461 QMap<QString, QgsProperty> QgsFieldMappingModel::fieldPropertyMap() const
462 {
463  QMap< QString, QgsProperty > fieldMap;
464  for ( const QgsFieldMappingModel::Field &field : mMapping )
465  {
466  const QgsExpression exp( field.expression );
467  const bool isField = exp.isField();
468  fieldMap.insert( field.originalName, isField
469  ? QgsProperty::fromField( static_cast<const QgsExpressionNodeColumnRef *>( exp.rootNode() )->name() )
470  : QgsProperty::fromExpression( field.expression ) );
471  }
472  return fieldMap;
473 }
474 
475 void QgsFieldMappingModel::setFieldPropertyMap( const QMap<QString, QgsProperty> &map )
476 {
477  beginResetModel();
478  for ( int i = 0; i < mMapping.count(); ++i )
479  {
480  Field &f = mMapping[i];
481  if ( map.contains( f.field.name() ) )
482  {
483  const QgsProperty prop = map.value( f.field.name() );
484  switch ( prop.propertyType() )
485  {
488  break;
489 
491  f.expression = prop.field();
492  break;
493 
495  f.expression = prop.expressionString();
496  break;
497 
499  f.expression.clear();
500  break;
501  }
502  }
503  else
504  {
505  f.expression.clear();
506  }
507  }
508  endResetModel();
509 }
510 
511 void QgsFieldMappingModel::appendField( const QgsField &field, const QString &expression )
512 {
513  const int lastRow { rowCount( QModelIndex( ) ) };
514  beginInsertRows( QModelIndex(), lastRow, lastRow );
515  Field f;
516  f.field = field;
517  f.field.setTypeName( qgsFieldToTypeName( field ) );
518  f.expression = expression;
519  f.originalName = field.name();
520  mMapping.push_back( f );
521  endInsertRows( );
522 }
523 
524 bool QgsFieldMappingModel::removeField( const QModelIndex &index )
525 {
526  if ( index.isValid() && index.model() == this && index.row() < rowCount( QModelIndex() ) )
527  {
528  beginRemoveRows( QModelIndex(), index.row(), index.row() );
529  mMapping.removeAt( index.row() );
530  endRemoveRows();
531  return true;
532  }
533  else
534  {
535  return false;
536  }
537 }
538 
539 bool QgsFieldMappingModel::moveUp( const QModelIndex &index )
540 {
541  return moveUpOrDown( index );
542 }
543 
544 bool QgsFieldMappingModel::moveDown( const QModelIndex &index )
545 {
546  return moveUpOrDown( index, false );
547 }
548 
549 QgsFieldMappingModel::ExpressionContextGenerator::ExpressionContextGenerator( const QgsFields &sourceFields )
550  : mSourceFields( sourceFields )
551 {
552 }
553 
554 QgsExpressionContext QgsFieldMappingModel::ExpressionContextGenerator::createExpressionContext() const
555 {
556  if ( mBaseGenerator )
557  {
558  QgsExpressionContext ctx = mBaseGenerator->createExpressionContext();
559  std::unique_ptr< QgsExpressionContextScope > fieldMappingScope = std::make_unique< QgsExpressionContextScope >( tr( "Field Mapping" ) );
560  fieldMappingScope->setFields( mSourceFields );
561  ctx.appendScope( fieldMappingScope.release() );
562  return ctx;
563  }
564  else
565  {
568  ctx.setFields( mSourceFields );
569  QgsFeature feature { mSourceFields };
570  feature.setValid( true );
571  ctx.setFeature( feature );
572  return ctx;
573  }
574 }
575 
576 void QgsFieldMappingModel::ExpressionContextGenerator::setBaseExpressionContextGenerator( const QgsExpressionContextGenerator *generator )
577 {
578  mBaseGenerator = generator;
579 }
580 
581 void QgsFieldMappingModel::ExpressionContextGenerator::setSourceFields( const QgsFields &fields )
582 {
583  mSourceFields = fields;
584 }
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.
Definition: qgsfeature.cpp:214
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.
@ 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:51
QString name
Definition: qgsfield.h:60
void setPrecision(int precision)
Set the field precision.
Definition: qgsfield.cpp:199
void setName(const QString &name)
Set the field name.
Definition: qgsfield.cpp:175
void setLength(int len)
Set the field length.
Definition: qgsfield.cpp:195
QVariant::Type type
Definition: qgsfield.h:58
QVariant::Type subType() const
If the field is a collection, gets its element's type.
Definition: qgsfield.cpp:134
void setSubType(QVariant::Type subType)
If the field is a collection, set its element's type.
Definition: qgsfield.cpp:185
void setType(QVariant::Type type)
Set variant type.
Definition: qgsfield.cpp:180
QgsFieldConstraints constraints
Definition: qgsfield.h:63
void setTypeName(const QString &typeName)
Set the field type.
Definition: qgsfield.cpp:190
Container of fields for a vector layer.
Definition: qgsfields.h:45
QStringList names() const
Returns a list with field names.
Definition: qgsfields.cpp:143
A store for object properties.
Definition: qgsproperty.h:231
@ ExpressionBasedProperty
Expression based property (QgsExpressionBasedProperty)
Definition: qgsproperty.h:240
@ StaticProperty
Static property (QgsStaticProperty)
Definition: qgsproperty.h:238
@ FieldBasedProperty
Field based property (QgsFieldBasedProperty)
Definition: qgsproperty.h:239
@ InvalidProperty
Invalid (not set) property.
Definition: qgsproperty.h:237
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.
const QgsField & field
Definition: qgsfield.h:463
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.