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 )
72 containsActionColumn =
true;
76 for (
const auto &
field : fields )
85 mColumns.append( newColumn );
89 if ( !containsActionColumn )
94 actionConfig.
hidden =
true;
96 mColumns.append( actionConfig );
102 const auto constMColumns = mColumns;
103 for (
const ColumnConfig &columnConfig : constMColumns )
105 if ( columnConfig.type ==
Action && !columnConfig.hidden )
113 for (
int i = 0; i < mColumns.size(); ++i )
115 if ( mColumns.at( i ).type ==
Action )
117 mColumns[i].hidden = !visible;
124 return mActionWidgetStyle;
137 QDomNode configNode = node.namedItem( QStringLiteral(
"attributetableconfig" ) );
138 if ( !configNode.isNull() )
140 QDomNode columnsNode = configNode.toElement().namedItem( QStringLiteral(
"columns" ) );
142 QDomNodeList
columns = columnsNode.childNodes();
144 for (
int i = 0; i <
columns.size(); ++i )
146 QDomElement columnElement =
columns.at( i ).toElement();
150 if ( columnElement.attribute( QStringLiteral(
"type" ) ) == QLatin1String(
"actions" ) )
157 column.
name = columnElement.attribute( QStringLiteral(
"name" ) );
160 column.
hidden = columnElement.attribute( QStringLiteral(
"hidden" ) ) == QLatin1String(
"1" );
161 column.
width = columnElement.attribute( QStringLiteral(
"width" ), QStringLiteral(
"-1" ) ).toDouble();
163 mColumns.append( column );
166 if ( configNode.toElement().attribute( QStringLiteral(
"actionWidgetStyle" ) ) == QLatin1String(
"buttonList" ) )
175 QDomNodeList editTypeNodes = node.namedItem( QStringLiteral(
"edittypes" ) ).childNodes();
177 for (
int i = 0; i < editTypeNodes.size(); i++ )
179 QDomElement editTypeElement = editTypeNodes.at( i ).toElement();
181 if ( editTypeElement.attribute( QStringLiteral(
"widgetv2type" ) ) == QLatin1String(
"Hidden" ) )
185 column.
name = editTypeElement.attribute( QStringLiteral(
"name" ) );
188 mColumns.append( column );
193 mSortExpression = configNode.toElement().attribute( QStringLiteral(
"sortExpression" ) );
194 Qt::SortOrder
sortOrder =
static_cast<Qt::SortOrder
>( configNode.toElement().attribute( QStringLiteral(
"sortOrder" ) ).toInt() );
200 return mSortExpression;
210 return mColumns.at( column ).width;
215 mColumns[ column ].width = width;
220 return mColumns.at( column ).hidden;
225 mColumns[ column ].hidden = hidden;
230 return mSortExpression != other.mSortExpression || mColumns != other.mColumns || mActionWidgetStyle != other.mActionWidgetStyle || mSortOrder != other.mSortOrder;
251 QDomDocument doc( node.ownerDocument() );
253 QDomElement configElement = doc.createElement( QStringLiteral(
"attributetableconfig" ) );
254 configElement.setAttribute( QStringLiteral(
"actionWidgetStyle" ), mActionWidgetStyle ==
ButtonList ?
"buttonList" :
"dropDown" );
256 configElement.setAttribute( QStringLiteral(
"sortExpression" ), mSortExpression );
258 configElement.setAttribute( QStringLiteral(
"sortOrder" ), mSortOrder );
260 QDomElement columnsElement = doc.createElement( QStringLiteral(
"columns" ) );
262 const auto constMColumns = mColumns;
265 QDomElement columnElement = doc.createElement( QStringLiteral(
"column" ) );
267 if ( column.type ==
Action )
269 columnElement.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"actions" ) );
273 columnElement.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"field" ) );
274 columnElement.setAttribute( QStringLiteral(
"name" ), column.name );
277 columnElement.setAttribute( QStringLiteral(
"hidden" ), column.hidden );
278 columnElement.setAttribute( QStringLiteral(
"width" ), QString::number( column.width ) );
280 columnsElement.appendChild( columnElement );
283 configElement.appendChild( columnsElement );
285 node.appendChild( configElement );
292 for (
int i = 0; i <
columns().size(); i++ )