Skip to content

Commit

Permalink
Fix #43539, backport from #43579
Browse files Browse the repository at this point in the history
  • Loading branch information
domi4484 authored and nyalldawson committed Jun 14, 2021
1 parent 1e3aae0 commit 4cb8343
Showing 1 changed file with 10 additions and 25 deletions.
35 changes: 10 additions & 25 deletions src/gui/qgsrelationeditorwidget.cpp
Expand Up @@ -233,18 +233,7 @@ void QgsRelationEditorWidget::setRelationFeature( const QgsRelation &relation, c

updateTitle();

QgsVectorLayer *lyr = relation.referencingLayer();

bool canChangeAttributes = lyr->dataProvider()->capabilities() & QgsVectorDataProvider::ChangeAttributeValues;
if ( canChangeAttributes && !lyr->readOnly() )
{
mToggleEditingButton->setEnabled( true );
updateButtons();
}
else
{
mToggleEditingButton->setEnabled( false );
}
updateButtons();

setObjectName( QStringLiteral( "referenced/" ) + mRelation.name() );

Expand Down Expand Up @@ -345,18 +334,6 @@ void QgsRelationEditorWidget::setRelations( const QgsRelation &relation, const Q

updateTitle();

QgsVectorLayer *lyr = relation.referencingLayer();

bool canChangeAttributes = lyr->dataProvider()->capabilities() & QgsVectorDataProvider::ChangeAttributeValues;
if ( canChangeAttributes && !lyr->readOnly() )
{
mToggleEditingButton->setEnabled( true );
}
else
{
mToggleEditingButton->setEnabled( false );
}

updateButtons();

setObjectName( QStringLiteral( "referenced/" ) + mRelation.name() );
Expand Down Expand Up @@ -405,24 +382,32 @@ void QgsRelationEditorWidget::setFeature( const QgsFeature &feature, bool update

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

if ( mRelation.isValid() )
{
bool canSupportEditing = mRelation.referencingLayer()->dataProvider()->capabilities() & QgsVectorDataProvider::EditingCapabilities;
canSupportEditing &= !mRelation.referencingLayer()->readOnly();
toggleEditingButtonEnabled = canSupportEditing;
editable = mRelation.referencingLayer()->isEditable();
linkable = mRelation.referencingLayer()->isEditable();
spatial = mRelation.referencingLayer()->isSpatial();
}

if ( mNmRelation.isValid() )
{
bool canSupportEditing = mNmRelation.referencedLayer()->dataProvider()->capabilities() & QgsVectorDataProvider::EditingCapabilities;
canSupportEditing &= !mNmRelation.referencedLayer()->readOnly();
toggleEditingButtonEnabled |= canSupportEditing;
editable = mNmRelation.referencedLayer()->isEditable();
spatial = mNmRelation.referencedLayer()->isSpatial();
}

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

mToggleEditingButton->setVisible( !mLayerInSameTransactionGroup );
mLinkFeatureButton->setVisible( mButtonsVisibility.testFlag( QgsAttributeEditorRelation::Button::Link ) );
Expand Down

0 comments on commit 4cb8343

Please sign in to comment.