QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
qgsmodelundocommand.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsmodelundocommand.cpp
3 ----------------------------------
4 Date : March 2020
5 Copyright : (C) 2020 Nyall Dawson
6 Email : nyall dot dawson at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#include "qgsmodelundocommand.h"
17
19
21
22
23QgsModelUndoCommand::QgsModelUndoCommand( QgsProcessingModelAlgorithm *model, const QString &text, int id, QUndoCommand *parent )
24 : QUndoCommand( text, parent )
25 , mModel( model )
26 , mId( id )
27{
28 mBeforeState = model->toVariant();
29}
30
31void QgsModelUndoCommand::saveAfterState()
32{
33 mAfterState = mModel->toVariant();
34}
35
36int QgsModelUndoCommand::id() const
37{
38 return mId;
39}
40
41void QgsModelUndoCommand::undo()
42{
43 QUndoCommand::undo();
44
45 // some settings must live "outside" the undo stack
46 const QVariantMap params = mModel->designerParameterValues();
47
48 mModel->loadVariant( mBeforeState );
49
50 mModel->setDesignerParameterValues( params );
51}
52
53void QgsModelUndoCommand::redo()
54{
55 if ( mFirstRun )
56 {
57 mFirstRun = false;
58 return;
59 }
60 QUndoCommand::redo();
61
62 // some settings must live "outside" the undo stack
63 const QVariantMap params = mModel->designerParameterValues();
64
65 mModel->loadVariant( mAfterState );
66
67 mModel->setDesignerParameterValues( params );
68}
69
70bool QgsModelUndoCommand::mergeWith( const QUndoCommand *other )
71{
72 if ( other->id() == 0 || other->id() != mId )
73 return false;
74
75 if ( const QgsModelUndoCommand *c = dynamic_cast<const QgsModelUndoCommand *>( other ) )
76 {
77 mAfterState = c->mAfterState;
78 return true;
79 }
80 else
81 {
82 return false;
83 }
84}
85
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c