37 if ( mConnString.isEmpty() )
42 else if ( mConnString != connString || mProviderKey != layer->
providerType() )
47 mLayers.insert( layer );
50 connect( layer, &QgsVectorLayer::destroyed,
this, &QgsTransactionGroup::onLayerDeleted );
70 void QgsTransactionGroup::onEditingStarted()
80 mTransaction->begin( errorMsg );
84 mTransaction->addLayer( layer );
91 void QgsTransactionGroup::onLayerDeleted()
93 mLayers.remove( static_cast<QgsVectorLayer *>( sender() ) );
96 void QgsTransactionGroup::onCommitChanges()
98 if ( mEditingStopping )
101 mEditingStopping =
true;
106 if ( mTransaction->commit( errMsg ) )
110 if ( layer != sender() )
114 disableTransaction();
120 QTimer::singleShot( 0, triggeringLayer, SLOT( startEditing() ) );
122 mEditingStopping =
false;
125 void QgsTransactionGroup::onRollback()
127 if ( mEditingStopping )
130 mEditingStopping =
true;
135 if ( mTransaction->rollback( errMsg ) )
139 if ( layer != triggeringLayer )
142 disableTransaction();
147 QTimer::singleShot( 0, triggeringLayer, SLOT( startEditing() ) );
149 mEditingStopping =
false;
152 void QgsTransactionGroup::disableTransaction()
154 mTransaction.reset();
170 return mLayers.isEmpty();
QSet< QgsVectorLayer * > layers() const
Gets the set of layers currently managed by this transaction group.
static QgsTransaction * create(const QString &connString, const QString &providerKey)
Create a transaction for the specified connection string connString and provider with providerKey...
void beforeRollBack()
Is emitted, before changes are rolled back.
bool commitChanges()
Attempts to commit to the underlying data provider any buffered changes made since the last to call t...
bool startEditing()
Makes the layer editable.
QString source() const
Returns the source for the layer.
QString connString() const
Returns the connection string used by this transaction group.
void beforeCommitChanges()
Is emitted, before changes are committed to the data provider.
bool isEmpty() const
Returns true if there are no layers in this transaction group.
bool rollBack(bool deleteBuffer=true)
Stops a current editing operation and discards any uncommitted edits.
void beforeEditingStarted()
Is emitted, before editing on this layer is started.
bool addLayer(QgsVectorLayer *layer)
Add a layer to this transaction group.
QString providerKey() const
Returns the provider key used by this transaction group.
virtual bool isModified() const
Returns true if the provider has been modified since the last commit.
static bool supportsTransaction(const QgsVectorLayer *layer)
Checks if the provider of a given layer supports transactions.
QString providerType() const
Returns the provider type for this layer.
QgsTransactionGroup(QObject *parent=nullptr)
Constructor for QgsTransactionGroup.
bool modified() const
Returns true if any of the layers in this group reports a modification.
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.