QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
qgsprocessingaggregatewidgets.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsprocessingaggregatewidgets.h
3 ---------------------
4 Date : June 2020
5 Copyright : (C) 2020 by Nyall Dawson
6 Email : nyall dot dawson at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#ifndef QGSPROCESSINGAGGREGATEWIDGETS_H
17#define QGSPROCESSINGAGGREGATEWIDGETS_H
18
19#include <QAbstractTableModel>
20#include <QStyledItemDelegate>
21#include <QPointer>
22
23#include "qgsfields.h"
26#include "qgspanelwidget.h"
27
28class QLineEdit;
29class QToolButton;
30class QItemSelectionModel;
31class QTableView;
32
33
41class GUI_EXPORT QgsAggregateMappingModel : public QAbstractTableModel
42{
43 Q_OBJECT
44
45 public:
49 enum class ColumnDataIndex : int
50 {
51 SourceExpression,
52 Aggregate,
53 Delimiter,
54 DestinationName,
55 DestinationType,
56 DestinationLength,
57 DestinationPrecision,
58 };
59
61
65 struct Aggregate
66 {
68 QString source;
69
71 QString aggregate;
72
74 QString delimiter;
75
78 };
79
84 QgsAggregateMappingModel( const QgsFields &sourceFields = QgsFields(), QObject *parent = nullptr );
85
87 QgsFields sourceFields() const;
88
90 QList<QgsAggregateMappingModel::Aggregate> mapping() const;
91
95 void setMapping( const QList<QgsAggregateMappingModel::Aggregate> &mapping );
96
98 void appendField( const QgsField &field, const QString &source = QString(), const QString &aggregate = QString() );
99
101 bool removeField( const QModelIndex &index );
102
104 bool moveUp( const QModelIndex &index );
105
107 bool moveDown( const QModelIndex &index );
108
110 void setSourceFields( const QgsFields &sourceFields );
111
113 QgsExpressionContextGenerator *contextGenerator() const;
114
119 void setBaseExpressionContextGenerator( const QgsExpressionContextGenerator *generator );
120
121 // QAbstractItemModel interface
122 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
123 int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
124 QVariant data( const QModelIndex &index, int role ) const override;
125 QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
126 Qt::ItemFlags flags( const QModelIndex &index ) const override;
127 bool setData( const QModelIndex &index, const QVariant &value, int role ) override;
128
129 private:
130 bool moveUpOrDown( const QModelIndex &index, bool up = true );
131
132 QList<Aggregate> mMapping;
133 QgsFields mSourceFields;
134 std::unique_ptr<QgsFieldMappingModel::ExpressionContextGenerator> mExpressionContextGenerator;
135};
136
144{
145 Q_OBJECT
146
147 public:
152 explicit QgsAggregateMappingWidget( QWidget *parent = nullptr, const QgsFields &sourceFields = QgsFields() );
153
155 QgsAggregateMappingModel *model() const;
156
158 QList<QgsAggregateMappingModel::Aggregate> mapping() const;
159
163 void setMapping( const QList<QgsAggregateMappingModel::Aggregate> &mapping );
164
166 QItemSelectionModel *selectionModel();
167
169 void setSourceFields( const QgsFields &sourceFields );
170
176 void setSourceLayer( QgsVectorLayer *layer );
177
185 QgsVectorLayer *sourceLayer();
186
190 void scrollTo( const QModelIndex &index ) const;
191
196 void registerExpressionContextGenerator( const QgsExpressionContextGenerator *generator );
197
198 signals:
199
203 void changed();
204
205 public slots:
206
208 void appendField( const QgsField &field, const QString &source = QString(), const QString &aggregate = QString() );
209
211 bool removeSelectedFields();
212
214 bool moveSelectedFieldsUp();
215
217 bool moveSelectedFieldsDown();
218
219 private:
220 QTableView *mTableView = nullptr;
221 QAbstractTableModel *mModel = nullptr;
222 QPointer<QgsVectorLayer> mSourceLayer;
223 void updateColumns();
225 std::list<int> selectedRows();
226};
227
229
230#ifndef SIP_RUN
231
232class QgsAggregateMappingDelegate : public QStyledItemDelegate
233{
234 Q_OBJECT
235
236 public:
237 QgsAggregateMappingDelegate( QObject *parent = nullptr );
238
239 // QAbstractItemDelegate interface
240 QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
241 void setEditorData( QWidget *editor, const QModelIndex &index ) const override;
242 void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const override;
243
244 private:
246 static const QStringList aggregates();
247};
248
249#endif
250
252
253#endif // QGSPROCESSINGAGGREGATEWIDGETS_H
The QgsAggregateMappingModel holds mapping information for defining sets of aggregates of fields from...
Q_ENUM(ColumnDataIndex)
ColumnDataIndex
The ColumnDataIndex enum represents the column index for the view.
The QgsAggregateMappingWidget class creates a mapping for defining sets of aggregates of fields from ...
void changed()
Emitted when the aggregates defined in the widget are changed.
Abstract interface for generating an expression context.
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.
The Aggregate struct holds information about an aggregate column.
QString source
The source expression used as the input for the aggregate calculation.
QgsField field
The field in its current status (it might have been renamed)