QGIS API Documentation  3.0.2-Girona (307d082)
qgslayoutundocommand.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgslayoutundocommand.cpp
3  ------------------------
4  begin : July 2017
5  copyright : (C) 2017 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7 ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "qgslayoutundocommand.h"
19 
20 
21 QgsAbstractLayoutUndoCommand::QgsAbstractLayoutUndoCommand( const QString &text, int id, QUndoCommand *parent )
22  : QUndoCommand( text, parent )
23  , mId( id )
24 {}
25 
27 {
28  QUndoCommand::undo();
29  restoreState( mBeforeState );
30 }
31 
33 {
34  if ( mFirstRun )
35  {
36  mFirstRun = false;
37  return;
38  }
39  QUndoCommand::redo();
40  restoreState( mAfterState );
41 }
42 
44 {
45  saveState( mBeforeState );
46 }
47 
49 {
50  saveState( mAfterState );
51 }
52 
54 {
55  return !( mBeforeState.isNull() || mAfterState.isNull() || mBeforeState.toString() == mAfterState.toString() );
56 }
57 
58 void QgsAbstractLayoutUndoCommand::setAfterState( const QDomDocument &stateDoc )
59 {
60  mAfterState = stateDoc;
61 }
virtual void restoreState(QDomDocument &stateDoc)=0
Restores the state of the object from the specified stateDoc.
void saveBeforeState()
Saves current layout state as before state.
virtual void saveState(QDomDocument &stateDoc) const =0
Saves the state of the object to the specified stateDoc.
QgsAbstractLayoutUndoCommand(const QString &text, int id=0, QUndoCommand *parent=nullptr)
Constructor for QgsLayoutUndoCommand.
void setAfterState(const QDomDocument &stateDoc)
Manually sets the after state for the command.
virtual bool containsChange() const
Returns true if both the before and after states are valid and different.
void saveAfterState()
Saves current layout state as after state.
bool mFirstRun
Flag to prevent the first redo() if the command is pushed to the undo stack.