18 #include <QStringList>
27 return mColumns.isEmpty();
32 return mColumns.size();
37 for (
int i = 0; i < mColumns.size(); ++i )
39 if ( mColumns.at( i ).hidden )
44 if ( visibleColumn == i )
59 bool containsActionColumn =
false;
61 for (
int i = mColumns.count() - 1; i >= 0; --i )
77 containsActionColumn =
true;
81 for (
const auto &
field : fields )
89 if ( containsActionColumn )
91 mColumns.insert( mColumns.size() - 1, newColumn );
95 mColumns.append( newColumn );
100 if ( !containsActionColumn )
105 actionConfig.
hidden =
true;
107 mColumns.append( actionConfig );
113 const auto constMColumns = mColumns;
114 for (
const ColumnConfig &columnConfig : constMColumns )
116 if ( columnConfig.type ==
Action && !columnConfig.hidden )
124 for (
int i = 0; i < mColumns.size(); ++i )
126 if ( mColumns.at( i ).type ==
Action )
128 mColumns[i].hidden = !visible;
135 return mActionWidgetStyle;
148 const QDomNode configNode = node.namedItem( QStringLiteral(
"attributetableconfig" ) );
149 if ( !configNode.isNull() )
151 const QDomNode columnsNode = configNode.toElement().namedItem( QStringLiteral(
"columns" ) );
153 const QDomNodeList
columns = columnsNode.childNodes();
155 for (
int i = 0; i <
columns.size(); ++i )
157 const QDomElement columnElement =
columns.at( i ).toElement();
161 if ( columnElement.attribute( QStringLiteral(
"type" ) ) == QLatin1String(
"actions" ) )
168 column.
name = columnElement.attribute( QStringLiteral(
"name" ) );
171 column.
hidden = columnElement.attribute( QStringLiteral(
"hidden" ) ) == QLatin1String(
"1" );
172 column.
width = columnElement.attribute( QStringLiteral(
"width" ), QStringLiteral(
"-1" ) ).toDouble();
174 mColumns.append( column );
177 if ( configNode.toElement().attribute( QStringLiteral(
"actionWidgetStyle" ) ) == QLatin1String(
"buttonList" ) )
186 const QDomNodeList editTypeNodes = node.namedItem( QStringLiteral(
"edittypes" ) ).childNodes();
188 for (
int i = 0; i < editTypeNodes.size(); i++ )
190 const QDomElement editTypeElement = editTypeNodes.at( i ).toElement();
192 if ( editTypeElement.attribute( QStringLiteral(
"widgetv2type" ) ) == QLatin1String(
"Hidden" ) )
196 column.
name = editTypeElement.attribute( QStringLiteral(
"name" ) );
199 mColumns.append( column );
204 mSortExpression = configNode.toElement().attribute( QStringLiteral(
"sortExpression" ) );
205 const Qt::SortOrder
sortOrder =
static_cast<Qt::SortOrder
>( configNode.toElement().attribute( QStringLiteral(
"sortOrder" ) ).toInt() );
211 return mSortExpression;
221 return mColumns.at( column ).width;
226 mColumns[ column ].width = width;
231 return mColumns.at( column ).hidden;
236 mColumns[ column ].hidden = hidden;
241 return mSortExpression != other.mSortExpression || mColumns != other.mColumns || mActionWidgetStyle != other.mActionWidgetStyle || mSortOrder != other.mSortOrder;
262 QDomDocument doc( node.ownerDocument() );
264 QDomElement configElement = doc.createElement( QStringLiteral(
"attributetableconfig" ) );
265 configElement.setAttribute( QStringLiteral(
"actionWidgetStyle" ), mActionWidgetStyle ==
ButtonList ?
"buttonList" :
"dropDown" );
267 configElement.setAttribute( QStringLiteral(
"sortExpression" ), mSortExpression );
269 configElement.setAttribute( QStringLiteral(
"sortOrder" ), mSortOrder );
271 QDomElement columnsElement = doc.createElement( QStringLiteral(
"columns" ) );
273 const auto constMColumns = mColumns;
276 QDomElement columnElement = doc.createElement( QStringLiteral(
"column" ) );
278 if ( column.type ==
Action )
280 columnElement.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"actions" ) );
284 columnElement.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"field" ) );
285 columnElement.setAttribute( QStringLiteral(
"name" ), column.name );
288 columnElement.setAttribute( QStringLiteral(
"hidden" ), column.hidden );
289 columnElement.setAttribute( QStringLiteral(
"width" ), QString::number( column.width ) );
291 columnsElement.appendChild( columnElement );
294 configElement.appendChild( columnsElement );
296 node.appendChild( configElement );
303 for (
int i = 0; i <
columns().size(); i++ )