QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
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
152 void invertSelection( );
153
154 private:
155
156 QTableView *mTableView = nullptr;
157 QAbstractTableModel *mModel = nullptr;
158
159 QPointer< QgsVectorLayer > mSourceLayer;
160 void updateColumns();
162 std::list<int> selectedRows( );
163
165
166};
167
169
170#ifndef SIP_RUN
171
172class QgsFieldMappingExpressionDelegate: public QStyledItemDelegate
173{
174 Q_OBJECT
175
176 public:
177
178 QgsFieldMappingExpressionDelegate( QObject *parent = nullptr );
179
180 // QAbstractItemDelegate interface
181 QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
182 void setEditorData( QWidget *editor, const QModelIndex &index ) const override;
183 void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const override;
184};
185
186class QgsFieldMappingTypeDelegate: public QStyledItemDelegate
187{
188 Q_OBJECT
189
190 public:
191
192 QgsFieldMappingTypeDelegate( QObject *parent = nullptr );
193
194 // QAbstractItemDelegate interface
195 QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
196 void setEditorData( QWidget *editor, const QModelIndex &index ) const override;
197 void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const override;
198};
199
200#endif
201
203
204#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:53
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.