Skip to content
Permalink
Browse files

Signal transaction rollback and some refactoring of transactions

  • Loading branch information
m-kuhn committed Nov 30, 2015
1 parent d388a4f commit ca4d12aba230f463f2a2d3c61eb3c49d02ad1321
@@ -397,47 +397,47 @@ ADD_FLEX_FILES(QGIS_CORE_SRCS qgsexpressionlexer.ll)
ADD_BISON_FILES(QGIS_CORE_SRCS qgsexpressionparser.yy)

SET(QGIS_CORE_MOC_HDRS

qgsapplication.h
qgsbrowsermodel.h
qgscontexthelp.h
qgscoordinatetransform.h
qgscredentials.h
qgsdataitem.h
qgsdataprovider.h
qgseditformconfig.h
qgsgeometryvalidator.h
qgsgml.h
qgsgmlschema.h
qgsmaplayer.h
qgsmaplayerlegend.h
qgsmaplayerregistry.h
qgsmaplayerstylemanager.h
qgsmaprenderer.h
qgsmaprenderercache.h
qgsmaprenderercustompainterjob.h
qgsmaprenderer.h
qgsmaprendererjob.h
qgsmaprendererparalleljob.h
qgsmaprenderersequentialjob.h
qgsmessageoutput.h
qgsmessagelog.h
qgsnetworkreplyparser.h
qgsmessageoutput.h
qgsnetworkaccessmanager.h
qgsnetworkcontentfetcher.h
qgsnetworkreplyparser.h
qgsofflineediting.h
qgscredentials.h
qgspluginlayer.h
qgspointlocator.h
qgsproject.h
qgsrunprocess.h
qgsrelationmanager.h
qgsrunprocess.h
qgssnappingutils.h
qgsvectorlayer.h
qgsvectorlayereditpassthrough.h
qgsvectorlayereditbuffer.h
qgsnetworkaccessmanager.h
qgstransaction.h
qgsvectordataprovider.h
qgsvectorlayercache.h
qgsvectorlayereditbuffer.h
qgsvectorlayereditpassthrough.h
qgsvectorlayer.h
qgsvectorlayerjoinbuffer.h
qgsvisibilitypresetcollection.h
qgsgeometryvalidator.h
qgswebview.h

auth/qgsauthmanager.h
@@ -632,7 +632,7 @@ SET(QGIS_CORE_HDRS
qgsstatisticalsummary.h
qgsstringutils.h
qgstolerance.h
qgstransaction.h

qgsvectordataprovider.h
qgsvectorlayercache.h
qgsvectorfilewriter.h
@@ -99,6 +99,16 @@ bool QgsTransaction::addLayer( const QString& layerId )
}

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;
@@ -124,11 +134,13 @@ bool QgsTransaction::addLayer( const QString& layerId )
if ( QgsDataSourceURI( layer->source() ).connectionInfo() != mConnString )
{
QgsDebugMsg( QString( "Couldn't start transaction because connection string for layer %1 : '%2' does not match '%3'" ).arg(
layerId, QgsDataSourceURI( layer->source() ).connectionInfo(), mConnString ) );
layer->id(), QgsDataSourceURI( layer->source() ).connectionInfo(), mConnString ) );
return false;
}

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

@@ -157,9 +169,8 @@ bool QgsTransaction::commit( QString& errorMsg )
return false;
}

Q_FOREACH ( const QString& layerid, mLayers )
Q_FOREACH ( QgsVectorLayer* l, mLayers )
{
QgsMapLayer* l = QgsMapLayerRegistry::instance()->mapLayer( layerid );
if ( !l || l->isEditable() )
{
return false;
@@ -183,10 +194,9 @@ bool QgsTransaction::rollback( QString& errorMsg )
return false;
}

Q_FOREACH ( const QString& layerid, mLayers )
Q_FOREACH ( QgsVectorLayer* l, mLayers )
{
QgsMapLayer* l = QgsMapLayerRegistry::instance()->mapLayer( layerid );
if ( !l || l->isEditable() )
if ( l->isEditable() )
{
return false;
}
@@ -199,15 +209,25 @@ bool QgsTransaction::rollback( QString& errorMsg )

setLayerTransactionIds( 0 );
mTransactionActive = false;

emit afterRollback();

return true;
}

void QgsTransaction::onLayersDeleted( const QStringList& layerids )
{
Q_FOREACH ( QString layerid, layerids )
Q_FOREACH ( QgsVectorLayer* l, mLayers )
if ( l->id() == layerid )
mLayers.remove( l );
}

void QgsTransaction::setLayerTransactionIds( QgsTransaction* transaction )
{
Q_FOREACH ( const QString& layerid, mLayers )
Q_FOREACH ( QgsVectorLayer* vl, mLayers )
{
QgsVectorLayer* vl = qobject_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( layerid ) );
if ( vl && vl->dataProvider() )
if ( vl->dataProvider() )
{
vl->dataProvider()->setTransaction( transaction );
}
@@ -22,6 +22,7 @@
#include <QString>

class QgsVectorDataProvider;
class QgsVectorLayer;

/**
* This class allows to include a set of layers in a database-side transaction,
@@ -44,8 +45,10 @@ class QgsVectorDataProvider;
*
* Edits on features can get rejected if another conflicting transaction is active.
*/
class CORE_EXPORT QgsTransaction
class CORE_EXPORT QgsTransaction : public QObject
{
Q_OBJECT

public:
/** Creates a transaction for the specified connection string and provider */
static QgsTransaction* create( const QString& connString, const QString& providerKey );
@@ -59,6 +62,9 @@ class CORE_EXPORT QgsTransaction
/** Add layer to the transaction. The layer must not be in edit mode. The transaction must not be active. */
bool addLayer( const QString& layerId );

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

/** Begin transaction
* The statement timeout, in seconds, specifies how long an sql statement
* is allowed to block QGIS before it is aborted. Statements can block,
@@ -78,6 +84,12 @@ class CORE_EXPORT QgsTransaction
/** Executes sql */
virtual bool executeSql( const QString& sql, QString& error ) = 0;

signals:
void afterRollback();

private slots:
void onLayersDeleted( const QStringList& layerids );

protected:
QgsTransaction( const QString& connString );

@@ -88,7 +100,7 @@ class CORE_EXPORT QgsTransaction
const QgsTransaction& operator=( const QgsTransaction& other );

bool mTransactionActive;
QSet<QString> mLayers;
QSet<QgsVectorLayer*> mLayers;

void setLayerTransactionIds( QgsTransaction *transaction );

@@ -15,19 +15,21 @@ SET(PG_SRCS
qgscolumntypethread.cpp
qgspostgresexpressioncompiler.cpp
)

SET(PG_MOC_HDRS
qgspostgresprovider.h
qgscolumntypethread.h
qgspgnewconnection.h
qgspgsourceselect.h
qgspgtablemodel.h
qgspostgresconn.h
qgspostgresconnpool.h
qgspostgresdataitems.h
qgspgsourceselect.h
qgspgnewconnection.h
qgspgtablemodel.h
qgscolumntypethread.h
qgspostgresprovider.h
qgspostgrestransaction.h

)

SET(PG_HDRS
qgspostgrestransaction.h
qgspostgresexpressioncompiler.h
)

@@ -24,6 +24,8 @@ class QgsPostgresConn;

class QgsPostgresTransaction : public QgsTransaction
{
Q_OBJECT

public:
explicit QgsPostgresTransaction( const QString& connString );
bool executeSql( const QString& sql, QString& error ) override;

0 comments on commit ca4d12a

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