LibrePCB Developers Documentation
undocommandgroup.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_UNDOCOMMANDGROUP_H
21 #define LIBREPCB_EDITOR_UNDOCOMMANDGROUP_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "undocommand.h"
27 
28 #include <QtCore>
29 
30 /*******************************************************************************
31  * Namespace / Forward Declarations
32  ******************************************************************************/
33 namespace librepcb {
34 namespace editor {
35 
36 /*******************************************************************************
37  * Class UndoCommandGroup
38  ******************************************************************************/
39 
44 class UndoCommandGroup : public UndoCommand {
45  Q_DECLARE_TR_FUNCTIONS(UndoCommandGroup)
46 
47 public:
48  // Constructors / Destructor
49  UndoCommandGroup() = delete;
50  UndoCommandGroup(const UndoCommandGroup& other) = delete;
51  explicit UndoCommandGroup(const QString& text) noexcept;
52  virtual ~UndoCommandGroup() noexcept;
53 
54  // Getters
55  int getChildCount() const noexcept { return mChilds.count(); }
56 
57  // General Methods
58 
74  bool appendChild(UndoCommand* cmd);
75 
76  // Operator Overloadings
77  UndoCommandGroup& operator=(const UndoCommandGroup& rhs) = delete;
78 
79 protected:
81  virtual bool performExecute() override;
82 
84  virtual void performUndo() override;
85 
87  virtual void performRedo() override;
88 
97  virtual void performPostExecution() noexcept {}
98 
106  void execNewChildCmd(UndoCommand* cmd);
107 
108 private:
113 
120  QList<UndoCommand*> mChilds;
121 };
122 
123 /*******************************************************************************
124  * End of File
125  ******************************************************************************/
126 
127 } // namespace editor
128 } // namespace librepcb
129 
130 #endif
virtual void performUndo() override
Undo the command.
Definition: undocommandgroup.cpp:99
virtual bool performExecute() override
Execute the command the first time.
Definition: undocommandgroup.cpp:82
The UndoCommandGroup class makes it possible to pack multiple undo commands together (it acts as a pa...
Definition: undocommandgroup.h:44
int getChildCount() const noexcept
Definition: undocommandgroup.h:55
void execNewChildCmd(UndoCommand *cmd)
Helper method for derived classes to execute and add new child commands.
Definition: undocommandgroup.cpp:129
Definition: occmodel.cpp:77
QList< UndoCommand * > mChilds
All child commands.
Definition: undocommandgroup.h:120
UndoCommandGroup & operator=(const UndoCommandGroup &rhs)=delete
The UndoCommand class represents a command which you can undo/redo.
Definition: undocommand.h:46
virtual ~UndoCommandGroup() noexcept
Definition: undocommandgroup.cpp:44
bool mHasDoneSomething
Memorized return value of performExecute()
Definition: undocommandgroup.h:112
bool appendChild(UndoCommand *cmd)
Append a new command to the list of child commands.
Definition: undocommandgroup.cpp:55
virtual void performRedo() override
Redo the command.
Definition: undocommandgroup.cpp:112
virtual void performPostExecution() noexcept
Perform custom actions after modifying the undo stack state.
Definition: undocommandgroup.h:97