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_UNDOCOMMANDGROUP_H 21 #define LIBREPCB_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 35 /******************************************************************************* 36 * Class UndoCommandGroup 37 ******************************************************************************/ 38 39 /** 40 * @brief The UndoCommandGroup class makes it possible to pack multiple undo 41 * commands together (it acts as a parent of it's child commands) 42 */ 43 class UndoCommandGroup : public UndoCommand { 44 Q_DECLARE_TR_FUNCTIONS(UndoCommandGroup) 45 46 public: 47 // Constructors / Destructor 48 UndoCommandGroup() = delete; 49 UndoCommandGroup(const UndoCommandGroup& other) = delete; 50 explicit UndoCommandGroup(const QString& text) noexcept; 51 virtual ~UndoCommandGroup() noexcept; 52 53 // Getters getChildCount()54 int getChildCount() const noexcept { return mChilds.count(); } 55 56 // General Methods 57 58 /** 59 * @brief Append a new command to the list of child commands 60 * 61 * @param cmd The command to add (must not be executed already) 62 * 63 * @retval true If the command was executed and has done some changes 64 * @retval false If the command was not executed or has done nothing 65 * 66 * @note If this command was already executed (#execute() called), this method 67 * will also immediately execute the newly added child command. 68 * Otherwise, it will be executed as soon as #execute() is called. 69 * 70 * @warning This method must not be called after #undo() was called the first 71 * time. 72 */ 73 bool appendChild(UndoCommand* cmd); 74 75 // Operator Overloadings 76 UndoCommandGroup& operator=(const UndoCommandGroup& rhs) = delete; 77 78 protected: 79 /// @copydoc UndoCommand::performExecute() 80 virtual bool performExecute() override; 81 82 /// @copydoc UndoCommand::performUndo() 83 virtual void performUndo() override; 84 85 /// @copydoc UndoCommand::performRedo() 86 virtual void performRedo() override; 87 88 /** 89 * @brief Helper method for derived classes to execute and add new child 90 * commands 91 * 92 * @param cmd The command to execute and add (must not be executed 93 * already) 94 */ 95 void execNewChildCmd(UndoCommand* cmd); 96 97 private: 98 /** 99 * @brief All child commands 100 * 101 * The child which is executed first is at index zero, the last executed 102 * command is at the top of the list. 103 */ 104 QList<UndoCommand*> mChilds; 105 }; 106 107 /******************************************************************************* 108 * End of File 109 ******************************************************************************/ 110 111 } // namespace librepcb 112 113 #endif // LIBREPCB_UNDOCOMMANDGROUP_H 114