37 if ( mConnString.isEmpty() )
42 else if ( mConnString != connString || mProviderKey != layer->
providerType() )
47 mLayers.insert( layer );
50 connect( layer, &QgsVectorLayer::destroyed,
this, &QgsTransactionGroup::onLayerDeleted );
62 const auto constMLayers = mLayers;
65 if ( layer->isModified() )
71 void QgsTransactionGroup::onEditingStarted()
81 mTransaction->begin( errorMsg );
83 const auto constMLayers = mLayers;
86 mTransaction->addLayer( layer );
87 layer->startEditing();
93 void QgsTransactionGroup::onLayerDeleted()
95 mLayers.remove( static_cast<QgsVectorLayer *>( sender() ) );
98 void QgsTransactionGroup::onCommitChanges()
100 if ( mEditingStopping )
103 mEditingStopping =
true;
108 if ( mTransaction->commit( errMsg ) )
110 const auto constMLayers = mLayers;
113 if ( layer != sender() )
114 layer->commitChanges();
117 disableTransaction();
125 mEditingStopping =
false;
128 void QgsTransactionGroup::onRollback()
130 if ( mEditingStopping )
133 mEditingStopping =
true;
138 if ( mTransaction->rollback( errMsg ) )
140 const auto constMLayers = mLayers;
143 if ( layer != triggeringLayer )
146 disableTransaction();
153 mEditingStopping =
false;
156 void QgsTransactionGroup::disableTransaction()
158 mTransaction.reset();
160 const auto constMLayers = mLayers;
175 return mLayers.isEmpty();
static QgsTransaction * create(const QString &connString, const QString &providerKey)
Create a transaction for the specified connection string connString and provider with providerKey...
void beforeRollBack()
Emitted before changes are rolled back.
QString providerType() const
Returns the provider type (provider key) for this layer.
bool startEditing()
Makes the layer editable.
QSet< QgsVectorLayer * > layers() const
Gets the set of layers currently managed by this transaction group.
void beforeCommitChanges()
Emitted before changes are committed to the data provider.
QString providerKey() const
Returns the provider key used by this transaction group.
void beforeEditingStarted()
Emitted before editing on this layer is started.
bool addLayer(QgsVectorLayer *layer)
Add a layer to this transaction group.
static bool supportsTransaction(const QgsVectorLayer *layer)
Checks if the provider of a given layer supports transactions.
QgsTransactionGroup(QObject *parent=nullptr)
Constructor for QgsTransactionGroup.
QString source() const
Returns the source for the layer.
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.
Represents a vector layer which manages a vector based data sets.
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.