18 #include <QStringList> 27 return mColumns.isEmpty();
32 for (
int i = 0; i < mColumns.size(); ++i )
34 if ( mColumns.at( i ).hidden )
39 if ( visibleColumn == i )
54 bool containsActionColumn =
false;
56 for (
int i = mColumns.count() - 1; i >= 0; --i )
67 columns.append( column.
name );
72 containsActionColumn =
true;
76 for (
const auto &field : fields )
78 if ( !columns.contains( field.name() ) )
83 newColumn.
name = field.name();
85 mColumns.append( newColumn );
89 if ( !containsActionColumn )
94 actionConfig.
hidden =
true;
96 mColumns.append( actionConfig );
102 Q_FOREACH (
const ColumnConfig &columnConfig, mColumns )
112 for (
int i = 0; i < mColumns.size(); ++i )
114 if ( mColumns.at( i ).type ==
Action )
116 mColumns[i].hidden = !visible;
123 return mActionWidgetStyle;
136 QDomNode configNode = node.namedItem( QStringLiteral(
"attributetableconfig" ) );
137 if ( !configNode.isNull() )
139 QDomNode columnsNode = configNode.toElement().namedItem( QStringLiteral(
"columns" ) );
141 QDomNodeList
columns = columnsNode.childNodes();
143 for (
int i = 0; i < columns.size(); ++i )
145 QDomElement columnElement = columns.at( i ).toElement();
149 if ( columnElement.attribute( QStringLiteral(
"type" ) ) == QLatin1String(
"actions" ) )
156 column.
name = columnElement.attribute( QStringLiteral(
"name" ) );
159 column.
hidden = columnElement.attribute( QStringLiteral(
"hidden" ) ) == QLatin1String(
"1" );
160 column.
width = columnElement.attribute( QStringLiteral(
"width" ), QStringLiteral(
"-1" ) ).toDouble();
162 mColumns.append( column );
165 if ( configNode.toElement().attribute( QStringLiteral(
"actionWidgetStyle" ) ) == QLatin1String(
"buttonList" ) )
174 QDomNodeList editTypeNodes = node.namedItem( QStringLiteral(
"edittypes" ) ).childNodes();
176 for (
int i = 0; i < editTypeNodes.size(); i++ )
178 QDomElement editTypeElement = editTypeNodes.at( i ).toElement();
180 if ( editTypeElement.attribute( QStringLiteral(
"widgetv2type" ) ) == QLatin1String(
"Hidden" ) )
184 column.
name = editTypeElement.attribute( QStringLiteral(
"name" ) );
187 mColumns.append( column );
192 mSortExpression = configNode.toElement().attribute( QStringLiteral(
"sortExpression" ) );
193 Qt::SortOrder
sortOrder =
static_cast<Qt::SortOrder
>( configNode.toElement().attribute( QStringLiteral(
"sortOrder" ) ).toInt() );
199 return mSortExpression;
209 return mColumns.at( column ).width;
214 mColumns[ column ].width = width;
219 return mColumns.at( column ).hidden;
224 mColumns[ column ].hidden = hidden;
229 return mSortExpression != other.mSortExpression || mColumns != other.mColumns || mActionWidgetStyle != other.mActionWidgetStyle || mSortOrder != other.mSortOrder;
240 if ( sortOrder != Qt::AscendingOrder && sortOrder != Qt::DescendingOrder )
242 sortOrder = Qt::AscendingOrder;
250 QDomDocument doc( node.ownerDocument() );
252 QDomElement configElement = doc.createElement( QStringLiteral(
"attributetableconfig" ) );
253 configElement.setAttribute( QStringLiteral(
"actionWidgetStyle" ), mActionWidgetStyle ==
ButtonList ?
"buttonList" :
"dropDown" );
255 configElement.setAttribute( QStringLiteral(
"sortExpression" ), mSortExpression );
257 configElement.setAttribute( QStringLiteral(
"sortOrder" ), mSortOrder );
259 QDomElement columnsElement = doc.createElement( QStringLiteral(
"columns" ) );
263 QDomElement columnElement = doc.createElement( QStringLiteral(
"column" ) );
267 columnElement.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"actions" ) );
271 columnElement.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"field" ) );
272 columnElement.setAttribute( QStringLiteral(
"name" ), column.
name );
275 columnElement.setAttribute( QStringLiteral(
"hidden" ), column.
hidden );
276 columnElement.setAttribute( QStringLiteral(
"width" ), QString::number( column.
width ) );
278 columnsElement.appendChild( columnElement );
281 configElement.appendChild( columnsElement );
283 node.appendChild( configElement );
290 for (
int i = 0; i <
columns().size(); i++ )
307 return type == other.
type && name == other.
name && hidden == other.
hidden && width == other.
width;
QgsAttributeTableConfig::Type type
The type of this column.
void setSortExpression(const QString &sortExpression)
Set the sort expression used for sorting.
void update(const QgsFields &fields)
Update the configuration with the given fields.
bool actionWidgetVisible() const
Returns true if the action widget is visible.
void setSortOrder(Qt::SortOrder sortOrder)
Set the sort order.
bool columnHidden(int column) const
Returns true if the specified column is hidden.
int columnWidth(int column) const
Returns the width of a column, or -1 if column should use default width.
Container of fields for a vector layer.
This column represents an action widget.
int mapVisibleColumnToIndex(int visibleColumn) const
Maps a visible column index to its original column index.
ActionWidgetStyle
The style of the action widget in the attribute table.
void setActionWidgetStyle(ActionWidgetStyle actionWidgetStyle)
Set the style of the action widget.
void setActionWidgetVisible(bool visible)
Set if the action widget is visible.
void setColumnWidth(int column, int width)
Sets the width of a column.
ActionWidgetStyle actionWidgetStyle() const
Gets the style of the action widget.
bool hidden
Flag that controls if the column is hidden.
QString name
The name of the attribute if this column represents a field.
void writeXml(QDomNode &node) const
Serialize to XML on layer save.
QVector< QgsAttributeTableConfig::ColumnConfig > columns() const
Gets the list with all columns and their configuration.
bool operator==(const QgsAttributeTableConfig::ColumnConfig &other) const
int width
Width of column, or -1 for default width.
bool isEmpty() const
Returns true if the configuration is empty, ie it contains no columns.
void setColumns(const QVector< QgsAttributeTableConfig::ColumnConfig > &columns)
Set the list of columns visible in the attribute table.
int indexOf(const QString &fieldName) const
Gets the field index from the field name.
A tool button with a drop-down to select the current action.
void setColumnHidden(int column, bool hidden)
Sets whether the specified column should be hidden.
This column represents a field.
Defines the configuration of a column in the attribute table.
bool operator!=(const QgsAttributeTableConfig &other) const
Compare this configuration to other.
This is a container for configuration of the attribute table.
Qt::SortOrder sortOrder() const
Gets the sort order.
QString sortExpression() const
Gets the expression used for sorting.
bool hasSameColumns(const QgsAttributeTableConfig &other) const
Compare this configuration's columns name, type, and order to other.
void readXml(const QDomNode &node)
Deserialize to XML on layer load.