QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
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
35class QGridLayout;
36class QgsVectorLayer;
37class QPushButton;
41class QgsLayoutTableAvailableSortProxyModel;
42class QgsLayoutObject;
45
53class 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:
115
116};
117
126{
127 Q_OBJECT
128
129 public:
130
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
174 {}
175
176 QVector<QgsLayoutTableColumn> &columns() const override;
177
178 QList<Column> displayedColumns() const override
179 {
180 return {Attribute, SortOrder};
181 }
182};
183
191class 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
211class 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;
235 QgsExpressionContext createExpressionContext() const override;
236};
237
245class 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
266class 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
288class 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 QgsLayoutAttributeTableColumnModel *mColumnModel = nullptr;
312 QgsLayoutColumnAlignmentDelegate *mColumnAlignmentDelegate = nullptr;
313 QgsLayoutColumnSourceDelegate *mColumnSourceDelegate = nullptr;
314 QgsLayoutColumnWidthDelegate *mColumnWidthDelegate = nullptr;
315
316 QgsLayoutTableSortModel *mSortColumnModel = nullptr;
317 QgsLayoutColumnSourceDelegate *mSortColumnSourceDelegate = nullptr;
318 QgsLayoutColumnSortOrderDelegate *mSortColumnOrderDelegate = nullptr;
319
320
321};
322
323#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 sorting 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 QVector< QgsLayoutTableColumn > & columns() const =0
To be reimplemented to provide the display or the sort columns.
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.
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.
QgsLayoutTableSortModel(QgsLayoutItemAttributeTable *table, QObject *parent=nullptr)
Constructor for QgsLayoutTableSortColumnsProxyModel.
QList< Column > displayedColumns() const override
To be reimplemented to choose which column should be used by the model.
Represents a vector layer which manages a vector based data sets.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53