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