QGIS API Documentation 3.27.0-Master (f261cc1f8b)
qgsfieldmappingwidget.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsfieldmappingwidget.h - QgsFieldMappingWidget
3
4 ---------------------
5 begin : 16.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 QGSFIELDMAPPINGWIDGET_H
17#define QGSFIELDMAPPINGWIDGET_H
18
19#include <QWidget>
20#include <QAbstractTableModel>
21#include <QStyledItemDelegate>
22#include <QPointer>
23
24#include "qgis_gui.h"
26#include "qgspanelwidget.h"
27
28class QTableView;
29class QItemSelectionModel;
30class QgsVectorLayer;
31
39class GUI_EXPORT QgsFieldMappingWidget : public QgsPanelWidget
40{
41 Q_OBJECT
42
43 public:
44
52 explicit QgsFieldMappingWidget( QWidget *parent = nullptr,
53 const QgsFields &sourceFields = QgsFields(),
54 const QgsFields &destinationFields = QgsFields(),
55 const QMap<QString, QString> &expressions = QMap<QString, QString>() );
56
58 void setDestinationEditable( bool editable );
59
61 bool destinationEditable() const;
62
64 QgsFieldMappingModel *model() const;
65
67 QList<QgsFieldMappingModel::Field> mapping() const;
68
75 QMap< QString, QgsProperty > fieldPropertyMap() const;
76
82 void setFieldPropertyMap( const QMap< QString, QgsProperty > &map );
83
85 QItemSelectionModel *selectionModel();
86
88 void setSourceFields( const QgsFields &sourceFields );
89
95 void setSourceLayer( QgsVectorLayer *layer );
96
104 QgsVectorLayer *sourceLayer();
105
112 void setDestinationFields( const QgsFields &destinationFields,
113 const QMap<QString, QString> &expressions = QMap<QString, QString>() );
114
118 void scrollTo( const QModelIndex &index ) const;
119
124 void registerExpressionContextGenerator( const QgsExpressionContextGenerator *generator );
125
126 signals:
127
131 void changed();
132
133 public slots:
134
136 void appendField( const QgsField &field, const QString &expression = QString() );
137
139 bool removeSelectedFields( );
140
142 bool moveSelectedFieldsUp( );
143
145 bool moveSelectedFieldsDown( );
146
147 private:
148
149 QTableView *mTableView = nullptr;
150 QAbstractTableModel *mModel = nullptr;
151
152 QPointer< QgsVectorLayer > mSourceLayer;
153 void updateColumns();
155 std::list<int> selectedRows( );
156
158
159};
160
162
163#ifndef SIP_RUN
164
165class QgsFieldMappingExpressionDelegate: public QStyledItemDelegate
166{
167 Q_OBJECT
168
169 public:
170
171 QgsFieldMappingExpressionDelegate( QObject *parent = nullptr );
172
173 // QAbstractItemDelegate interface
174 QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
175 void setEditorData( QWidget *editor, const QModelIndex &index ) const override;
176 void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const override;
177};
178
179class QgsFieldMappingTypeDelegate: public QStyledItemDelegate
180{
181 Q_OBJECT
182
183 public:
184
185 QgsFieldMappingTypeDelegate( QObject *parent = nullptr );
186
187 // QAbstractItemDelegate interface
188 QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
189 void setEditorData( QWidget *editor, const QModelIndex &index ) const override;
190 void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const override;
191};
192
193#endif
194
196
197#endif // QGSFIELDMAPPINGWIDGET_H
The QgsAggregateMappingWidget class creates a mapping for defining sets of aggregates of fields from ...
Abstract interface for generating an expression context.
The QgsFieldMappingModel holds mapping information for mapping from one set of QgsFields to another,...
The QgsFieldMappingWidget class creates a mapping from one set of QgsFields to another,...
void changed()
Emitted when the fields defined in the widget are changed.
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:51
Container of fields for a vector layer.
Definition: qgsfields.h:45
Base class for any widget that can be shown as a inline panel.
Represents a vector layer which manages a vector based data sets.
const QgsField & field
Definition: qgsfield.h:463