QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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"
25 #include "qgsfieldmappingmodel.h"
26 #include "qgspanelwidget.h"
27 
28 class QTableView;
29 class QItemSelectionModel;
30 class QgsVectorLayer;
31 
39 class 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 
147  private:
148 
149  QTableView *mTableView = nullptr;
150  QAbstractTableModel *mModel = nullptr;
151 
152  QPointer< QgsVectorLayer > mSourceLayer;
153  void updateColumns();
155  std::list<int> selectedRows( );
156 
157  class ExpressionDelegate: public QStyledItemDelegate
158  {
159 
160  public:
161 
162  ExpressionDelegate( QObject *parent = nullptr );
163 
164  // QAbstractItemDelegate interface
165  QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
166  void setEditorData( QWidget *editor, const QModelIndex &index ) const override;
167  void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const override;
168  };
169 
170  class TypeDelegate: public QStyledItemDelegate
171  {
172 
173  public:
174 
175  TypeDelegate( QObject *parent = nullptr );
176 
177  // QAbstractItemDelegate interface
178  QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
179  void setEditorData( QWidget *editor, const QModelIndex &index ) const override;
180  void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const override;
181  };
182 
184 
185 };
186 
187 
188 #endif // QGSFIELDMAPPINGWIDGET_H
QgsFields
Container of fields for a vector layer.
Definition: qgsfields.h:45
field
const QgsField & field
Definition: qgsfield.h:456
QgsAggregateMappingWidget
The QgsAggregateMappingWidget class creates a mapping for defining sets of aggregates of fields from ...
Definition: qgsprocessingaggregatewidgets.h:150
QgsFieldMappingModel
The QgsFieldMappingModel holds mapping information for mapping from one set of QgsFields to another,...
Definition: qgsfieldmappingmodel.h:40
QgsPanelWidget
Base class for any widget that can be shown as a inline panel.
Definition: qgspanelwidget.h:30
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:387
qgspanelwidget.h
QgsFieldMappingWidget::changed
void changed()
Emitted when the fields defined in the widget are changed.
QgsExpressionContextGenerator
Abstract interface for generating an expression context.
Definition: qgsexpressioncontextgenerator.h:37
QgsFieldMappingWidget
The QgsFieldMappingWidget class creates a mapping from one set of QgsFields to another,...
Definition: qgsfieldmappingwidget.h:40
qgsfieldmappingmodel.h
QgsField
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:50