17#include "moc_qgstransactiongroup.cpp" 
   39  if ( mConnString.isEmpty() )
 
   49  mLayers.insert( layer );
 
   52  connect( layer, &QgsVectorLayer::destroyed, 
this, &QgsTransactionGroup::onLayerDeleted );
 
 
   64  const auto constMLayers = mLayers;
 
   67    if ( layer->isModified() )
 
 
   73void QgsTransactionGroup::onEditingStarted()
 
   83  mTransaction->begin( errorMsg );
 
   85  const auto triggeringLayer = qobject_cast<QgsVectorLayer *>( sender() );
 
   87  const auto constMLayers = mLayers;
 
   90    mTransaction->addLayer( layer, 
true );
 
   93    if ( layer != triggeringLayer )
 
   95      layer->startEditing();
 
  104void QgsTransactionGroup::onLayerDeleted()
 
  109void QgsTransactionGroup::onBeforeCommitChanges( 
bool stopEditing )
 
  111  if ( mEditingStopping )
 
  114  mEditingStopping = 
true;
 
  116  const QgsVectorLayer *triggeringLayer = qobject_cast<QgsVectorLayer *>( sender() );
 
  119  if ( mTransaction->commit( errMsg ) )
 
  121    const auto constMLayers = mLayers;
 
  124      if ( layer != triggeringLayer )
 
  126        layer->commitChanges( stopEditing );
 
  132      disableTransaction();
 
  136      if ( ! mTransaction->begin( errMsg ) )
 
  138        QgsDebugError( QStringLiteral( 
"Could not restart a transaction for %1: %2" ).arg( triggeringLayer->
name() ).arg( errMsg ) );
 
  146    restartTransaction( triggeringLayer );
 
  148  mEditingStopping = 
false;
 
  151void QgsTransactionGroup::onRollback()
 
  153  if ( mEditingStopping )
 
  156  mEditingStopping = 
true;
 
  158  QgsVectorLayer *triggeringLayer = qobject_cast<QgsVectorLayer *>( sender() );
 
  161  if ( mTransaction->rollback( errMsg ) )
 
  163    const auto constMLayers = mLayers;
 
  166      if ( layer != triggeringLayer )
 
  169    disableTransaction();
 
  173    restartTransaction( triggeringLayer );
 
  175  mEditingStopping = 
false;
 
  178void QgsTransactionGroup::disableTransaction()
 
  180  mTransaction.reset();
 
  182  const auto constMLayers = mLayers;
 
  190void QgsTransactionGroup::restartTransaction( 
const QgsVectorLayer *layer )
 
  203  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 dataset.
 
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)