Skip to content
Permalink
Browse files

Use transaction groups

  • Loading branch information
m-kuhn committed Jan 15, 2016
1 parent 9b51007 commit 8ee25b7e172c8a042f5af8fb0466cc2b7e178883
Showing with 337 additions and 59 deletions.
  1. +57 −2 src/app/qgisapp.cpp
  2. +7 −0 src/app/qgisapp.h
  3. +2 −0 src/app/qgsoptions.cpp
  4. +271 −57 src/ui/qgsoptionsbase.ui
@@ -233,6 +233,8 @@
#include "qgslegendfilterbutton.h"
#include "qgsvirtuallayerdefinition.h"
#include "qgsvirtuallayerdefinitionutils.h"
#include "qgstransaction.h"
#include "qgstransactiongroup.h"

#include "qgssublayersdialog.h"
#include "ogr/qgsopenvectorlayerdialog.h"
@@ -7512,6 +7514,22 @@ 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()
@@ -9334,9 +9352,8 @@ void QgisApp::extentChanged()

void QgisApp::layersWereAdded( const QList<QgsMapLayer *>& theLayers )
{
for ( int i = 0; i < theLayers.size(); ++i )
Q_FOREACH ( QgsMapLayer* layer, theLayers )
{
QgsMapLayer * layer = theLayers.at( i );
QgsDataProvider *provider = nullptr;

QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer );
@@ -9352,6 +9369,27 @@ void QgisApp::layersWereAdded( const QList<QgsMapLayer *>& theLayers )
connect( vlayer, SIGNAL( editingStarted() ), this, SLOT( layerEditStateChanged() ) );
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 ), this, SLOT( displayMapToolMessage( QString, QgsMessageBar::MessageLevel ) ) );
}
tg->addLayer( vlayer );
}
}

provider = vProvider;
}

@@ -9995,6 +10033,23 @@ 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 );
}
}

/////////////////////////////////////////////////////////////////
//
//
@@ -64,6 +64,7 @@ class QgsProviderRegistry;
class QgsPythonUtils;
class QgsRectangle;
class QgsSnappingUtils;
class QgsTransactionGroup;
class QgsUndoWidget;
class QgsUserInputDockWidget;
class QgsVectorLayer;
@@ -671,6 +672,9 @@ 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)
@@ -1668,6 +1672,9 @@ 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;

@@ -591,6 +591,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl ) :
cbxAddOracleDC->setChecked( mSettings->value( "/qgis/addOracleDC", 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() );
@@ -1141,6 +1142,7 @@ 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() );

0 comments on commit 8ee25b7

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