Skip to content

Commit

Permalink
Merge pull request #40963 from elpaso/bugfix-gh40910-valuerelation-mu…
Browse files Browse the repository at this point in the history
…lti-edit

Fix drill-down in multi-edit mode
  • Loading branch information
elpaso committed Jan 12, 2021
2 parents cbfd7b0 + 7a9d3f5 commit fa6d281
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 22 deletions.
3 changes: 2 additions & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -10104,12 +10104,13 @@ void QgisApp::modifyAttributesOfSelectedFeatures()
}

//dummy feature
QgsFeature f;
QgsFeature f( vl->fields() );
QgsAttributeEditorContext context( createAttributeEditorContext() );
context.setAllowCustomUi( false );
context.setVectorLayerTools( mVectorLayerTools );
context.setCadDockWidget( mAdvancedDigitizingDockWidget );
context.setMapCanvas( mMapCanvas );
context.setAttributeFormMode( QgsAttributeEditorContext::Mode::MultiEditMode );

QgsAttributeDialog *dialog = new QgsAttributeDialog( vl, &f, false, this, true, context );
dialog->setMode( QgsAttributeEditorContext::MultiEditMode );
Expand Down
15 changes: 12 additions & 3 deletions src/gui/editorwidgets/qgsvaluerelationwidgetwrapper.cpp
Expand Up @@ -281,9 +281,18 @@ void QgsValueRelationWidgetWrapper::widgetValueChanged( const QString &attribute
// If the value has changed as a result of another widget's value change,
// we need to emit the signal to make sure other dependent widgets are
// updated.
if ( oldValue != value() && fieldIdx() < formFeature().fields().count() )
QgsFields formFields( formFeature().fields() );

// Also check for fields in the layer in case this is a multi-edit form
// and there is not form feature set
if ( formFields.count() == 0 && layer() )
{
formFields = layer()->fields();
}

if ( oldValue != value() && fieldIdx() < formFields.count() )
{
QString attributeName( formFeature().fields().names().at( fieldIdx() ) );
QString attributeName( formFields.names().at( fieldIdx() ) );
setFormFeatureAttribute( attributeName, value( ) );
emitValueChanged();
}
Expand All @@ -305,7 +314,7 @@ void QgsValueRelationWidgetWrapper::setFeature( const QgsFeature &feature )
// A bit of logic to set the default value if AllowNull is false and this is a new feature
// Note that this needs to be here after the cache has been created/updated by populate()
// and signals unblocked (we want this to propagate to the feature itself)
if ( formFeature().isValid()
if ( context().attributeFormMode() != QgsAttributeEditorContext::Mode::MultiEditMode
&& ! formFeature().attribute( fieldIdx() ).isValid()
&& ! mCache.isEmpty()
&& ! config( QStringLiteral( "AllowNull" ) ).toBool( ) )
Expand Down
41 changes: 24 additions & 17 deletions src/gui/qgsattributeform.cpp
Expand Up @@ -704,8 +704,8 @@ bool QgsAttributeForm::saveMultiEdits()

bool success = true;

const auto constMMultiEditFeatureIds = mMultiEditFeatureIds;
for ( QgsFeatureId fid : constMMultiEditFeatureIds )
const auto constMultiEditFeatureIds = mMultiEditFeatureIds;
for ( QgsFeatureId fid : constMultiEditFeatureIds )
{
QgsAttributeMap::const_iterator aIt = newAttributeValues.constBegin();
for ( ; aIt != newAttributeValues.constEnd(); ++aIt )
Expand Down Expand Up @@ -914,6 +914,8 @@ void QgsAttributeForm::onAttributeChanged( const QVariant &value, const QVariant
mMultiEditUnsavedMessageBarItem = new QgsMessageBarItem( msgLabel, Qgis::Warning );
if ( !mButtonBox->isVisible() )
mMessageBar->pushItem( mMultiEditUnsavedMessageBarItem );

emit widgetValueChanged( eww->field().name(), value, !mIsSettingFeature );
}
break;
}
Expand Down Expand Up @@ -1008,30 +1010,35 @@ void QgsAttributeForm::updateContainersVisibility()

void QgsAttributeForm::updateConstraint( const QgsFeature &ft, QgsEditorWidgetWrapper *eww )
{
QgsFieldConstraints::ConstraintOrigin constraintOrigin = mLayer->isEditable() ? QgsFieldConstraints::ConstraintOriginNotSet : QgsFieldConstraints::ConstraintOriginLayer;

if ( eww->layer()->fields().fieldOrigin( eww->fieldIdx() ) == QgsFields::OriginJoin )
if ( mContext.attributeFormMode() != QgsAttributeEditorContext::Mode::MultiEditMode )
{
int srcFieldIdx;
const QgsVectorLayerJoinInfo *info = eww->layer()->joinBuffer()->joinForFieldIndex( eww->fieldIdx(), eww->layer()->fields(), srcFieldIdx );

if ( info && info->joinLayer() && info->isDynamicFormEnabled() )
QgsFieldConstraints::ConstraintOrigin constraintOrigin = mLayer->isEditable() ? QgsFieldConstraints::ConstraintOriginNotSet : QgsFieldConstraints::ConstraintOriginLayer;

if ( eww->layer()->fields().fieldOrigin( eww->fieldIdx() ) == QgsFields::OriginJoin )
{
if ( mJoinedFeatures.contains( info ) )
{
eww->updateConstraint( info->joinLayer(), srcFieldIdx, mJoinedFeatures[info], constraintOrigin );
return;
}
else // if we are here, it means there's not joined field for this feature
int srcFieldIdx;
const QgsVectorLayerJoinInfo *info = eww->layer()->joinBuffer()->joinForFieldIndex( eww->fieldIdx(), eww->layer()->fields(), srcFieldIdx );

if ( info && info->joinLayer() && info->isDynamicFormEnabled() )
{
eww->updateConstraint( QgsFeature() );
return;
if ( mJoinedFeatures.contains( info ) )
{
eww->updateConstraint( info->joinLayer(), srcFieldIdx, mJoinedFeatures[info], constraintOrigin );
return;
}
else // if we are here, it means there's not joined field for this feature
{
eww->updateConstraint( QgsFeature() );
return;
}
}
}
// default constraint update
eww->updateConstraint( ft, constraintOrigin );
}

// default constraint update
eww->updateConstraint( ft, constraintOrigin );
}

void QgsAttributeForm::updateLabels()
Expand Down
3 changes: 2 additions & 1 deletion src/gui/qgsattributeformeditorwidget.cpp
Expand Up @@ -221,7 +221,8 @@ void QgsAttributeFormEditorWidget::setFieldTriggered()

void QgsAttributeFormEditorWidget::onAggregateChanged()
{
for ( QgsSearchWidgetWrapper *searchWidget : searchWidgetWrappers() )
const auto constWigets( searchWidgetWrappers() );
for ( QgsSearchWidgetWrapper *searchWidget : constWigets )
searchWidget->setAggregate( mAggregateButton->aggregate() );
}

Expand Down

0 comments on commit fa6d281

Please sign in to comment.