1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ 2 3 /* 4 Rosegarden 5 A MIDI and audio sequencer and musical notation editor. 6 Copyright 2000-2021 the Rosegarden development team. 7 8 Other copyrights also apply to some parts of this work. Please 9 see the AUTHORS file and individual file headers for details. 10 11 This program is free software; you can redistribute it and/or 12 modify it under the terms of the GNU General Public License as 13 published by the Free Software Foundation; either version 2 of the 14 License, or (at your option) any later version. See the file 15 COPYING included with this distribution for more information. 16 */ 17 18 #include "Command.h" 19 20 namespace Rosegarden 21 { 22 MacroCommand(QString name)23MacroCommand::MacroCommand(QString name) : 24 m_name(name) 25 { 26 } 27 ~MacroCommand()28MacroCommand::~MacroCommand() 29 { 30 for (size_t i = 0; i < m_commands.size(); ++i) { 31 delete m_commands[i]; 32 } 33 } 34 35 void addCommand(Command * command)36MacroCommand::addCommand(Command *command) 37 { 38 m_commands.push_back(command); 39 } 40 41 void deleteCommand(Command * command)42MacroCommand::deleteCommand(Command *command) 43 { 44 for (std::vector<Command *>::iterator i = m_commands.begin(); 45 i != m_commands.end(); ++i) { 46 47 if (*i == command) { 48 m_commands.erase(i); 49 delete command; 50 return; 51 } 52 } 53 } 54 55 bool haveCommands() const56MacroCommand::haveCommands() const 57 { 58 return !m_commands.empty(); 59 } 60 61 void execute()62MacroCommand::execute() 63 { 64 for (size_t i = 0; i < m_commands.size(); ++i) { 65 m_commands[i]->execute(); 66 } 67 } 68 69 void unexecute()70MacroCommand::unexecute() 71 { 72 for (size_t i = 0; i < m_commands.size(); ++i) { 73 m_commands[m_commands.size() - i - 1]->unexecute(); 74 } 75 } 76 77 QString getName() const78MacroCommand::getName() const 79 { 80 return m_name; 81 } 82 83 void setName(QString name)84MacroCommand::setName(QString name) 85 { 86 m_name = name; 87 } 88 BundleCommand(QString name)89BundleCommand::BundleCommand(QString name) : 90 MacroCommand(name) 91 { 92 } 93 ~BundleCommand()94BundleCommand::~BundleCommand() 95 { 96 } 97 98 QString getName() const99BundleCommand::getName() const 100 { 101 if (m_commands.size() == 1) return m_name; 102 return tr("%1 (%n change(s))", "", m_commands.size()).arg(m_name); 103 } 104 105 } 106