Command.cpp
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4  Sonic Visualiser
5  An audio file viewer and annotation editor.
6  Centre for Digital Music, Queen Mary, University of London.
7  This file copyright 2006 Chris Cannam.
8 
9  This program is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2 of the
12  License, or (at your option) any later version. See the file
13  COPYING included with this distribution for more information.
14 */
15 
16 #include "Command.h"
17 #include <QCoreApplication>
18 
20  m_name(name)
21 {
22 }
23 
25 {
26  for (size_t i = 0; i < m_commands.size(); ++i) {
27  delete m_commands[i];
28  }
29 }
30 
31 void
33 {
34  m_commands.push_back(command);
35 }
36 
37 void
39 {
40  for (std::vector<Command *>::iterator i = m_commands.begin();
41  i != m_commands.end(); ++i) {
42 
43  if (*i == command) {
44  m_commands.erase(i);
45  delete command;
46  return;
47  }
48  }
49 }
50 
51 bool
53 {
54  return !m_commands.empty();
55 }
56 
57 void
59 {
60  for (size_t i = 0; i < m_commands.size(); ++i) {
61  m_commands[i]->execute();
62  }
63 }
64 
65 void
67 {
68  for (size_t i = 0; i < m_commands.size(); ++i) {
69  m_commands[m_commands.size() - i - 1]->unexecute();
70  }
71 }
72 
73 QString
75 {
76  return m_name;
77 }
78 
79 void
80 MacroCommand::setName(QString name)
81 {
82  m_name = name;
83 }
84 
86  MacroCommand(name)
87 {
88 }
89 
91 {
92 }
93 
94 QString
96 {
97  if (m_commands.size() == 1) return m_name;
98  return tr("%1 (%n change(s))", "", int(m_commands.size())).arg(m_name);
99 }
100 
std::vector< Command * > m_commands
Definition: Command.h:104
virtual ~BundleCommand()
Definition: Command.cpp:90
QString getName() const override
Definition: Command.cpp:95
virtual void setName(QString name)
Definition: Command.cpp:80
virtual ~MacroCommand()
Definition: Command.cpp:24
virtual void deleteCommand(Command *command)
Definition: Command.cpp:38
MacroCommand(QString name)
Definition: Command.cpp:19
QString getName() const override
Definition: Command.cpp:74
QString m_name
Definition: Command.h:103
virtual void addCommand(Command *command)
Definition: Command.cpp:32
virtual bool haveCommands() const
Definition: Command.cpp:52
BundleCommand(QString name)
Definition: Command.cpp:85
void execute() override
Definition: Command.cpp:58
void unexecute() override
Definition: Command.cpp:66