QGIS API Documentation 3.39.0-Master (93ce9bf5c90)
Loading...
Searching...
No Matches
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
19
20
21QgsAbstractLayoutUndoCommand::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
47
52
54{
55 return !( mBeforeState.isNull() || mAfterState.isNull() || mBeforeState.toString() == mAfterState.toString() );
56}
57
58void QgsAbstractLayoutUndoCommand::setAfterState( const QDomDocument &stateDoc )
59{
60 mAfterState = stateDoc;
61}
bool mFirstRun
Flag to prevent the first redo() if the command is pushed to the undo stack.
virtual bool containsChange() const
Returns true if both the before and after states are valid and different.
virtual void saveState(QDomDocument &stateDoc) const =0
Saves the state of the object to the specified stateDoc.
void setAfterState(const QDomDocument &stateDoc)
Manually sets the after state for the command.
virtual void restoreState(QDomDocument &stateDoc)=0
Restores the state of the object from the specified stateDoc.
void saveAfterState()
Saves current layout state as after state.
QgsAbstractLayoutUndoCommand(const QString &text, int id=0, QUndoCommand *parent=nullptr)
Constructor for QgsLayoutUndoCommand.
void saveBeforeState()
Saves current layout state as before state.