Skip to content
Permalink
Browse files

Merge pull request #39286 from elpaso/bugfix-gh39282-transaction-grou…

…p-editing-status-on-other-layers

Transaction group: keep editing status after save
  • Loading branch information
elpaso committed Oct 10, 2020
2 parents 6829e63 + 72c8673 commit 8eb52c8282df73d4b4114ad580ef1febc4560877
@@ -85,7 +85,7 @@ void QgsTransactionGroup::onEditingStarted()
{
mTransaction->addLayer( layer );
layer->startEditing();
connect( layer, &QgsVectorLayer::beforeCommitChanges, this, &QgsTransactionGroup::onCommitChanges );
connect( layer, &QgsVectorLayer::beforeCommitChanges, this, &QgsTransactionGroup::onBeforeCommitChanges );
connect( layer, &QgsVectorLayer::beforeRollBack, this, &QgsTransactionGroup::onRollback );
}
}
@@ -95,7 +95,7 @@ void QgsTransactionGroup::onLayerDeleted()
mLayers.remove( static_cast<QgsVectorLayer *>( sender() ) );
}

void QgsTransactionGroup::onCommitChanges()
void QgsTransactionGroup::onBeforeCommitChanges( bool stopEditing )
{
if ( mEditingStopping )
return;
@@ -111,7 +111,7 @@ void QgsTransactionGroup::onCommitChanges()
for ( QgsVectorLayer *layer : constMLayers )
{
if ( layer != sender() )
layer->commitChanges();
layer->commitChanges( stopEditing );
}

disableTransaction();
@@ -160,7 +160,7 @@ void QgsTransactionGroup::disableTransaction()
const auto constMLayers = mLayers;
for ( QgsVectorLayer *layer : constMLayers )
{
disconnect( layer, &QgsVectorLayer::beforeCommitChanges, this, &QgsTransactionGroup::onCommitChanges );
disconnect( layer, &QgsVectorLayer::beforeCommitChanges, this, &QgsTransactionGroup::onBeforeCommitChanges );
disconnect( layer, &QgsVectorLayer::beforeRollBack, this, &QgsTransactionGroup::onRollback );
}
}
@@ -82,7 +82,7 @@ class CORE_EXPORT QgsTransactionGroup : public QObject
private slots:
void onEditingStarted();
void onLayerDeleted();
void onCommitChanges();
void onBeforeCommitChanges( bool stopEditing );
void onRollback();

private:
@@ -104,6 +104,27 @@ def test_transactionsGroup(self):
self.assertIsNone(noTg)
self.rollbackTransaction()

def test_transactionGroupEditingStatus(self):
"""Not particularly related to PG but it fits here nicely: test GH #39282"""

project = QgsProject()
project.setAutoTransaction(True)

vl_b = QgsVectorLayer(self.dbconn + ' sslmode=disable key=\'pk\' table="qgis_test"."books" sql=', 'books',
'postgres')
vl_a = QgsVectorLayer(self.dbconn + ' sslmode=disable key=\'pk\' table="qgis_test"."authors" sql=',
'authors', 'postgres')

project.addMapLayers([vl_a, vl_b])

vl_a.startEditing()
self.assertTrue(vl_a.isEditable())
self.assertTrue(vl_b.isEditable())

self.assertTrue(vl_a.commitChanges(False))
self.assertTrue(vl_a.isEditable())
self.assertTrue(vl_b.isEditable())


if __name__ == '__main__':
unittest.main()

0 comments on commit 8eb52c8

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