Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
refresh QgsAttributeForm using updatedFields() signal to cover all ch…
…anges
  • Loading branch information
blazek committed Sep 29, 2015
1 parent 8e971c2 commit d70c854
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/gui/qgsattributeform.cpp
Expand Up @@ -52,8 +52,13 @@ QgsAttributeForm::QgsAttributeForm( QgsVectorLayer* vl, const QgsFeature &featur
initPython();
setFeature( feature );

// Using attributeAdded() attributeDeleted() are not emited on all fields changes (e.g. layer fields changed,
// joined fields changed) -> use updatedFields() instead
#if 0
connect( vl, SIGNAL( attributeAdded( int ) ), this, SLOT( onAttributeAdded( int ) ) );
connect( vl, SIGNAL( attributeDeleted( int ) ), this, SLOT( onAttributeDeleted( int ) ) );
#endif
connect( vl, SIGNAL( updatedFields() ), this, SLOT( onUpdatedFields() ) );
connect( vl, SIGNAL( beforeAddingExpressionField( QString ) ), this, SLOT( preventFeatureRefresh() ) );
connect( vl, SIGNAL( beforeRemovingExpressionField( int ) ), this, SLOT( preventFeatureRefresh() ) );
}
Expand Down Expand Up @@ -303,6 +308,35 @@ void QgsAttributeForm::onAttributeDeleted( int idx )
setFeature( mFeature );
}

void QgsAttributeForm::onUpdatedFields()
{
mPreventFeatureRefresh = false;
if ( mFeature.isValid() )
{
QgsAttributes attrs( layer()->fields().size() );
for ( int i = 0; i < layer()->fields().size(); i++ )
{
int idx = mFeature.fields()->indexFromName( layer()->fields()[i].name() );
if ( idx != -1 )
{
attrs[i] = mFeature.attributes()[idx];
if ( mFeature.attributes()[idx].type() != layer()->fields()[i].type() )
{
attrs[i].convert( layer()->fields()[i].type() );
}
}
else
{
attrs[i] = QVariant( layer()->fields()[i].type() );
}
}
mFeature.setFields( layer()->fields() );
mFeature.setAttributes( attrs );
}
init();
setFeature( mFeature );
}

void QgsAttributeForm::preventFeatureRefresh()
{
mPreventFeatureRefresh = true;
Expand Down
1 change: 1 addition & 0 deletions src/gui/qgsattributeform.h
Expand Up @@ -173,6 +173,7 @@ class GUI_EXPORT QgsAttributeForm : public QWidget
void onAttributeChanged( const QVariant& value );
void onAttributeAdded( int idx );
void onAttributeDeleted( int idx );
void onUpdatedFields();

void preventFeatureRefresh();
void synchronizeEnabledState();
Expand Down

0 comments on commit d70c854

Please sign in to comment.