QGIS API Documentation 3.41.0-Master (af5edcb665c)
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:
62 {
64 ShiftDown
65 };
66
70 enum Column
71 {
76 SortOrder
77 };
78
85
87 virtual QVector<QgsLayoutTableColumn> &columns() const = 0;
88
90 virtual QList<Column> displayedColumns() const = 0;
91
92 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
93 int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
94 QVariant data( const QModelIndex &index, int role ) const override;
95 QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
96 bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
97 Qt::ItemFlags flags( const QModelIndex &index ) const override;
98 bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() ) override;
99 bool insertRows( int row, int count, const QModelIndex &parent = QModelIndex() ) override;
100 QModelIndex index( int row, int column, const QModelIndex &parent ) const override;
101 QModelIndex parent( const QModelIndex &child ) const override;
102
110 bool moveRow( int row, ShiftDirection direction );
111
112 protected:
114};
115
124{
125 Q_OBJECT
126
127 public:
136
137 QVector<QgsLayoutTableColumn> &columns() const override;
138
139 QList<Column> displayedColumns() const override
140 {
141 return { Attribute, Heading, Alignment, Width };
142 }
143
148 void resetToLayer();
149};
150
159{
160 Q_OBJECT
161
162 public:
170 {}
171
172 QVector<QgsLayoutTableColumn> &columns() const override;
173
174 QList<Column> displayedColumns() const override
175 {
176 return { Attribute, SortOrder };
177 }
178};
179
187class GUI_EXPORT QgsLayoutColumnAlignmentDelegate : public QItemDelegate
188{
189 Q_OBJECT
190
191 public:
193 explicit QgsLayoutColumnAlignmentDelegate( QObject *parent = nullptr );
194 QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
195 void setEditorData( QWidget *editor, const QModelIndex &index ) const override;
196 void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const override;
197 void updateEditorGeometry( QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
198};
199
207class GUI_EXPORT QgsLayoutColumnSourceDelegate : public QItemDelegate, private QgsExpressionContextGenerator
208{
209 Q_OBJECT
210
211 public:
218 QgsLayoutColumnSourceDelegate( QgsVectorLayer *vlayer, QObject *parent = nullptr, const QgsLayoutObject *layoutObject = nullptr, bool forceExpressions = false );
219
220 QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
221 void setEditorData( QWidget *editor, const QModelIndex &index ) const override;
222 void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const override;
223 void updateEditorGeometry( QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
224 private slots:
225 void commitAndCloseEditor();
226
227 private:
228 QgsVectorLayer *mVectorLayer = nullptr;
229 const QgsLayoutObject *mLayoutObject = nullptr;
230 bool mForceExpressions = false;
231 QgsExpressionContext createExpressionContext() const override;
232};
233
241class GUI_EXPORT QgsLayoutColumnWidthDelegate : public QItemDelegate
242{
243 Q_OBJECT
244
245 public:
247 explicit QgsLayoutColumnWidthDelegate( QObject *parent = nullptr );
248 QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
249 void setEditorData( QWidget *editor, const QModelIndex &index ) const override;
250 void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const override;
251 void updateEditorGeometry( QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
252};
253
261class GUI_EXPORT QgsLayoutColumnSortOrderDelegate : public QItemDelegate
262{
263 Q_OBJECT
264
265 public:
267 explicit QgsLayoutColumnSortOrderDelegate( QObject *parent = nullptr );
268 QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
269 void setEditorData( QWidget *editor, const QModelIndex &index ) const override;
270 void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const override;
271 void updateEditorGeometry( QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
272};
273
274
282class GUI_EXPORT QgsLayoutAttributeSelectionDialog : public QDialog, private Ui::QgsLayoutAttributeSelectionDialogBase
283{
284 Q_OBJECT
285 public:
287 QgsLayoutAttributeSelectionDialog( QgsLayoutItemAttributeTable *table, QgsVectorLayer *vLayer, QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags() );
288
289 private slots:
290 void mRemoveColumnPushButton_clicked();
291 void mAddColumnPushButton_clicked();
292 void mColumnUpPushButton_clicked();
293 void mColumnDownPushButton_clicked();
294 void mResetColumnsPushButton_clicked();
295 void mClearColumnsPushButton_clicked();
296 void mAddSortColumnPushButton_clicked();
297 void mRemoveSortColumnPushButton_clicked();
298 void mSortColumnUpPushButton_clicked();
299 void mSortColumnDownPushButton_clicked();
300 void showHelp();
301
302 private:
303 QgsLayoutItemAttributeTable *mTable = 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#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