Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix #43539 Bad edit button states in relation editor widget for n:m r…
…elations (#43579)

* Fix #43539

Use QgsVectorLayer::supportsEditing() instead of QgsVectorLayer::Capability::ChangeAttributeValues

Additional fix link and save edit buttons enabled/disabled correctly
when only the final or the middle table are editable

* Layers should not read only

* Toggle button enabled if at least one involved layer supports editing
  • Loading branch information
domi4484 committed Jun 10, 2021
1 parent 6aa0cbe commit fc1ded8
Showing 1 changed file with 9 additions and 25 deletions.
34 changes: 9 additions & 25 deletions src/gui/qgsrelationeditorwidget.cpp
Expand Up @@ -273,24 +273,28 @@ void QgsRelationEditorWidget::setViewMode( QgsDualView::ViewMode mode )

void QgsRelationEditorWidget::updateButtons()
{
bool toggleEditingButtonEnabled = false;
bool editable = false;
bool linkable = false;
bool spatial = false;
bool selectionNotEmpty = mFeatureSelectionMgr ? mFeatureSelectionMgr->selectedFeatureCount() : false;

if ( mRelation.isValid() )
{
toggleEditingButtonEnabled = mRelation.referencingLayer()->supportsEditing();
editable = mRelation.referencingLayer()->isEditable();
linkable = mRelation.referencingLayer()->isEditable();
spatial = mRelation.referencingLayer()->isSpatial();
}

if ( mNmRelation.isValid() )
{
toggleEditingButtonEnabled |= mNmRelation.referencedLayer()->supportsEditing();
editable = mNmRelation.referencedLayer()->isEditable();
spatial = mNmRelation.referencedLayer()->isSpatial();
}

mToggleEditingButton->setEnabled( toggleEditingButtonEnabled );
mAddFeatureButton->setEnabled( editable );
mAddFeatureGeometryButton->setEnabled( editable );
mDuplicateFeatureButton->setEnabled( editable && selectionNotEmpty );
Expand All @@ -299,7 +303,7 @@ void QgsRelationEditorWidget::updateButtons()
mUnlinkFeatureButton->setEnabled( linkable && selectionNotEmpty );
mZoomToFeatureButton->setEnabled( selectionNotEmpty );
mToggleEditingButton->setChecked( editable );
mSaveEditsButton->setEnabled( editable );
mSaveEditsButton->setEnabled( editable || linkable );

mToggleEditingButton->setVisible( !mLayerInSameTransactionGroup );

Expand Down Expand Up @@ -503,25 +507,16 @@ void QgsRelationEditorWidget::beforeSetRelationFeature( const QgsRelation &newRe

void QgsRelationEditorWidget::afterSetRelationFeature()
{
mToggleEditingButton->setEnabled( false );

if ( ! mRelation.isValid() )
{
updateButtons();
return;
}

connect( mRelation.referencingLayer(), &QgsVectorLayer::editingStarted, this, &QgsRelationEditorWidget::updateButtons );
connect( mRelation.referencingLayer(), &QgsVectorLayer::editingStopped, this, &QgsRelationEditorWidget::updateButtons );

QgsVectorLayer *vl = mRelation.referencingLayer();
bool canChangeAttributes = vl->dataProvider()->capabilities() & QgsVectorDataProvider::ChangeAttributeValues;
if ( canChangeAttributes && !vl->readOnly() )
{
mToggleEditingButton->setEnabled( true );
updateButtons();
}
else
{
mToggleEditingButton->setEnabled( false );
}
updateButtons();

QgsFeatureRequest myRequest = mRelation.getRelatedFeaturesRequest( mFeature );
initDualView( mRelation.referencingLayer(), myRequest );
Expand Down Expand Up @@ -559,17 +554,6 @@ void QgsRelationEditorWidget::afterSetRelations()
connect( mNmRelation.referencedLayer(), &QgsVectorLayer::editingStopped, this, &QgsRelationEditorWidget::updateButtons );
}

QgsVectorLayer *vl = mRelation.referencingLayer();
bool canChangeAttributes = vl->dataProvider()->capabilities() & QgsVectorDataProvider::ChangeAttributeValues;
if ( canChangeAttributes && !vl->readOnly() )
{
mToggleEditingButton->setEnabled( true );
}
else
{
mToggleEditingButton->setEnabled( false );
}

updateButtons();
}

Expand Down

0 comments on commit fc1ded8

Please sign in to comment.