Chris@49: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
Chris@19: 
Chris@19: /*
Chris@52:     Sonic Visualiser
Chris@52:     An audio file viewer and annotation editor.
Chris@52:     Centre for Digital Music, Queen Mary, University of London.
Chris@52:     This file copyright 2006 Chris Cannam.
Chris@19:     
Chris@52:     This program is free software; you can redistribute it and/or
Chris@52:     modify it under the terms of the GNU General Public License as
Chris@52:     published by the Free Software Foundation; either version 2 of the
Chris@52:     License, or (at your option) any later version.  See the file
Chris@52:     COPYING included with this distribution for more information.
Chris@19: */
Chris@19: 
Chris@19: #include "Command.h"
Chris@423: #include <QCoreApplication>
Chris@19: 
Chris@19: MacroCommand::MacroCommand(QString name) :
Chris@19:     m_name(name)
Chris@19: {
Chris@19: }
Chris@19: 
Chris@19: MacroCommand::~MacroCommand()
Chris@19: {
Chris@19:     for (size_t i = 0; i < m_commands.size(); ++i) {
Chris@19: 	delete m_commands[i];
Chris@19:     }
Chris@19: }
Chris@19: 
Chris@19: void
Chris@19: MacroCommand::addCommand(Command *command)
Chris@19: {
Chris@19:     m_commands.push_back(command);
Chris@19: }
Chris@19: 
Chris@19: void
Chris@19: MacroCommand::deleteCommand(Command *command)
Chris@19: {
Chris@19:     for (std::vector<Command *>::iterator i = m_commands.begin();
Chris@19: 	 i != m_commands.end(); ++i) {
Chris@19: 
Chris@19: 	if (*i == command) {
Chris@19: 	    m_commands.erase(i);
Chris@19: 	    delete command;
Chris@19: 	    return;
Chris@19: 	}
Chris@19:     }
Chris@19: }
Chris@19: 
Chris@47: bool
Chris@47: MacroCommand::haveCommands() const
Chris@47: {
Chris@47:     return !m_commands.empty();
Chris@47: }
Chris@47: 
Chris@19: void
Chris@19: MacroCommand::execute()
Chris@19: {
Chris@19:     for (size_t i = 0; i < m_commands.size(); ++i) {
Chris@19: 	m_commands[i]->execute();
Chris@19:     }
Chris@19: }
Chris@19: 
Chris@19: void
Chris@19: MacroCommand::unexecute()
Chris@19: {
Chris@19:     for (size_t i = 0; i < m_commands.size(); ++i) {
Chris@19: 	m_commands[m_commands.size() - i - 1]->unexecute();
Chris@19:     }
Chris@19: }
Chris@19: 
Chris@47: QString
Chris@47: MacroCommand::getName() const
Chris@47: {
Chris@47:     return m_name;
Chris@47: }
Chris@47: 
Chris@47: void
Chris@47: MacroCommand::setName(QString name)
Chris@47: {
Chris@47:     m_name = name;
Chris@47: }
Chris@47: 
Chris@423: BundleCommand::BundleCommand(QString name) :
Chris@423:     MacroCommand(name)
Chris@423: {
Chris@423: }
Chris@423: 
Chris@423: BundleCommand::~BundleCommand()
Chris@423: {
Chris@423: }
Chris@423: 
Chris@423: QString
Chris@423: BundleCommand::getName() const
Chris@423: {
Chris@423:     if (m_commands.size() == 1) return m_name;
Chris@1038:     return tr("%1 (%n change(s))", "", int(m_commands.size())).arg(m_name);
Chris@423: }
Chris@423: