QGIS API Documentation 4.1.0-Master (60fea48833c)
Loading...
Searching...
No Matches
qgsattributetableconfig.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsattributetableconfig.h - QgsAttributeTableConfig
3
4 ---------------------
5 begin : 27.4.2016
6 copyright : (C) 2016 by Matthias Kuhn
8 ***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16#ifndef QGSATTRIBUTETABLECONFIG_H
17#define QGSATTRIBUTETABLECONFIG_H
18
19#include "qgis_core.h"
20#include "qgis_sip.h"
21
22#include <QDomNode>
23#include <QString>
24#include <QVariant>
25#include <QVector>
26
27class QgsFields;
28
35class CORE_EXPORT QgsAttributeTableConfig
36{
37 public:
41 enum Type
42 {
45 };
46
50 struct CORE_EXPORT ColumnConfig
51 {
52 ColumnConfig() = default;
53
54 // TODO c++20 - replace with = default
56
59
61 QString name;
62
64 bool hidden = false;
65
67 int width = -1;
68 };
69
78
80
85 QVector<QgsAttributeTableConfig::ColumnConfig> columns() const;
86
92 bool isEmpty() const;
93
99 int size() const;
100
101#ifdef SIP_RUN
102 // clang-format off
103 int __len__() const;
104 % MethodCode
105 sipRes = sipCpp->size();
106 % End
107// clang-format on
108#endif
109
115 int mapVisibleColumnToIndex( int visibleColumn ) const;
116
121 void setColumns( const QVector<QgsAttributeTableConfig::ColumnConfig> &columns );
122
129 void update( const QgsFields &fields );
130
134 bool actionWidgetVisible() const;
135
139 void setActionWidgetVisible( bool visible );
140
145
150
154 void writeXml( QDomNode &node ) const;
155
159 void readXml( const QDomNode &node );
160
164 QString sortExpression() const;
165
169 void setSortExpression( const QString &sortExpression );
170
171#ifndef SIP_RUN
172
178 int columnWidth( int column ) const;
179#else
180 // clang-format off
181
188 int columnWidth( int column ) const;
189 % MethodCode
190 {
191 if ( a0 < 0 || a0 >= sipCpp->size() )
192 {
193 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
194 sipIsErr = 1;
195 }
196 else
197 {
198 return PyLong_FromLong( sipCpp->columnWidth( a0 ) );
199 }
200 }
201 % End
202// clang-format on
203#endif
204
205#ifndef SIP_RUN
206
213 void setColumnWidth( int column, int width );
214#else
215 // clang-format off
216
224 void setColumnWidth( int column, int width );
225 % MethodCode
226 if ( a0 < 0 || a0 >= sipCpp->size() )
227 {
228 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
229 sipIsErr = 1;
230 }
231 else
232 {
233 sipCpp->setColumnWidth( a0, a1 );
234 }
235 % End
236// clang-format on
237#endif
238
239#ifndef SIP_RUN
240
246 bool columnHidden( int column ) const;
247#else
248 // clang-format off
249
256 bool columnHidden( int column ) const;
257 % MethodCode
258 {
259 if ( a0 < 0 || a0 >= sipCpp->size() )
260 {
261 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
262 sipIsErr = 1;
263 }
264 else
265 {
266 return PyBool_FromLong( sipCpp->columnHidden( a0 ) );
267 }
268 }
269 % End
270// clang-format on
271#endif
272
273#ifndef SIP_RUN
274
281 void setColumnHidden( int column, bool hidden );
282#else
283 // clang-format off
284
292 void setColumnHidden( int column, bool hidden );
293 % MethodCode
294 if ( a0 < 0 || a0 >= sipCpp->size() )
295 {
296 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
297 sipIsErr = 1;
298 }
299 else
300 {
301 sipCpp->setColumnHidden( a0, a1 );
302 }
303 % End
304// clang-format on
305#endif
306
310 Qt::SortOrder sortOrder() const;
311
315 void setSortOrder( Qt::SortOrder sortOrder );
316
321 bool hasSameColumns( const QgsAttributeTableConfig &other ) const;
322
323 bool operator!=( const QgsAttributeTableConfig &other ) const;
324
325 private:
326 QVector<ColumnConfig> mColumns;
327 ActionWidgetStyle mActionWidgetStyle = DropDown;
328 QString mSortExpression;
329 Qt::SortOrder mSortOrder = Qt::AscendingOrder;
330};
331
333
334#endif // QGSATTRIBUTETABLECONFIG_H
void setActionWidgetVisible(bool visible)
Set if the action widget is visible.
bool isEmpty() const
Returns true if the configuration is empty, ie it contains no columns.
void setSortExpression(const QString &sortExpression)
Set the sort expression used for sorting.
Type
The type of an attribute table column.
@ Action
This column represents an action widget.
@ Field
This column represents a field.
void readXml(const QDomNode &node)
Deserialize to XML on layer load.
QVector< QgsAttributeTableConfig::ColumnConfig > columns() const
Gets the list with all columns and their configuration.
int mapVisibleColumnToIndex(int visibleColumn) const
Maps a visible column index to its original column index.
void update(const QgsFields &fields)
Update the configuration with the given fields.
ActionWidgetStyle
The style of the action widget in the attribute table.
@ DropDown
A tool button with a drop-down to select the current action.
bool actionWidgetVisible() const
Returns true if the action widget is visible.
void setActionWidgetStyle(ActionWidgetStyle actionWidgetStyle)
Set the style of the action widget.
int columnWidth(int column) const
Returns the width of a column, or -1 if column should use default width.
QgsAttributeTableConfig()=default
void setColumns(const QVector< QgsAttributeTableConfig::ColumnConfig > &columns)
Set the list of columns visible in the attribute table.
ActionWidgetStyle actionWidgetStyle() const
Gets the style of the action widget.
QString sortExpression() const
Gets the expression used for sorting.
void writeXml(QDomNode &node) const
Serialize to XML on layer save.
int size() const
Returns the number of columns in the configuration.
Container of fields for a vector layer.
Definition qgsfields.h:46
#define SIP_SKIP
Definition qgis_sip.h:133
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
Defines the configuration of a column in the attribute table.
QgsAttributeTableConfig::Type type
The type of this column.
bool hidden
Flag that controls if the column is hidden.
int width
Width of column, or -1 for default width.
QString name
The name of the attribute if this column represents a field.