Skip to content
Permalink
Browse files

Merge pull request #40963 from elpaso/bugfix-gh40910-valuerelation-mu…

…lti-edit

Fix drill-down in multi-edit mode
  • Loading branch information
elpaso committed Jan 12, 2021
2 parents cbfd7b0 + 7a9d3f5 commit fa6d28100cf103e15729bc30df879263a2e96f50
@@ -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 );
@@ -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();
}
@@ -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( ) )
@@ -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 )
@@ -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;
}
@@ -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()
@@ -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() );
}

0 comments on commit fa6d281

Please sign in to comment.
You can’t perform that action at this time.