svcore  1.9
Command.cpp
Go to the documentation of this file.
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
00002 
00003 /*
00004     Sonic Visualiser
00005     An audio file viewer and annotation editor.
00006     Centre for Digital Music, Queen Mary, University of London.
00007     This file copyright 2006 Chris Cannam.
00008     
00009     This program is free software; you can redistribute it and/or
00010     modify it under the terms of the GNU General Public License as
00011     published by the Free Software Foundation; either version 2 of the
00012     License, or (at your option) any later version.  See the file
00013     COPYING included with this distribution for more information.
00014 */
00015 
00016 #include "Command.h"
00017 #include <QCoreApplication>
00018 
00019 MacroCommand::MacroCommand(QString name) :
00020     m_name(name)
00021 {
00022 }
00023 
00024 MacroCommand::~MacroCommand()
00025 {
00026     for (size_t i = 0; i < m_commands.size(); ++i) {
00027         delete m_commands[i];
00028     }
00029 }
00030 
00031 void
00032 MacroCommand::addCommand(Command *command)
00033 {
00034     m_commands.push_back(command);
00035 }
00036 
00037 void
00038 MacroCommand::deleteCommand(Command *command)
00039 {
00040     for (std::vector<Command *>::iterator i = m_commands.begin();
00041          i != m_commands.end(); ++i) {
00042 
00043         if (*i == command) {
00044             m_commands.erase(i);
00045             delete command;
00046             return;
00047         }
00048     }
00049 }
00050 
00051 bool
00052 MacroCommand::haveCommands() const
00053 {
00054     return !m_commands.empty();
00055 }
00056 
00057 void
00058 MacroCommand::execute()
00059 {
00060     for (size_t i = 0; i < m_commands.size(); ++i) {
00061         m_commands[i]->execute();
00062     }
00063 }
00064 
00065 void
00066 MacroCommand::unexecute()
00067 {
00068     for (size_t i = 0; i < m_commands.size(); ++i) {
00069         m_commands[m_commands.size() - i - 1]->unexecute();
00070     }
00071 }
00072 
00073 QString
00074 MacroCommand::getName() const
00075 {
00076     return m_name;
00077 }
00078 
00079 void
00080 MacroCommand::setName(QString name)
00081 {
00082     m_name = name;
00083 }
00084 
00085 BundleCommand::BundleCommand(QString name) :
00086     MacroCommand(name)
00087 {
00088 }
00089 
00090 BundleCommand::~BundleCommand()
00091 {
00092 }
00093 
00094 QString
00095 BundleCommand::getName() const
00096 {
00097     if (m_commands.size() == 1) return m_name;
00098     return tr("%1 (%n change(s))", "", m_commands.size()).arg(m_name);
00099 }
00100