Skip to content

Commit

Permalink
Use transaction groups
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Jan 15, 2016
1 parent 9b51007 commit 8ee25b7
Show file tree
Hide file tree
Showing 4 changed files with 337 additions and 59 deletions.
59 changes: 57 additions & 2 deletions src/app/qgisapp.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 );
Expand All @@ -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;
}

Expand Down Expand Up @@ -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 );
}
}

/////////////////////////////////////////////////////////////////
//
//
Expand Down
7 changes: 7 additions & 0 deletions src/app/qgisapp.h
Expand Up @@ -64,6 +64,7 @@ class QgsProviderRegistry;
class QgsPythonUtils;
class QgsRectangle;
class QgsSnappingUtils;
class QgsTransactionGroup;
class QgsUndoWidget;
class QgsUserInputDockWidget;
class QgsVectorLayer;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions src/app/qgsoptions.cpp
Expand Up @@ -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() );
Expand Down Expand Up @@ -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() );
Expand Down

0 comments on commit 8ee25b7

Please sign in to comment.