QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
qgslayoutattributeselectiondialog.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgslayoutattributeselectiondialog.h
3  -----------------------------------
4  begin : November 2017
5  copyright : (C) 2017 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef QGSLAYOUTATTRIBUTESELECTIONDIALOG_H
19 #define QGSLAYOUTATTRIBUTESELECTIONDIALOG_H
20 
21 // We don't want to expose this in the public API
22 #define SIP_NO_FILE
23 
24 #include <QDialog>
25 #include <QMap>
26 #include <QSet>
27 #include <QItemDelegate>
28 #include <QAbstractTableModel>
29 #include <QSortFilterProxyModel>
30 #include "qgis_gui.h"
31 #include "qgis_sip.h"
32 #include "ui_qgslayoutattributeselectiondialogbase.h"
34 
35 class QGridLayout;
36 class QgsVectorLayer;
37 class QPushButton;
41 class QgsLayoutTableAvailableSortProxyModel;
42 class QgsLayoutObject;
45 
53 class GUI_EXPORT QgsLayoutAttributeTableColumnModelBase: public QAbstractTableModel
54 {
55  Q_OBJECT
56 
57  public:
58 
63  {
65  ShiftDown
66  };
67 
71  enum Column
72  {
77  SortOrder
78  };
79 
86 
88  virtual QVector<QgsLayoutTableColumn> &columns() const = 0;
89 
91  virtual QList<Column> displayedColumns() const = 0;
92 
93  int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
94  int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
95  QVariant data( const QModelIndex &index, int role ) const override;
96  QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
97  bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
98  Qt::ItemFlags flags( const QModelIndex &index ) const override;
99  bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() ) override;
100  bool insertRows( int row, int count, const QModelIndex &parent = QModelIndex() ) override;
101  QModelIndex index( int row, int column, const QModelIndex &parent ) const override;
102  QModelIndex parent( const QModelIndex &child ) const override;
103 
111  bool moveRow( int row, ShiftDirection direction );
112 
113  protected:
114  QgsLayoutItemAttributeTable *mTable = nullptr;
115 
116 };
117 
126 {
127  Q_OBJECT
128 
129  public:
130 
137  : QgsLayoutAttributeTableColumnModelBase( table, parent )
138  {}
139 
140  QVector<QgsLayoutTableColumn> &columns() const override;
141 
142  QList<Column> displayedColumns() const override
143  {
144  return {Attribute, Heading, Alignment, Width};
145  }
146 
151  void resetToLayer();
152 };
153 
162 {
163  Q_OBJECT
164 
165  public:
166 
173  : QgsLayoutAttributeTableColumnModelBase( table, parent )
174  {}
175 
176  QVector<QgsLayoutTableColumn> &columns() const override;
177 
178  QList<Column> displayedColumns() const override
179  {
180  return {Attribute, SortOrder};
181  }
182 };
183 
191 class GUI_EXPORT QgsLayoutColumnAlignmentDelegate : public QItemDelegate
192 {
193  Q_OBJECT
194 
195  public:
197  explicit QgsLayoutColumnAlignmentDelegate( QObject *parent = nullptr );
198  QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
199  void setEditorData( QWidget *editor, const QModelIndex &index ) const override;
200  void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const override;
201  void updateEditorGeometry( QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
202 };
203 
211 class GUI_EXPORT QgsLayoutColumnSourceDelegate : public QItemDelegate, private QgsExpressionContextGenerator
212 {
213  Q_OBJECT
214 
215  public:
217  QgsLayoutColumnSourceDelegate( QgsVectorLayer *vlayer, QObject *parent = nullptr, const QgsLayoutObject *layoutObject = nullptr );
218  QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
219  void setEditorData( QWidget *editor, const QModelIndex &index ) const override;
220  void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const override;
221  void updateEditorGeometry( QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
222  private slots:
223  void commitAndCloseEditor();
224  private:
225  QgsVectorLayer *mVectorLayer = nullptr;
226  const QgsLayoutObject *mLayoutObject = nullptr;
227  QgsExpressionContext createExpressionContext() const override;
228 };
229 
237 class GUI_EXPORT QgsLayoutColumnWidthDelegate : public QItemDelegate
238 {
239  Q_OBJECT
240 
241  public:
243  explicit QgsLayoutColumnWidthDelegate( QObject *parent = nullptr );
244  QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
245  void setEditorData( QWidget *editor, const QModelIndex &index ) const override;
246  void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const override;
247  void updateEditorGeometry( QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
248 
249 };
250 
258 class GUI_EXPORT QgsLayoutColumnSortOrderDelegate : public QItemDelegate
259 {
260  Q_OBJECT
261 
262  public:
264  explicit QgsLayoutColumnSortOrderDelegate( QObject *parent = nullptr );
265  QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
266  void setEditorData( QWidget *editor, const QModelIndex &index ) const override;
267  void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const override;
268  void updateEditorGeometry( QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
269 
270 };
271 
272 
280 class GUI_EXPORT QgsLayoutAttributeSelectionDialog: public QDialog, private Ui::QgsLayoutAttributeSelectionDialogBase
281 {
282  Q_OBJECT
283  public:
285  QgsLayoutAttributeSelectionDialog( QgsLayoutItemAttributeTable *table, QgsVectorLayer *vLayer, QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags() );
286 
287  private slots:
288  void mRemoveColumnPushButton_clicked();
289  void mAddColumnPushButton_clicked();
290  void mColumnUpPushButton_clicked();
291  void mColumnDownPushButton_clicked();
292  void mResetColumnsPushButton_clicked();
293  void mClearColumnsPushButton_clicked();
294  void mAddSortColumnPushButton_clicked();
295  void mRemoveSortColumnPushButton_clicked();
296  void mSortColumnUpPushButton_clicked();
297  void mSortColumnDownPushButton_clicked();
298  void showHelp();
299 
300  private:
301  QgsLayoutItemAttributeTable *mTable = nullptr;
302 
303  const QgsVectorLayer *mVectorLayer = nullptr;
304 
305  QgsLayoutAttributeTableColumnModel *mColumnModel = nullptr;
306  QgsLayoutColumnAlignmentDelegate *mColumnAlignmentDelegate = nullptr;
307  QgsLayoutColumnSourceDelegate *mColumnSourceDelegate = nullptr;
308  QgsLayoutColumnWidthDelegate *mColumnWidthDelegate = nullptr;
309 
310  QgsLayoutTableSortModel *mSortColumnModel = nullptr;
311  QgsLayoutColumnSourceDelegate *mSortColumnSourceDelegate = nullptr;
312  QgsLayoutColumnSortOrderDelegate *mSortColumnOrderDelegate = nullptr;
313 
314 
315 };
316 
317 #endif // QGSLAYOUTATTRIBUTESELECTIONDIALOG_H
Abstract interface for generating an expression context.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
A dialog to select what attributes to display (in the table item), set the column properties and spec...
A base model to hold the displaying or sortings columns used in a QgsLayoutAttributeTable.
Column
Available columns for the configuration table to be used by the model.
@ Attribute
Attribute for a field or an expression.
@ Alignment
Defines the alignment of the column.
virtual QList< Column > displayedColumns() const =0
To be reimplemented to choose which column should be used by the model.
ShiftDirection
Controls whether a row/column is shifted up or down.
virtual QVector< QgsLayoutTableColumn > & columns() const =0
To be reimplemented to provide the display or the sort columns.
A model for displaying columns shown in a QgsLayoutAttributeTable.
QList< Column > displayedColumns() const override
To be reimplemented to choose which column should be used by the model.
QgsLayoutAttributeTableColumnModel(QgsLayoutItemAttributeTable *table, QObject *parent=nullptr)
Constructor for QgsLayoutAttributeTableColumnModel.
A delegate for showing column alignment as a combo box.
A delegate for showing column sort order as a combo box.
A delegate for showing column attribute source as a QgsFieldExpressionWidget.
A delegate for showing column width as a spin box.
A layout table subclass that displays attributes from a vector layer.
A base class for objects which belong to a layout.
Stores properties of a column for a QgsLayoutTable.
Allows for filtering QgsComposerAttributeTable columns by columns which are sorted or unsorted.
QList< Column > displayedColumns() const override
To be reimplemented to choose which column should be used by the model.
QgsLayoutTableSortModel(QgsLayoutItemAttributeTable *table, QObject *parent=nullptr)
Constructor for QgsLayoutTableSortColumnsProxyModel.
Represents a vector layer which manages a vector based data sets.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53