QGIS API Documentation 3.41.0-Master (57ec4277f5e)
Loading...
Searching...
No Matches
qgsfieldmappingmodel.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsfieldmappingmodel.h - 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#ifndef QGSFIELDMAPPINGMODEL_H
17#define QGSFIELDMAPPINGMODEL_H
18
19#include <QAbstractTableModel>
20#include <QStyledItemDelegate>
21
22#include "qgsfields.h"
24#include "qgsfieldconstraints.h"
25#include "qgsproperty.h"
27#include "qgis_gui.h"
28
29
40class GUI_EXPORT QgsFieldMappingModel : public QAbstractTableModel
41{
42 Q_OBJECT
43
44 public:
48 enum class ColumnDataIndex : int
49 {
50 SourceExpression,
51 DestinationName,
52 DestinationType,
53 DestinationLength,
54 DestinationPrecision,
55 DestinationConstraints,
56 DestinationAlias,
57 DestinationComment,
58 };
59
61
65 struct Field
66 {
68 QString originalName;
72 QString expression;
73 };
74
82 QgsFieldMappingModel( const QgsFields &sourceFields = QgsFields(), const QgsFields &destinationFields = QgsFields(), const QMap<QString, QString> &expressions = QMap<QString, QString>(), QObject *parent = nullptr );
83
85 bool destinationEditable() const;
86
88 void setDestinationEditable( bool editable );
89
94 Q_DECL_DEPRECATED static const QMap<QMetaType::Type, QString> dataTypes();
95
100 static const QList<QgsVectorDataProvider::NativeType> supportedDataTypes();
101
103 QgsFields sourceFields() const;
104
106 QList<QgsFieldMappingModel::Field> mapping() const;
107
114 QMap<QString, QgsProperty> fieldPropertyMap() const;
115
121 void setFieldPropertyMap( const QMap<QString, QgsProperty> &map );
122
124 void appendField( const QgsField &field, const QString &expression = QString() );
125
127 bool removeField( const QModelIndex &index );
128
130 bool moveUp( const QModelIndex &index );
131
133 bool moveDown( const QModelIndex &index );
134
136 void setSourceFields( const QgsFields &sourceFields );
137
139 QgsExpressionContextGenerator *contextGenerator() const;
140
145 void setBaseExpressionContextGenerator( const QgsExpressionContextGenerator *generator );
146
152 void setDestinationFields( const QgsFields &destinationFields, const QMap<QString, QString> &expressions = QMap<QString, QString>() );
153
154
155 // QAbstractItemModel interface
156 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
157 int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
158 QVariant data( const QModelIndex &index, int role ) const override;
159 QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
160 Qt::ItemFlags flags( const QModelIndex &index ) const override;
161 bool setData( const QModelIndex &index, const QVariant &value, int role ) override;
162
163 private:
164 class ExpressionContextGenerator : public QgsExpressionContextGenerator
165 {
166 public:
167 ExpressionContextGenerator( const QgsFields &sourceFields );
168
169 // QgsExpressionContextGenerator interface
170 QgsExpressionContext createExpressionContext() const override;
171 void setBaseExpressionContextGenerator( const QgsExpressionContextGenerator *generator );
172 void setSourceFields( const QgsFields &fields );
173
174 private:
175 const QgsExpressionContextGenerator *mBaseGenerator = nullptr;
176
177 QgsFields mSourceFields;
178 };
179
180
181 QgsFieldConstraints::Constraints fieldConstraints( const QgsField &field ) const;
182
187 static const QString qgsFieldToTypeName( const QgsField &field );
188
193 static void setFieldTypeFromName( QgsField &field, const QString &name );
194
195 bool moveUpOrDown( const QModelIndex &index, bool up = true );
196
206 QString findExpressionForDestinationField( const QgsFieldMappingModel::Field &field, QStringList &excludedFieldNames );
207
208 QList<Field> mMapping;
209 bool mDestinationEditable = false;
210 QgsFields mSourceFields;
211 std::unique_ptr<ExpressionContextGenerator> mExpressionContextGenerator;
212
214};
215
216
217#endif // QGSFIELDMAPPINGMODEL_H
The QgsAggregateMappingModel holds mapping information for defining sets of aggregates of fields from...
Abstract interface for generating an expression context.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QFlags< Constraint > Constraints
The QgsFieldMappingModel holds mapping information for mapping from one set of QgsFields to another,...
ColumnDataIndex
The ColumnDataIndex enum represents the column index for the view.
Q_ENUM(ColumnDataIndex)
Encapsulate a field in an attribute table or data source.
Definition qgsfield.h:53
Container of fields for a vector layer.
Definition qgsfields.h:46
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.