Skip to content
Permalink
Browse files
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 fc1ded802eefb6ba99156c33ddad15498442d256
Showing with 9 additions and 25 deletions.
  1. +9 −25 src/gui/qgsrelationeditorwidget.cpp
@@ -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 );
@@ -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 );

@@ -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 );
@@ -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();
}

0 comments on commit fc1ded8

Please sign in to comment.