QGIS API Documentation  3.21.0-Master (909859188c)
qgslayoutundocommand.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgslayoutundocommand.h
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 #ifndef QGSLAYOUTUNDOCOMMAND_H
19 #define QGSLAYOUTUNDOCOMMAND_H
20 
21 #include <QUndoCommand>
22 #include "qgis_sip.h"
23 #include <QDomDocument>
24 
25 #include "qgis_core.h"
26 
27 class QgsLayout;
28 
34 class CORE_EXPORT QgsAbstractLayoutUndoCommand: public QUndoCommand
35 {
36  public:
37 
43  QgsAbstractLayoutUndoCommand( const QString &text, int id = 0, QUndoCommand *parent SIP_TRANSFERTHIS = nullptr );
44 
45  void undo() override;
46  void redo() override;
47  int id() const override { return mId; }
48 
54  void saveBeforeState();
55 
61  void saveAfterState();
62 
68  QDomDocument beforeState() const { return mBeforeState.cloneNode().toDocument(); }
69 
75  QDomDocument afterState() const { return mAfterState.cloneNode().toDocument(); }
76 
80  virtual bool containsChange() const;
81 
82  protected:
83 
91  virtual void saveState( QDomDocument &stateDoc ) const = 0;
92 
100  virtual void restoreState( QDomDocument &stateDoc ) = 0;
101 
105  void setAfterState( const QDomDocument &stateDoc );
106 
108  bool mFirstRun = true;
109 
110  private:
111 
113  QDomDocument mBeforeState;
114 
116  QDomDocument mAfterState;
117 
119  int mId = 0;
120 
121 };
122 
129 {
130  public:
131 
135  virtual ~QgsLayoutUndoObjectInterface() = default;
136 
143  virtual QgsAbstractLayoutUndoCommand *createCommand( const QString &text, int id = 0, QUndoCommand *parent = nullptr ) = 0 SIP_FACTORY;
144 };
145 
146 
147 #endif // QGSLAYOUTUNDOCOMMAND_H
Base class for commands to undo/redo layout and layout object changes.
virtual void saveState(QDomDocument &stateDoc) const =0
Saves the state of the object to the specified stateDoc.
QDomDocument beforeState() const
Returns the before state for the layout.
virtual void restoreState(QDomDocument &stateDoc)=0
Restores the state of the object from the specified stateDoc.
QDomDocument afterState() const
Returns the after state for the layout.
Interface for layout objects which support undo/redo commands.
virtual ~QgsLayoutUndoObjectInterface()=default
Destructor for QgsLayoutUndoObjectInterface.
virtual QgsAbstractLayoutUndoCommand * createCommand(const QString &text, int id=0, QUndoCommand *parent=nullptr)=0
Creates a new layout undo command with the specified text and parent.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:51
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
#define SIP_FACTORY
Definition: qgis_sip.h:76