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() )
72void QgsTransactionGroup::onEditingStarted()
82 mTransaction->begin( errorMsg );
84 const auto triggeringLayer = qobject_cast<QgsVectorLayer *>( sender() );
86 const auto constMLayers = mLayers;
89 mTransaction->addLayer( layer,
true );
92 if ( layer != triggeringLayer )
94 layer->startEditing();
103void QgsTransactionGroup::onLayerDeleted()
108void QgsTransactionGroup::onBeforeCommitChanges(
bool stopEditing )
110 if ( mEditingStopping )
113 mEditingStopping =
true;
115 const QgsVectorLayer *triggeringLayer = qobject_cast<QgsVectorLayer *>( sender() );
118 if ( mTransaction->commit( errMsg ) )
120 const auto constMLayers = mLayers;
123 if ( layer != triggeringLayer )
125 layer->commitChanges( stopEditing );
131 disableTransaction();
135 if ( ! mTransaction->begin( errMsg ) )
137 QgsDebugError( QStringLiteral(
"Could not restart a transaction for %1: %2" ).arg( triggeringLayer->
name() ).arg( errMsg ) );
145 restartTransaction( triggeringLayer );
147 mEditingStopping =
false;
150void QgsTransactionGroup::onRollback()
152 if ( mEditingStopping )
155 mEditingStopping =
true;
157 QgsVectorLayer *triggeringLayer = qobject_cast<QgsVectorLayer *>( sender() );
160 if ( mTransaction->rollback( errMsg ) )
162 const auto constMLayers = mLayers;
165 if ( layer != triggeringLayer )
168 disableTransaction();
172 restartTransaction( triggeringLayer );
174 mEditingStopping =
false;
177void QgsTransactionGroup::disableTransaction()
179 mTransaction.reset();
181 const auto constMLayers = mLayers;
189void QgsTransactionGroup::restartTransaction(
const QgsVectorLayer *layer )
202 return mLayers.isEmpty();
QString source() const
Returns the source for the layer.
QString providerType() const
Returns the provider type (provider key) for this layer.
QString connString() const
Returns the connection string used by this transaction group.
bool modified() const
Returns true if any of the layers in this group reports a modification.
QgsTransactionGroup(QObject *parent=nullptr)
Constructor for QgsTransactionGroup.
bool isEmpty() const
Returns true if there are no layers in this transaction group.
void commitError(const QString &msg)
Will be emitted whenever there is a commit error.
QString providerKey() const
Returns the provider key used by this transaction group.
bool addLayer(QgsVectorLayer *layer)
Add a layer to this transaction group.
QSet< QgsVectorLayer * > layers() const
Gets the set of layers currently managed by this transaction group.
static bool supportsTransaction(const QgsVectorLayer *layer)
Checks if the provider of a given layer supports transactions.
QString connectionString() const
Returns the connection string of the transaction.
static QgsTransaction * create(const QString &connString, const QString &providerKey)
Create a transaction for the specified connection string connString and provider with providerKey.
Represents a vector layer which manages a vector based data sets.
void beforeCommitChanges(bool stopEditing)
Emitted before changes are committed to the data provider.
Q_INVOKABLE bool startEditing()
Makes the layer editable.
void beforeEditingStarted()
Emitted before editing on this layer is started.
void beforeRollBack()
Emitted before changes are rolled back.
#define QgsDebugError(str)