Skip to content
Permalink
Browse files

Fix repeated editing of transactiongroups

  • Loading branch information
m-kuhn committed Jan 18, 2016
1 parent b66e50b commit c288311553f0ca7757a548b4286f70bc878868f9
Showing with 19 additions and 5 deletions.
  1. +16 −4 src/core/qgstransactiongroup.cpp
  2. +3 −1 src/core/qgstransactiongroup.h
@@ -26,14 +26,12 @@ QgsTransactionGroup::QgsTransactionGroup( QObject *parent )
: QObject( parent )
, mEditingStarting( false )
, mEditingStopping( false )
, mTransaction( nullptr )
{

}

QgsTransactionGroup::~QgsTransactionGroup()
{
delete mTransaction;
}

bool QgsTransactionGroup::addLayer( QgsVectorLayer* layer )
@@ -63,10 +61,10 @@ bool QgsTransactionGroup::addLayer( QgsVectorLayer* layer )

void QgsTransactionGroup::onEditingStarted()
{
if ( mTransaction )
if ( !mTransaction.isNull() )
return;

mTransaction = QgsTransaction::create( mConnString, mProviderKey );
mTransaction.reset( QgsTransaction::create( mConnString, mProviderKey ) );

QString errorMsg;
mTransaction->begin( errorMsg );
@@ -102,6 +100,8 @@ void QgsTransactionGroup::onCommitChanges()
if ( layer != sender() )
layer->commitChanges();
}

disableTransaction();
}
else
{
@@ -129,6 +129,7 @@ void QgsTransactionGroup::onRollback()
if ( layer != triggeringLayer )
layer->rollBack();
}
disableTransaction();
}
else
{
@@ -138,6 +139,17 @@ void QgsTransactionGroup::onRollback()
mEditingStopping = false;
}

void QgsTransactionGroup::disableTransaction()
{
mTransaction.reset();

Q_FOREACH ( QgsVectorLayer* layer, mLayers )
{
disconnect( layer, SIGNAL( beforeCommitChanges() ), this, SLOT( onCommitChanges() ) );
disconnect( layer, SIGNAL( beforeRollBack() ), this, SLOT( onRollback() ) );
}
}

QString QgsTransactionGroup::providerKey() const
{
return mProviderKey;
@@ -70,9 +70,11 @@ class CORE_EXPORT QgsTransactionGroup : public QObject
bool mEditingStarting;
bool mEditingStopping;

void disableTransaction();

QSet<QgsVectorLayer*> mLayers;
//! Only set while a transaction is active
QgsTransaction* mTransaction;
QScopedPointer<QgsTransaction> mTransaction;
//! Layers have to be compatible with the connection string
QString mConnString;
QString mProviderKey;

0 comments on commit c288311

Please sign in to comment.
You can’t perform that action at this time.