LibrePCB Developers Documentation
Loading...
Searching...
No Matches
undostack.h
Go to the documentation of this file.
1/*
2 * LibrePCB - Professional EDA for everyone!
3 * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
4 * https://librepcb.org/
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef LIBREPCB_EDITOR_UNDOSTACK_H
21#define LIBREPCB_EDITOR_UNDOSTACK_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include <QtCore>
27
28/*******************************************************************************
29 * Namespace / Forward Declarations
30 ******************************************************************************/
31namespace librepcb {
32namespace editor {
33
34class UndoCommand;
35class UndoCommandGroup;
36class UndoStack;
37
38/*******************************************************************************
39 * Class UndoStackTransaction
40 ******************************************************************************/
41
57public:
58 // Constructors / Destructor
61 UndoStackTransaction(UndoStack& stack, const QString& text);
62 ~UndoStackTransaction() noexcept;
63
64 // General Methods
65 void append(UndoCommand* cmd);
66 void abort();
67 bool commit();
68
69 // Operator Overloadings
70 UndoStackTransaction& operator=(const UndoStackTransaction& rhs) = delete;
71
72private:
75};
76
77/*******************************************************************************
78 * Class UndoStack
79 ******************************************************************************/
80
106class UndoStack final : public QObject {
107 Q_OBJECT
108
109public:
110 // Constructors / Destructor
111 UndoStack(const UndoStack& other) = delete;
112 UndoStack& operator=(const UndoStack& rhs) = delete;
113
117 UndoStack() noexcept;
118
122 ~UndoStack() noexcept;
123
124 // Getters
125
130 QString getUndoText() const noexcept;
131
136 QString getRedoText() const noexcept;
137
142 bool canUndo() const noexcept;
143
148 bool canRedo() const noexcept;
149
158 uint getUniqueStateId() const noexcept;
159
170 bool isClean() const noexcept;
171
178 bool isCommandGroupActive() const noexcept;
179
180 // Setters
181
185 void setClean() noexcept;
186
187 // General Methods
188
212 bool execCmd(UndoCommand* cmd, bool forceKeepCmd = false);
213
225 void beginCmdGroup(const QString& text);
226
242 bool appendToCmdGroup(UndoCommand* cmd);
243
253 bool commitCmdGroup();
254
261 void abortCmdGroup();
262
274 void undo();
275
283 void redo();
284
291 void clear() noexcept;
292
293signals:
294 void undoTextChanged(const QString& text);
295 void redoTextChanged(const QString& text);
296 void canUndoChanged(bool canUndo);
297 void canRedoChanged(bool canRedo);
298 void cleanChanged(bool clean);
299 void commandGroupEnded();
300 void commandGroupAborted();
301 void stateModified();
302
303private:
310 QList<UndoCommand*> mCommands;
311
320 int mCurrentIndex;
321
326 int mCleanIndex;
327
336 UndoCommandGroup* mActiveCommandGroup;
337};
338
339/*******************************************************************************
340 * End of File
341 ******************************************************************************/
342
343} // namespace editor
344} // namespace librepcb
345
346#endif
The UndoCommandGroup class makes it possible to pack multiple undo commands together (it acts as a pa...
Definition undocommandgroup.h:44
The UndoCommand class represents a command which you can undo/redo.
Definition undocommand.h:46
The UndoStack class holds UndoCommand objects and provides undo/redo commands.
Definition undostack.h:106
UndoStack(const UndoStack &other)=delete
UndoStack & operator=(const UndoStack &rhs)=delete
The UndoStackTransaction class helps to execute transactions on an UndoStack.
Definition undostack.h:56
void append(UndoCommand *cmd)
Definition undostack.cpp:58
UndoStack & mStack
Definition undostack.h:73
~UndoStackTransaction() noexcept
Definition undostack.cpp:49
bool mCmdActive
Definition undostack.h:74
void abort()
Definition undostack.cpp:63
UndoStackTransaction(const UndoStackTransaction &other)=delete
bool commit()
Definition undostack.cpp:69
Definition occmodel.cpp:76