Skip to content
Permalink
Browse files

Move AutoTransaction setting to project properties

Was in global app settings
  • Loading branch information
m-kuhn committed Apr 6, 2016
1 parent dd54cf2 commit 4586a787b0d2cf520c591047b31bf8f8ddcfcd91
@@ -65,8 +65,12 @@ class QgsProject : QObject
*/
void dirty( bool b ) /Deprecated/;

/** Set project as dirty (modified).
* @note added in 2.4 */
/**
* Flag the project as dirty (modified). If this flag is set, the user will
* be asked to save changes to the project before closing the current project.
*
* @note added in 2.4
*/
void setDirty( bool b );
//@}

@@ -301,6 +305,26 @@ class QgsProject : QObject
*/
QStringList nonIdentifiableLayers() const;

/**
* Transactional editing means that on supported datasources (postgres databases) the edit state of
* all tables that originate from the same database are synchronized and executed in a server side
* transaction.
*
* @note Added in QGIS 2.16
*/
bool autoTransaction() const;

/**
* Transactional editing means that on supported datasources (postgres databases) the edit state of
* all tables that originate from the same database are synchronized and executed in a server side
* transaction.
*
* Make sure that this is only called when all layers are not in edit mode.
*
* @note Added in QGIS 2.16
*/
void setAutoTransaction(bool autoTransaction );

protected:

/** Set error message from read/write operation
@@ -7248,8 +7248,9 @@ bool QgisApp::toggleEditing( QgsMapLayer *layer, bool allowCancel )
QString connString = QgsDataSourceURI( vlayer->source() ).connectionInfo();
QString key = vlayer->providerType();

QMap< QPair< QString, QString>, QgsTransactionGroup*>::iterator tIt = mTransactionGroups.find( qMakePair( key, connString ) );
QgsTransactionGroup* tg = ( tIt != mTransactionGroups.end() ? tIt.value() : nullptr );
QMap< QPair< QString, QString>, QgsTransactionGroup*> transactionGroups = QgsProject::instance()->transactionGroups();
QMap< QPair< QString, QString>, QgsTransactionGroup*>::iterator tIt = transactionGroups .find( qMakePair( key, connString ) );
QgsTransactionGroup* tg = ( tIt != transactionGroups.end() ? tIt.value() : nullptr );

bool isModified = false;

@@ -7707,22 +7708,6 @@ void QgisApp::removingLayers( const QStringList& theLayers )

toggleEditing( vlayer, false );
}

if ( autoTransaction() )
{
for ( QMap< QPair< QString, QString>, QgsTransactionGroup*>::Iterator tg = mTransactionGroups.begin(); tg != mTransactionGroups.end(); )
{
if ( tg.value()->isEmpty() )
{
delete tg.value();
tg = mTransactionGroups.erase( tg );
}
else
{
++tg;
}
}
}
}

void QgisApp::removeAllLayers()
@@ -9606,26 +9591,6 @@ void QgisApp::layersWereAdded( const QList<QgsMapLayer *>& theLayers )
connect( vlayer, SIGNAL( editingStopped() ), this, SLOT( layerEditStateChanged() ) );
}

if ( autoTransaction() )
{
if ( QgsTransaction::supportsTransaction( vlayer ) )
{
QString connString = QgsDataSourceURI( vlayer->source() ).connectionInfo();
QString key = vlayer->providerType();

QgsTransactionGroup* tg = mTransactionGroups.value( qMakePair( key, connString ) );

if ( !tg )
{
tg = new QgsTransactionGroup();
mTransactionGroups.insert( qMakePair( key, connString ), tg );

connect( tg, SIGNAL( commitError( QString ) ), this, SLOT( displayMapToolMessage( QString ) ) );
}
tg->addLayer( vlayer );
}
}

connect( vlayer, SIGNAL( raiseError( QString ) ), this, SLOT( onLayerError( QString ) ) );

provider = vProvider;
@@ -10254,23 +10219,6 @@ void QgisApp::refreshActionFeatureAction()
mActionFeatureAction->setEnabled( layerHasActions );
}

bool QgisApp::autoTransaction() const
{
QSettings settings;
return settings.value( "/qgis/autoTransaction", false ).toBool();
}

void QgisApp::setAutoTransaction( bool state )
{
QSettings settings;

if ( settings.value( "/qgis/autoTransaction", false ).toBool() != state )
{

settings.setValue( "/qgis/autoTransaction", state );
}
}

/////////////////////////////////////////////////////////////////
//
//
@@ -672,9 +672,6 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow

QMenu *panelMenu() { return mPanelMenu; }

bool autoTransaction() const;
void setAutoTransaction( bool state );

protected:

//! Handle state changes (WindowTitleChange)
@@ -1683,9 +1680,6 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow

QgsComposerManager *mComposerManager;

//! map of transaction group: QPair( providerKey, connString ) -> transactionGroup
QMap< QPair< QString, QString>, QgsTransactionGroup*> mTransactionGroups;

//! Persistent tile scale slider
QgsTileScaleWidget *mpTileScaleWidget;

@@ -604,7 +604,6 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl ) :
cbxEvaluateDefaultValues->setChecked( mSettings->value( "/qgis/evaluateDefaultValues", false ).toBool() );
cbxCompileExpressions->setChecked( mSettings->value( "/qgis/compileExpressions", true ).toBool() );
cbxCreateRasterLegendIcons->setChecked( mSettings->value( "/qgis/createRasterLegendIcons", false ).toBool() );
cbxAutoTransaction->setChecked( QgisApp::instance()->autoTransaction() );
cbxCopyWKTGeomFromTable->setChecked( mSettings->value( "/qgis/copyGeometryAsWKT", true ).toBool() );
leNullValue->setText( mSettings->value( "qgis/nullValue", "NULL" ).toString() );
cbxIgnoreShapeEncoding->setChecked( mSettings->value( "/qgis/ignoreShapeEncoding", true ).toBool() );
@@ -1158,7 +1157,6 @@ void QgsOptions::saveOptions()
mSettings->setValue( "/qgis/defaultLegendGraphicResolution", mLegendGraphicResolutionSpinBox->value() );
bool createRasterLegendIcons = mSettings->value( "/qgis/createRasterLegendIcons", false ).toBool();
mSettings->setValue( "/qgis/createRasterLegendIcons", cbxCreateRasterLegendIcons->isChecked() );
QgisApp::instance()->setAutoTransaction( cbxAutoTransaction->isChecked() );
mSettings->setValue( "/qgis/copyGeometryAsWKT", cbxCopyWKTGeomFromTable->isChecked() );
mSettings->setValue( "/qgis/new_layers_visible", chkAddedVisibility->isChecked() );
mSettings->setValue( "/qgis/enable_anti_aliasing", chkAntiAliasing->isChecked() );
@@ -142,6 +142,16 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
///////////////////////////////////////////////////////////
// Properties stored in QgsProject

Q_FOREACH ( QgsVectorLayer* layer, QgsMapLayerRegistry::instance()->layers<QgsVectorLayer*>() )
{
if ( layer->isEditable() )
{
mAutoTransaction->setEnabled( false );
mAutoTransaction->setToolTip( tr( "Layers are in edit mode. Stop edit mode on all layers to toggle transactional editing." ) );
}
}

mAutoTransaction->setChecked( QgsProject::instance()->autoTransaction() );
title( QgsProject::instance()->title() );
projectFileName->setText( QgsProject::instance()->fileName() );

@@ -703,6 +713,9 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
on_cbxProjectionEnabled_toggled( myProjectionEnabled );
}

mAutoTransaction->setChecked( QgsProject::instance()->autoTransaction() );

// Variables editor
mVariableEditor->context()->appendScope( QgsExpressionContextUtils::globalScope() );
mVariableEditor->context()->appendScope( QgsExpressionContextUtils::projectScope() );
mVariableEditor->reloadContext();
@@ -787,6 +800,7 @@ void QgsProjectProperties::apply()

// Set the project title
QgsProject::instance()->setTitle( title() );
QgsProject::instance()->setAutoTransaction( mAutoTransaction->isChecked() );

// set the mouse display precision method and the
// number of decimal places for the manual option
@@ -37,6 +37,8 @@
#include "qgsvisibilitypresetcollection.h"
#include "qgslayerdefinition.h"
#include "qgsunittypes.h"
#include "qgstransaction.h"
#include "qgstransactiongroup.h"

#include <QApplication>
#include <QFileInfo>
@@ -324,6 +326,7 @@ struct QgsProject::Imp
QFile file; // current physical project file
QgsPropertyKey properties_; // property hierarchy
QString title; // project title
bool autoTransaction; // transaction grouped editing
bool dirty; // project has been modified since it has been read or saved

Imp()
@@ -344,6 +347,7 @@ struct QgsProject::Imp
file.setFileName( QString() );
properties_.clearKeys();
title.clear();
autoTransaction = false;
dirty = false;
}

@@ -363,6 +367,8 @@ QgsProject::QgsProject()
// whenever layers are added to or removed from the registry,
// layer tree will be updated
mLayerTreeRegistryBridge = new QgsLayerTreeRegistryBridge( mRootGroup, this );
connect( QgsMapLayerRegistry::instance(), SIGNAL( layersAdded( QList<QgsMapLayer*> ) ), this, SLOT( addToTransactionGroups( QList<QgsMapLayer*> ) ) );
connect( QgsMapLayerRegistry::instance(), SIGNAL( layersRemoved( QStringList ) ), this, SLOT( cleanTransactionGroups() ) );
} // QgsProject ctor


@@ -884,6 +890,14 @@ bool QgsProject::read()
// now get project title
_getTitle( *doc, imp_->title );

QDomNodeList nl = doc->elementsByTagName( "autotransaction" );
if ( nl.count() )
{
QDomElement transactionElement = nl.at( 0 ).toElement();
if ( transactionElement.attribute( "active", "0" ).toInt() == 1 )
imp_->autoTransaction = true;
}

// read the layer tree from project file

mRootGroup->setCustomProperty( "loading", 1 );
@@ -992,6 +1006,52 @@ void QgsProject::loadEmbeddedNodes( QgsLayerTreeGroup *group )
}
}

void QgsProject::addToTransactionGroups( const QList<QgsMapLayer*> layers )
{
if ( autoTransaction() )
{
Q_FOREACH ( QgsMapLayer* layer, layers )
{
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer*>( layer );
if ( vlayer )
{
if ( QgsTransaction::supportsTransaction( vlayer ) )
{
QString connString = QgsDataSourceURI( vlayer->source() ).connectionInfo();
QString key = vlayer->providerType();

QgsTransactionGroup* tg = mTransactionGroups.value( qMakePair( key, connString ) );

if ( !tg )
{
tg = new QgsTransactionGroup();
mTransactionGroups.insert( qMakePair( key, connString ), tg );

connect( tg, SIGNAL( commitError( QString ) ), this, SLOT( displayMapToolMessage( QString ) ) );

This comment has been minimized.

Copy link
@3nids

3nids Mar 2, 2017

Member

@m-kuhn there is no displayMapToolMessage slot in QgsProject.

This comment has been minimized.

Copy link
@m-kuhn

m-kuhn Mar 2, 2017

Author Member

Crappy old-style connections.
I'll have a look.
Thanks for reporting.

}
tg->addLayer( vlayer );
}
}
}
}
}

void QgsProject::cleanTransactionGroups( bool force )
{
for ( QMap< QPair< QString, QString>, QgsTransactionGroup*>::Iterator tg = mTransactionGroups.begin(); tg != mTransactionGroups.end(); )
{
if ( tg.value()->isEmpty() || force )
{
delete tg.value();
tg = mTransactionGroups.erase( tg );
}
else
{
++tg;
}
}
}

bool QgsProject::read( QDomNode &layerNode )
{
QList<QDomNode> brokenNodes;
@@ -1042,6 +1102,10 @@ bool QgsProject::write()
QDomElement titleNode = doc->createElement( "title" );
qgisNode.appendChild( titleNode );

QDomElement transactionNode = doc->createElement( "autotransaction" );
transactionNode.setAttribute( "active", imp_->autoTransaction ? "1" : "0" );
qgisNode.appendChild( transactionNode );

QDomText titleText = doc->createTextNode( title() ); // XXX why have title TWICE?
titleNode.appendChild( titleText );

@@ -2152,3 +2216,26 @@ QStringList QgsProject::nonIdentifiableLayers() const
{
return QgsProject::instance()->readListEntry( "Identify", "/disabledLayers" );
}

bool QgsProject::autoTransaction() const
{
return imp_->autoTransaction;
}

void QgsProject::setAutoTransaction( bool autoTransaction )
{
if ( autoTransaction != imp_->autoTransaction )
{
imp_->autoTransaction = autoTransaction;

if ( autoTransaction )
addToTransactionGroups( QgsMapLayerRegistry::instance()->mapLayers().values() );
else
cleanTransactionGroups( true );
}
}

QMap<QPair<QString, QString>, QgsTransactionGroup*> QgsProject::transactionGroups()
{
return mTransactionGroups;
}

0 comments on commit 4586a78

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