Skip to content

Commit

Permalink
Set editor widget setup to Hidden
Browse files Browse the repository at this point in the history
  • Loading branch information
pblottiere committed Oct 9, 2017
1 parent baa2b96 commit 97ee342
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
4 changes: 3 additions & 1 deletion python/core/qgsauxiliarystorage.sip
Expand Up @@ -156,7 +156,9 @@ class QgsAuxiliaryLayer : QgsVectorLayer

bool addAuxiliaryField( const QgsPropertyDefinition &definition );
%Docstring
Add an an auxiliary field for the given property.
Add an an auxiliary field for the given property. Setup for widget
editors are updated in the target layer as weel as the attribute
table config to hide auxiliary fields by default.

\param definition The definition of the property to add

Expand Down
25 changes: 23 additions & 2 deletions src/core/qgsauxiliarystorage.cpp
Expand Up @@ -259,8 +259,29 @@ bool QgsAuxiliaryLayer::addAuxiliaryField( const QgsPropertyDefinition &definiti

if ( index >= 0 && auxIndex >= 0 )
{
if ( definition.standardTemplate() == QgsPropertyDefinition::ColorNoAlpha
|| definition.standardTemplate() == QgsPropertyDefinition::ColorWithAlpha )
if ( isHiddenProperty( auxIndex ) )
{
// update editor widget
QgsEditorWidgetSetup setup = QgsEditorWidgetSetup( QStringLiteral( "Hidden" ), QVariantMap() );
setEditorWidgetSetup( auxIndex, setup );

// column is hidden
QgsAttributeTableConfig attrCfg = mLayer->attributeTableConfig();
attrCfg.update( mLayer->fields() );
QVector<QgsAttributeTableConfig::ColumnConfig> columns = attrCfg.columns();
QVector<QgsAttributeTableConfig::ColumnConfig>::iterator it;

for ( it = columns.begin(); it != columns.end(); ++it )
{
if ( it->name.compare( mLayer->fields().field( index ).name() ) == 0 )
it->hidden = true;
}

attrCfg.setColumns( columns );
mLayer->setAttributeTableConfig( attrCfg );
}
else if ( definition.standardTemplate() == QgsPropertyDefinition::ColorNoAlpha
|| definition.standardTemplate() == QgsPropertyDefinition::ColorWithAlpha )
{
QgsEditorWidgetSetup setup = QgsEditorWidgetSetup( QStringLiteral( "Color" ), QVariantMap() );
setEditorWidgetSetup( auxIndex, setup );
Expand Down
4 changes: 3 additions & 1 deletion src/core/qgsauxiliarystorage.h
Expand Up @@ -178,7 +178,9 @@ class CORE_EXPORT QgsAuxiliaryLayer : public QgsVectorLayer
bool exists( const QgsPropertyDefinition &definition ) const;

/**
* Add an an auxiliary field for the given property.
* Add an an auxiliary field for the given property. Setup for widget
* editors are updated in the target layer as weel as the attribute
* table config to hide auxiliary fields by default.
*
* \param definition The definition of the property to add
*
Expand Down
25 changes: 0 additions & 25 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -3077,31 +3077,6 @@ void QgsVectorLayer::updateFields()
mFields[index].setEditorWidgetSetup( fieldWidgetIterator.value() );
}

// update attribute table config
mAttributeTableConfig.update( fields() );

if ( auxiliaryLayer() )
{
QVector<QgsAttributeTableConfig::ColumnConfig> columns = mAttributeTableConfig.columns();

QVector<QgsAttributeTableConfig::ColumnConfig>::iterator it;
for ( it = columns.begin(); it != columns.end(); ++it )
{
int idx = fields().lookupField( it->name );
if ( idx >= 0 )
{
int srcIdx = -1;
if ( !isAuxiliaryField( idx, srcIdx ) )
continue;

if ( auxiliaryLayer()->isHiddenProperty( srcIdx ) )
it->hidden = true;
}
}

mAttributeTableConfig.setColumns( columns );
}

if ( oldFields != mFields )
{
emit updatedFields();
Expand Down

0 comments on commit 97ee342

Please sign in to comment.