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