QgsAttributeTableConfig class

This is a container for configuration of the attribute table.

The configuration is specific for one vector layer.

Public types

struct ColumnConfig
Defines the configuration of a column in the attribute table.
enum ActionWidgetStyle { ButtonList, DropDown }
The style of the action widget in the attribute table.
enum Type { Field, Action }
The type of an attribute table column.

Constructors, destructors, conversion operators

QgsAttributeTableConfig() defaulted
Constructor for QgsAttributeTableConfig.

Public functions

auto actionWidgetStyle() const -> ActionWidgetStyle
Gets the style of the action widget.
auto actionWidgetVisible() const -> bool
Returns true if the action widget is visible.
auto columnHidden(int column) const -> bool
Returns true if the specified column is hidden.
auto columns() const -> QVector<QgsAttributeTableConfig::ColumnConfig>
Gets the list with all columns and their configuration.
auto columnWidth(int column) const -> int
Returns the width of a column, or -1 if column should use default width.
auto hasSameColumns(const QgsAttributeTableConfig& other) const -> bool
Compare this configuration's columns name, type, and order to other.
auto isEmpty() const -> bool
Returns true if the configuration is empty, ie it contains no columns.
auto mapVisibleColumnToIndex(int visibleColumn) const -> int
Maps a visible column index to its original column index.
auto operator!=(const QgsAttributeTableConfig& other) const -> bool
Compare this configuration to other.
void readXml(const QDomNode& node)
Deserialize to XML on layer load.
void setActionWidgetStyle(ActionWidgetStyle actionWidgetStyle)
Set the style of the action widget.
void setActionWidgetVisible(bool visible)
Set if the action widget is visible.
void setColumnHidden(int column, bool hidden)
Sets whether the specified column should be hidden.
void setColumns(const QVector<QgsAttributeTableConfig::ColumnConfig>& columns)
Set the list of columns visible in the attribute table.
void setColumnWidth(int column, int width)
Sets the width of a column.
void setSortExpression(const QString& sortExpression)
Set the sort expression used for sorting.
void setSortOrder(Qt::SortOrder sortOrder)
Set the sort order.
auto sortExpression() const -> QString
Gets the expression used for sorting.
auto sortOrder() const -> Qt::SortOrder
Gets the sort order.
void update(const QgsFields& fields)
Update the configuration with the given fields.
void writeXml(QDomNode& node) const
Serialize to XML on layer save.

Enum documentation

enum QgsAttributeTableConfig::ActionWidgetStyle

The style of the action widget in the attribute table.

Enumerators
ButtonList

A list of buttons.

DropDown

A tool button with a drop-down to select the current action.

enum QgsAttributeTableConfig::Type

The type of an attribute table column.

Enumerators
Field

This column represents a field.

Action

This column represents an action widget.

Function documentation

bool QgsAttributeTableConfig::columnHidden(int column) const

Returns true if the specified column is hidden.

Parameters
column column index

QVector<QgsAttributeTableConfig::ColumnConfig> QgsAttributeTableConfig::columns() const

Gets the list with all columns and their configuration.

The list order defines the order of appearance.

int QgsAttributeTableConfig::columnWidth(int column) const

Returns the width of a column, or -1 if column should use default width.

Parameters
column column index

bool QgsAttributeTableConfig::hasSameColumns(const QgsAttributeTableConfig& other) const

Compare this configuration's columns name, type, and order to other.

The column's width is not considered.

int QgsAttributeTableConfig::mapVisibleColumnToIndex(int visibleColumn) const

Maps a visible column index to its original column index.

Parameters
visibleColumn index of visible column
Returns corresponding index when hidden columns are considered

void QgsAttributeTableConfig::setColumnHidden(int column, bool hidden)

Sets whether the specified column should be hidden.

Parameters
column column index
hidden set to true to hide column

void QgsAttributeTableConfig::setColumns(const QVector<QgsAttributeTableConfig::ColumnConfig>& columns)

Set the list of columns visible in the attribute table.

The list order defines the order of appearance.

void QgsAttributeTableConfig::setColumnWidth(int column, int width)

Sets the width of a column.

Parameters
column column index
width column width in pixels, or -1 if column should use default width

void QgsAttributeTableConfig::setSortOrder(Qt::SortOrder sortOrder)

Set the sort order.

Qt::SortOrder QgsAttributeTableConfig::sortOrder() const

Gets the sort order.

void QgsAttributeTableConfig::update(const QgsFields& fields)

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.