QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 
23 #include "qgis_gui.h"
24 #include "qgsfieldmappingmodel.h"
25 #include "qgspanelwidget.h"
26 
27 class QTableView;
28 class QItemSelectionModel;
29 
37 class GUI_EXPORT QgsFieldMappingWidget : public QgsPanelWidget
38 {
39  Q_OBJECT
40 
41  public:
42 
50  explicit QgsFieldMappingWidget( QWidget *parent = nullptr,
51  const QgsFields &sourceFields = QgsFields(),
52  const QgsFields &destinationFields = QgsFields(),
53  const QMap<QString, QString> &expressions = QMap<QString, QString>() );
54 
56  void setDestinationEditable( bool editable );
57 
59  bool destinationEditable() const;
60 
62  QgsFieldMappingModel *model() const;
63 
65  QList<QgsFieldMappingModel::Field> mapping() const;
66 
73  QMap< QString, QgsProperty > fieldPropertyMap() const;
74 
80  void setFieldPropertyMap( const QMap< QString, QgsProperty > &map );
81 
83  QItemSelectionModel *selectionModel();
84 
86  void setSourceFields( const QgsFields &sourceFields );
87 
94  void setDestinationFields( const QgsFields &destinationFields,
95  const QMap<QString, QString> &expressions = QMap<QString, QString>() );
96 
100  void scrollTo( const QModelIndex &index ) const;
101 
106  void registerExpressionContextGenerator( const QgsExpressionContextGenerator *generator );
107 
108  signals:
109 
113  void changed();
114 
115  public slots:
116 
118  void appendField( const QgsField &field, const QString &expression = QString() );
119 
121  bool removeSelectedFields( );
122 
124  bool moveSelectedFieldsUp( );
125 
127  bool moveSelectedFieldsDown( );
128 
129  private:
130 
131  QTableView *mTableView = nullptr;
132  QAbstractTableModel *mModel = nullptr;
133  void updateColumns();
135  std::list<int> selectedRows( );
136 
137  class ExpressionDelegate: public QStyledItemDelegate
138  {
139 
140  public:
141 
142  ExpressionDelegate( QObject *parent = nullptr );
143 
144  // QAbstractItemDelegate interface
145  QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
146  void setEditorData( QWidget *editor, const QModelIndex &index ) const override;
147  void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const override;
148  };
149 
150  class TypeDelegate: public QStyledItemDelegate
151  {
152 
153  public:
154 
155  TypeDelegate( QObject *parent = nullptr );
156 
157  // QAbstractItemDelegate interface
158  QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
159  void setEditorData( QWidget *editor, const QModelIndex &index ) const override;
160  void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const override;
161  };
162 
164 
165 };
166 
167 
168 #endif // QGSFIELDMAPPINGWIDGET_H
QgsFields
Definition: qgsfields.h:44
QgsAggregateMappingWidget
Definition: qgsprocessingaggregatewidgets.h:148
QgsFieldMappingModel
Definition: qgsfieldmappingmodel.h:39
QgsPanelWidget
Base class for any widget that can be shown as a inline panel.
Definition: qgspanelwidget.h:29
qgspanelwidget.h
QgsExpressionContextGenerator
Definition: qgsexpressioncontextgenerator.h:36
QgsFieldMappingWidget
Definition: qgsfieldmappingwidget.h:37
qgsfieldmappingmodel.h
QgsField
Definition: qgsfield.h:49