Skip to content
Permalink
Browse files
Enable save icon for embedded relations in same transaction group
Fixes #43061
  • Loading branch information
elpaso committed Jun 18, 2021
1 parent cc41628 commit fc40045e5071981d32280c4a4017a83d3bed144f
Showing with 38 additions and 1 deletion.
  1. +36 −1 src/app/qgsattributetabledialog.cpp
  2. +2 −0 src/app/qgsattributetabledialog.h
@@ -57,6 +57,7 @@
#include "qgisapp.h"
#include "qgsorganizetablecolumnsdialog.h"
#include "qgsvectorlayereditbuffer.h"
#include "qgstransactiongroup.h"

QgsExpressionContext QgsAttributeTableDialog::createExpressionContext() const
{
@@ -231,6 +232,21 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *layer, QgsAttr
connect( mLayer, &QgsVectorLayer::readOnlyChanged, this, &QgsAttributeTableDialog::editingToggled );
connect( mLayer, &QgsVectorLayer::layerModified, this, &QgsAttributeTableDialog::updateLayerModifiedActions );

// When transaction group is enabled, collect related layers and connect modified actions to enable save action
const auto relations { QgsProject::instance()->relationManager()->referencedRelations( mLayer ) };
const auto transactionGroups = QgsProject::instance()->transactionGroups();
for ( const auto &relation : std::as_const( relations ) )
{
for ( auto it = transactionGroups.constBegin(); it != transactionGroups.constEnd(); ++it )
{
if ( relation.isValid() )
{
mReferencingLayers.push_back( relation.referencingLayer() );
connect( relation.referencingLayer(), &QgsVectorLayer::layerModified, this, &QgsAttributeTableDialog::updateLayerModifiedActions );
}
}
}

// connect table info to window
connect( mMainView, &QgsDualView::filterChanged, this, &QgsAttributeTableDialog::updateTitle );
connect( mMainView, &QgsDualView::filterExpressionSet, this, &QgsAttributeTableDialog::formFilterSet );
@@ -606,6 +622,13 @@ void QgsAttributeTableDialog::mActionOpenFieldCalculator_triggered()
void QgsAttributeTableDialog::mActionSaveEdits_triggered()
{
QgisApp::instance()->saveEdits( mLayer, true, true );
for ( const auto &referencingLayer : std::as_const( mReferencingLayers ) )
{
if ( referencingLayer )
{
QgisApp::instance()->saveEdits( referencingLayer, true, true );
}
}
}

void QgsAttributeTableDialog::mActionReload_triggered()
@@ -1057,7 +1080,19 @@ void QgsAttributeTableDialog::toggleDockMode( bool docked )

void QgsAttributeTableDialog::updateLayerModifiedActions()
{
mActionSaveEdits->setEnabled( mActionToggleEditing->isEnabled() && mLayer->isEditable() && mLayer->isModified() );
bool saveEnabled { mActionToggleEditing->isEnabled() &&mLayer->isEditable() &&mLayer->isModified() };
if ( ! saveEnabled && mActionToggleEditing->isEnabled() )
{
for ( const auto &referencingLayer : std::as_const( mReferencingLayers ) )
{
if ( referencingLayer && referencingLayer->isEditable() && referencingLayer->isModified() )
{
saveEnabled = true;
break;
}
}
}
mActionSaveEdits->setEnabled( saveEnabled );
}

//
@@ -228,6 +228,8 @@ class APP_EXPORT QgsAttributeTableDialog : public QDialog, private Ui::QgsAttrib
void updateMultiEditButtonState();
void deleteFeature( QgsFeatureId fid );

QList< QPointer< QgsVectorLayer> > mReferencingLayers;

friend class TestQgsAttributeTable;
};

0 comments on commit fc40045

Please sign in to comment.