QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
Classes | Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
QgsFieldMappingModel Class Reference

The QgsFieldMappingModel holds mapping information for mapping from one set of QgsFields to another, for each set of "destination" fields an expression defines how to obtain the values of the "destination" fields. The model can be optionally set "editable" allowing to modify all the fields, by default only the mapping expression is editable. More...

#include <qgsfieldmappingmodel.h>

Inheritance diagram for QgsFieldMappingModel:
Inheritance graph
[legend]

Classes

struct  Field
 The Field struct holds information about a mapped field. More...
 

Public Types

enum  ColumnDataIndex : int {
  ColumnDataIndex::SourceExpression, ColumnDataIndex::DestinationName, ColumnDataIndex::DestinationType, ColumnDataIndex::DestinationLength,
  ColumnDataIndex::DestinationPrecision, ColumnDataIndex::DestinationConstraints
}
 The ColumnDataIndex enum represents the column index for the view. More...
 

Public Member Functions

 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, initial values for the expressions can be optionally specified through expressions which is a map from the original field name to the corresponding expression. More...
 
void appendField (const QgsField &field, const QString &expression=QString())
 Appends a new field to the model, with an optional expression. More...
 
int columnCount (const QModelIndex &parent=QModelIndex()) const override
 
QgsExpressionContextGeneratorcontextGenerator () const
 Returns the context generator with the source fields. More...
 
QVariant data (const QModelIndex &index, int role) const override
 
bool destinationEditable () const
 Returns true if the destination fields are editable. More...
 
QMap< QString, QgsPropertyfieldPropertyMap () const
 Returns a map of destination field name to QgsProperty definition for field value, representing the current status of the model. More...
 
Qt::ItemFlags flags (const QModelIndex &index) const override
 
QVariant headerData (int section, Qt::Orientation orientation, int role) const override
 
QList< QgsFieldMappingModel::Fieldmapping () const
 Returns a list of Field objects representing the current status of the model. More...
 
bool moveDown (const QModelIndex &index)
 Moves up the field at index. More...
 
bool moveUp (const QModelIndex &index)
 Moves down the field at index. More...
 
 Q_ENUM (ColumnDataIndex)
 
bool removeField (const QModelIndex &index)
 Removes the field at index from the model, returns true on success. More...
 
int rowCount (const QModelIndex &parent=QModelIndex()) const override
 
void setBaseExpressionContextGenerator (const QgsExpressionContextGenerator *generator)
 Sets the base expression context generator, which will generate the expression contexts for expression based widgets used by the model. More...
 
bool setData (const QModelIndex &index, const QVariant &value, int role) override
 
void setDestinationEditable (bool editable)
 Sets the destination fields editable state to editable. More...
 
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 specified through expressions which is a map from the original field name to the corresponding expression. More...
 
void setFieldPropertyMap (const QMap< QString, QgsProperty > &map)
 Sets a map of destination field name to QgsProperty definition for field value. More...
 
void setSourceFields (const QgsFields &sourceFields)
 Set source fields to sourceFields. More...
 
QgsFields sourceFields () const
 Returns a list of source fields. More...
 

Static Public Member Functions

static const Q_DECL_DEPRECATED QMap< QVariant::Type, QString > dataTypes ()
 Returns a static map of supported data types. More...
 
static const QList< QgsVectorDataProvider::NativeTypesupportedDataTypes ()
 Returns a static list of supported data types. More...
 

Friends

class QgsAggregateMappingModel
 

Detailed Description

The QgsFieldMappingModel holds mapping information for mapping from one set of QgsFields to another, for each set of "destination" fields an expression defines how to obtain the values of the "destination" fields. The model can be optionally set "editable" allowing to modify all the fields, by default only the mapping expression is editable.

Since
QGIS 3.14

Definition at line 40 of file qgsfieldmappingmodel.h.

Member Enumeration Documentation

◆ ColumnDataIndex

The ColumnDataIndex enum represents the column index for the view.

Enumerator
SourceExpression 

Expression.

DestinationName 

Destination field name.

DestinationType 

Destination field type string.

DestinationLength 

Destination field length.

DestinationPrecision 

Destination field precision.

DestinationConstraints 

Destination field constraints.

Definition at line 64 of file qgsfieldmappingmodel.h.

Constructor & Destructor Documentation

◆ 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, initial values for the expressions can be optionally specified through expressions which is a map from the original field name to the corresponding expression.

A parent object can be also specified.

Definition at line 22 of file qgsfieldmappingmodel.cpp.

Member Function Documentation

◆ appendField()

void QgsFieldMappingModel::appendField ( const QgsField field,
const QString &  expression = QString() 
)

Appends a new field to the model, with an optional expression.

Definition at line 511 of file qgsfieldmappingmodel.cpp.

◆ columnCount()

int QgsFieldMappingModel::columnCount ( const QModelIndex &  parent = QModelIndex()) const
override

Definition at line 91 of file qgsfieldmappingmodel.cpp.

◆ contextGenerator()

QgsExpressionContextGenerator * QgsFieldMappingModel::contextGenerator ( ) const

Returns the context generator with the source fields.

Definition at line 337 of file qgsfieldmappingmodel.cpp.

◆ data()

QVariant QgsFieldMappingModel::data ( const QModelIndex &  index,
int  role 
) const
override

Definition at line 98 of file qgsfieldmappingmodel.cpp.

◆ dataTypes()

const QMap< QVariant::Type, QString > QgsFieldMappingModel::dataTypes ( )
static

Returns a static map of supported data types.

Deprecated:
QGIS 3.24 use supportedDataTypes() instead

Definition at line 392 of file qgsfieldmappingmodel.cpp.

◆ destinationEditable()

bool QgsFieldMappingModel::destinationEditable ( ) const

Returns true if the destination fields are editable.

Definition at line 382 of file qgsfieldmappingmodel.cpp.

◆ fieldPropertyMap()

QMap< QString, QgsProperty > QgsFieldMappingModel::fieldPropertyMap ( ) const

Returns a map of destination field name to QgsProperty definition for field value, representing the current status of the model.

See also
setFieldPropertyMap()

Definition at line 461 of file qgsfieldmappingmodel.cpp.

◆ flags()

Qt::ItemFlags QgsFieldMappingModel::flags ( const QModelIndex &  index) const
override

Definition at line 176 of file qgsfieldmappingmodel.cpp.

◆ headerData()

QVariant QgsFieldMappingModel::headerData ( int  section,
Qt::Orientation  orientation,
int  role 
) const
override

Definition at line 33 of file qgsfieldmappingmodel.cpp.

◆ mapping()

QList< QgsFieldMappingModel::Field > QgsFieldMappingModel::mapping ( ) const

Returns a list of Field objects representing the current status of the model.

Definition at line 456 of file qgsfieldmappingmodel.cpp.

◆ moveDown()

bool QgsFieldMappingModel::moveDown ( const QModelIndex &  index)

Moves up the field at index.

Definition at line 544 of file qgsfieldmappingmodel.cpp.

◆ moveUp()

bool QgsFieldMappingModel::moveUp ( const QModelIndex &  index)

Moves down the field at index.

Definition at line 539 of file qgsfieldmappingmodel.cpp.

◆ Q_ENUM()

QgsFieldMappingModel::Q_ENUM ( ColumnDataIndex  )

◆ removeField()

bool QgsFieldMappingModel::removeField ( const QModelIndex &  index)

Removes the field at index from the model, returns true on success.

Definition at line 524 of file qgsfieldmappingmodel.cpp.

◆ rowCount()

int QgsFieldMappingModel::rowCount ( const QModelIndex &  parent = QModelIndex()) const
override

Definition at line 84 of file qgsfieldmappingmodel.cpp.

◆ setBaseExpressionContextGenerator()

void QgsFieldMappingModel::setBaseExpressionContextGenerator ( const QgsExpressionContextGenerator generator)

Sets the base expression context generator, which will generate the expression contexts for expression based widgets used by the model.

Definition at line 342 of file qgsfieldmappingmodel.cpp.

◆ setData()

bool QgsFieldMappingModel::setData ( const QModelIndex &  index,
const QVariant &  value,
int  role 
)
override

Definition at line 189 of file qgsfieldmappingmodel.cpp.

◆ setDestinationEditable()

void QgsFieldMappingModel::setDestinationEditable ( bool  editable)

Sets the destination fields editable state to editable.

Definition at line 387 of file qgsfieldmappingmodel.cpp.

◆ setDestinationFields()

void QgsFieldMappingModel::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 specified through expressions which is a map from the original field name to the corresponding expression.

Definition at line 347 of file qgsfieldmappingmodel.cpp.

◆ setFieldPropertyMap()

void QgsFieldMappingModel::setFieldPropertyMap ( const QMap< QString, QgsProperty > &  map)

Sets a map of destination field name to QgsProperty definition for field value.

See also
fieldPropertyMap()

Definition at line 475 of file qgsfieldmappingmodel.cpp.

◆ setSourceFields()

void QgsFieldMappingModel::setSourceFields ( const QgsFields sourceFields)

Set source fields to sourceFields.

Definition at line 311 of file qgsfieldmappingmodel.cpp.

◆ sourceFields()

QgsFields QgsFieldMappingModel::sourceFields ( ) const

Returns a list of source fields.

Definition at line 79 of file qgsfieldmappingmodel.cpp.

◆ supportedDataTypes()

const QList< QgsVectorDataProvider::NativeType > QgsFieldMappingModel::supportedDataTypes ( )
static

Returns a static list of supported data types.

Since
QGIS 3.24

Definition at line 409 of file qgsfieldmappingmodel.cpp.

Friends And Related Function Documentation

◆ QgsAggregateMappingModel

friend class QgsAggregateMappingModel
friend

Definition at line 236 of file qgsfieldmappingmodel.h.


The documentation for this class was generated from the following files: