QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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;
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
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:370
QgsLayoutColumnSortOrderDelegate
A delegate for showing column sort order as a combo box.
Definition: qgslayoutattributeselectiondialog.h:259
QgsLayoutAttributeTableColumnModelBase::Column
Column
Available columns for the configuration table to be used by the model.
Definition: qgslayoutattributeselectiondialog.h:72
QgsLayoutAttributeTableColumnModelBase::ShiftUp
@ ShiftUp
Shift the row/column up.
Definition: qgslayoutattributeselectiondialog.h:64
QgsLayoutAttributeTableColumnModelBase::columns
virtual QVector< QgsLayoutTableColumn > & columns() const =0
To be reimplemented to provide the display or the sort columns.
QgsLayoutAttributeTableColumnModelBase::Heading
@ Heading
Defines the title of the column.
Definition: qgslayoutattributeselectiondialog.h:74
QgsLayoutColumnSourceDelegate
A delegate for showing column attribute source as a QgsFieldExpressionWidget.
Definition: qgslayoutattributeselectiondialog.h:212
QgsLayoutAttributeSelectionDialog
A dialog to select what attributes to display (in the table item), set the column properties and spec...
Definition: qgslayoutattributeselectiondialog.h:281
QgsLayoutAttributeTableColumnModelBase::displayedColumns
virtual QList< Column > displayedColumns() const =0
To be reimplemented to choose which column should be used by the model.
QgsLayoutAttributeTableColumnModelBase::Width
@ Width
Defines the width of the column.
Definition: qgslayoutattributeselectiondialog.h:76
QgsLayoutAttributeTableColumnModelBase::Attribute
@ Attribute
Attribute for a field or an expression.
Definition: qgslayoutattributeselectiondialog.h:73
QgsLayoutTableSortModel
Allows for filtering QgsComposerAttributeTable columns by columns which are sorted or unsorted.
Definition: qgslayoutattributeselectiondialog.h:162
QgsLayoutAttributeTableColumnModel::QgsLayoutAttributeTableColumnModel
QgsLayoutAttributeTableColumnModel(QgsLayoutItemAttributeTable *table, QObject *parent=nullptr)
Constructor for QgsLayoutAttributeTableColumnModel.
Definition: qgslayoutattributeselectiondialog.h:136
qgis_sip.h
QgsExpressionContextGenerator::createExpressionContext
virtual QgsExpressionContext createExpressionContext() const =0
This method needs to be reimplemented in all classes which implement this interface and return an exp...
QgsLayoutItemAttributeTable
A layout table subclass that displays attributes from a vector layer.
Definition: qgslayoutitemattributetable.h:35
QgsLayoutAttributeTableColumnModelBase
A base model to hold the displaying or sortings columns used in a QgsLayoutAttributeTable.
Definition: qgslayoutattributeselectiondialog.h:54
QgsLayoutAttributeTableColumnModelBase::Alignment
@ Alignment
Defines the alignment of the column.
Definition: qgslayoutattributeselectiondialog.h:75
QgsLayoutAttributeTableColumnModel::displayedColumns
QList< Column > displayedColumns() const override
To be reimplemented to choose which column should be used by the model.
Definition: qgslayoutattributeselectiondialog.h:142
QgsLayoutTableSortModel::QgsLayoutTableSortModel
QgsLayoutTableSortModel(QgsLayoutItemAttributeTable *table, QObject *parent=nullptr)
Constructor for QgsLayoutTableSortColumnsProxyModel.
Definition: qgslayoutattributeselectiondialog.h:172
qgsexpressioncontextgenerator.h
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:387
QgsLayoutAttributeTableColumnModelBase::ShiftDirection
ShiftDirection
Controls whether a row/column is shifted up or down.
Definition: qgslayoutattributeselectiondialog.h:63
QgsLayoutColumnWidthDelegate
A delegate for showing column width as a spin box.
Definition: qgslayoutattributeselectiondialog.h:238
QgsLayoutAttributeTableColumnModel
A model for displaying columns shown in a QgsLayoutAttributeTable.
Definition: qgslayoutattributeselectiondialog.h:126
QgsLayoutTableColumn
Stores properties of a column for a QgsLayoutTable.
Definition: qgslayouttablecolumn.h:37
QgsExpressionContextGenerator
Abstract interface for generating an expression context.
Definition: qgsexpressioncontextgenerator.h:37
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
QgsLayoutObject
A base class for objects which belong to a layout.
Definition: qgslayoutobject.h:40
QgsLayoutColumnAlignmentDelegate
A delegate for showing column alignment as a combo box.
Definition: qgslayoutattributeselectiondialog.h:192
QgsLayoutTableSortModel::displayedColumns
QList< Column > displayedColumns() const override
To be reimplemented to choose which column should be used by the model.
Definition: qgslayoutattributeselectiondialog.h:178