QGIS API Documentation  3.2.0-Bonn (bc43194)
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.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
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
Base class for commands to undo/redo layout and layout object changes.
QDomDocument beforeState() const
Returns the before state for the layout.
#define SIP_FACTORY
Definition: qgis_sip.h:69
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:49
Interface for layout objects which support undo/redo commands.
QDomDocument afterState() const
Returns the after state for the layout.