Skip to content

Commit 8207161

Browse files
committed
Remove layer edit state restrictions from transactions
1 parent 0b96621 commit 8207161

File tree

2 files changed

+8
-26
lines changed

2 files changed

+8
-26
lines changed

src/core/qgstransaction.cpp

+4-22
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,12 @@ QgsTransaction::~QgsTransaction()
8383

8484
bool QgsTransaction::addLayer( const QString& layerId )
8585
{
86-
if ( mTransactionActive )
87-
return false;
88-
8986
QgsVectorLayer* layer = qobject_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( layerId ) );
9087
return addLayer( layer );
9188
}
9289

9390
bool QgsTransaction::addLayer( QgsVectorLayer* layer )
9491
{
95-
if ( mTransactionActive )
96-
return false;
97-
9892
if ( !layer )
9993
return false;
10094

@@ -119,6 +113,10 @@ bool QgsTransaction::addLayer( QgsVectorLayer* layer )
119113
connect( this, SIGNAL( afterRollback() ), layer->dataProvider(), SIGNAL( dataChanged() ) );
120114
connect( QgsMapLayerRegistry::instance(), SIGNAL( layersWillBeRemoved( QStringList ) ), this, SLOT( onLayersDeleted( QStringList ) ) );
121115
mLayers.insert( layer );
116+
117+
if ( mTransactionActive )
118+
layer->dataProvider()->setTransaction( this );
119+
122120
return true;
123121
}
124122

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

144-
Q_FOREACH ( QgsVectorLayer* l, mLayers )
145-
{
146-
if ( !l || l->isEditable() )
147-
{
148-
return false;
149-
}
150-
}
151-
152142
if ( !commitTransaction( errorMsg ) )
153143
return false;
154144

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

165-
Q_FOREACH ( QgsVectorLayer* l, mLayers )
166-
{
167-
if ( l->isEditable() )
168-
{
169-
return false;
170-
}
171-
}
172-
173155
if ( !rollbackTransaction( errorMsg ) )
174156
return false;
175157

src/core/qgstransaction.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ class CORE_EXPORT QgsTransaction : public QObject
6060

6161
virtual ~QgsTransaction();
6262

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

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

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

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

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

8585
/** Executes sql */

0 commit comments

Comments
 (0)