Exemple #1
0
bool QgsTransaction::addLayer( QgsVectorLayer* layer )
{
  if ( !layer )
    return false;

  if ( layer->isEditable() )
    return false;

  //test if provider supports transactions
  if ( !layer->dataProvider() || ( layer->dataProvider()->capabilities() & QgsVectorDataProvider::TransactionSupport ) == 0 )
    return false;

  if ( layer->dataProvider()->transaction() )
    return false;

  //connection string not compatible
  if ( QgsDataSourceURI( layer->source() ).connectionInfo( false ) != mConnString )
  {
    QgsDebugMsg( QString( "Couldn't start transaction because connection string for layer %1 : '%2' does not match '%3'" ).arg(
                   layer->id(), QgsDataSourceURI( layer->source() ).connectionInfo( false ), mConnString ) );
    return false;
  }

  connect( this, SIGNAL( afterRollback() ), layer->dataProvider(), SIGNAL( dataChanged() ) );
  connect( QgsMapLayerRegistry::instance(), SIGNAL( layersWillBeRemoved( QStringList ) ), this, SLOT( onLayersDeleted( QStringList ) ) );
  mLayers.insert( layer );

  if ( mTransactionActive )
    layer->dataProvider()->setTransaction( this );

  return true;
}
Exemple #2
0
bool QgsTransaction::rollback( QString& errorMsg )
{
  if ( !mTransactionActive )
  {
    return false;
  }

  Q_FOREACH ( QgsVectorLayer* l, mLayers )
  {
    if ( l->isEditable() )
    {
      return false;
    }
  }

  if ( !rollbackTransaction( errorMsg ) )
  {
    return false;
  }

  setLayerTransactionIds( 0 );
  mTransactionActive = false;

  emit afterRollback();

  return true;
}
Exemple #3
0
bool QgsTransaction::rollback( QString& errorMsg )
{
  if ( !mTransactionActive )
    return false;

  if ( !rollbackTransaction( errorMsg ) )
    return false;

  setLayerTransactionIds( nullptr );
  mTransactionActive = false;

  emit afterRollback();

  return true;
}