Skip to content

Commit

Permalink
Undo/redo for atlas settings changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 5, 2018
1 parent 25170da commit d62bc35
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/app/layout/qgslayoutatlaswidget.cpp
Expand Up @@ -22,9 +22,11 @@
#include "qgsprintlayout.h"
#include "qgslayoutatlas.h"
#include "qgsexpressionbuilderdialog.h"
#include "qgslayoutundostack.h"

QgsLayoutAtlasWidget::QgsLayoutAtlasWidget( QWidget *parent, QgsPrintLayout *layout )
: QWidget( parent )
, mLayout( layout )
, mAtlas( layout->atlas() )
{
setupUi( this );
Expand Down Expand Up @@ -86,6 +88,7 @@ void QgsLayoutAtlasWidget::changeCoverageLayer( QgsMapLayer *layer )
{
QgsVectorLayer *vl = dynamic_cast<QgsVectorLayer *>( layer );

mLayout->undoStack()->beginCommand( mAtlas, tr( "Change Atlas Layer" ) );
if ( !vl )
{
mAtlas->setCoverageLayer( nullptr );
Expand All @@ -95,11 +98,13 @@ void QgsLayoutAtlasWidget::changeCoverageLayer( QgsMapLayer *layer )
mAtlas->setCoverageLayer( vl );
updateAtlasFeatures();
}
mLayout->undoStack()->endCommand();
}

void QgsLayoutAtlasWidget::mAtlasFilenamePatternEdit_editingFinished()
{
QString error;
mLayout->undoStack()->beginCommand( mAtlas, tr( "Change Atlas Filename" ) );
if ( !mAtlas->setFilenameExpression( mAtlasFilenamePatternEdit->text(), error ) )
{
//expression could not be set
Expand All @@ -110,6 +115,7 @@ void QgsLayoutAtlasWidget::mAtlasFilenamePatternEdit_editingFinished()
error )
);
}
mLayout->undoStack()->endCommand();
}

void QgsLayoutAtlasWidget::mAtlasFilenameExpressionButton_clicked()
Expand All @@ -131,6 +137,7 @@ void QgsLayoutAtlasWidget::mAtlasFilenameExpressionButton_clicked()
//set atlas filename expression
mAtlasFilenamePatternEdit->setText( expression );
QString error;
mLayout->undoStack()->beginCommand( mAtlas, tr( "Change Atlas Filename" ) );
if ( !mAtlas->setFilenameExpression( expression, error ) )
{
//expression could not be set
Expand All @@ -141,13 +148,16 @@ void QgsLayoutAtlasWidget::mAtlasFilenameExpressionButton_clicked()
error )
);
}
mLayout->undoStack()->endCommand();
}
}
}

void QgsLayoutAtlasWidget::mAtlasHideCoverageCheckBox_stateChanged( int state )
{
mLayout->undoStack()->beginCommand( mAtlas, tr( "Toggle Atlas Layer" ) );
mAtlas->setHideCoverage( state == Qt::Checked );
mLayout->undoStack()->endCommand();
}

void QgsLayoutAtlasWidget::mAtlasSingleFileCheckBox_stateChanged( int state )
Expand Down Expand Up @@ -179,7 +189,9 @@ void QgsLayoutAtlasWidget::mAtlasSortFeatureCheckBox_stateChanged( int state )
mAtlasSortFeatureDirectionButton->setEnabled( false );
mAtlasSortFeatureKeyComboBox->setEnabled( false );
}
mLayout->undoStack()->beginCommand( mAtlas, tr( "Toggle Atlas Sorting" ) );
mAtlas->setSortFeatures( state == Qt::Checked );
mLayout->undoStack()->endCommand();
updateAtlasFeatures();
}

Expand All @@ -203,7 +215,9 @@ void QgsLayoutAtlasWidget::updateAtlasFeatures()

void QgsLayoutAtlasWidget::changesSortFeatureField( const QString &fieldName )
{
mLayout->undoStack()->beginCommand( mAtlas, tr( "Change Atlas Sort" ) );
mAtlas->setSortExpression( fieldName );
mLayout->undoStack()->endCommand();
updateAtlasFeatures();
}

Expand All @@ -219,7 +233,9 @@ void QgsLayoutAtlasWidget::mAtlasFeatureFilterCheckBox_stateChanged( int state )
mAtlasFeatureFilterEdit->setEnabled( false );
mAtlasFeatureFilterButton->setEnabled( false );
}
mLayout->undoStack()->beginCommand( mAtlas, tr( "Change Atlas Filter" ) );
mAtlas->setFilterFeatures( state == Qt::Checked );
mLayout->undoStack()->endCommand();
updateAtlasFeatures();
}

Expand All @@ -231,13 +247,17 @@ void QgsLayoutAtlasWidget::pageNameExpressionChanged( const QString &, bool vali
return;
}

mLayout->undoStack()->beginCommand( mAtlas, tr( "Change Atlas Name" ) );
mAtlas->setPageNameExpression( expression );
mLayout->undoStack()->endCommand();
}

void QgsLayoutAtlasWidget::mAtlasFeatureFilterEdit_editingFinished()
{
QString error;
mLayout->undoStack()->beginCommand( mAtlas, tr( "Change Atlas Filter" ) );
mAtlas->setFilterExpression( mAtlasFeatureFilterEdit->text(), error );
mLayout->undoStack()->endCommand();
updateAtlasFeatures();
}

Expand All @@ -261,7 +281,9 @@ void QgsLayoutAtlasWidget::mAtlasFeatureFilterButton_clicked()
{
mAtlasFeatureFilterEdit->setText( expression );
QString error;
mLayout->undoStack()->beginCommand( mAtlas, tr( "Change Atlas Filter" ) );
mAtlas->setFilterExpression( mAtlasFeatureFilterEdit->text(), error );
mLayout->undoStack()->endCommand();
updateAtlasFeatures();
}
}
Expand All @@ -273,7 +295,9 @@ void QgsLayoutAtlasWidget::mAtlasSortFeatureDirectionButton_clicked()
at = ( at == Qt::UpArrow ) ? Qt::DownArrow : Qt::UpArrow;
mAtlasSortFeatureDirectionButton->setArrowType( at );

mLayout->undoStack()->beginCommand( mAtlas, tr( "Change Atlas Sort" ) );
mAtlas->setSortAscending( at == Qt::UpArrow );
mLayout->undoStack()->endCommand();
updateAtlasFeatures();
}

Expand Down

0 comments on commit d62bc35

Please sign in to comment.