38 if ( mConnString.isEmpty() )
48 mLayers.insert( layer );
51 connect( layer, &QgsVectorLayer::destroyed,
this, &QgsTransactionGroup::onLayerDeleted );
63 const auto constMLayers = mLayers;
66 if ( layer->isModified() )
72 void QgsTransactionGroup::onEditingStarted()
82 mTransaction->begin( errorMsg );
84 const auto constMLayers = mLayers;
87 mTransaction->addLayer( layer );
88 layer->startEditing();
94 void QgsTransactionGroup::onLayerDeleted()
99 void QgsTransactionGroup::onBeforeCommitChanges(
bool stopEditing )
101 if ( mEditingStopping )
104 mEditingStopping =
true;
106 const QgsVectorLayer *triggeringLayer = qobject_cast<QgsVectorLayer *>( sender() );
109 if ( mTransaction->commit( errMsg ) )
111 const auto constMLayers = mLayers;
114 if ( layer != triggeringLayer )
116 layer->commitChanges( stopEditing );
122 disableTransaction();
126 if ( ! mTransaction->begin( errMsg ) )
128 QgsDebugMsg( QStringLiteral(
"Could not restart a transaction for %1: %2" ).arg( triggeringLayer->
name() ).arg( errMsg ) );
136 restartTransaction( triggeringLayer );
138 mEditingStopping =
false;
141 void QgsTransactionGroup::onRollback()
143 if ( mEditingStopping )
146 mEditingStopping =
true;
148 QgsVectorLayer *triggeringLayer = qobject_cast<QgsVectorLayer *>( sender() );
151 if ( mTransaction->rollback( errMsg ) )
153 const auto constMLayers = mLayers;
156 if ( layer != triggeringLayer )
159 disableTransaction();
163 restartTransaction( triggeringLayer );
165 mEditingStopping =
false;
168 void QgsTransactionGroup::disableTransaction()
170 mTransaction.reset();
172 const auto constMLayers = mLayers;
180 void QgsTransactionGroup::restartTransaction(
const QgsVectorLayer *layer )
193 return mLayers.isEmpty();