QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 }
QgsFieldMappingModel::setDestinationFields
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...
Definition: qgsfieldmappingmodel.cpp:347
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:406
QgsFieldMappingModel::contextGenerator
QgsExpressionContextGenerator * contextGenerator() const
Returns the context generator with the source fields.
Definition: qgsfieldmappingmodel.cpp:337
qgsexpressioncontextutils.h
QgsFieldMappingModel::QgsFieldMappingModel
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,...
Definition: qgsfieldmappingmodel.cpp:22
QgsProperty::fromField
static QgsProperty fromField(const QString &fieldName, bool isActive=true)
Returns a new FieldBasedProperty created from the specified field name.
Definition: qgsproperty.cpp:245
QgsProperty
A store for object properties.
Definition: qgsproperty.h:230
QgsField::setSubType
void setSubType(QVariant::Type subType)
If the field is a collection, set its element's type.
Definition: qgsfield.cpp:185
QgsExpressionContextUtils::globalScope
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context.
Definition: qgsexpressioncontextutils.cpp:40
QgsFieldMappingModel::Field::originalName
QString originalName
The original name of the field.
Definition: qgsfieldmappingmodel.h:82
QgsFieldMappingModel::removeField
bool removeField(const QModelIndex &index)
Removes the field at index from the model, returns true on success.
Definition: qgsfieldmappingmodel.cpp:524
QgsFieldConstraints
Stores information about constraints which may be present on a field.
Definition: qgsfieldconstraints.h:32
QgsExpression::rootNode
const QgsExpressionNode * rootNode() const
Returns the root node of the expression.
Definition: qgsexpression.cpp:1355
QgsExpressionNodeColumnRef
An expression node which takes it value from a feature's field.
Definition: qgsexpressionnodeimpl.h:512
QgsProperty::FieldBasedProperty
@ FieldBasedProperty
Field based property (QgsFieldBasedProperty)
Definition: qgsproperty.h:239
QgsFieldMappingModel::columnCount
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Definition: qgsfieldmappingmodel.cpp:91
QgsFields
Container of fields for a vector layer.
Definition: qgsfields.h:44
QgsFieldMappingModel::rowCount
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition: qgsfieldmappingmodel.cpp:84
QgsFieldMappingModel::ColumnDataIndex
ColumnDataIndex
The ColumnDataIndex enum represents the column index for the view.
Definition: qgsfieldmappingmodel.h:64
QgsFeature::setValid
void setValid(bool validity)
Sets the validity of the feature.
Definition: qgsfeature.cpp:221
QgsExpressionContext::setFields
void setFields(const QgsFields &fields)
Convenience function for setting a fields for the context.
Definition: qgsexpressioncontext.cpp:587
QgsFieldMappingModel::sourceFields
QgsFields sourceFields() const
Returns a list of source fields.
Definition: qgsfieldmappingmodel.cpp:79
QgsProperty::fromExpression
static QgsProperty fromExpression(const QString &expression, bool isActive=true)
Returns a new ExpressionBasedProperty created from the specified expression.
Definition: qgsproperty.cpp:237
field
const QgsField & field
Definition: qgsfield.h:463
QgsProperty::propertyType
Type propertyType() const
Returns the property type.
Definition: qgsproperty.cpp:286
QgsVectorDataProvider::NativeType
Definition: qgsvectordataprovider.h:471
QgsFieldMappingModel::dataTypes
static const Q_DECL_DEPRECATED QMap< QVariant::Type, QString > dataTypes()
Returns a static map of supported data types.
Definition: qgsfieldmappingmodel.cpp:392
QgsField::name
QString name
Definition: qgsfield.h:60
QgsFieldConstraints::ConstraintNotNull
@ ConstraintNotNull
Field may not be null.
Definition: qgsfieldconstraints.h:45
QgsFieldMappingModel::destinationEditable
bool destinationEditable() const
Returns true if the destination fields are editable.
Definition: qgsfieldmappingmodel.cpp:382
QgsProperty::value
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...
Definition: qgsproperty.cpp:585
QgsFieldMappingModel::supportedDataTypes
static const QList< QgsVectorDataProvider::NativeType > supportedDataTypes()
Returns a static list of supported data types.
Definition: qgsfieldmappingmodel.cpp:409
QgsFieldMappingModel::moveUp
bool moveUp(const QModelIndex &index)
Moves down the field at index.
Definition: qgsfieldmappingmodel.cpp:539
QgsProperty::expressionString
QString expressionString() const
Returns the expression used for the property value.
Definition: qgsproperty.cpp:389
QgsFieldMappingModel::setDestinationEditable
void setDestinationEditable(bool editable)
Sets the destination fields editable state to editable.
Definition: qgsfieldmappingmodel.cpp:387
QgsExpression::quotedValue
static QString quotedValue(const QVariant &value)
Returns a string representation of a literal value, including appropriate quotations where required.
Definition: qgsexpression.cpp:82
QgsFieldMappingModel::mapping
QList< QgsFieldMappingModel::Field > mapping() const
Returns a list of Field objects representing the current status of the model.
Definition: qgsfieldmappingmodel.cpp:456
QgsFieldMappingModel::appendField
void appendField(const QgsField &field, const QString &expression=QString())
Appends a new field to the model, with an optional expression.
Definition: qgsfieldmappingmodel.cpp:511
QgsFieldMappingModel::setBaseExpressionContextGenerator
void setBaseExpressionContextGenerator(const QgsExpressionContextGenerator *generator)
Sets the base expression context generator, which will generate the expression contexts for expressio...
Definition: qgsfieldmappingmodel.cpp:342
precision
int precision
Definition: qgswfsgetfeature.cpp:103
QgsProperty::ExpressionBasedProperty
@ ExpressionBasedProperty
Expression based property (QgsExpressionBasedProperty)
Definition: qgsproperty.h:240
QgsField::setTypeName
void setTypeName(const QString &typeName)
Set the field type.
Definition: qgsfield.cpp:190
QgsFieldMappingModel::Field::field
QgsField field
The field in its current status (it might have been renamed)
Definition: qgsfieldmappingmodel.h:84
QgsFieldMappingModel::flags
Qt::ItemFlags flags(const QModelIndex &index) const override
Definition: qgsfieldmappingmodel.cpp:176
qgsvariantutils.h
QgsFieldConstraints::ConstraintUnique
@ ConstraintUnique
Field must have a unique value.
Definition: qgsfieldconstraints.h:46
QgsField::setLength
void setLength(int len)
Set the field length.
Definition: qgsfield.cpp:195
QgsFieldMappingModel::setFieldPropertyMap
void setFieldPropertyMap(const QMap< QString, QgsProperty > &map)
Sets a map of destination field name to QgsProperty definition for field value.
Definition: qgsfieldmappingmodel.cpp:475
QgsFieldConstraints::ConstraintStrengthHard
@ ConstraintStrengthHard
Constraint must be honored before feature can be accepted.
Definition: qgsfieldconstraints.h:67
QgsExpressionContext::appendScope
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
Definition: qgsexpressioncontext.cpp:494
QgsField::subType
QVariant::Type subType() const
If the field is a collection, gets its element's type.
Definition: qgsfield.cpp:134
QgsVariantUtils::typeToDisplayString
static QString typeToDisplayString(QVariant::Type type, QVariant::Type subType=QVariant::Type::Invalid)
Returns a user-friendly translated string representing a QVariant type.
Definition: qgsvariantutils.cpp:19
QgsFieldMappingModel::ColumnDataIndex::DestinationPrecision
@ DestinationPrecision
Destination field precision.
QgsFieldMappingModel::Field
The Field struct holds information about a mapped field.
Definition: qgsfieldmappingmodel.h:79
qgsexpressionnodeimpl.h
QgsExpressionNodeColumnRef::name
QString name() const
The name of the column.
Definition: qgsexpressionnodeimpl.h:534
QgsField::setPrecision
void setPrecision(int precision)
Set the field precision.
Definition: qgsfield.cpp:199
QgsFieldMappingModel::ColumnDataIndex::SourceExpression
@ SourceExpression
Expression.
QgsFieldMappingModel::setData
bool setData(const QModelIndex &index, const QVariant &value, int role) override
Definition: qgsfieldmappingmodel.cpp:189
QgsFieldMappingModel::ColumnDataIndex::DestinationConstraints
@ DestinationConstraints
Destination field constraints.
QgsProperty::field
QString field() const
Returns the current field name the property references.
Definition: qgsproperty.cpp:357
QgsFieldConstraints::ConstraintExpression
@ ConstraintExpression
Field has an expression constraint set. See constraintExpression().
Definition: qgsfieldconstraints.h:47
QgsFieldMappingModel::data
QVariant data(const QModelIndex &index, int role) const override
Definition: qgsfieldmappingmodel.cpp:98
QgsExpression::quotedColumnRef
static QString quotedColumnRef(QString name)
Returns a quoted column reference (in double quotes)
Definition: qgsexpression.cpp:68
QgsField::constraints
QgsFieldConstraints constraints
Definition: qgsfield.h:63
QgsField::setType
void setType(QVariant::Type type)
Set variant type.
Definition: qgsfield.cpp:180
QgsFeature
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:55
QgsProperty::staticValue
QVariant staticValue() const
Returns the current static value for the property.
Definition: qgsproperty.cpp:341
QgsExpression::isField
bool isField() const
Checks whether an expression consists only of a single field reference.
Definition: qgsexpression.cpp:1360
QgsFieldMappingModel::fieldPropertyMap
QMap< QString, QgsProperty > fieldPropertyMap() const
Returns a map of destination field name to QgsProperty definition for field value,...
Definition: qgsfieldmappingmodel.cpp:461
QgsFieldMappingModel::setSourceFields
void setSourceFields(const QgsFields &sourceFields)
Set source fields to sourceFields.
Definition: qgsfieldmappingmodel.cpp:311
QgsFieldMappingModel::Field::expression
QString expression
The expression for the mapped field from the source fields.
Definition: qgsfieldmappingmodel.h:86
QgsExpression
Class for parsing and evaluation of expressions (formerly called "search strings")....
Definition: qgsexpression.h:102
QgsProperty::StaticProperty
@ StaticProperty
Static property (QgsStaticProperty)
Definition: qgsproperty.h:238
QgsFieldMappingModel::ColumnDataIndex::DestinationName
@ DestinationName
Destination field name.
QgsFieldMappingModel::moveDown
bool moveDown(const QModelIndex &index)
Moves up the field at index.
Definition: qgsfieldmappingmodel.cpp:544
QgsExpressionContextGenerator
Abstract interface for generating an expression context.
Definition: qgsexpressioncontextgenerator.h:36
QgsFieldMappingModel::ColumnDataIndex::DestinationLength
@ DestinationLength
Destination field length.
QgsFieldMappingModel::headerData
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
Definition: qgsfieldmappingmodel.cpp:33
QgsField::type
QVariant::Type type
Definition: qgsfield.h:58
QgsField::setName
void setName(const QString &name)
Set the field name.
Definition: qgsfield.cpp:175
qgsfieldmappingmodel.h
QgsProperty::InvalidProperty
@ InvalidProperty
Invalid (not set) property.
Definition: qgsproperty.h:237
QgsFields::names
QStringList names() const
Returns a list with field names.
Definition: qgsfields.cpp:143
QgsFieldMappingModel::ColumnDataIndex::DestinationType
@ DestinationType
Destination field type string.
QgsExpressionContext::setFeature
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
Definition: qgsexpressioncontext.cpp:525
QgsField
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:50