QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
Loading...
Searching...
No Matches
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
27class QgsLayout;
28
33class CORE_EXPORT QgsAbstractLayoutUndoCommand: public QUndoCommand
34{
35 public:
36
42 QgsAbstractLayoutUndoCommand( const QString &text, int id = 0, QUndoCommand *parent SIP_TRANSFERTHIS = nullptr );
43
44 void undo() override;
45 void redo() override;
46 int id() const override { return mId; }
47
53 void saveBeforeState();
54
60 void saveAfterState();
61
67 QDomDocument beforeState() const { return mBeforeState.cloneNode().toDocument(); }
68
74 QDomDocument afterState() const { return mAfterState.cloneNode().toDocument(); }
75
79 virtual bool containsChange() const;
80
81 protected:
82
90 virtual void saveState( QDomDocument &stateDoc ) const = 0;
91
99 virtual void restoreState( QDomDocument &stateDoc ) = 0;
100
104 void setAfterState( const QDomDocument &stateDoc );
105
107 bool mFirstRun = true;
108
109 private:
110
112 QDomDocument mBeforeState;
113
115 QDomDocument mAfterState;
116
118 int mId = 0;
119
120};
121
127{
128 public:
129
130 virtual ~QgsLayoutUndoObjectInterface() = default;
131
138 virtual QgsAbstractLayoutUndoCommand *createCommand( const QString &text, int id = 0, QUndoCommand *parent = nullptr ) = 0 SIP_FACTORY;
139};
140
141
142#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 QgsAbstractLayoutUndoCommand * createCommand(const QString &text, int id=0, QUndoCommand *parent=nullptr)=0
Creates a new layout undo command with the specified text and parent.
virtual ~QgsLayoutUndoObjectInterface()=default
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition qgslayout.h:49
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_FACTORY
Definition qgis_sip.h:76