File tree Expand file tree Collapse file tree 4 files changed +29
-29
lines changed Expand file tree Collapse file tree 4 files changed +29
-29
lines changed Original file line number Diff line number Diff line change @@ -156,7 +156,9 @@ class QgsAuxiliaryLayer : QgsVectorLayer
156156
157157 bool addAuxiliaryField( const QgsPropertyDefinition &definition );
158158%Docstring
159- Add an an auxiliary field for the given property.
159+ Add an an auxiliary field for the given property. Setup for widget
160+ editors are updated in the target layer as weel as the attribute
161+ table config to hide auxiliary fields by default.
160162
161163 \param definition The definition of the property to add
162164
Original file line number Diff line number Diff line change @@ -259,8 +259,29 @@ bool QgsAuxiliaryLayer::addAuxiliaryField( const QgsPropertyDefinition &definiti
259259
260260 if ( index >= 0 && auxIndex >= 0 )
261261 {
262- if ( definition.standardTemplate () == QgsPropertyDefinition::ColorNoAlpha
263- || definition.standardTemplate () == QgsPropertyDefinition::ColorWithAlpha )
262+ if ( isHiddenProperty ( auxIndex ) )
263+ {
264+ // update editor widget
265+ QgsEditorWidgetSetup setup = QgsEditorWidgetSetup ( QStringLiteral ( " Hidden" ), QVariantMap () );
266+ setEditorWidgetSetup ( auxIndex, setup );
267+
268+ // column is hidden
269+ QgsAttributeTableConfig attrCfg = mLayer ->attributeTableConfig ();
270+ attrCfg.update ( mLayer ->fields () );
271+ QVector<QgsAttributeTableConfig::ColumnConfig> columns = attrCfg.columns ();
272+ QVector<QgsAttributeTableConfig::ColumnConfig>::iterator it;
273+
274+ for ( it = columns.begin (); it != columns.end (); ++it )
275+ {
276+ if ( it->name .compare ( mLayer ->fields ().field ( index ).name () ) == 0 )
277+ it->hidden = true ;
278+ }
279+
280+ attrCfg.setColumns ( columns );
281+ mLayer ->setAttributeTableConfig ( attrCfg );
282+ }
283+ else if ( definition.standardTemplate () == QgsPropertyDefinition::ColorNoAlpha
284+ || definition.standardTemplate () == QgsPropertyDefinition::ColorWithAlpha )
264285 {
265286 QgsEditorWidgetSetup setup = QgsEditorWidgetSetup ( QStringLiteral ( " Color" ), QVariantMap () );
266287 setEditorWidgetSetup ( auxIndex, setup );
Original file line number Diff line number Diff line change @@ -178,7 +178,9 @@ class CORE_EXPORT QgsAuxiliaryLayer : public QgsVectorLayer
178178 bool exists ( const QgsPropertyDefinition &definition ) const ;
179179
180180 /* *
181- * Add an an auxiliary field for the given property.
181+ * Add an an auxiliary field for the given property. Setup for widget
182+ * editors are updated in the target layer as weel as the attribute
183+ * table config to hide auxiliary fields by default.
182184 *
183185 * \param definition The definition of the property to add
184186 *
Original file line number Diff line number Diff line change @@ -3077,31 +3077,6 @@ void QgsVectorLayer::updateFields()
30773077 mFields [index].setEditorWidgetSetup ( fieldWidgetIterator.value () );
30783078 }
30793079
3080- // update attribute table config
3081- mAttributeTableConfig .update ( fields () );
3082-
3083- if ( auxiliaryLayer () )
3084- {
3085- QVector<QgsAttributeTableConfig::ColumnConfig> columns = mAttributeTableConfig .columns ();
3086-
3087- QVector<QgsAttributeTableConfig::ColumnConfig>::iterator it;
3088- for ( it = columns.begin (); it != columns.end (); ++it )
3089- {
3090- int idx = fields ().lookupField ( it->name );
3091- if ( idx >= 0 )
3092- {
3093- int srcIdx = -1 ;
3094- if ( !isAuxiliaryField ( idx, srcIdx ) )
3095- continue ;
3096-
3097- if ( auxiliaryLayer ()->isHiddenProperty ( srcIdx ) )
3098- it->hidden = true ;
3099- }
3100- }
3101-
3102- mAttributeTableConfig .setColumns ( columns );
3103- }
3104-
31053080 if ( oldFields != mFields )
31063081 {
31073082 emit updatedFields ();
You can’t perform that action at this time.
0 commit comments