Skip to content
Permalink
Browse files

use member to keep state if related layer is in transaction group to …

…set toggleEditing and SaveEdits button visibility

check the "other parent" in transaction group depending on if it's a many-to-many cardinality or one-to-many

fix that it sets toggle-edit and save button to invisible if child layer is in transaction group (even if it's not in the same transaction group like the parent)

Means:
on one-to-many, we check if parent and child are in the same transaction group:
parent-layer (relation->referencedLayer)
child-layer (relation->referencingLayer)

on many-to-many, we check if parent and child and the other parent are in the same transaction group:
parent-layer (relation->referencedLayer)
child-layer / relation-layer (relation->referencingLayer)
other parent layer (nmrelation->referencedLayer)
  • Loading branch information
signedav committed Sep 11, 2020
1 parent 68c4f9b commit 899b4d8eda4b3cfee07e6c55a3b66007ae4fabbe
Showing with 15 additions and 4 deletions.
  1. +14 −4 src/gui/qgsrelationeditorwidget.cpp
  2. +1 −0 src/gui/qgsrelationeditorwidget.h
@@ -314,14 +314,23 @@ void QgsRelationEditorWidget::setRelations( const QgsRelation &relation, const Q
if ( !mRelation.isValid() )
return;

mToggleEditingButton->setVisible( true );
mLayerInSameTransactionGroup = false;

const auto transactionGroups = QgsProject::instance()->transactionGroups();
for ( auto it = transactionGroups.constBegin(); it != transactionGroups.constEnd(); ++it )
{
if ( it.value()->layers().contains( mRelation.referencingLayer() ) )
if ( mNmRelation.isValid() )
{
if ( it.value()->layers().contains( mRelation.referencedLayer() ) &&
it.value()->layers().contains( mRelation.referencingLayer() ) &&
it.value()->layers().contains( mNmRelation.referencedLayer() ) )
mLayerInSameTransactionGroup = true;
}
else
{
mToggleEditingButton->setVisible( false );
if ( it.value()->layers().contains( mRelation.referencedLayer() ) &&
it.value()->layers().contains( mRelation.referencingLayer() ) )
mLayerInSameTransactionGroup = true;
}
}

@@ -424,9 +433,10 @@ void QgsRelationEditorWidget::updateButtons()
mToggleEditingButton->setChecked( editable );
mSaveEditsButton->setEnabled( editable );

mToggleEditingButton->setVisible( !mLayerInSameTransactionGroup );
mLinkFeatureButton->setVisible( mButtonsVisibility.testFlag( QgsAttributeEditorRelation::Button::Link ) );
mUnlinkFeatureButton->setVisible( mButtonsVisibility.testFlag( QgsAttributeEditorRelation::Button::Unlink ) );
mSaveEditsButton->setVisible( mButtonsVisibility.testFlag( QgsAttributeEditorRelation::Button::SaveChildEdits ) && mToggleEditingButton->isVisible() );
mSaveEditsButton->setVisible( mButtonsVisibility.testFlag( QgsAttributeEditorRelation::Button::SaveChildEdits ) && !mLayerInSameTransactionGroup );
mAddFeatureButton->setVisible( mButtonsVisibility.testFlag( QgsAttributeEditorRelation::Button::AddChildFeature ) );
mAddFeatureGeometryButton->setVisible( mButtonsVisibility.testFlag( QgsAttributeEditorRelation::Button::AddChildFeature ) && mEditorContext.mapCanvas() && mEditorContext.cadDockWidget() && spatial );
mDuplicateFeatureButton->setVisible( mButtonsVisibility.testFlag( QgsAttributeEditorRelation::Button::DuplicateChildFeature ) );
@@ -332,6 +332,7 @@ class GUI_EXPORT QgsRelationEditorWidget : public QgsCollapsibleGroupBox
QgsAttributeEditorRelation::Buttons mButtonsVisibility;
bool mShowLabel = true;
bool mVisible = false;
bool mLayerInSameTransactionGroup = false;

bool mForceSuppressFormPopup = false;
QVariant mNmRelationId;

0 comments on commit 899b4d8

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