LibrePCB Developers Documentation
undocommand.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_UNDOCOMMAND_H
21#define LIBREPCB_EDITOR_UNDOCOMMAND_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include <QtCore>
27
28/*******************************************************************************
29 * Namespace / Forward Declarations
30 ******************************************************************************/
31namespace librepcb {
32namespace editor {
33
34/*******************************************************************************
35 * Class UndoCommand
36 ******************************************************************************/
37
47 Q_DECLARE_TR_FUNCTIONS(UndoCommand)
48
49public:
50 // Constructors / Destructor
51 UndoCommand() = delete;
52 UndoCommand(const UndoCommand& other) = delete;
53 explicit UndoCommand(const QString& text) noexcept;
54 virtual ~UndoCommand() noexcept;
55
56 // Getters
57 const QString& getText() const noexcept { return mText; }
58
63 bool wasEverExecuted() const noexcept { return (mRedoCount > 0); }
64
69 bool wasEverReverted() const noexcept { return (mUndoCount > 0); }
70
75 bool isCurrentlyExecuted() const noexcept { return mRedoCount > mUndoCount; }
76
77 // General Methods
78
86 virtual bool execute() final;
87
91 virtual void undo() final;
92
96 virtual void redo() final;
97
98 // Operator Overloadings
99 UndoCommand& operator=(const UndoCommand& rhs) = delete;
100
101protected:
114 virtual bool performExecute() = 0;
115
121 virtual void performUndo() = 0;
122
128 virtual void performRedo() = 0;
129
130private:
131 QString mText;
135};
136
137/*******************************************************************************
138 * End of File
139 ******************************************************************************/
140
141} // namespace editor
142} // namespace librepcb
143
144#endif
The UndoCommand class represents a command which you can undo/redo.
Definition: undocommand.h:46
virtual void undo() final
Undo the command.
Definition: undocommand.cpp:63
virtual bool performExecute()=0
Execute the command the first time.
virtual ~UndoCommand() noexcept
Definition: undocommand.cpp:43
int mUndoCount
Counter of how often undo() was called.
Definition: undocommand.h:134
bool wasEverReverted() const noexcept
This method shows whether that command was ever reverted (undo() called at least one time)
Definition: undocommand.h:69
UndoCommand(const UndoCommand &other)=delete
bool wasEverExecuted() const noexcept
This method shows whether that command was ever executed (execute() called successfully)
Definition: undocommand.h:63
QString mText
Definition: undocommand.h:131
int mRedoCount
Counter of how often redo() was called.
Definition: undocommand.h:133
virtual void performRedo()=0
Redo the command.
virtual void redo() final
Redo the command.
Definition: undocommand.cpp:72
virtual void performUndo()=0
Undo the command.
virtual bool execute() final
Execute the command (must only be called once)
Definition: undocommand.cpp:51
const QString & getText() const noexcept
Definition: undocommand.h:57
bool mIsExecuted
Shows whether execute() was called or not.
Definition: undocommand.h:132
bool isCurrentlyExecuted() const noexcept
This method shows whether that command is currently executed (redo() called one time more than undo()...
Definition: undocommand.h:75
Definition: occmodel.cpp:77