QGIS API Documentation 4.1.0-Master (376402f9aeb)
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 Q_GADGET
38
39 public:
43 enum Type
44 {
47 };
48
52 struct CORE_EXPORT ColumnConfig
53 {
54 ColumnConfig() = default;
55
56 // TODO c++20 - replace with = default
58
61
63 QString name;
64
66 bool hidden = false;
67
69 int width = -1;
70 };
71
80
84 enum class AddFeatureMethod : int
85 {
86 Unset,
87 Form,
88 Table
89 };
90 Q_ENUM( AddFeatureMethod )
91
92
94
100
106 bool isEmpty() const;
107
113 int size() const;
114
115#ifdef SIP_RUN
116 // clang-format off
117 int __len__() const;
118 % MethodCode
119 sipRes = sipCpp->size();
120 % End
121// clang-format on
122#endif
123
129 int mapVisibleColumnToIndex( int visibleColumn ) const;
130
135 void setColumns( const QVector<QgsAttributeTableConfig::ColumnConfig> &columns );
136
143 void update( const QgsFields &fields );
144
148 bool actionWidgetVisible() const;
149
153 void setActionWidgetVisible( bool visible );
154
159
164
168 void writeXml( QDomNode &node ) const;
169
173 void readXml( const QDomNode &node );
174
178 QString sortExpression() const;
179
183 void setSortExpression( const QString &sortExpression );
184
191
198
199#ifndef SIP_RUN
200
206 int columnWidth( int column ) const;
207#else
208 // clang-format off
209
216 int columnWidth( int column ) const;
217 % MethodCode
218 {
219 if ( a0 < 0 || a0 >= sipCpp->size() )
220 {
221 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
222 sipIsErr = 1;
223 }
224 else
225 {
226 return PyLong_FromLong( sipCpp->columnWidth( a0 ) );
227 }
228 }
229 % End
230// clang-format on
231#endif
232
233#ifndef SIP_RUN
234
241 void setColumnWidth( int column, int width );
242#else
243 // clang-format off
244
252 void setColumnWidth( int column, int width );
253 % MethodCode
254 if ( a0 < 0 || a0 >= sipCpp->size() )
255 {
256 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
257 sipIsErr = 1;
258 }
259 else
260 {
261 sipCpp->setColumnWidth( a0, a1 );
262 }
263 % End
264// clang-format on
265#endif
266
267#ifndef SIP_RUN
268
274 bool columnHidden( int column ) const;
275#else
276 // clang-format off
277
284 bool columnHidden( int column ) const;
285 % MethodCode
286 {
287 if ( a0 < 0 || a0 >= sipCpp->size() )
288 {
289 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
290 sipIsErr = 1;
291 }
292 else
293 {
294 return PyBool_FromLong( sipCpp->columnHidden( a0 ) );
295 }
296 }
297 % End
298// clang-format on
299#endif
300
301#ifndef SIP_RUN
302
309 void setColumnHidden( int column, bool hidden );
310#else
311 // clang-format off
312
320 void setColumnHidden( int column, bool hidden );
321 % MethodCode
322 if ( a0 < 0 || a0 >= sipCpp->size() )
323 {
324 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
325 sipIsErr = 1;
326 }
327 else
328 {
329 sipCpp->setColumnHidden( a0, a1 );
330 }
331 % End
332// clang-format on
333#endif
334
338 Qt::SortOrder sortOrder() const;
339
343 void setSortOrder( Qt::SortOrder sortOrder );
344
349 bool hasSameColumns( const QgsAttributeTableConfig &other ) const;
350
351 bool operator!=( const QgsAttributeTableConfig &other ) const;
352
353 private:
354 QVector<ColumnConfig> mColumns;
355 ActionWidgetStyle mActionWidgetStyle = DropDown;
356 QString mSortExpression;
357 Qt::SortOrder mSortOrder = Qt::AscendingOrder;
358 AddFeatureMethod mAddFeatureMethod = AddFeatureMethod::Unset;
359};
360
362
363#endif // QGSATTRIBUTETABLECONFIG_H
void setAddFeatureMethod(const AddFeatureMethod addFeatureMethod)
Sets the addFeatureMethod that defines how features are added (single form or embedded in a table).
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.
AddFeatureMethod addFeatureMethod() const
Returns the method that defines how features are added (single form or embedded in a table).
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.
AddFeatureMethod
The way to add features in the attribute table.
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.