QGIS API Documentation 3.41.0-Master (af5edcb665c)
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;
31
39class GUI_EXPORT QgsFieldMappingWidget : public QgsPanelWidget
40{
41 Q_OBJECT
42
43 public:
51 explicit QgsFieldMappingWidget( QWidget *parent = nullptr, const QgsFields &sourceFields = QgsFields(), const QgsFields &destinationFields = QgsFields(), const QMap<QString, QString> &expressions = QMap<QString, QString>() );
52
54 void setDestinationEditable( bool editable );
55
57 bool destinationEditable() const;
58
60 QgsFieldMappingModel *model() const;
61
63 QList<QgsFieldMappingModel::Field> mapping() const;
64
71 QMap<QString, QgsProperty> fieldPropertyMap() const;
72
78 void setFieldPropertyMap( const QMap<QString, QgsProperty> &map );
79
81 QItemSelectionModel *selectionModel();
82
84 void setSourceFields( const QgsFields &sourceFields );
85
91 void setSourceLayer( QgsVectorLayer *layer );
92
100 QgsVectorLayer *sourceLayer();
101
108 void setDestinationFields( const QgsFields &destinationFields, const QMap<QString, QString> &expressions = QMap<QString, QString>() );
109
113 void scrollTo( const QModelIndex &index ) const;
114
119 void registerExpressionContextGenerator( const QgsExpressionContextGenerator *generator );
120
121 signals:
122
126 void changed();
127
128 public slots:
129
131 void appendField( const QgsField &field, const QString &expression = QString() );
132
134 bool removeSelectedFields();
135
137 bool moveSelectedFieldsUp();
138
140 bool moveSelectedFieldsDown();
141
147 void invertSelection();
148
149 private:
150 QTableView *mTableView = nullptr;
151 QAbstractTableModel *mModel = nullptr;
152
153 QPointer<QgsVectorLayer> mSourceLayer;
154 void updateColumns();
156 std::list<int> selectedRows();
157
159};
160
162
163#ifndef SIP_RUN
164
165class QgsFieldMappingExpressionDelegate : public QStyledItemDelegate
166{
167 Q_OBJECT
168
169 public:
170 QgsFieldMappingExpressionDelegate( QObject *parent = nullptr );
171
172 // QAbstractItemDelegate interface
173 QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
174 void setEditorData( QWidget *editor, const QModelIndex &index ) const override;
175 void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const override;
176};
177
178class QgsFieldMappingTypeDelegate : public QStyledItemDelegate
179{
180 Q_OBJECT
181
182 public:
183 QgsFieldMappingTypeDelegate( QObject *parent = nullptr );
184
185 // QAbstractItemDelegate interface
186 QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
187 void setEditorData( QWidget *editor, const QModelIndex &index ) const override;
188 void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const override;
189};
190
191#endif
192
194
195#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.