annotate base/Command.cpp @ 316:3a6725f285d6

* Make RemoteFile far more pervasive, and use it for local files as well so that we can handle both transparently. Make it shallow copy with reference counting, so it can be used by value without having to worry about the cache file lifetime. Use RemoteFile for MainWindow file-open functions, etc
author Chris Cannam
date Thu, 18 Oct 2007 15:31:20 +0000
parents d397ea0a79f5
children 6a96bff0bd59
rev   line source
Chris@49 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@19 2
Chris@19 3 /*
Chris@52 4 Sonic Visualiser
Chris@52 5 An audio file viewer and annotation editor.
Chris@52 6 Centre for Digital Music, Queen Mary, University of London.
Chris@52 7 This file copyright 2006 Chris Cannam.
Chris@19 8
Chris@52 9 This program is free software; you can redistribute it and/or
Chris@52 10 modify it under the terms of the GNU General Public License as
Chris@52 11 published by the Free Software Foundation; either version 2 of the
Chris@52 12 License, or (at your option) any later version. See the file
Chris@52 13 COPYING included with this distribution for more information.
Chris@19 14 */
Chris@19 15
Chris@19 16 #include "Command.h"
Chris@19 17
Chris@19 18 MacroCommand::MacroCommand(QString name) :
Chris@19 19 m_name(name)
Chris@19 20 {
Chris@19 21 }
Chris@19 22
Chris@19 23 MacroCommand::~MacroCommand()
Chris@19 24 {
Chris@19 25 for (size_t i = 0; i < m_commands.size(); ++i) {
Chris@19 26 delete m_commands[i];
Chris@19 27 }
Chris@19 28 }
Chris@19 29
Chris@19 30 void
Chris@19 31 MacroCommand::addCommand(Command *command)
Chris@19 32 {
Chris@19 33 m_commands.push_back(command);
Chris@19 34 }
Chris@19 35
Chris@19 36 void
Chris@19 37 MacroCommand::deleteCommand(Command *command)
Chris@19 38 {
Chris@19 39 for (std::vector<Command *>::iterator i = m_commands.begin();
Chris@19 40 i != m_commands.end(); ++i) {
Chris@19 41
Chris@19 42 if (*i == command) {
Chris@19 43 m_commands.erase(i);
Chris@19 44 delete command;
Chris@19 45 return;
Chris@19 46 }
Chris@19 47 }
Chris@19 48 }
Chris@19 49
Chris@47 50 bool
Chris@47 51 MacroCommand::haveCommands() const
Chris@47 52 {
Chris@47 53 return !m_commands.empty();
Chris@47 54 }
Chris@47 55
Chris@19 56 void
Chris@19 57 MacroCommand::execute()
Chris@19 58 {
Chris@19 59 for (size_t i = 0; i < m_commands.size(); ++i) {
Chris@19 60 m_commands[i]->execute();
Chris@19 61 }
Chris@19 62 }
Chris@19 63
Chris@19 64 void
Chris@19 65 MacroCommand::unexecute()
Chris@19 66 {
Chris@19 67 for (size_t i = 0; i < m_commands.size(); ++i) {
Chris@19 68 m_commands[m_commands.size() - i - 1]->unexecute();
Chris@19 69 }
Chris@19 70 }
Chris@19 71
Chris@47 72 QString
Chris@47 73 MacroCommand::getName() const
Chris@47 74 {
Chris@47 75 return m_name;
Chris@47 76 }
Chris@47 77
Chris@47 78 void
Chris@47 79 MacroCommand::setName(QString name)
Chris@47 80 {
Chris@47 81 m_name = name;
Chris@47 82 }
Chris@47 83