QGIS API Documentation 4.3.0-Master (16649ce5cc6)
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 "qgis_gui.h"
21#include "qgspanelwidget.h"
22
23#include <QAbstractTableModel>
24#include <QPointer>
25#include <QStyledItemDelegate>
26#include <QWidget>
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
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
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
142
143 public slots:
144
146 void appendField( const QgsField &field, const QString &expression = QString() );
147
150
153
156
162 void invertSelection();
163
164 private:
165 QTableView *mTableView = nullptr;
166 QgsFieldMappingModel *mModel = nullptr;
167
168 QgsFieldMappingTypeDelegate *mTypeDelegate = nullptr;
169
170 QPointer<QgsVectorLayer> mSourceLayer;
171 void updateColumns();
173 std::list<int> selectedRows();
174
176};
177
179
180#ifndef SIP_RUN
181
182class QgsFieldMappingExpressionDelegate : public QStyledItemDelegate
183{
184 Q_OBJECT
185
186 public:
187 QgsFieldMappingExpressionDelegate( QObject *parent = nullptr );
188
189 // QAbstractItemDelegate interface
190 QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
191 void setEditorData( QWidget *editor, const QModelIndex &index ) const override;
192 void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const override;
193};
194
195class QgsFieldMappingTypeDelegate : public QStyledItemDelegate
196{
197 Q_OBJECT
198
199 public:
200 QgsFieldMappingTypeDelegate( const QList< QgsVectorDataProvider::NativeType > &nativeTypes, QObject *parent = nullptr );
201
202 // QAbstractItemDelegate interface
203 QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
204 void setEditorData( QWidget *editor, const QModelIndex &index ) const override;
205 void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const override;
206
216 void setNativeTypes( const QList< QgsVectorDataProvider::NativeType > &nativeTypes );
217
218 private:
219 QList< QgsVectorDataProvider::NativeType > mNativeTypes;
220};
221
222#endif
223
225
226#endif // QGSFIELDMAPPINGWIDGET_H
Abstract interface for generating an expression context.
Holds mapping information for mapping from one set of QgsFields to another.
bool removeSelectedFields()
Removes the currently selected field from the model.
void setSourceLayer(QgsVectorLayer *layer)
Sets a source layer to use when generating expression previews in the widget.
QgsFieldMappingModel * model() const
Returns the underlying mapping model.
void registerExpressionContextGenerator(const QgsExpressionContextGenerator *generator)
Register an expression context generator class that will be used to retrieve an expression context fo...
bool moveSelectedFieldsDown()
Moves down the currently selected field.
QgsFieldMappingWidget(QWidget *parent=nullptr, const QgsFields &sourceFields=QgsFields(), const QgsFields &destinationFields=QgsFields(), const QMap< QString, QString > &expressions=QMap< QString, QString >(), const QList< QgsVectorDataProvider::NativeType > &nativeTypes=QList< QgsVectorDataProvider::NativeType >())
Constructs a QgsFieldMappingWidget from a set of sourceFields and destinationFields,...
QItemSelectionModel * selectionModel()
Returns the selection model.
void setSourceFields(const QgsFields &sourceFields)
Set source fields of the underlying mapping model to sourceFields.
QMap< QString, QgsProperty > fieldPropertyMap() const
Returns a map of destination field name to QgsProperty definition for field value,...
bool moveSelectedFieldsUp()
Moves up currently selected field.
void invertSelection()
Invert the field selection state.
QList< QgsFieldMappingModel::Field > mapping() const
Returns a list of Field objects representing the current status of the underlying mapping model.
void setFieldPropertyMap(const QMap< QString, QgsProperty > &map)
Sets a map of destination field name to QgsProperty definition for field value.
QgsVectorLayer * sourceLayer()
Returns the source layer for use when generating expression previews.
void setDestinationFields(const QgsFields &destinationFields, const QMap< QString, QString > &expressions=QMap< QString, QString >())
Set destination fields to destinationFields in the underlying model, initial values for the expressio...
void setDestinationEditable(bool editable)
Sets the destination fields editable state to editable.
void appendField(const QgsField &field, const QString &expression=QString())
Appends a new field to the model, with an optional expression.
void scrollTo(const QModelIndex &index) const
Scroll the fields view to index.
void setNativeTypes(const QList< QgsVectorDataProvider::NativeType > &nativeTypes)
Sets the list of nativeTypes supported by a data provider.
bool destinationEditable() const
Returns true if the destination fields are editable in the model.
Encapsulate a field in an attribute table or data source.
Definition qgsfield.h:56
Container of fields for a vector layer.
Definition qgsfields.h:45
QgsPanelWidget(QWidget *parent=nullptr)
Base class for any widget that can be shown as an inline panel.
Represents a vector layer which manages a vector based dataset.