Skip to content

Commit

Permalink
Remove layer edit state restrictions from transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Jan 15, 2016
1 parent 0b96621 commit 8207161
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 26 deletions.
26 changes: 4 additions & 22 deletions src/core/qgstransaction.cpp
Expand Up @@ -83,18 +83,12 @@ QgsTransaction::~QgsTransaction()

bool QgsTransaction::addLayer( const QString& layerId )
{
if ( mTransactionActive )
return false;

QgsVectorLayer* layer = qobject_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( layerId ) );
return addLayer( layer );
}

bool QgsTransaction::addLayer( QgsVectorLayer* layer )
{
if ( mTransactionActive )
return false;

if ( !layer )
return false;

Expand All @@ -119,6 +113,10 @@ bool QgsTransaction::addLayer( QgsVectorLayer* layer )
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;
}

Expand All @@ -141,14 +139,6 @@ bool QgsTransaction::commit( QString& errorMsg )
if ( !mTransactionActive )
return false;

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

if ( !commitTransaction( errorMsg ) )
return false;

Expand All @@ -162,14 +152,6 @@ bool QgsTransaction::rollback( QString& errorMsg )
if ( !mTransactionActive )
return false;

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

if ( !rollbackTransaction( errorMsg ) )
return false;

Expand Down
8 changes: 4 additions & 4 deletions src/core/qgstransaction.h
Expand Up @@ -60,10 +60,10 @@ class CORE_EXPORT QgsTransaction : public QObject

virtual ~QgsTransaction();

/** Add layer to the transaction. The layer must not be in edit mode. The transaction must not be active. */
/** Add layer to the transaction. The layer must not be in edit mode.*/
bool addLayer( const QString& layerId );

/** Add layer to the transaction. The layer must not be in edit mode. The transaction must not be active. */
/** Add layer to the transaction. The layer must not be in edit mode.*/
bool addLayer( QgsVectorLayer* layer );

/** Begin transaction
Expand All @@ -76,10 +76,10 @@ class CORE_EXPORT QgsTransaction : public QObject
* Some providers might not honour the statement timeout. */
bool begin( QString& errorMsg, int statementTimeout = 20 );

/** Commit transaction. All layers need to be in read-only mode. */
/** Commit transaction. */
bool commit( QString& errorMsg );

/** Roll back transaction. All layers need to be in read-only mode. */
/** Roll back transaction. */
bool rollback( QString& errorMsg );

/** Executes sql */
Expand Down

0 comments on commit 8207161

Please sign in to comment.