/
qgsattributetableconfig.h
332 lines (283 loc) · 8.51 KB
/
qgsattributetableconfig.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
/***************************************************************************
qgsattributetableconfig.h - QgsAttributeTableConfig
---------------------
begin : 27.4.2016
copyright : (C) 2016 by Matthias Kuhn
email : matthias@opengis.ch
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSATTRIBUTETABLECONFIG_H
#define QGSATTRIBUTETABLECONFIG_H
#include <QString>
#include <QVector>
#include <QDomNode>
#include <QVariant>
#include "qgis_sip.h"
#include "qgis_core.h"
class QgsFields;
/**
* \ingroup core
* \brief This is a container for configuration of the attribute table.
* The configuration is specific for one vector layer.
*/
class CORE_EXPORT QgsAttributeTableConfig
{
public:
/**
* The type of an attribute table column.
*/
enum Type
{
Field, //!< This column represents a field
Action //!< This column represents an action widget
};
/**
* Defines the configuration of a column in the attribute table.
*/
struct CORE_EXPORT ColumnConfig
{
//! Constructor for ColumnConfig
ColumnConfig() = default;
// TODO c++20 - replace with = default
bool operator== ( const QgsAttributeTableConfig::ColumnConfig &other ) const SIP_SKIP;
//! The type of this column.
QgsAttributeTableConfig::Type type = Field;
//! The name of the attribute if this column represents a field
QString name;
//! Flag that controls if the column is hidden
bool hidden = false;
//! Width of column, or -1 for default width
int width = -1;
};
/**
* The style of the action widget in the attribute table.
*/
enum ActionWidgetStyle
{
ButtonList, //!< A list of buttons
DropDown //!< A tool button with a drop-down to select the current action
};
/**
* Constructor for QgsAttributeTableConfig.
*/
QgsAttributeTableConfig() = default;
/**
* Gets the list with all columns and their configuration.
* The list order defines the order of appearance.
*/
QVector<QgsAttributeTableConfig::ColumnConfig> columns() const;
/**
* Returns TRUE if the configuration is empty, ie it contains no columns.
*
* \see size()
*/
bool isEmpty() const;
/**
* Returns the number of columns in the configuration.
*
* \since QGIS 3.22
*/
int size() const;
#ifdef SIP_RUN
int __len__() const;
% MethodCode
sipRes = sipCpp->size();
% End
#endif
/**
* Maps a visible column index to its original column index.
* \param visibleColumn index of visible column
* \returns corresponding index when hidden columns are considered
*/
int mapVisibleColumnToIndex( int visibleColumn ) const;
/**
* Set the list of columns visible in the attribute table.
* The list order defines the order of appearance.
*/
void setColumns( const QVector<QgsAttributeTableConfig::ColumnConfig> &columns );
/**
* Update the configuration with the given fields.
* Any field which is present in the configuration but not present in the
* parameter fields will be removed. Any field which is in the parameter
* fields but not in the configuration will be appended.
*/
void update( const QgsFields &fields );
/**
* Returns TRUE if the action widget is visible
*/
bool actionWidgetVisible() const;
/**
* Set if the action widget is visible
*/
void setActionWidgetVisible( bool visible );
/**
* Gets the style of the action widget
*/
ActionWidgetStyle actionWidgetStyle() const;
/**
* Set the style of the action widget
*/
void setActionWidgetStyle( ActionWidgetStyle actionWidgetStyle );
/**
* Serialize to XML on layer save
*/
void writeXml( QDomNode &node ) const;
/**
* Deserialize to XML on layer load
*/
void readXml( const QDomNode &node );
/**
* Gets the expression used for sorting.
*/
QString sortExpression() const;
/**
* Set the sort expression used for sorting.
*/
void setSortExpression( const QString &sortExpression );
#ifndef SIP_RUN
/**
* Returns the width of a column, or -1 if column should use default width.
* \param column column index
* \see setColumnWidth()
*/
int columnWidth( int column ) const;
#else
/**
* Returns the width of a column, or -1 if column should use default width.
* \param column column index
* \throws IndexError if the column is not found
* \see setColumnWidth()
*/
int columnWidth( int column ) const;
% MethodCode
{
if ( a0 < 0 || a0 >= sipCpp->size() )
{
PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
sipIsErr = 1;
}
else
{
return PyLong_FromLong( sipCpp->columnWidth( a0 ) );
}
}
% End
#endif
#ifndef SIP_RUN
/**
* Sets the width of a column.
* \param column column index
* \param width column width in pixels, or -1 if column should use default width
* \see columnWidth()
*/
void setColumnWidth( int column, int width );
#else
/**
* Sets the width of a column.
* \param column column index
* \param width column width in pixels, or -1 if column should use default width
* \throws IndexError if the column is not found
* \see columnWidth()
*/
void setColumnWidth( int column, int width );
% MethodCode
if ( a0 < 0 || a0 >= sipCpp->size() )
{
PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
sipIsErr = 1;
}
else
{
sipCpp->setColumnWidth( a0, a1 );
}
% End
#endif
#ifndef SIP_RUN
/**
* Returns TRUE if the specified column is hidden.
* \param column column index
* \see setColumnHidden()
*/
bool columnHidden( int column ) const;
#else
/**
* Returns TRUE if the specified column is hidden.
* \param column column index
* \throws IndexError if the column is not found
* \see setColumnHidden()
*/
bool columnHidden( int column ) const;
% MethodCode
{
if ( a0 < 0 || a0 >= sipCpp->size() )
{
PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
sipIsErr = 1;
}
else
{
return PyBool_FromLong( sipCpp->columnHidden( a0 ) );
}
}
% End
#endif
#ifndef SIP_RUN
/**
* Sets whether the specified column should be hidden.
* \param column column index
* \param hidden set to TRUE to hide column
* \see columnHidden()
*/
void setColumnHidden( int column, bool hidden );
#else
/**
* Sets whether the specified column should be hidden.
* \param column column index
* \param hidden set to TRUE to hide column
* \throws IndexError if the column is not found
* \see columnHidden()
*/
void setColumnHidden( int column, bool hidden );
% MethodCode
if ( a0 < 0 || a0 >= sipCpp->size() )
{
PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
sipIsErr = 1;
}
else
{
sipCpp->setColumnHidden( a0, a1 );
}
% End
#endif
/**
* Gets the sort order
*/
Qt::SortOrder sortOrder() const;
/**
* Set the sort order
*/
void setSortOrder( Qt::SortOrder sortOrder );
/**
* Compare this configuration's columns name, type, and order to \a other.
* The column's width is not considered.
*/
bool hasSameColumns( const QgsAttributeTableConfig &other ) const;
/**
* Compare this configuration to other.
*/
bool operator!= ( const QgsAttributeTableConfig &other ) const;
private:
QVector<ColumnConfig> mColumns;
ActionWidgetStyle mActionWidgetStyle = DropDown;
QString mSortExpression;
Qt::SortOrder mSortOrder = Qt::AscendingOrder;
};
Q_DECLARE_METATYPE( QgsAttributeTableConfig::ColumnConfig )
#endif // QGSATTRIBUTETABLECONFIG_H