QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 }
QgsAbstractLayoutUndoCommand::saveState
virtual void saveState(QDomDocument &stateDoc) const =0
Saves the state of the object to the specified stateDoc.
QgsAbstractLayoutUndoCommand::saveAfterState
void saveAfterState()
Saves current layout state as after state.
Definition: qgslayoutundocommand.cpp:48
QgsAbstractLayoutUndoCommand::saveBeforeState
void saveBeforeState()
Saves current layout state as before state.
Definition: qgslayoutundocommand.cpp:43
QgsAbstractLayoutUndoCommand::undo
void undo() override
Definition: qgslayoutundocommand.cpp:26
QgsAbstractLayoutUndoCommand::restoreState
virtual void restoreState(QDomDocument &stateDoc)=0
Restores the state of the object from the specified stateDoc.
QgsAbstractLayoutUndoCommand::QgsAbstractLayoutUndoCommand
QgsAbstractLayoutUndoCommand(const QString &text, int id=0, QUndoCommand *parent=nullptr)
Constructor for QgsLayoutUndoCommand.
Definition: qgslayoutundocommand.cpp:21
qgslayoutundocommand.h
QgsAbstractLayoutUndoCommand::mFirstRun
bool mFirstRun
Flag to prevent the first redo() if the command is pushed to the undo stack.
Definition: qgslayoutundocommand.h:108
QgsAbstractLayoutUndoCommand::containsChange
virtual bool containsChange() const
Returns true if both the before and after states are valid and different.
Definition: qgslayoutundocommand.cpp:53
QgsAbstractLayoutUndoCommand::redo
void redo() override
Definition: qgslayoutundocommand.cpp:32
QgsAbstractLayoutUndoCommand::setAfterState
void setAfterState(const QDomDocument &stateDoc)
Manually sets the after state for the command.
Definition: qgslayoutundocommand.cpp:58