QGIS API Documentation 3.99.0-Master (26c88405ac0)
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:
38
42 enum Type
43 {
46 };
47
51 struct CORE_EXPORT ColumnConfig
52 {
53 ColumnConfig() = default;
54
55 // TODO c++20 - replace with = default
57
60
62 QString name;
63
65 bool hidden = false;
66
68 int width = -1;
69 };
70
79
81
86 QVector<QgsAttributeTableConfig::ColumnConfig> columns() const;
87
93 bool isEmpty() const;
94
100 int size() const;
101
102#ifdef SIP_RUN
103 int __len__() const;
104 % MethodCode
105 sipRes = sipCpp->size();
106 % End
107#endif
108
114 int mapVisibleColumnToIndex( int visibleColumn ) const;
115
120 void setColumns( const QVector<QgsAttributeTableConfig::ColumnConfig> &columns );
121
128 void update( const QgsFields &fields );
129
133 bool actionWidgetVisible() const;
134
138 void setActionWidgetVisible( bool visible );
139
144
149
153 void writeXml( QDomNode &node ) const;
154
158 void readXml( const QDomNode &node );
159
163 QString sortExpression() const;
164
168 void setSortExpression( const QString &sortExpression );
169
170#ifndef SIP_RUN
171
177 int columnWidth( int column ) const;
178#else
179
186 int columnWidth( int column ) const;
187 % MethodCode
188 {
189 if ( a0 < 0 || a0 >= sipCpp->size() )
190 {
191 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
192 sipIsErr = 1;
193 }
194 else
195 {
196 return PyLong_FromLong( sipCpp->columnWidth( a0 ) );
197 }
198 }
199 % End
200#endif
201
202#ifndef SIP_RUN
203
210 void setColumnWidth( int column, int width );
211#else
212
220 void setColumnWidth( int column, int width );
221 % MethodCode
222 if ( a0 < 0 || a0 >= sipCpp->size() )
223 {
224 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
225 sipIsErr = 1;
226 }
227 else
228 {
229 sipCpp->setColumnWidth( a0, a1 );
230 }
231 % End
232#endif
233
234#ifndef SIP_RUN
235
241 bool columnHidden( int column ) const;
242#else
243
250 bool columnHidden( int column ) const;
251 % MethodCode
252 {
253 if ( a0 < 0 || a0 >= sipCpp->size() )
254 {
255 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
256 sipIsErr = 1;
257 }
258 else
259 {
260 return PyBool_FromLong( sipCpp->columnHidden( a0 ) );
261 }
262 }
263 % End
264#endif
265
266#ifndef SIP_RUN
267
274 void setColumnHidden( int column, bool hidden );
275#else
276
284 void setColumnHidden( int column, bool hidden );
285 % MethodCode
286 if ( a0 < 0 || a0 >= sipCpp->size() )
287 {
288 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
289 sipIsErr = 1;
290 }
291 else
292 {
293 sipCpp->setColumnHidden( a0, a1 );
294 }
295 % End
296#endif
297
301 Qt::SortOrder sortOrder() const;
302
306 void setSortOrder( Qt::SortOrder sortOrder );
307
312 bool hasSameColumns( const QgsAttributeTableConfig &other ) const;
313
314 bool operator!= ( const QgsAttributeTableConfig &other ) const;
315
316 private:
317 QVector<ColumnConfig> mColumns;
318 ActionWidgetStyle mActionWidgetStyle = DropDown;
319 QString mSortExpression;
320 Qt::SortOrder mSortOrder = Qt::AscendingOrder;
321};
322
324
325#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:134
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.