QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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
7  email : [email protected]
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 <QString>
20 #include <QVector>
21 #include <QDomNode>
22 #include <QVariant>
23 
24 #include "qgis_sip.h"
25 #include "qgis_core.h"
26 
27 class QgsFields;
28 
36 class CORE_EXPORT QgsAttributeTableConfig
37 {
38  public:
39 
43  enum Type
44  {
46  Action
47  };
48 
52  struct ColumnConfig
53  {
55  ColumnConfig() = default;
56 
57  // TODO c++20 - replace with = default
59 
62 
64  QString name;
65 
67  bool hidden = false;
68 
70  int width = -1;
71  };
72 
77  {
79  DropDown
80  };
81 
85  QgsAttributeTableConfig() = default;
86 
91  QVector<QgsAttributeTableConfig::ColumnConfig> columns() const;
92 
98  bool isEmpty() const;
99 
105  int size() const;
106 
107 #ifdef SIP_RUN
108  int __len__() const;
109  % MethodCode
110  sipRes = sipCpp->size();
111  % End
112 #endif
113 
119  int mapVisibleColumnToIndex( int visibleColumn ) const;
120 
125  void setColumns( const QVector<QgsAttributeTableConfig::ColumnConfig> &columns );
126 
133  void update( const QgsFields &fields );
134 
138  bool actionWidgetVisible() const;
139 
143  void setActionWidgetVisible( bool visible );
144 
148  ActionWidgetStyle actionWidgetStyle() const;
149 
153  void setActionWidgetStyle( ActionWidgetStyle actionWidgetStyle );
154 
158  void writeXml( QDomNode &node ) const;
159 
163  void readXml( const QDomNode &node );
164 
168  QString sortExpression() const;
169 
173  void setSortExpression( const QString &sortExpression );
174 
175 #ifndef SIP_RUN
176 
182  int columnWidth( int column ) const;
183 #else
184 
191  int columnWidth( int column ) const;
192  % MethodCode
193  {
194  if ( a0 < 0 || a0 >= sipCpp->size() )
195  {
196  PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
197  sipIsErr = 1;
198  }
199  else
200  {
201  return PyLong_FromLong( sipCpp->columnWidth( a0 ) );
202  }
203  }
204  % End
205 #endif
206 
207 #ifndef SIP_RUN
208 
215  void setColumnWidth( int column, int width );
216 #else
217 
225  void setColumnWidth( int column, int width );
226  % MethodCode
227  if ( a0 < 0 || a0 >= sipCpp->size() )
228  {
229  PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
230  sipIsErr = 1;
231  }
232  else
233  {
234  sipCpp->setColumnWidth( a0, a1 );
235  }
236  % End
237 #endif
238 
239 #ifndef SIP_RUN
240 
246  bool columnHidden( int column ) const;
247 #else
248 
255  bool columnHidden( int column ) const;
256  % MethodCode
257  {
258  if ( a0 < 0 || a0 >= sipCpp->size() )
259  {
260  PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
261  sipIsErr = 1;
262  }
263  else
264  {
265  return PyBool_FromLong( sipCpp->columnHidden( a0 ) );
266  }
267  }
268  % End
269 #endif
270 
271 #ifndef SIP_RUN
272 
279  void setColumnHidden( int column, bool hidden );
280 #else
281 
289  void setColumnHidden( int column, bool hidden );
290  % MethodCode
291  if ( a0 < 0 || a0 >= sipCpp->size() )
292  {
293  PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
294  sipIsErr = 1;
295  }
296  else
297  {
298  sipCpp->setColumnHidden( a0, a1 );
299  }
300  % End
301 #endif
302 
307  Qt::SortOrder sortOrder() const;
308 
313  void setSortOrder( Qt::SortOrder sortOrder );
314 
319  bool hasSameColumns( const QgsAttributeTableConfig &other ) const;
320 
324  bool operator!= ( const QgsAttributeTableConfig &other ) const;
325 
326  private:
327  QVector<ColumnConfig> mColumns;
328  ActionWidgetStyle mActionWidgetStyle = DropDown;
329  QString mSortExpression;
330  Qt::SortOrder mSortOrder = Qt::AscendingOrder;
331 };
332 
334 
335 #endif // QGSATTRIBUTETABLECONFIG_H
operator==
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
Definition: qgsfeatureiterator.h:425
QgsAttributeTableConfig::ActionWidgetStyle
ActionWidgetStyle
The style of the action widget in the attribute table.
Definition: qgsattributetableconfig.h:76
QgsFields
Container of fields for a vector layer.
Definition: qgsfields.h:44
QgsAttributeTableConfig::ColumnConfig
Defines the configuration of a column in the attribute table.
Definition: qgsattributetableconfig.h:52
QgsAttributeTableConfig::ButtonList
@ ButtonList
A list of buttons.
Definition: qgsattributetableconfig.h:78
operator!=
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
Definition: qgsfeatureiterator.h:430
QgsAttributeTableConfig::Field
@ Field
This column represents a field.
Definition: qgsattributetableconfig.h:45
QgsAttributeTableConfig
This is a container for configuration of the attribute table. The configuration is specific for one v...
Definition: qgsattributetableconfig.h:36
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
qgis_sip.h
QgsAttributeTableConfig::Type
Type
The type of an attribute table column.
Definition: qgsattributetableconfig.h:43
QgsAttributeTableConfig::ColumnConfig::name
QString name
The name of the attribute if this column represents a field.
Definition: qgsattributetableconfig.h:64
Q_DECLARE_METATYPE
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)