QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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:
216 
223  QgsLayoutColumnSourceDelegate( QgsVectorLayer *vlayer, QObject *parent = nullptr, const QgsLayoutObject *layoutObject = nullptr, bool forceExpressions = false );
224 
225  QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
226  void setEditorData( QWidget *editor, const QModelIndex &index ) const override;
227  void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const override;
228  void updateEditorGeometry( QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
229  private slots:
230  void commitAndCloseEditor();
231  private:
232  QgsVectorLayer *mVectorLayer = nullptr;
233  const QgsLayoutObject *mLayoutObject = nullptr;
234  bool mForceExpressions = false;
236 };
237 
245 class GUI_EXPORT QgsLayoutColumnWidthDelegate : public QItemDelegate
246 {
247  Q_OBJECT
248 
249  public:
251  explicit QgsLayoutColumnWidthDelegate( QObject *parent = nullptr );
252  QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
253  void setEditorData( QWidget *editor, const QModelIndex &index ) const override;
254  void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const override;
255  void updateEditorGeometry( QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
256 
257 };
258 
266 class GUI_EXPORT QgsLayoutColumnSortOrderDelegate : public QItemDelegate
267 {
268  Q_OBJECT
269 
270  public:
272  explicit QgsLayoutColumnSortOrderDelegate( QObject *parent = nullptr );
273  QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
274  void setEditorData( QWidget *editor, const QModelIndex &index ) const override;
275  void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const override;
276  void updateEditorGeometry( QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
277 
278 };
279 
280 
288 class GUI_EXPORT QgsLayoutAttributeSelectionDialog: public QDialog, private Ui::QgsLayoutAttributeSelectionDialogBase
289 {
290  Q_OBJECT
291  public:
293  QgsLayoutAttributeSelectionDialog( QgsLayoutItemAttributeTable *table, QgsVectorLayer *vLayer, QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags() );
294 
295  private slots:
296  void mRemoveColumnPushButton_clicked();
297  void mAddColumnPushButton_clicked();
298  void mColumnUpPushButton_clicked();
299  void mColumnDownPushButton_clicked();
300  void mResetColumnsPushButton_clicked();
301  void mClearColumnsPushButton_clicked();
302  void mAddSortColumnPushButton_clicked();
303  void mRemoveSortColumnPushButton_clicked();
304  void mSortColumnUpPushButton_clicked();
305  void mSortColumnDownPushButton_clicked();
306  void showHelp();
307 
308  private:
309  QgsLayoutItemAttributeTable *mTable = nullptr;
310 
311  const QgsVectorLayer *mVectorLayer = nullptr;
312 
313  QgsLayoutAttributeTableColumnModel *mColumnModel = nullptr;
314  QgsLayoutColumnAlignmentDelegate *mColumnAlignmentDelegate = nullptr;
315  QgsLayoutColumnSourceDelegate *mColumnSourceDelegate = nullptr;
316  QgsLayoutColumnWidthDelegate *mColumnWidthDelegate = nullptr;
317 
318  QgsLayoutTableSortModel *mSortColumnModel = nullptr;
319  QgsLayoutColumnSourceDelegate *mSortColumnSourceDelegate = nullptr;
320  QgsLayoutColumnSortOrderDelegate *mSortColumnOrderDelegate = nullptr;
321 
322 
323 };
324 
325 #endif // QGSLAYOUTATTRIBUTESELECTIONDIALOG_H
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:406
QgsLayoutColumnSortOrderDelegate
A delegate for showing column sort order as a combo box.
Definition: qgslayoutattributeselectiondialog.h:266
QgsLayoutAttributeTableColumnModelBase::Column
Column
Available columns for the configuration table to be used by the model.
Definition: qgslayoutattributeselectiondialog.h:71
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:211
QgsLayoutAttributeSelectionDialog
A dialog to select what attributes to display (in the table item), set the column properties and spec...
Definition: qgslayoutattributeselectiondialog.h:288
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:161
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:34
QgsLayoutAttributeTableColumnModelBase
A base model to hold the displaying or sortings columns used in a QgsLayoutAttributeTable.
Definition: qgslayoutattributeselectiondialog.h:53
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:391
QgsLayoutAttributeTableColumnModelBase::ShiftDirection
ShiftDirection
Controls whether a row/column is shifted up or down.
Definition: qgslayoutattributeselectiondialog.h:62
QgsLayoutColumnWidthDelegate
A delegate for showing column width as a spin box.
Definition: qgslayoutattributeselectiondialog.h:245
QgsLayoutAttributeTableColumnModel
A model for displaying columns shown in a QgsLayoutAttributeTable.
Definition: qgslayoutattributeselectiondialog.h:125
QgsLayoutTableColumn
Stores properties of a column for a QgsLayoutTable.
Definition: qgslayouttablecolumn.h:37
QgsExpressionContextGenerator
Abstract interface for generating an expression context.
Definition: qgsexpressioncontextgenerator.h:36
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
QgsLayoutObject
A base class for objects which belong to a layout.
Definition: qgslayoutobject.h:39
QgsLayoutColumnAlignmentDelegate
A delegate for showing column alignment as a combo box.
Definition: qgslayoutattributeselectiondialog.h:191
QgsLayoutTableSortModel::displayedColumns
QList< Column > displayedColumns() const override
To be reimplemented to choose which column should be used by the model.
Definition: qgslayoutattributeselectiondialog.h:178