Skip to content

Commit

Permalink
update container visibilty on mode change
Browse files Browse the repository at this point in the history
  • Loading branch information
signedav committed Sep 11, 2018
1 parent 4da6e69 commit 05b1e83
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/gui/qgsattributeform.cpp
Expand Up @@ -77,9 +77,9 @@ QgsAttributeForm::QgsAttributeForm( QgsVectorLayer *vl, const QgsFeature &featur
connect( vl, &QgsVectorLayer::beforeAddingExpressionField, this, &QgsAttributeForm::preventFeatureRefresh );
connect( vl, &QgsVectorLayer::beforeRemovingExpressionField, this, &QgsAttributeForm::preventFeatureRefresh );
connect( vl, &QgsVectorLayer::selectionChanged, this, &QgsAttributeForm::layerSelectionChanged );
connect( this, &QgsAttributeForm::modeChanged, this, &QgsAttributeForm::updateContainersVisibility );

// constraints management
updateAllConstraints();
updateContainersVisibility();
}

QgsAttributeForm::~QgsAttributeForm()
Expand Down Expand Up @@ -823,6 +823,7 @@ void QgsAttributeForm::updateConstraints( QgsEditorWidgetWrapper *eww )
synchronizeEnabledState();

mExpressionContext.setFeature( ft );

mExpressionContext << QgsExpressionContextUtils::formScope( ft, modeString( mMode ) );

// Recheck visibility for all containers which are controlled by this value
Expand All @@ -834,6 +835,22 @@ void QgsAttributeForm::updateConstraints( QgsEditorWidgetWrapper *eww )
}
}

void QgsAttributeForm::updateContainersVisibility()
{

mExpressionContext << QgsExpressionContextUtils::formScope( QgsFeature( mFeature ), modeString( mMode ) );

const QVector<ContainerInformation *> infos = mContainerVisibilityInformation;

for ( ContainerInformation *info : infos )
{
info->apply( &mExpressionContext );
}

//and update the constraints
updateAllConstraints();
}

void QgsAttributeForm::updateConstraint( const QgsFeature &ft, QgsEditorWidgetWrapper *eww )
{
QgsFieldConstraints::ConstraintOrigin constraintOrigin = mLayer->isEditable() ? QgsFieldConstraints::ConstraintOriginNotSet : QgsFieldConstraints::ConstraintOriginLayer;
Expand Down
1 change: 1 addition & 0 deletions src/gui/qgsattributeform.h
Expand Up @@ -364,6 +364,7 @@ class GUI_EXPORT QgsAttributeForm : public QWidget
//! constraints management
void updateAllConstraints();
void updateConstraints( QgsEditorWidgetWrapper *w );
void updateContainersVisibility();
void updateConstraint( const QgsFeature &ft, QgsEditorWidgetWrapper *eww );
bool currentFormFeature( QgsFeature &feature );
bool currentFormValidConstraints( QStringList &invalidFields, QStringList &descriptions );
Expand Down

0 comments on commit 05b1e83

Please sign in to comment.