QGIS API Documentation 3.43.0-Master (b60ef06885e)
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
39class GUI_EXPORT QgsFieldMappingWidget : public QgsPanelWidget
40{
41 Q_OBJECT
42
43 public:
56 explicit QgsFieldMappingWidget(
57 QWidget *parent = nullptr,
58 const QgsFields &sourceFields = QgsFields(),
59 const QgsFields &destinationFields = QgsFields(),
60 const QMap<QString, QString> &expressions = QMap<QString, QString>(),
61 const QList< QgsVectorDataProvider::NativeType > &nativeTypes = QList< QgsVectorDataProvider::NativeType >()
62 );
63
65 void setDestinationEditable( bool editable );
66
68 bool destinationEditable() const;
69
71 QgsFieldMappingModel *model() const;
72
74 QList<QgsFieldMappingModel::Field> mapping() const;
75
82 QMap<QString, QgsProperty> fieldPropertyMap() const;
83
89 void setFieldPropertyMap( const QMap<QString, QgsProperty> &map );
90
92 QItemSelectionModel *selectionModel();
93
95 void setSourceFields( const QgsFields &sourceFields );
96
102 void setSourceLayer( QgsVectorLayer *layer );
103
111 QgsVectorLayer *sourceLayer();
112
119 void setDestinationFields( const QgsFields &destinationFields, const QMap<QString, QString> &expressions = QMap<QString, QString>() );
120
130 void setNativeTypes( const QList< QgsVectorDataProvider::NativeType > &nativeTypes );
131
135 void scrollTo( const QModelIndex &index ) const;
136
141 void registerExpressionContextGenerator( const QgsExpressionContextGenerator *generator );
142
143 signals:
144
148 void changed();
149
150 public slots:
151
153 void appendField( const QgsField &field, const QString &expression = QString() );
154
156 bool removeSelectedFields();
157
159 bool moveSelectedFieldsUp();
160
162 bool moveSelectedFieldsDown();
163
169 void invertSelection();
170
171 private:
172 QTableView *mTableView = nullptr;
173 QgsFieldMappingModel *mModel = nullptr;
174
175 QgsFieldMappingTypeDelegate *mTypeDelegate = nullptr;
176
177 QPointer<QgsVectorLayer> mSourceLayer;
178 void updateColumns();
180 std::list<int> selectedRows();
181
183};
184
186
187#ifndef SIP_RUN
188
189class QgsFieldMappingExpressionDelegate : public QStyledItemDelegate
190{
191 Q_OBJECT
192
193 public:
194 QgsFieldMappingExpressionDelegate( QObject *parent = nullptr );
195
196 // QAbstractItemDelegate interface
197 QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
198 void setEditorData( QWidget *editor, const QModelIndex &index ) const override;
199 void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const override;
200};
201
202class QgsFieldMappingTypeDelegate : public QStyledItemDelegate
203{
204 Q_OBJECT
205
206 public:
207 QgsFieldMappingTypeDelegate( const QList< QgsVectorDataProvider::NativeType > &nativeTypes, QObject *parent = nullptr );
208
209 // QAbstractItemDelegate interface
210 QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
211 void setEditorData( QWidget *editor, const QModelIndex &index ) const override;
212 void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const override;
213
223 void setNativeTypes( const QList< QgsVectorDataProvider::NativeType > &nativeTypes );
224
225 private:
226 QList< QgsVectorDataProvider::NativeType > mNativeTypes;
227};
228
229#endif
230
232
233#endif // QGSFIELDMAPPINGWIDGET_H
A widget which creates a mapping for defining sets of aggregates of fields from a QgsFields object.
Abstract interface for generating an expression context.
Holds mapping information for mapping from one set of QgsFields to another.
Creates a mapping from one set of QgsFields to another, for each set of "destination" fields an expre...
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 an inline panel.
Represents a vector layer which manages a vector based dataset.