QGIS API Documentation 3.43.0-Master (9e873c7bc91)
Loading...
Searching...
No Matches
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;
31class QgsFieldMappingTypeDelegate;
32
40class GUI_EXPORT QgsFieldMappingWidget : public QgsPanelWidget
41{
42 Q_OBJECT
43
44 public:
57 explicit QgsFieldMappingWidget(
58 QWidget *parent = nullptr,
59 const QgsFields &sourceFields = QgsFields(),
60 const QgsFields &destinationFields = QgsFields(),
61 const QMap<QString, QString> &expressions = QMap<QString, QString>(),
62 const QList< QgsVectorDataProvider::NativeType > &nativeTypes = QList< QgsVectorDataProvider::NativeType >()
63 );
64
66 void setDestinationEditable( bool editable );
67
69 bool destinationEditable() const;
70
72 QgsFieldMappingModel *model() const;
73
75 QList<QgsFieldMappingModel::Field> mapping() const;
76
83 QMap<QString, QgsProperty> fieldPropertyMap() const;
84
90 void setFieldPropertyMap( const QMap<QString, QgsProperty> &map );
91
93 QItemSelectionModel *selectionModel();
94
96 void setSourceFields( const QgsFields &sourceFields );
97
103 void setSourceLayer( QgsVectorLayer *layer );
104
112 QgsVectorLayer *sourceLayer();
113
120 void setDestinationFields( const QgsFields &destinationFields, const QMap<QString, QString> &expressions = QMap<QString, QString>() );
121
131 void setNativeTypes( const QList< QgsVectorDataProvider::NativeType > &nativeTypes );
132
136 void scrollTo( const QModelIndex &index ) const;
137
142 void registerExpressionContextGenerator( const QgsExpressionContextGenerator *generator );
143
144 signals:
145
149 void changed();
150
151 public slots:
152
154 void appendField( const QgsField &field, const QString &expression = QString() );
155
157 bool removeSelectedFields();
158
160 bool moveSelectedFieldsUp();
161
163 bool moveSelectedFieldsDown();
164
170 void invertSelection();
171
172 private:
173 QTableView *mTableView = nullptr;
174 QgsFieldMappingModel *mModel = nullptr;
175
176 QgsFieldMappingTypeDelegate *mTypeDelegate = nullptr;
177
178 QPointer<QgsVectorLayer> mSourceLayer;
179 void updateColumns();
181 std::list<int> selectedRows();
182
184};
185
187
188#ifndef SIP_RUN
189
190class QgsFieldMappingExpressionDelegate : public QStyledItemDelegate
191{
192 Q_OBJECT
193
194 public:
195 QgsFieldMappingExpressionDelegate( QObject *parent = nullptr );
196
197 // QAbstractItemDelegate interface
198 QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
199 void setEditorData( QWidget *editor, const QModelIndex &index ) const override;
200 void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const override;
201};
202
203class QgsFieldMappingTypeDelegate : public QStyledItemDelegate
204{
205 Q_OBJECT
206
207 public:
208 QgsFieldMappingTypeDelegate( const QList< QgsVectorDataProvider::NativeType > &nativeTypes, QObject *parent = nullptr );
209
210 // QAbstractItemDelegate interface
211 QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
212 void setEditorData( QWidget *editor, const QModelIndex &index ) const override;
213 void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const override;
214
224 void setNativeTypes( const QList< QgsVectorDataProvider::NativeType > &nativeTypes );
225
226 private:
227 QList< QgsVectorDataProvider::NativeType > mNativeTypes;
228};
229
230#endif
231
233
234#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:46
Base class for any widget that can be shown as a inline panel.
Represents a vector layer which manages a vector based data sets.